Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
459
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. public void SaveProducts()
  2. {
  3. TempSave _Save = new TempSave();
  4. _Save.Localization = _LocationLabel.Text + "," + _LocNumbLab.Text;
  5. string items = "";
  6. for (int i = 0; i < _ProductsGrid.Rows.Count; i++)
  7. {
  8. items += _ProductsGrid.Rows[i].Cells[1].Value.ToString();
  9. items += ",";
  10. }
  11. string Qnt = "";
  12. for (int i = 0; i < _ProductsGrid.Rows.Count; i++)
  13. {
  14. Qnt += _ProductsGrid.Rows[i].Cells[0].Value.ToString();
  15. Qnt += ",";
  16. }
  17. try
  18. {
  19. items = items.Remove(items.Length - 1, 1);
  20. Qnt = Qnt.Remove(Qnt.Length - 1, 1);
  21. }
  22. catch{}
  23. _Save.Items = items;
  24. _Save.Quantity = Qnt;
  25.  
  26. IEnumerable<TempSave> _CheackTem;
  27.  
  28. string Cheak_TempSave = "SELECT * FROM TempSave WHERE Localization='" + _Save.Localization + "'";
  29.  
  30. using (MySqlConnection Con = new MySqlConnection("server=localhost; database=wintestbeta;user=root; password=;"))
  31. {
  32. Con.Open();
  33. _CheackTem = Con.Query<TempSave>(Cheak_TempSave);
  34. Con.Close();
  35. }
  36.  
  37. if (_CheackTem.Count() == 0)
  38. {
  39. string _TempSave = "INSERT INTO TempSave (Localization,items,Quantity) VALUES('" + _Save.Localization + "','" + _Save.Items + "','" + _Save.Quantity + "')";
  40.  
  41. using (MySqlConnection Con = new MySqlConnection("server=localhost; database=wintestbeta;user=root; password=;"))
  42. {
  43. Con.Open();
  44. Con.Query(_TempSave);
  45. Con.Close();
  46. }
  47. }
  48. else
  49. {
  50. string _TempDelete = "DELETE FROM TempSave WHERE Localization='" + _Save.Localization + "'";
  51.  
  52. using (MySqlConnection Con = new MySqlConnection("server=localhost; database=wintestbeta;user=root; password=;"))
  53. {
  54. Con.Open();
  55. Con.Query(_TempDelete);
  56. Con.Close();
  57. }
  58. string _TempSave = "INSERT INTO TempSave (Localization,items,Quantity) VALUES('" + _Save.Localization + "','" + _Save.Items + "','" + _Save.Quantity+ "')";
  59.  
  60. using (MySqlConnection Con = new MySqlConnection("server=localhost; database=wintestbeta;user=root; password=;"))
  61. {
  62. Con.Open();
  63. Con.Query(_TempSave);
  64. Con.Close();
  65. }
  66.  
  67. }
  68. }
  69.  
  70. public class TempSave
  71. {
  72. public int id { get; set; }
  73. public string Localization { get; set; }
  74. public string Items { get; set; }
  75. public string Quantity { get; set; }
  76. }
  77.  
  78. +---------------------+
  79. |Qnt|Description|Value|
  80. +---------------------+
  81.  
  82. string items = "";
  83. for (int i = 0; i < _ProductsGrid.Rows.Count; i++)
  84. {
  85. items += _ProductsGrid.Rows[i].Cells[1].Value.ToString();
  86. items += ",";
  87. }
  88.  
  89. items = items.Remove(items.Length - 1, 1);
  90.  
  91. if (items.Length > 1)
  92. items = items.Remove(items.Length - 1, 1);
  93.  
  94. var rows = _ProductsGrid.Rows.Cast<DataRow>();
  95. string items String.Join(";",
  96. rows.Select(x => Convert.ToString(x.Cells[1].Value)));
  97.  
  98. string query = "SELECT * FROM TempSave WHERE Localization=@Localization";
  99.  
  100. using (var cmd = new MySqlCommand(query, connection))
  101. {
  102. cmd.Parameters.AddWithValue("@Localization", _Save.Localization);
  103.  
  104. // ...
  105. }
  106.  
  107. using (var reader = cmd.ExecuteReader())
  108. {
  109. // ...
  110. }
  111.  
  112. if (CheackTemDataAlreadyExists())
  113. DeleteCheackTemData();
  114.  
  115. InsertCheackTemData();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement