Exemplo n.º 1
0
        private void button3_Click(object sender, EventArgs e)
        {
            DataClasses1DataContext db = new DataClasses1DataContext();

            try
            {
                int curQuantity = Int32.Parse(textBox2.Text);
                int retQuantity = Int32.Parse(textBox3.Text);

                if (retQuantity <= curQuantity)
                {
                    int    newQuantity  = curQuantity - retQuantity;
                    int    drugID       = 0;
                    string saveDrugName = "";
                    int    buyCost      = 0;
                    int    sellPrice    = 0;
                    var    q            = from n in db.SalesTables
                                          where n.Id == Int32.Parse(textBox1.Text)
                                          select n;
                    foreach (var nn in q)
                    {
                        drugID       = (int)nn.DrugID;
                        saveDrugName = nn.DrugName;
                        buyCost      = (int)nn.DrugTable.BuyingCostPerUnit;
                        sellPrice    = (int)nn.DrugTable.SellingPricePerUnit;
                        break;
                    }

                    // update salestable -> quantity sold is dec and new profit/loss
                    SalesTable qq = (from n in db.SalesTables
                                     where n.Id == Int32.Parse(textBox1.Text)
                                     select n).Single();
                    qq.QuantitySold = newQuantity;
                    qq.Profit_Loss  = newQuantity * sellPrice - newQuantity * buyCost;
                    db.SubmitChanges();

                    // update drugtable -> item sold decrease!
                    DrugTable qq2 = (from n in db.DrugTables
                                     where n.Id == drugID
                                     select n).Single();
                    qq2.QuantitySold -= retQuantity;
                    db.SubmitChanges();

                    string msg = "";
                    msg += "ITEM UPDATED: \n";
                    msg += "Sells ID: " + textBox1.Text + "\n";
                    msg += "Drug Name: " + saveDrugName + "\n";
                    msg += "Return Quantity: " + retQuantity.ToString() + "\n";
                    MessageBox.Show(msg);
                }
                else
                {
                    MessageBox.Show("Return Amount is bigger than Sold Amount");
                }
            }
            catch
            {
                MessageBox.Show("invalid input");
            }
        }
Exemplo n.º 2
0
        private void cancel()
        {
            DataClasses1DataContext db = new DataClasses1DataContext();
            OrderTable dt = new OrderTable();

            try
            {
                var q = from OrderTable in db.OrderTables
                        where OrderTable.Id == Int32.Parse(domainUpDown1.Text)
                        select OrderTable;

                db.OrderTables.DeleteAllOnSubmit(q);
                db.SubmitChanges();
                MessageBox.Show("Succesfully cancelled!\n");


                DrugTable q2 = (from DrugTable in db.DrugTables
                                where DrugTable.Id == Int32.Parse(domainUpDown2.Text)
                                select DrugTable).Single();
                q2.Status = "valid";
                db.SubmitChanges();

                clearFields();
                loadDomainBoxOrderID();
            }
            catch
            {
                MessageBox.Show("invalid input\n");
            }
        }
Exemplo n.º 3
0
        // add to recipt
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (textBox2.Text != "" && textBox4.Text != "")
                {
                    int dID      = Int32.Parse(textBox2.Text);
                    int quantity = Int32.Parse(textBox4.Text);

                    DataClasses1DataContext db = new DataClasses1DataContext();
                    DrugTable dt = new DrugTable();

                    var q = from DrugTable in db.DrugTables
                            where DrugTable.Id == dID
                            select DrugTable;

                    foreach (var DrugTable in q)
                    {
                        if (quantity <= DrugTable.QuantityBought - DrugTable.QuantitySold && (DateTime)DrugTable.ExpiredDate > System.DateTime.Today && arrSoldQuantityChk[DrugTable.Id] + quantity <= DrugTable.QuantityBought - DrugTable.QuantitySold)
                        {
                            this.dataGridView1.Rows.Add(rowCount + 1, DrugTable.Name, quantity, DrugTable.SellingPricePerUnit, DrugTable.ExpiredDate, DrugTable.BatchNo);
                            arrSoldID[rowCount + 1]           = DrugTable.Id;
                            arrSoldQuantity[rowCount + 1]     = quantity;
                            arrSoldQuantityChk[DrugTable.Id] += quantity;
                            rowCount++;
                            totalCost  += quantity * (int)DrugTable.SellingPricePerUnit;
                            label6.Text = "Total Cost = " + totalCost.ToString();
                        }
                        else if (quantity > DrugTable.QuantityBought - DrugTable.QuantitySold || arrSoldQuantityChk[DrugTable.Id] + quantity > DrugTable.QuantityBought - DrugTable.QuantitySold)
                        {
                            MessageBox.Show("Not Enough Quantity Remaining!");
                        }
                        else if ((DateTime)DrugTable.ExpiredDate <= System.DateTime.Today)
                        {
                            MessageBox.Show("Date Expired!!!");
                        }

                        break;
                    }
                }
            }
            catch
            {
                MessageBox.Show("Invalid Input!");
            }
        }
