private void btnUpdate1_Click(object sender, EventArgs e) { int result1 = 0; int.TryParse(txtTotal.Text, out result1); int result2 = 0; int.TryParse(txtTotal1.Text, out result2); txtTotal2.Text = (result1 + result2).ToString(); DateTime td = DoT.Value; DateTime ep = DoE.Value; TimeSpan ts = ep - td; double days = ts.TotalDays; if (txtName.Text == "") { MessageBox.Show("Kindly Enter The Products' Name", MessageBoxIcon.Error.ToString()); txtName.Focus(); } else if (cboCategory.Text == "<--Category-->" | cboCategory.Text == "") { MessageBox.Show("Kindly Select The Products' Category", MessageBoxIcon.Error.ToString()); cboCategory.Focus(); } else if (txtSupplier.Text == "") { MessageBox.Show("Kindly Enter The Products' Manufacturer", MessageBoxIcon.Error.ToString()); txtSupplier.Focus(); } else if (txtCash.Text == "") { MessageBox.Show("Kindly Enter The Product purchase Amount", MessageBoxIcon.Error.ToString()); txtCash.Focus(); } else if (days < 354) { MessageBox.Show("The Expiry Date Is Today, Change It Or The Products Has Expired", "Pharmacy System"); DoE.Focus(); } else if (metroCheckBox1.Checked == false) { MessageBox.Show("Kindly Check The Update Quantity Box", "Pharmacy System"); metroCheckBox1.Show(); metroCheckBox1.Focus(); } else { try { con.Open(); SqlCommand command = new SqlCommand("select * from tblPurchases where Category='" + cboCategory.Text + "' and PName='" + txtName.Text + "' and PID='" + txtID.Text + "' and Dosage='" + txtDosage.Text + "' and Strength='" + txtStrength.Text + "' and DoT='" + DoT.Text + "'", con); SqlDataReader rd = command.ExecuteReader(); int count = 0; while (rd.Read()) { count++; } con.Close(); if (count == 1) { try { con.Open(); SqlCommand cmd = new SqlCommand("Update [dbo].[tblPurchases] set [Manufacturer]='" + txtSupplier.Text + "',[Cost]='" + txtCash.Text + "',[PurchaseType]='" + cboPurType.Text + "',[PTotal]='" + txtTotal.Text + "',[DoE]='" + DoE.Text + "' where [DoT]='" + DoT.Text + "' and Category='" + cboCategory.Text + "' and PName='" + txtName.Text + "' and PID='" + txtID.Text + "' and Strength='" + txtStrength.Text + "' and Dosage='" + txtDosage.Text + "'", con); cmd.ExecuteNonQuery(); con.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); con.Close(); } } else { MessageBox.Show("The Product Is Not Found In The Database", "Pharmacy System"); con.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); con.Close(); } try { con.Open(); SqlCommand comd = new SqlCommand("select * from tblTotal where Category='" + cboCategory.Text + "' and Name='" + txtName.Text + "' and PID='" + txtID.Text + "' and Dosage='" + txtDosage.Text + "' and Strength='" + txtStrength.Text + "'", con); SqlDataReader rd = comd.ExecuteReader(); int count = 0; while (rd.Read()) { count++; } con.Close(); if (count == 1) { try { con.Open(); SqlCommand md = new SqlCommand("update tblTotal set PTotal='" + txtUp2.Text + "' where Category='" + cboCategory.Text + "' and Name='" + txtName.Text + "' and PID='" + txtID.Text + "' and Dosage='" + txtDosage.Text + "' and Strength='" + txtStrength.Text + "'", con); md.ExecuteNonQuery(); MessageBox.Show("Product Updated Successfully", "Pharmacy System"); con.Close(); FillDataGride(); getNo(); clear(); } catch (Exception ex) { MessageBox.Show(ex.Message); con.Close(); } } else { MessageBox.Show("There Was An Error While Updating The Product Try Saving It First", "Pharmacy System"); } } catch (Exception ex) { MessageBox.Show(ex.Message); con.Close(); } } }
private void btnDelete_Click(object sender, EventArgs e) { DateTime td = DoT.Value; DateTime ep = DoE.Value; TimeSpan ts = ep - td; double days = ts.TotalDays; if (txtName.Text == "") { MessageBox.Show("Kindly Enter The Products' Name", MessageBoxIcon.Error.ToString()); txtName.Focus(); } else if (cboCategory.Text == "<--Category-->" | cboCategory.Text == "") { MessageBox.Show("Kindly Select The Products' Category", MessageBoxIcon.Error.ToString()); cboCategory.Focus(); } else if (txtSupplier.Text == "") { MessageBox.Show("Kindly Enter The Products' Manufacturer", MessageBoxIcon.Error.ToString()); txtSupplier.Focus(); } else if (txtCash.Text == "") { MessageBox.Show("Kindly Enter The Product purchase Amount", MessageBoxIcon.Error.ToString()); txtCash.Focus(); } else if (days < 354) { MessageBox.Show("The Expiry Date Is Today, Change It Or The Products Has Expired", "Pharmacy System"); DoE.Focus(); } else { try { con.Open(); SqlCommand command = new SqlCommand("select * from tblPurchases where Category='" + cboCategory.Text + "' and PName='" + txtName.Text + "' and PID='" + txtID.Text + "' and Dosage='" + txtDosage.Text + "' and Strength='" + txtStrength.Text + "' and DoT='" + DoT.Text + "'", con); SqlDataReader rd = command.ExecuteReader(); int count = 0; while (rd.Read()) { count++; } con.Close(); if (count == 1) { try { con.Open(); SqlCommand cmd = new SqlCommand("delete from [dbo].[tblPurchases] where [DoT]='" + DoT.Text + "' and Category='" + cboCategory.Text + "' and PName='" + txtName.Text + "' and PID='" + txtID.Text + "' and Strength='" + txtStrength.Text + "' and Dosage='" + txtDosage.Text + "'", con); cmd.ExecuteNonQuery(); con.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); con.Close(); } } else { MessageBox.Show("The Product Is Not Found In The Database", "Pharmacy System"); con.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); con.Close(); } try { con.Open(); SqlCommand comd = new SqlCommand("select * from tblTotal where Category='" + cboCategory.Text + "' and Name='" + txtName.Text + "' and PID='" + txtID.Text + "' and Dosage='" + txtDosage.Text + "' and Strength='" + txtStrength.Text + "'", con); SqlDataReader rd = comd.ExecuteReader(); int count = 0; while (rd.Read()) { count++; } con.Close(); if (count == 1) { if (int.Parse(txtUp1.Text) <= int.Parse(txtTotal1.Text)) { try { con.Open(); SqlCommand md = new SqlCommand("delete from tblTotal where Category='" + cboCategory.Text + "' and Name='" + txtName.Text + "' and PID='" + txtID.Text + "' and Dosage='" + txtDosage.Text + "' and Strength='" + txtStrength.Text + "'", con); md.ExecuteNonQuery(); MessageBox.Show("Product Deleted Successfully", "Pharmacy System"); con.Close(); FillDataGride(); getNo(); clear(); } catch (Exception ex) { MessageBox.Show(ex.Message); con.Close(); } } else { try { con.Open(); SqlCommand md = new SqlCommand("update tblTotal set PTotal='" + txtUp1.Text + "' where Category='" + cboCategory.Text + "' and Name='" + txtName.Text + "' and PID='" + txtID.Text + "' and Dosage='" + txtDosage.Text + "' and Strength='" + txtStrength.Text + "'", con); md.ExecuteNonQuery(); MessageBox.Show("Product Deleted Successfully", "Pharmacy System"); con.Close(); FillDataGride(); getNo(); clear(); } catch (Exception ex) { MessageBox.Show(ex.Message); con.Close(); } } } else { MessageBox.Show("There Was An Error While Deleting The Product,Possible Because It Is Not Saved", "Pharmacy System"); } } catch (Exception ex) { MessageBox.Show(ex.Message); con.Close(); } } }
private void btnSave_Click(object sender, EventArgs e) { DateTime td = DoT.Value; DateTime ep = DoE.Value; TimeSpan ts = ep - td; double days = ts.TotalDays; if (txtName.Text == "") { MessageBox.Show("Kindly Enter The Products' Name", MessageBoxIcon.Error.ToString()); txtName.Focus(); } else if (cboCategory.Text == "<--Category-->" | cboCategory.Text == "") { MessageBox.Show("Kindly Select The Products' Category", MessageBoxIcon.Error.ToString()); cboCategory.Focus(); } else if (txtSupplier.Text == "") { MessageBox.Show("Kindly Enter The Products' Manufacturer", MessageBoxIcon.Error.ToString()); txtSupplier.Focus(); } else if (txtCash.Text == "") { MessageBox.Show("Kindly Enter The Product purchase Amount", MessageBoxIcon.Error.ToString()); txtCash.Focus(); } else if (days < 354) { MessageBox.Show("The Expiry Date Is Today, Change It Or The Products Has Expired", "Pharmacy System"); DoE.Focus(); } else { int result1 = 0; int.TryParse(txtTotal.Text, out result1); int result2 = 0; int.TryParse(txtTotal1.Text, out result2); txtTotal2.Text = (result1 + result2).ToString(); try { con.Open(); SqlCommand command = new SqlCommand("select * from tblPurchases where Category='" + cboCategory.Text + "' and PName='" + txtName.Text + "' and PID='" + txtID.Text + "' and Dosage='" + txtDosage.Text + "' and Strength='" + txtStrength.Text + "' and DoT='" + DoT.Text + "'", con); SqlDataReader rd = command.ExecuteReader(); int count = 0; while (rd.Read()) { count++; } con.Close(); if (count < 1) { try { con.Open(); SqlCommand cmd = new SqlCommand("INSERT INTO [dbo].[tblPurchases] ([Category],[PName],[PID],[Strength],[Dosage] ,[Manufacturer],[Cost],[PurchaseType],[PTotal],[DoE],[DoT]) VALUES ('" + cboCategory.Text + "','" + txtName.Text + "','" + txtID.Text + "','" + txtStrength.Text + "','" + txtDosage.Text + "','" + txtSupplier.Text + "','" + txtCash.Text + "','" + cboPurType.Text + "','" + txtTotal.Text + "','" + DoE.Text + "','" + DoT.Text + "')", con); cmd.ExecuteNonQuery(); con.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); con.Close(); } } else { MessageBox.Show("The Product Is Already Saved", "Pharmacy System"); con.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); con.Close(); } try { con.Open(); SqlCommand comd = new SqlCommand("select * from tblTotal where Category='" + cboCategory.Text + "' and Name='" + txtName.Text + "' and PID='" + txtID.Text + "' and Dosage='" + txtDosage.Text + "' and Strength='" + txtStrength.Text + "'", con); SqlDataReader rd = comd.ExecuteReader(); int count = 0; while (rd.Read()) { count++; } con.Close(); if (count == 1) { try { con.Open(); SqlCommand md = new SqlCommand("update tblTotal set PTotal='" + txtTotal2.Text + "' where Category='" + cboCategory.Text + "' and Name='" + txtName.Text + "' and PID='" + txtID.Text + "' and Dosage='" + txtDosage.Text + "' and Strength='" + txtStrength.Text + "'", con); md.ExecuteNonQuery(); MessageBox.Show("Product Updated Successfully", "Pharmacy System"); con.Close(); FillDataGride(); getNo(); clear(); } catch (Exception ex) { MessageBox.Show(ex.Message); con.Close(); } } else { try { con.Open(); SqlCommand cmd = new SqlCommand("insert into tblTotal (Category,Name,PID,Strength,Dosage,PTotal) values ('" + cboCategory.Text + "','" + txtName.Text + "','" + txtID.Text + "','" + txtStrength.Text + "','" + txtDosage.Text + "','" + txtTotal.Text + "')", con); cmd.ExecuteNonQuery(); MessageBox.Show("Product Added Successfully", "Pharmacy System"); con.Close(); FillDataGride(); getNo(); clear(); } catch (Exception ex) { MessageBox.Show(ex.Message); con.Close(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); con.Close(); } } }