Example #1
0
        private void buttonUpdateCopies_Click(object sender, EventArgs e)
        {
            //----------------------Update Copies of Drugs
            string givenID     = textBoxDrugIdUpdateCopies.Text;
            string givenCopies = textBoxUpdateCopies.Text;

            if (givenID != "" && givenCopies != "")
            {
                //---------------------------------------Query For found Id Exist in database
                string    query = "Select COUNT (*)  FROM PharmasyTable WHERE Id= '" + givenID + "'";
                DataTable dt    = new DataTable();
                ClassCommon.SqlC_DAOpenFillCose(query, dt);
                string truevalue = dt.Rows[0][0].ToString();

                if (truevalue == "1")
                {
                    //Database
                    int    Copies    = Convert.ToInt16(givenCopies);
                    string colmnName = "Copies";
                    ClassUpdate.UpdateAnyForPharmasy(colmnName, givenID, Copies);
                    MessageBox.Show("Success");
                    buttonShowPharmasyList_Click(sender, e);
                }
                else
                {
                    MessageBox.Show("ID " + givenID + " Not Found");
                }
            }
            else
            {
                MessageBox.Show("Please Fill All Field");
            }
        }
        private void buttonSellDrug_Click(object sender, EventArgs e)
        {
            string drugSellId = textBoxDrugId.Text;
            string col        = textBoxCollected.Text;
            string ret        = textBoxReturned.Text;

            string    query2 = "Select COUNT (*)  FROM PharmasyTable WHERE Id= '" + drugSellId + "'";
            DataTable dt2    = new DataTable();

            ClassCommon.SqlC_DAOpenFillCose(query2, dt2);
            string truevalue = dt2.Rows[0][0].ToString();

            if (truevalue == "1")
            {
                if (drugSellId != "" && col != "" && ret != "")     //------------- For Exception Handel (Sell Button Click Without Input)
                {
                    string    query = "SELECT Price , Name ,Copies, SoldCopies FROM PharmasyTable WHERE Id= '" + drugSellId + "' ";
                    DataTable dt    = new DataTable();
                    ClassCommon.SqlC_DAOpenFillCose(query, dt);
                    int    orginalPrice = Convert.ToInt16(dt.Rows[0][0].ToString());
                    string drugName     = dt.Rows[0][1].ToString();
                    int    RemainCopies = Convert.ToInt16(dt.Rows[0][2].ToString());
                    int    SoldCopies   = Convert.ToInt16(dt.Rows[0][3].ToString());

                    int collected = Convert.ToInt16(col);
                    int returned  = Convert.ToInt16(ret);


                    if (((collected - returned) == orginalPrice) && RemainCopies > 0)
                    {
                        string colmnName = "Copies";
                        ClassUpdate.UpdateAnyForPharmasy(colmnName, drugSellId, RemainCopies - 1);

                        string colmnName2 = "SoldCopies";
                        ClassUpdate.UpdateAnyForPharmasy(colmnName2, drugSellId, SoldCopies + 1);
                        ClassUpdate.UpdatePharmasySoldStatus(drugSellId);

                        MessageBox.Show("This Producted is sold, Now Print Recipt", "Success");
                        printReceipt(drugSellId, drugName, collected, returned, orginalPrice);
                    }
                    else
                    {
                        MessageBox.Show("Sell Not Possible ", "Price Not Matched", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                else
                {
                    MessageBox.Show("Fill All Box ", "Enter All Textbox", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                MessageBox.Show("This Id Is not Exist In Database");
            }
        }