Calculation.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace WSUniversalLib
  7. {
  8. public class Calculation
  9. {
  10. public static int GetQuantityForProduct(int productType, int materialType,
  11. int count, float width, float length)
  12. {
  13. float materialCount = 0f;
  14. if (width == null)
  15. {
  16. throw new ArgumentNullException("ширина = Null");
  17. }
  18. if (length == null)
  19. {
  20. throw new ArgumentNullException("длинна = Null");
  21. }
  22. if (count < 0)
  23. {
  24. throw new ArgumentException("Количество < 0");
  25. }
  26. if (width < 0)
  27. {
  28. throw new ArgumentException("Ширина < 0");
  29. }
  30. if (length < 0)
  31. {
  32. throw new ArgumentException("Длинна < 0");
  33. }
  34. switch (productType)
  35. {
  36. case 1:
  37. materialCount = width * length * 1.1f * count;
  38. break;
  39. case 2:
  40. materialCount = width * length * 2.5f * count;
  41. break;
  42. case 3:
  43. materialCount = width * length * 8.43f * count;
  44. break;
  45. default:
  46. return -1;
  47. }
  48. switch (materialType)
  49. {
  50. case 1:
  51. materialCount *= 1.003f;
  52. break;
  53. case 2:
  54. materialCount *= 1.0012f;
  55. break;
  56. default:
  57. return -1;
  58. }
  59. return (int)Math.Ceiling((decimal)materialCount);
  60. }
  61. }
  62. }