private void button1_Click(object sender, EventArgs e) { try { conn.Open(); string query = "select Store_Name from store where Store_Name='" + txtName.Text + "'"; MySqlCommand com = new MySqlCommand(query, conn); if (com.ExecuteScalar() == null) { if (txtName.Text != "") { string qeury = "insert into store (Store_Name,Store_Address,Store_Phone)values(@Name,@Address,@Phone)"; com = new MySqlCommand(qeury, conn); com.Parameters.Add("@Name", MySqlDbType.VarChar, 255); com.Parameters["@Name"].Value = txtName.Text; com.Parameters.Add("@Address", MySqlDbType.VarChar, 255); com.Parameters["@Address"].Value = txtAddress.Text; com.Parameters.Add("@Phone", MySqlDbType.VarChar, 255); com.Parameters["@Phone"].Value = txtPhone.Text; com.ExecuteNonQuery(); query = "select Type_ID from type order by Type_ID desc limit 1"; com = new MySqlCommand(query, conn); UserControl.UserRecord("store", "اضافة", com.ExecuteScalar().ToString(), DateTime.Now, conn); MessageBox.Show("add success"); clear(); txtName.Focus(); stores.DisplayStores(); } else { MessageBox.Show("enter Name"); } } else { MessageBox.Show("This Store already exist"); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } conn.Close(); }
private void btnUpdate_Click(object sender, EventArgs e) { try { if (txtName.Text != "") { conn.Open(); String query = "update store set Store_Name=@Name,Store_Address=@Address,Store_Phone=@Phone where Store_ID='" + ID + "'"; MySqlCommand com = new MySqlCommand(query, conn); com.Parameters.Add("@Name", MySqlDbType.VarChar, 255).Value = txtName.Text; com.Parameters.Add("@Address", MySqlDbType.VarChar, 255).Value = txtAddress.Text; com.Parameters.Add("@Phone", MySqlDbType.VarChar, 255).Value = txtPhone.Text; com.ExecuteNonQuery(); UserControl.UserRecord("store", "update", ID.ToString(), DateTime.Now, conn); MessageBox.Show("udpate success :)"); txtName.Focus(); stores.DisplayStores(); XtraTabPage xtraTabPage = getTabPage("تعديل مخزن"); xtraTabPage.ImageOptions.Image = null; } else { MessageBox.Show("enter name"); } } catch (Exception ee) { MessageBox.Show(ee.ToString()); conn.Close(); } conn.Close(); }