private void button1_Click(object sender, EventArgs e) { SqlConnection con = Connections.GetConnection(); if (ifRecordExists(con, textBox1.Text)) { con.Open(); var query = "DELETE FROM [dbo].[Products] WHERE [ProductCode] ='" + dataGridView1.SelectedRows[0].Cells[0].Value + "' "; SqlCommand cmd = new SqlCommand(query, con); cmd.ExecuteNonQuery(); con.Close(); } else { MessageBox.Show("Record Doesn't Exist!"); } loadData(); reset(); }
private void loginEnter(object sender, EventArgs e) { SqlConnection con = Connections.GetConnection(); SqlDataAdapter sda = new SqlDataAdapter(@"SELECT * FROM [Stock].[dbo].[login] WHERE UserName = '******' and Password = '******'", con); DataTable dt = new DataTable(); cyka = textBox1.Text; UserName = textBox1.Text; sda.Fill(dt); if (dt.Rows.Count == 1) { this.Hide(); StockMain main = new StockMain(); main.loggedUser = textBox1.Text; main.Show(); } else { MessageBox.Show("invalid username or password..!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); button1_Click(sender, e); } }
private void button2_Click(object sender, EventArgs e) { if (validation()) { SqlConnection con = Connections.GetConnection(); con.Open(); bool status = false; if (comboBox1.SelectedIndex == 0) { status = true; } else { status = false; } var sqlQuery = ""; if (ifRecordExists(con, textBox1.Text)) { sqlQuery = @"UPDATE [dbo].[Products] SET [ProductClass] = '" + textBox2.Text + "' , [ProductName] = '" + textBox3.Text + "' ,[ProductPrice] = '" + textBox4.Text + "' ,[ProductStatus] = '" + status + "' WHERE [ProductCode] = '" + textBox1.Text + "'"; } else { sqlQuery = @"INSERT INTO [dbo].[Products] ([ProductCode],[ProductClass],[ProductName],[ProductPrice],[ProductStatus]) VALUES ('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + status + "')"; } SqlCommand cmd = new SqlCommand(sqlQuery, con); cmd.ExecuteNonQuery(); con.Close(); //reader loadData(); reset(); } else { MessageBox.Show("Please fill the mandatory fields"); } }
public void Adisyon_Load(object sender, EventArgs e) { listView1.Columns.Add("Name", 150); listView1.Columns.Add("Price", 150); listView1.Columns.Add("Quantity", 150); listView1.View = View.Details; listView1.TabIndex = 0; listView1.FullRowSelect = true; SqlConnection cn = Connections.GetConnection(); SqlCommand cmd = new SqlCommand(); cmd.Connection = cn; cmd.Connection.Open(); cmd.CommandText = "SELECT * FROM [dbo].[Products]"; SqlDataReader dr = cmd.ExecuteReader(); List <string> str = new List <string>(); List <string> str2 = new List <string>(); List <string> str3 = new List <string>(); var a = dr; while (dr.Read()) { production[(string)dr["ProductName"]] = (int)dr["ProductPrice"]; str.Add(dr["ProductClass"].ToString()); str2.Add(dr["ProductClass"].ToString()); str2.Add(dr["ProductName"].ToString()); str2.Add(dr["ProductPrice"].ToString()); } cmd.Connection.Close(); foreach (string p in str.Distinct()) { Button l = new Button { Text = p.ToString(), ForeColor = Color.White, BackColor = Color.Orange, Font = new Font("Serif", 24), Width = 240, Height = 80, TextAlign = ContentAlignment.MiddleCenter, Margin = new Padding(5) }; flowLayoutPanel1.Controls.Add(l); l.Click += new System.EventHandler(l_Click); void l_Click(object s, EventArgs ev) { flowLayoutPanel2.Controls.Clear(); int i = 1; while (i <= str2.Count) { if (l.Text == str2[i - 1]) { Button l2 = new Button { Text = str2[i].ToString(), ForeColor = Color.White, BackColor = Color.Green, Font = new Font("Serif", 24), Width = 240, Height = 80, TextAlign = ContentAlignment.MiddleCenter, Margin = new Padding(5), }; string am = str2[i + 1].ToString(); flowLayoutPanel2.Controls.Add(l2); l2.Click += new System.EventHandler(l2_Click); void l2_Click(object sender2, EventArgs e2) { asd = countinArray(listView1, l2.Text); if (asd == 1) { row[0] = l2.Text; row[1] = am; row[2] = asd.ToString(); item = new ListViewItem(row); listView1.Items.Add(item); var t = item.SubItems[1].ToString(); // valorSum = 0; valorSum += double.Parse(listView1.Items[listView1.Items.Count - 1].SubItems[1].Text); } else { for (int z = 0; z < listView1.Items.Count; z++) { if (listView1.Items[z].SubItems[0].Text == l2.Text) { firstValue = Convert.ToInt32(listView1.Items[z].SubItems[2].Text); listView1.Items[z].SubItems[2].Text = (firstValue + 1).ToString(); listView1.Items[z].SubItems[1].Text = (Convert.ToInt32(listView1.Items[z].SubItems[2].Text) * ((production[listView1.Items[z].SubItems[0].Text]))).ToString(); valorSum += double.Parse(production[listView1.Items[z].SubItems[0].Text].ToString()); } } } /* asd = countinArray(listView1, l2.Text); * MessageBox.Show(asd.ToString());*/ label2.Text = valorSum.ToString(); } } i += 3; } ; } } }