Exemplo n.º 4
0
        private void discardDrug()
        {
            try
            {
                DataClasses1DataContext db = new DataClasses1DataContext();
                DrugTable q3 = (from DrugTable in db.DrugTables
                                where DrugTable.Id == Int32.Parse(domainUpDown1.Text)
                                select DrugTable).Single();
                q3.Status = "invalid";
                db.SubmitChanges();

                MessageBox.Show("Succesfully Discarded!");
                clearFields();
            }
            catch
            {
                MessageBox.Show("invalid input!");
            }
        }
Exemplo n.º 5
0
        private void button1_Click(object sender, EventArgs e)
        {
            string s    = textBox1.Text;
            string sCol = comboBox1.Text;

            DataClasses1DataContext db = new DataClasses1DataContext();
            DrugTable dt = new DrugTable();

            try
            {
                if (sCol.ToLower() == "name")
                {
                    var q = from DrugTable in db.DrugTables
                            where DrugTable.Name == s
                            select DrugTable;

                    dataGridView1.DataSource = q;
                }
                else if (sCol.ToLower() == "batchno")
                {
                    var q = from DrugTable in db.DrugTables
                            where DrugTable.BatchNo == Int32.Parse(s)
                            select DrugTable;

                    dataGridView1.DataSource = q;
                }


                else
                {
                    MessageBox.Show("Not Found!\n");
                }
            }

            catch
            {
                MessageBox.Show("Error! Input is invalid!\n");
            }
        }
Exemplo n.º 6
0
        private void updateDrug()
        {
            DataClasses1DataContext db = new DataClasses1DataContext();
            DrugTable dt = new DrugTable();

            try
            {
                int  cataID    = 0;
                bool validCata = false;
                if (comboBox1.Text != "")
                {
                    var q = from CatagoryTable in db.CatagoryTables
                            where CatagoryTable.Name == comboBox1.Text
                            select CatagoryTable;

                    foreach (var Ct in q)
                    {
                        cataID    = Ct.Id;
                        validCata = true;
                        break;
                    }
                }
                var q2 = from DrugTable in db.DrugTables
                         where DrugTable.Name == textBox1.Text
                         select DrugTable;
                bool alreadyExist = false;
                foreach (var DrugTable in q2)
                {
                    alreadyExist = true;
                    break;
                }
                if (alreadyExist)
                {
                    MessageBox.Show("Drug Already Exists \nTo make a new order please go to order page");
                }
                else if (validCata && !alreadyExist)
                {
                    DrugTable q3 = (from DrugTable in db.DrugTables
                                    where DrugTable.Id == Int32.Parse(domainUpDown1.Text)
                                    select DrugTable).Single();
                    q3.Name                = textBox1.Text;
                    q3.CatagoryId          = cataID;
                    q3.Status              = comboBox2.Text;
                    q3.ExpiredDate         = DateTime.Parse(dateTimePicker1.Text);
                    q3.SellingPricePerUnit = Int32.Parse(textBox2.Text);
                    q3.BuyingCostPerUnit   = Int32.Parse(textBox3.Text);

                    db.SubmitChanges();

                    MessageBox.Show("Succesfully updated! \nPlease Check in Orderpage to make a new order");
                    clearFields();
                }
                else
                {
                    MessageBox.Show("invalid input!");
                }
            }

            catch
            {
                MessageBox.Show("invalid input!");
            }
        }
