예제 #1
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtName.Text != "")
                {
                    dbconnection.Open();
                    String       query = "update sparepart set SparePart_Name=@Name,SparePart_Info=@info where SparePart_ID='" + row1[0].ToString() + "'";
                    MySqlCommand com   = new MySqlCommand(query, dbconnection);

                    com.Parameters.Add("@Name", MySqlDbType.VarChar, 255).Value = txtName.Text;
                    com.Parameters.Add("@info", MySqlDbType.VarChar, 255).Value = txtInfo.Text;

                    com.ExecuteNonQuery();
                    sparePart.DisplaySparePart();
                    MessageBox.Show("udpate success");
                    txtName.Focus();

                    XtraTabPage xtraTabPage = getTabPage("تعديل قطع الغيار");
                    xtraTabPage.ImageOptions.Image = null;
                }
                else
                {
                    MessageBox.Show("enter name");
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.ToString());
                dbconnection.Close();
            }
            dbconnection.Close();
        }
예제 #2
0
        private void btnAddSparePart_Click(object sender, EventArgs e)
        {
            try
            {
                dbconnection.Open();
                string       query = "select SparePart_ID from sparepart where SparePart_Name='" + txtName.Text + "'";
                MySqlCommand com   = new MySqlCommand(query, dbconnection);

                if (com.ExecuteScalar() == null)
                {
                    if (txtName.Text != "")
                    {
                        string qeury = "insert into sparepart (SparePart_Name,SparePart_Info)values(@Name,@info)";
                        com = new MySqlCommand(qeury, dbconnection);
                        com.Parameters.Add("@Name", MySqlDbType.VarChar, 255);
                        com.Parameters["@Name"].Value = txtName.Text;
                        com.Parameters.Add("@info", MySqlDbType.VarChar, 255);
                        com.Parameters["@info"].Value = txtInfo.Text;

                        com.ExecuteNonQuery();
                        sparePart.DisplaySparePart();
                        MessageBox.Show("add success");
                        clear();
                        txtName.Focus();
                    }
                    else
                    {
                        MessageBox.Show("enter Name");
                    }
                }
                else
                {
                    MessageBox.Show("This Store already exist");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            dbconnection.Close();
        }