コード例 #1
0
        private void guna2Button3_Click(object sender, EventArgs e)
        {
            DBconnection con1 = new DBconnection();

            if (chemicalUsed.Text.Trim() != string.Empty && quantity.Text.Trim() != string.Empty)
            {
                if (con1.findChemicalEquipment(chemicalUsed.Text))
                {
                    string q = con1.getCurrentQuantity(chemicalUsed.Text);
                    //MessageBox.Show(q);
                    double quantityInTheStock = Convert.ToDouble(q);
                    double quantityEntered    = Convert.ToDouble(quantity.Text);

                    if (quantityEntered > quantityInTheStock)
                    {
                        MessageBox.Show("Not Enough chemical in store!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        double newQuantity = quantityInTheStock - quantityEntered;
                        con1.updateChemicalAndEquipment(chemicalUsed.Text, newQuantity.ToString());
                        chemicalUsed.Text = "";
                        quantity.Text     = "";
                    }
                }
                else
                {
                    MessageBox.Show("Chemical not added to the Inventory!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Empty Fields!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (core.Text.Trim() == string.Empty)
            {
                MessageBox.Show("Empty Chemical or ID Field!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else if (name.Text.Trim() == string.Empty)
            {
                MessageBox.Show("Empty Name Field!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else if (price.Text.Trim() == string.Empty)
            {
                MessageBox.Show("Empty Price Field!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else if (quantity.Text.Trim() == string.Empty)
            {
                MessageBox.Show("Empty Quantity Field!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                DialogResult answer;
                answer = MessageBox.Show("Are you sure want to add Employee?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (answer == DialogResult.Yes)
                {
                    //******database connect ******
                    try
                    {
                        string date1 = date.Value.ToString();
                        if (core.Text.Equals("Chemical") || core.Text.Equals("Equipment"))
                        {
                            //float cPrice = float.Parse(price.Text);
                            string cPrice     = price.Text;
                            string cQuantity  = quantity.Text + cmbQuantity.Text;
                            string cReference = reference.Text;
                            string cName      = name.Text;

                            DBconnection dbconnection = new DBconnection();

                            if (dbconnection.findChemicalEquipment(cName))
                            {
                                string currentQuantity = dbconnection.getCurrentQuantity(name.Text);
                                int    q           = Convert.ToInt32(currentQuantity) + Convert.ToInt32(cQuantity);
                                string newQuantity = q.ToString();
                                dbconnection.updateChemicalAndEquipment(cName, newQuantity);
                            }
                            else
                            {
                                chemicalsAndEquipments chemicalsAndequipments = new chemicalsAndEquipments(date1, cName, cPrice, cQuantity, global.UserID, cReference);

                                dbconnection.addChemicalsAndEquipments(chemicalsAndequipments);
                            }
                            availableEquipmentsAndChemicals();
                            clearFileds();
                        }
                        else
                        {
                            MessageBox.Show("Enter valid Type(Chemical or Equipment)", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error:\n" + ex, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Console.WriteLine("Error: \n" + ex);
                    }
                }
            }
        }