private void btnAddP_Click(object sender, EventArgs e) { this.Hide(); Other_Files.AddToShop_Form ad = new Other_Files.AddToShop_Form(); ad.rank(2); ad.ShowDialog(); }
private void txtStrength_Leave(object sender, EventArgs e) { if (txtDosage.Text != "" & txtStrength.Text != "" & txtID.Text != "" & txtName.Text != "" & (cboCategory.Text != "" | cboCategory.SelectedIndex != 0)) { try { if (connection.State != ConnectionState.Open) { connection.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 + "'", connection); SqlDataReader rd = command.ExecuteReader(); int count = 0; while (rd.Read()) { count++; } connection.Close(); if (count >= 1) { try { connection.Open(); SqlCommand cmd = new SqlCommand("SELECT [Amount] FROM[dbo].[tblShopStore] where Category='" + cboCategory.Text + "' and PName='" + txtName.Text + "' and PID='" + txtID.Text + "' and Dosage='" + txtDosage.Text + "' and Strength='" + txtStrength.Text + "'", connection); SqlDataReader read = cmd.ExecuteReader(); int cnt = 0; while (read.Read()) { cnt++; } connection.Close(); if (cnt >= 1) { try { connection.Open(); SqlCommand comd = new SqlCommand("SELECT [Amount] FROM[dbo].[tblShopStore] where Category='" + cboCategory.Text + "' and PName='" + txtName.Text + "' and PID='" + txtID.Text + "' and Dosage='" + txtDosage.Text + "' and Strength='" + txtStrength.Text + "'", connection); SqlDataReader reader = comd.ExecuteReader(); while (reader.Read()) { txtQntyR.Text = reader["Amount"].ToString(); } connection.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); connection.Close(); } try { connection.Open(); SqlCommand cmod = 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 + "'", connection); SqlDataReader rad = cmod.ExecuteReader(); while (rad.Read()) { DoE.Text = rad["DoE"].ToString(); } connection.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); connection.Close(); } try { connection.Open(); SqlCommand comdo = new SqlCommand("SELECT * FROM[dbo].[tblProducts] where Category='" + cboCategory.Text + "' and PName='" + txtName.Text + "' and PID='" + txtID.Text + "' and Strength='" + txtStrength.Text + "'", connection); SqlDataReader red = comdo.ExecuteReader(); while (red.Read()) { txtAlert.Text = red["AlertQnty"].ToString(); txtQntyS.Text = red["SellingQnty"].ToString(); txtPrice.Text = red["Price"].ToString(); } connection.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); connection.Close(); } } else { DialogResult dia = MessageBox.Show("The Products Is Not Available In The Shelves,Do You Wish To Add It?", "Pharmacy System", MessageBoxButtons.YesNo); if (dia == DialogResult.Yes) { this.Hide(); Other_Files.AddToShop_Form ad = new Other_Files.AddToShop_Form(); ad.ShowDialog(); } else if (dia == DialogResult.No) { clear(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); connection.Close(); } } else { MessageBox.Show("The Product Is Not Yet Purchased", "Pharmacy System"); cboCategory.Focus(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); connection.Close(); } } }