private void button3_Click(object sender, EventArgs e) { using (SqlConnection con = new SqlConnection(@"Data source=.\SQLEXPRESS;Initial Catalog=I002_Solodkov;User ID=user;Password=Passw0rd;")) { try { con.Open(); SqlCommand cmd = con.CreateCommand(); //заполнение данных cmd.CommandText = "DELETE [psale] WHERE [psale].id=" + ids; cmd.ExecuteScalar(); sale_new uc = new sale_new(id_com); uc.Location = new Point(0, 30); uc.Size = Size; this.Parent.Controls.Add(uc); this.Parent.Controls.RemoveAt(1); } catch (Exception ex) { errol.Text = "Ошибка записи"; errol.Visible = true; } finally { con.Close(); } } }
private void button2_Click(object sender, EventArgs e) { sale_new uc = new sale_new(id_coming); uc.Location = new Point(0, 30); uc.Size = Size; this.Parent.Controls.Add(uc); this.Parent.Controls.RemoveAt(1); }
private void table_CellClick(object sender, DataGridViewCellEventArgs e) { try { if (e.ColumnIndex == 1 || e.ColumnIndex == 2 || e.ColumnIndex == 3 || e.ColumnIndex == 4 || e.ColumnIndex == 5) { String id = Convert.ToString(table.Rows[Convert.ToInt32(e.RowIndex.ToString())].Cells[0].Value); using (SqlConnection con = new SqlConnection(@"Data source=.\SQLEXPRESS;Initial Catalog=I002_Solodkov;User ID=user;Password=Passw0rd;")) { try { con.Open(); SqlCommand cmd = con.CreateCommand(); //заполнение данных cmd.CommandText = "UPDATE [sale] SET id_kontragent='" + id + "' Where [sale].id=" + ids; cmd.ExecuteScalar(); sale_new uc = new sale_new(ids); uc.Location = new Point(0, 30); uc.Size = Size; this.Parent.Controls.Add(uc); this.Parent.Controls.RemoveAt(1); } catch (Exception ex) { } finally { con.Close(); } } } } catch { } }
private void button1_Click(object sender, EventArgs e) { using (SqlConnection con = new SqlConnection(@"Data source=.\SQLEXPRESS;Initial Catalog=I002_Solodkov;User ID=user;Password=Passw0rd;")) { try { con.Open(); SqlCommand cmd = con.CreateCommand(); SqlDataReader reader; cmd.CommandText = "INSERT sale (date) VALUES ('" + Convert.ToString(DateTime.Now) + "')"; cmd.ExecuteScalar(); cmd.CommandText = "SELECT * FROM [sale] ORDER BY id DESC"; string id_coming = ""; reader = cmd.ExecuteReader(); while (reader.Read()) { id_coming = Convert.ToString(String.Format("{0}", reader[0])); break; } reader.Close(); sale_new uc = new sale_new(id_coming); uc.Location = new Point(0, 30); uc.Size = Size; this.Parent.Controls.Add(uc); this.Parent.Controls.RemoveAt(1); } catch (Exception ex) { MessageBox.Show(Convert.ToString(ex)); } finally { con.Close(); } } }
private void button1_Click(object sender, EventArgs e) { string namess = textBox2.Text; string kol = textBox1.Text; string prices = textBox3.Text; if (namess != "" && kol != "" && prices != "") { using (SqlConnection con = new SqlConnection(@"Data source=.\SQLEXPRESS;Initial Catalog=I002_Solodkov;User ID=user;Password=Passw0rd;")) { try { con.Open(); SqlCommand cmd = con.CreateCommand(); cmd.CommandText = "select * from psale where id_sale=" + id_coming + "AND id_product=" + ids; bool prov = true; SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { prov = false; } reader.Close(); if (prov) { //заполнение данных cmd.CommandText = "INSERT psale (id_sale, id_product,price,count) VALUES ('" + id_coming + "','" + ids + "','" + prices + "','" + kol + "')"; cmd.ExecuteScalar(); sale_new uc = new sale_new(id_coming); uc.Location = new Point(0, 30); uc.Size = Size; this.Parent.Controls.Add(uc); this.Parent.Controls.RemoveAt(1); } else { errol.Text = "Ошибка записи"; errol.Visible = true; } } catch (Exception ex) { errol.Text = "Ошибка записи"; errol.Visible = true; } finally { con.Close(); } } } else { errol.Text = "Не все поля заполнены"; errol.Visible = true; } }