Exemplo n.º 1
0
        private void BtnNew_Click(object sender, EventArgs e)
        {
            Txtsupplierid.Text      = "";
            Txtsuppliername.Text    = "";
            Txtsuppliercom.Text     = "";
            TxtSupplierEmail.Text   = "";
            Txtsuppliermob.Text     = "";
            Txtsupplierphone.Text   = "";
            Txtsuppliecity.Text     = "SELECT";
            Txtsupplieraddress.Text = "";
            //groupBox1.Enabled = true;

            try
            {
                con.Open();
                SqlDataAdapter ad = new SqlDataAdapter("SELECT * from Supplier_Master", con);
                DataSet        ds = new DataSet();
                ad.Fill(ds);
                DataTable dt = ds.Tables[0];
                dataGridView1.DataSource = dt;
                int b = (dt.Rows.Count);
                b++;
                Txtsupplierid.Text = b.ToString();
                Txtsupplierid.Focus();
                con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 2
0
        private void BtnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                con.Open();
                SqlCommand cmd = new SqlCommand();
                cmd             = con.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "select * from [Supplier_Master]";

                DialogResult re = MessageBox.Show("Do you want to delete this Record!", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (re == DialogResult.No)
                {
                    Txtsupplierid.Focus();
                }
                else
                {
                    cmd.CommandText = "DELETE FROM Supplier_Master WHERE  [Supplier_ID]='" + Txtsupplierid.Text + "'";
                    cmd.ExecuteNonQuery();
                    MessageBox.Show("Selected record is DELETED", "Delete", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                cmd.CommandText = "SELECT * FROM [Supplier_Master]";
                cmd.Connection.Close();

                SqlDataAdapter ad = new SqlDataAdapter("SELECT * FROM [Supplier_Master]", con);
                DataSet        ds = new DataSet();
                ad.Fill(ds);
                DataTable dt = ds.Tables[0];
                dataGridView1.DataSource = dt;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                Txtsupplierid.Text      = "";
                Txtsuppliername.Text    = "";
                Txtsuppliercom.Text     = "";
                TxtSupplierEmail.Text   = "";
                Txtsuppliermob.Text     = "";
                Txtsupplierphone.Text   = "";
                Txtsuppliecity.Text     = "SELECT";
                Txtsupplieraddress.Text = "";

                pictureBox4.Image = null;
                pictureBox5.Image = null;
                pictureBox6.Image = null;

                groupBox1.Enabled = true;
                con.Close();
            }
        }