Exemplo n.º 7
0
        private void addNewDrug()
        {
            DataClasses1DataContext db = new DataClasses1DataContext();
            DrugTable dt = new DrugTable();

            try
            {
                int  cataID    = 0;
                bool validCata = false;
                if (comboBox1.Text != "")
                {
                    var q = from CatagoryTable in db.CatagoryTables
                            where CatagoryTable.Name == comboBox1.Text
                            select CatagoryTable;

                    foreach (var Ct in q)
                    {
                        cataID    = Ct.Id;
                        validCata = true;
                        break;
                    }
                }
                var q2 = from DrugTable in db.DrugTables
                         where DrugTable.Name == textBox1.Text
                         select DrugTable;
                bool alreadyExist = false;
                foreach (var DrugTable in q2)
                {
                    alreadyExist = true;
                }
                if (alreadyExist)
                {
                    MessageBox.Show("Drug Already Exists \nTo make a new order please go to order page");
                }
                else if (validCata && !alreadyExist)
                {
                    dt.Name                = textBox1.Text;
                    dt.CatagoryId          = cataID;
                    dt.BatchNo             = 0;
                    dt.ExpiredDate         = DateTime.Now;
                    dt.QuantityBought      = 0;
                    dt.QuantitySold        = 0;
                    dt.SellingPricePerUnit = 0;
                    dt.BuyingCostPerUnit   = 0;
                    dt.Status              = "valid";

                    db.DrugTables.InsertOnSubmit(dt);
                    db.SubmitChanges();

                    MessageBox.Show("Succesfully added! \nPlease Check in Orderpage to make a new order");
                    clearFields();
                }
                else
                {
                    MessageBox.Show("invalid input!");
                }
            }

            catch
            {
                MessageBox.Show("invalid input!");
            }
        }
Exemplo n.º 8
0
        // sell button aka update drugtable and add to salesTable
        private void button8_Click(object sender, EventArgs e)
        {
            DataClasses1DataContext db = new DataClasses1DataContext();

            try
            {
                bool sold      = false;
                int  prvSaleID = 0;
                for (int i = 0; i < 1000; i++)
                {
                    if (arrSoldID[i] != -1)
                    {
                        if (!sold)
                        {
                            var q22 = from n in db.SalesTables
                                      select n;
                            foreach (var nn in q22)
                            {
                                prvSaleID = nn.Id;
                            }
                        }
                        sold = true;

                        // updating drugtable
                        DrugTable q = (from DrugTable in db.DrugTables
                                       where DrugTable.Id == arrSoldID[i]
                                       select DrugTable).Single();
                        q.QuantitySold += arrSoldQuantity[i];
                        db.SubmitChanges();


                        // adding to sales table
                        var q2 = from DrugTable in db.DrugTables
                                 where DrugTable.Id == arrSoldID[i]
                                 select DrugTable;
                        foreach (var DrugTable in q2)
                        {
                            SalesTable st = new SalesTable();
                            st.DrugID       = DrugTable.Id;
                            st.DrugName     = DrugTable.Name;
                            st.CatagoryID   = DrugTable.CatagoryId;
                            st.QuantitySold = arrSoldQuantity[i];
                            st.Date         = System.DateTime.Now;
                            st.Profit_Loss  = (DrugTable.SellingPricePerUnit - DrugTable.BuyingCostPerUnit) * arrSoldQuantity[i];
                            st.StaffID      = userID;

                            db.SalesTables.InsertOnSubmit(st);
                            db.SubmitChanges();

                            break;
                        }
                    }
                }
                if (sold)
                {
                    var q22 = from n in db.SalesTables
                              where n.Id > prvSaleID
                              select n;
                    string s = "";

                    foreach (var nn in q22)
                    {
                        if (nn.Id == prvSaleID + 1)
                        {
                            s += "SOLD ITEMS: \n";
                        }
                        s += "Sell ID: " + (nn.Id).ToString() + "\n";
                        s += "DrugName: " + nn.DrugName + "\n";
                        s += "Quantity: " + nn.QuantitySold + "\n";
                        s += "\n\n";
                    }
                    s += label6.Text;
                    MessageBox.Show(s);
                    refreshDataGrid2();
                }
            }
            catch
            {
                MessageBox.Show("Invalid Input!");
            }
        }
