Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void SaveProducts()
- {
- TempSave _Save = new TempSave();
- _Save.Localization = _LocationLabel.Text + "," + _LocNumbLab.Text;
- string items = "";
- for (int i = 0; i < _ProductsGrid.Rows.Count; i++)
- {
- items += _ProductsGrid.Rows[i].Cells[1].Value.ToString();
- items += ",";
- }
- string Qnt = "";
- for (int i = 0; i < _ProductsGrid.Rows.Count; i++)
- {
- Qnt += _ProductsGrid.Rows[i].Cells[0].Value.ToString();
- Qnt += ",";
- }
- try
- {
- items = items.Remove(items.Length - 1, 1);
- Qnt = Qnt.Remove(Qnt.Length - 1, 1);
- }
- catch{}
- _Save.Items = items;
- _Save.Quantity = Qnt;
- IEnumerable<TempSave> _CheackTem;
- string Cheak_TempSave = "SELECT * FROM TempSave WHERE Localization='" + _Save.Localization + "'";
- using (MySqlConnection Con = new MySqlConnection("server=localhost; database=wintestbeta;user=root; password=;"))
- {
- Con.Open();
- _CheackTem = Con.Query<TempSave>(Cheak_TempSave);
- Con.Close();
- }
- if (_CheackTem.Count() == 0)
- {
- string _TempSave = "INSERT INTO TempSave (Localization,items,Quantity) VALUES('" + _Save.Localization + "','" + _Save.Items + "','" + _Save.Quantity + "')";
- using (MySqlConnection Con = new MySqlConnection("server=localhost; database=wintestbeta;user=root; password=;"))
- {
- Con.Open();
- Con.Query(_TempSave);
- Con.Close();
- }
- }
- else
- {
- string _TempDelete = "DELETE FROM TempSave WHERE Localization='" + _Save.Localization + "'";
- using (MySqlConnection Con = new MySqlConnection("server=localhost; database=wintestbeta;user=root; password=;"))
- {
- Con.Open();
- Con.Query(_TempDelete);
- Con.Close();
- }
- string _TempSave = "INSERT INTO TempSave (Localization,items,Quantity) VALUES('" + _Save.Localization + "','" + _Save.Items + "','" + _Save.Quantity+ "')";
- using (MySqlConnection Con = new MySqlConnection("server=localhost; database=wintestbeta;user=root; password=;"))
- {
- Con.Open();
- Con.Query(_TempSave);
- Con.Close();
- }
- }
- }
- public class TempSave
- {
- public int id { get; set; }
- public string Localization { get; set; }
- public string Items { get; set; }
- public string Quantity { get; set; }
- }
- +---------------------+
- |Qnt|Description|Value|
- +---------------------+
- string items = "";
- for (int i = 0; i < _ProductsGrid.Rows.Count; i++)
- {
- items += _ProductsGrid.Rows[i].Cells[1].Value.ToString();
- items += ",";
- }
- items = items.Remove(items.Length - 1, 1);
- if (items.Length > 1)
- items = items.Remove(items.Length - 1, 1);
- var rows = _ProductsGrid.Rows.Cast<DataRow>();
- string items String.Join(";",
- rows.Select(x => Convert.ToString(x.Cells[1].Value)));
- string query = "SELECT * FROM TempSave WHERE Localization=@Localization";
- using (var cmd = new MySqlCommand(query, connection))
- {
- cmd.Parameters.AddWithValue("@Localization", _Save.Localization);
- // ...
- }
- using (var reader = cmd.ExecuteReader())
- {
- // ...
- }
- if (CheackTemDataAlreadyExists())
- DeleteCheackTemData();
- InsertCheackTemData();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement