FormSpisMaterial.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 FormSpisMaterial_Load(object sender, EventArgs e)
  20. {
  21. // TODO: This line of code loads data into the 'db_22factoryDataSet1.Furnitura' table. You can move, or remove it, as needed.
  22. this.furnituraTableAdapter.Fill(this.db_22factoryDataSet1.Furnitura);
  23. // TODO: This line of code loads data into the 'db_22factoryDataSet1.Tkan' table. You can move, or remove it, as needed.
  24. this.tkanTableAdapter.Fill(this.db_22factoryDataSet1.Tkan);
  25. }
  26. private void BtnToExcel_Click(object sender, EventArgs e)
  27. {
  28. Excel.Application exapp = new Excel.Application();
  29. exapp.Visible = true;
  30. exapp.Workbooks.Open(Application.StartupPath + "\\Списание.xlsx", Type.Missing, true);
  31. Excel.Worksheet list1 = (exapp.Worksheets.get_Item(1));
  32. int RowExcel = 24;
  33. for (int i = 0; i <= DgvTkan.RowCount - 1; i++)
  34. {
  35. int CountSpis = 0;
  36. try
  37. {
  38. CountSpis = Convert.ToInt32(DgvTkan.Rows[i].Cells[3].Value);
  39. }
  40. catch { }
  41. if (CountSpis == 0)
  42. continue;
  43. list1.get_Range("A" + RowExcel).Value = DgvTkan.Rows[i].Cells[0].Value;
  44. list1.get_Range("H" + RowExcel).Value = "см";
  45. list1.get_Range("J" + RowExcel).Value = "ткань";
  46. list1.get_Range("L" + RowExcel).Value = CountSpis;
  47. int WidthTkan = Convert.ToInt32(DgvTkan.Rows[i].Cells[1].Value);
  48. list1.get_Range("N" + RowExcel).Value = CountSpis * WidthTkan;
  49. list1.get_Range("R" + RowExcel).Value = DgvTkan.Rows[i].Cells[4].Value;
  50. RowExcel++;
  51. }
  52. for (int i = 0; i <= DgvFurnitura.RowCount - 1; i++)
  53. {
  54. int CountSpis = 0;
  55. try
  56. {
  57. CountSpis = Convert.ToInt32(DgvFurnitura.Rows[i].Cells[2].Value);
  58. }
  59. catch { }
  60. if (CountSpis == 0)
  61. continue;
  62. list1.get_Range("A" + RowExcel).Value = DgvFurnitura.Rows[i].Cells[0].Value;
  63. list1.get_Range("H" + RowExcel).Value = "шт";
  64. list1.get_Range("J" + RowExcel).Value = "фурнитура";
  65. list1.get_Range("L" + RowExcel).Value = CountSpis;
  66. list1.get_Range("R" + RowExcel).Value = DgvFurnitura.Rows[i].Cells[3].Value;
  67. RowExcel++;
  68. }
  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. BsTkani.EndEdit();
  91. this.tkanTableAdapter.Update(this.db_22factoryDataSet1.Tkan);
  92. for (int i = 0; i <= DgvFurnitura.RowCount - 1; i++)
  93. {
  94. int CountSpis = 0;
  95. try
  96. {
  97. CountSpis = Convert.ToInt32(DgvFurnitura.Rows[i].Cells[2].Value);
  98. }
  99. catch { }
  100. if (CountSpis == 0)
  101. continue;
  102. int CountFur = Convert.ToInt32(DgvFurnitura.Rows[i].Cells[1].Value);
  103. CountFur -= CountSpis;
  104. DgvFurnitura.Rows[i].Cells[1].Value = CountFur;
  105. }
  106. BsFurnitura.EndEdit();
  107. this.furnituraTableAdapter.Update(this.db_22factoryDataSet1.Furnitura);
  108. }
  109. }
  110. }