private void button1_Click(object sender, EventArgs e) { this.Hide(); AddingSupplier display = new AddingSupplier(); display.ShowDialog(); }
private void Form1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyData == Keys.F1) { //Add Supplier this.Hide(); AddingSupplier display = new AddingSupplier(); display.ShowDialog(); } if (e.KeyData == Keys.F2) { //Update string a = txtact.Text; if (txtsupname.Text == "" || txtaddress.Text == "" || txttel.Text == "") { MessageBox.Show("No such Record to Update", "Error"); return; } if (a.Equals("Y") || a.Equals("N") || a.Equals("y") || a.Equals("n") || a.Equals("")) { try { conn.dbcon(); cmb = new SqlCommandBuilder(sda); sda.Update(ds, "Supplier"); cmd = new SqlCommand("Update Suppliers set Supplier_Name = '" + txtsupname.Text + "' , Address = '" + txtaddress.Text + "', Telephone_No = '" + txttel.Text + "', Status = '" + txtact.Text + "' where Supplier_ID = '" + txtcustid.Text + "'"); cmd.Connection = Connectionclass.con; cmd.ExecuteNonQuery(); MessageBox.Show("Successfully Updated", "Update"); //clear txtsupname.Clear(); txtaddress.Clear(); txttel.Clear(); txtact.Clear(); txtsupname.ReadOnly = true; txtaddress.ReadOnly = true; txttel.ReadOnly = true; txtcustid.Clear(); txtact.ReadOnly = true; //refresh cmd = new SqlCommand("SELECT * FROM Suppliers"); cmd.Connection = Connectionclass.con; sda = new SqlDataAdapter(cmd); cmb = new SqlCommandBuilder(sda); ds = new DataSet(); sda.Fill(ds, "Supplier"); dt = ds.Tables["Supplier"]; data.DataSource = ds.Tables["Supplier"]; data.ReadOnly = false; data.SelectionMode = DataGridViewSelectionMode.FullRowSelect; } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error"); } finally { conn.Closecon(); } } else { MessageBox.Show("Y or N input Only; Y stands for Yes and N stands for No", "Error"); return; } } if (e.KeyData == Keys.Escape) { this.Hide(); Main display = new Main(); display.ShowDialog(); this.Close(); } }