Calculation.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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, int count, float width, float length)
  11. {
  12. float materialCount = 0f;
  13. if (count < 0)
  14. {
  15. throw new ArgumentException("Количество < 0");
  16. }
  17. if (width < 0)
  18. {
  19. throw new ArgumentException("Ширина < 0");
  20. }
  21. if (width == null)
  22. {
  23. throw new ArgumentNullException("ширина = NULL");
  24. }
  25. if (length < 0)
  26. {
  27. throw new ArgumentException("Длинна < 0");
  28. }
  29. if (length == null)
  30. {
  31. throw new ArgumentNullException("длинна = NULL");
  32. }
  33. switch (productType)
  34. {
  35. case 1:
  36. materialCount = width * length * count * 1.1f;
  37. break;
  38. case 2:
  39. materialCount = width * length * count * 2.5f;
  40. break;
  41. case 3:
  42. materialCount = width * length * count * 8.43f;
  43. break;
  44. default:
  45. return -1;
  46. }
  47. switch (materialType)
  48. {
  49. case 1:
  50. materialCount *= 1.003f;
  51. break;
  52. case 2:
  53. materialCount *= 1.0012f;
  54. break;
  55. default:
  56. return -1;
  57. }
  58. return (int)Math.Ceiling((decimal)materialCount);
  59. }
  60. }
  61. }