Exemplo n.º 9
0
        // change button!
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (textBox1.Text != "")
                {
                    int oID = Int32.Parse(textBox1.Text);

                    DataClasses1DataContext db = new DataClasses1DataContext();
                    OrderTable q = (from OrderTable in db.OrderTables
                                    where OrderTable.Id == oID
                                    select OrderTable).Single();
                    if (radioButton1.Checked && q.OrderStatus == "Pending")
                    {
                        q.OrderStatus   = "Ordered";
                        q.OrderDate     = DateTime.Now;
                        q.QuantityToAdd = Int32.Parse(textBox4.Text);
                        db.SubmitChanges();
                        MessageBox.Show("Successfully Ordered");
                        loadDataGridView1();
                    }
                    else if (radioButton2.Checked && q.OrderStatus == "Ordered")
                    {
                        if (DateTime.Parse(dateTimePicker1.Text) <= DateTime.Now)
                        {
                            MessageBox.Show("Check Expired Date!");
                        }
                        else if (textBox2.Text == "" && textBox3.Text == "")
                        {
                            MessageBox.Show("SPPU and BCPU is empty!");
                        }
                        else
                        {
                            q.OrderStatus      = "Received";
                            q.OrderReceiveDate = DateTime.Now;
                            db.SubmitChanges();

                            var q2 = from DrugTable in db.DrugTables
                                     where DrugTable.Name == drugName
                                     select DrugTable;
                            int maxBatchNo = 0;
                            int cid        = 0;
                            foreach (var DrugTable in q2)
                            {
                                cid = (int)DrugTable.CatagoryId;
                                if (maxBatchNo < (int)DrugTable.BatchNo)
                                {
                                    maxBatchNo = (int)DrugTable.BatchNo;
                                }
                            }
                            DrugTable dt = new DrugTable();
                            dt.Name                = drugName;
                            dt.CatagoryId          = cid;
                            dt.BatchNo             = maxBatchNo + 1;
                            dt.QuantityBought      = Int32.Parse(textBox4.Text);
                            dt.QuantitySold        = 0;
                            dt.SellingPricePerUnit = Int32.Parse(textBox2.Text);
                            dt.BuyingCostPerUnit   = Int32.Parse(textBox3.Text);
                            dt.ExpiredDate         = DateTime.Parse(dateTimePicker1.Text);

                            db.DrugTables.InsertOnSubmit(dt);
                            db.SubmitChanges();



                            MessageBox.Show("Successfully Received\n" + q.DrugName + "\nNew Batch No :" + (maxBatchNo + 1).ToString() + "\n" + "New Quantities : " + textBox4.Text);
                            loadDataGridView1();
                        }
                    }
                }
            }
            catch
            {
                MessageBox.Show("Invalid Input");
            }
        }
Exemplo n.º 10
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                //MessageBox.Show(dataGridView1.Rows[1].Cells[2].Value.ToString());

                if (textBox1.Text != "" && textBox3.Text != "" && textBox2.Text != "")
                {
                    //int index = dataGridView1.CurrentCell.RowIndex;
                    //int index2 = dataGridView2.CurrentCell.RowIndex;
                    //textBox1.Text = dataGridView1.Rows[index].Cells[0].Value.ToString();
                    ////textBox2.Text = dataGridView1.Rows[index].Cells[7].Value.ToString();
                    //textBox3.Text = dataGridView1.Rows[index2].Cells[0].Value.ToString();

                    DataClasses1DataContext db = new DataClasses1DataContext();
                    OrderTable dt = new OrderTable();
                    dt.DrugID        = Int32.Parse(textBox1.Text);
                    dt.QuantityToAdd = Int32.Parse(textBox2.Text);

                    if (dt.QuantityToAdd <= 0)
                    {
                        MessageBox.Show("Check Quantity to add again!");
                        dt.QuantityToAdd = 0;
                    }
                    else
                    {
                        dt.AdminID = userID;
                        //dt.OrderDate = DateTime.Now;
                        dt.VendorID    = Int32.Parse(textBox3.Text);
                        dt.OrderStatus = "Pending";

                        var q = from DrugTable in db.DrugTables
                                where DrugTable.Id == Int32.Parse(textBox1.Text)
                                select DrugTable;
                        foreach (var DrugTable in q)
                        {
                            dt.DrugName = DrugTable.Name;
                            break;
                        }
                        db.OrderTables.InsertOnSubmit(dt);
                        db.SubmitChanges();

                        DrugTable q2 = (from DrugTable in db.DrugTables
                                        where DrugTable.Id == Int32.Parse(textBox1.Text)
                                        select DrugTable).Single();
                        q2.Status = "invalid";
                        db.SubmitChanges();


                        MessageBox.Show("Successfully Added to Order List \nPlease Check the status in Order List");
                    }
                }
                else
                {
                    MessageBox.Show("Empty text box!");
                }
            }
            catch
            {
                MessageBox.Show("Invalid Input");
            }
        }