Example #1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            this.Hide();
            addcust display = new addcust();

            display.ShowDialog();
        }
Example #2
0
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.F1)
            {
                this.Hide();
                addcust display = new addcust();
                display.ShowDialog();
            }
            if (e.KeyData == Keys.Escape)
            {
                this.Hide();
                Main display = new Main();
                display.ShowDialog();
                this.Close();
            }
            if (e.KeyData == Keys.Enter || e.KeyData == Keys.F2)
            {
                string a = txtact.Text;

                if (txtcustid.Text == "" || txtname.Text == "" || txtaddress.Text == "" || txtcontact.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, "Customer");
                        cmd            = new SqlCommand("Update Customers set CustomerName  = '" + txtname.Text + "' , Address = '" + txtaddress.Text + "',Contact_No = '" + txtcontact.Text + "', Status = '" + txtact.Text + "' where Customer_ID = '" + txtcustid.Text + "'");
                        cmd.Connection = Connectionclass.con;
                        cmd.ExecuteNonQuery();
                        MessageBox.Show("Successfully Updated", "Update");

                        txtcustid.Clear();
                        txtname.Clear();
                        txtaddress.Clear();
                        txtcontact.Clear();
                        txtact.Clear();
                        txtcustid.ReadOnly  = true;
                        txtname.ReadOnly    = true;
                        txtaddress.ReadOnly = true;
                        txtcontact.ReadOnly = true;
                        txtact.ReadOnly     = true;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString(), "Error");
                    }
                    finally
                    {
                        conn.Closecon();
                    }
                    //////REFRESH!!!REFRESH!!!REFRESH!!!REFRESH!!!REFRESH!!!REFRESH!!!REFRESH!!!
                    try
                    {
                        conn.dbcon();
                        cmd            = new SqlCommand("SELECT * FROM Customers order by Customer_ID DESC");
                        cmd.Connection = Connectionclass.con;
                        sda            = new SqlDataAdapter(cmd);
                        cmb            = new SqlCommandBuilder(sda);
                        ds             = new DataSet();
                        sda.Fill(ds, "Customer");
                        dt = ds.Tables["Customer"];

                        data.DataSource    = ds.Tables["Customer"];
                        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;
                }
            }
        }