FormSpisMaterial.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using Excel = Microsoft.Office.Interop.Excel;
  11. namespace СУБД_Фабрика
  12. {
  13. public partial class FormSpisMaterial : Form
  14. {
  15. public FormSpisMaterial()
  16. {
  17. InitializeComponent();
  18. }
  19. private void BtnExcel_Click(object sender, EventArgs e)
  20. {
  21. Excel.Application exapp = new Excel.Application();
  22. exapp.Visible = true;
  23. exapp.Workbooks.Open(Application.StartupPath + "\\Списание.xlsx", Type.Missing, true);
  24. Excel.Worksheet list1 = (exapp.Worksheets.get_Item(1));
  25. int RowExcel = 24;
  26. for (int i = 0; i <= DgvTkan.RowCount - 1; i++)
  27. {
  28. int CountSpis = 0;
  29. try
  30. {
  31. CountSpis = Convert.ToInt32(DgvTkan.Rows[i].Cells[3].Value);
  32. }
  33. catch { }
  34. if (CountSpis == 0)
  35. continue;
  36. list1.get_Range("A" + RowExcel).Value = DgvTkan.Rows[i].Cells[0].Value;
  37. list1.get_Range("H" + RowExcel).Value = "см";
  38. list1.get_Range("J" + RowExcel).Value = "ткань";
  39. list1.get_Range("L" + RowExcel).Value = CountSpis;
  40. int WidthTkan = Convert.ToInt32(DgvTkan.Rows[i].Cells[1].Value);
  41. list1.get_Range("N" + RowExcel).Value = CountSpis * WidthTkan;
  42. list1.get_Range("R" + RowExcel).Value = DgvTkan.Rows[i].Cells[4].Value;
  43. RowExcel++;
  44. }
  45. for (int i = 0; i <= DgvFurn.RowCount - 1; i++)
  46. {
  47. int CountSpis = 0;
  48. try
  49. {
  50. CountSpis = Convert.ToInt32(DgvFurn.Rows[i].Cells[2].Value);
  51. }
  52. catch { }
  53. if (CountSpis == 0)
  54. continue;
  55. list1.get_Range("A" + RowExcel).Value = DgvFurn.Rows[i].Cells[0].Value;
  56. list1.get_Range("H" + RowExcel).Value = "шт";
  57. list1.get_Range("J" + RowExcel).Value = "фурнитура";
  58. list1.get_Range("L" + RowExcel).Value = CountSpis;
  59. list1.get_Range("R" + RowExcel).Value = DgvFurn.Rows[i].Cells[3].Value;
  60. RowExcel++;
  61. }
  62. }
  63. private void FormSpisMaterial_Load(object sender, EventArgs e)
  64. {
  65. // TODO: This line of code loads data into the 'sewingFactoryMURDataSet1.Furnitura' table. You can move, or remove it, as needed.
  66. this.furnituraTableAdapter.Fill(this.sewingFactoryMURDataSet1.Furnitura);
  67. // TODO: This line of code loads data into the 'sewingFactoryMURDataSet1.Cloth' table. You can move, or remove it, as needed.
  68. this.clothTableAdapter.Fill(this.sewingFactoryMURDataSet1.Cloth);
  69. }
  70. private void BtnSpisMaterial_Click(object sender, EventArgs e)
  71. {
  72. DialogResult rez = MessageBox.Show("Вы уверены, что нужно выбранные материалы?",
  73. "Внимание!", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  74. if (rez == DialogResult.No)
  75. return;
  76. for (int i = 0; i <= DgvTkan.RowCount - 1; i++)
  77. {
  78. int CountSpis = 0;
  79. try
  80. {
  81. CountSpis = Convert.ToInt32(DgvTkan.Rows[i].Cells[3].Value);
  82. }
  83. catch { }
  84. if (CountSpis == 0)
  85. continue;
  86. int LengthTkan = Convert.ToInt32(DgvTkan.Rows[i].Cells[2].Value);
  87. LengthTkan -= CountSpis;
  88. DgvTkan.Rows[i].Cells[2].Value = LengthTkan;
  89. }
  90. BsClothes.EndEdit();
  91. this.clothTableAdapter.Update(this.sewingFactoryMURDataSet1.Cloth);
  92. for (int i = 0; i <= DgvFurn.RowCount - 1; i++)
  93. {
  94. int CountSpis = 0;
  95. try
  96. {
  97. CountSpis = Convert.ToInt32(DgvFurn.Rows[i].Cells[2].Value);
  98. }
  99. catch { }
  100. if (CountSpis == 0)
  101. continue;
  102. int CountFur = Convert.ToInt32(DgvFurn.Rows[i].Cells[1].Value);
  103. CountFur -= CountSpis;
  104. DgvFurn.Rows[i].Cells[1].Value = CountFur;
  105. }
  106. BsFurn.EndEdit();
  107. this.furnituraTableAdapter.Update(this.sewingFactoryMURDataSet1.Furnitura);
  108. }
  109. }
  110. }