コード例 #1
0
 private void deleteButton_Click(object sender, EventArgs e)
 {
     if (deleteMedicineID != "")
     {
         DataClasses1DataContext context         = new DataClasses1DataContext();
         MedicineTable           dataToBeDeleted = context.MedicineTables.SingleOrDefault(x => x.MedicineID == deleteMedicineID);
         context.MedicineTables.DeleteOnSubmit(dataToBeDeleted);
         context.SubmitChanges();
         deleteDataGridView.DataSource = context.MedicineTables;
         MessageBox.Show("Data Deleted Successfully");
     }
 }
コード例 #2
0
 partial void DeleteMedicineTable(MedicineTable instance);
コード例 #3
0
 partial void UpdateMedicineTable(MedicineTable instance);
コード例 #4
0
 partial void InsertMedicineTable(MedicineTable instance);
コード例 #5
0
        private void addNewMedicine_Click(object sender, EventArgs e)
        {
            using (DataClasses1DataContext context = new DataClasses1DataContext())
            {
                int check = 0;
                if (editMedicineName.Text.Trim() == "")
                {
                    editMedicineNameError.Text = "Field Required";
                }
                else
                {
                    editMedicineNameError.Text = "";
                    check++;
                }
                if (editManufacturer.Text.Trim() == "")
                {
                    editManufacturerError.Text = "Field Required";
                }
                else
                {
                    editManufacturerError.Text = "";
                    check++;
                }
                if (editCategory.Text.Trim() == "")
                {
                    editCategoryError.Text = "Field Required";
                }
                else
                {
                    editCategoryError.Text = "";
                    check++;
                }
                if (editQuantity.Text.Trim() == "")
                {
                    editQuantityError.Text = "Field Required";
                }
                else
                {
                    int d;
                    if (!int.TryParse(editQuantity.Text.Trim(), out d))
                    {
                        editQuantityError.Text = "Non-Decimal \n Number input only";
                    }
                    else
                    {
                        editQuantityError.Text = "";
                        check++;
                    }
                }

                if (editSellingPrice.Text.Trim() == "")
                {
                    editSellingPriceError.Text = "Field Required";
                }
                else
                {
                    double d;
                    if (!double.TryParse(editSellingPrice.Text.Trim(), out d))
                    {
                        editSellingPriceError.Text = "Number input only";
                    }
                    else
                    {
                        editSellingPriceError.Text = "";
                        check++;
                    }
                }
                if (editBuyingPrice.Text.Trim() == "")
                {
                    editBuyingPriceError.Text = "Field Required";
                }
                else
                {
                    double d;
                    if (!double.TryParse(editBuyingPrice.Text.Trim(), out d))
                    {
                        editBuyingPriceError.Text = "Number input only";
                    }
                    else
                    {
                        editBuyingPriceError.Text = "";
                        check++;
                    }
                }
                if (check == 6)
                {
                    String   editMedicinename   = editMedicineName.Text;
                    String   editcategory       = editCategory.Text;
                    String   editmanufacturer   = editManufacturer.Text;
                    int      editquantity       = Convert.ToInt32(editQuantity.Text);
                    DateTime editEntrydate      = DateTime.Now;
                    DateTime editProductiondate = Convert.ToDateTime(editProductionDate.Text);
                    DateTime editExpiringDate   = Convert.ToDateTime(editExpiryDate.Text);
                    Double   editSellingprice   = Convert.ToDouble(editSellingPrice.Text);
                    Double   editBuyingprice    = Convert.ToDouble(editBuyingPrice.Text);

                    MedicineTable dd = context.MedicineTables.SingleOrDefault(x => x.MedicineID == editMedicineID);
                    dd.Medicine_Name   = editMedicinename;
                    dd.Category        = editcategory;
                    dd.Manufacturer    = editmanufacturer;
                    dd.Quantity        = editquantity;
                    dd.Entry_Date      = editEntrydate;
                    dd.Production_Date = editProductiondate;
                    dd.Expiring_Date   = editExpiringDate;
                    dd.Selling_Price   = editSellingprice;
                    dd.Buying_Price    = editBuyingprice;
                    context.SubmitChanges();
                    MessageBox.Show("Data Updated");
                    dataGridView1.DataSource = context.MedicineTables;
                    clearEdit();
                }
            }
        }
コード例 #6
0
        private void button3_Click(object sender, EventArgs e)
        {
            int check = 0;
            if (addMedicineID.Text.Trim() == "")
            {
                addMedicineIDError.Text = "Field Required";
            }
            else
            {
                using (DataClasses1DataContext context = new DataClasses1DataContext())
                {
                    var medicineId = from d in context.MedicineTables 
                                     where d.MedicineID == addMedicineID.Text
                                     select d;
             
                if (medicineId.Any())
                    addMedicineIDError.Text = "Id Already Exists";
                else
                {
                    addMedicineIDError.Text = "";
                    check++; 
                }
                }
            }
            if (addMedicineName.Text.Trim() == "")
            {
                addMedicineNameError.Text = "Field Required";
            }
            else
            {
                addMedicineNameError.Text = "";
                check++;
            }
            if (addManufacturer.Text.Trim() == "")
            {
                addManufacturerError.Text = "Field Required";
            }
            else
            {
                addManufacturerError.Text = "";
                check++;
            }
            if (addCategory.Text.Trim() == "")
            {
                addCategoryError.Text = "Field Required";
            }
            else
            {
                addCategoryError.Text = "";
                check++;
            }
            if (addQuantity.Text.Trim() == "")
            {
                addQuantityError.Text = "Field Required";
            }
            else
            {
                int d;
                if (!int.TryParse(addQuantity.Text.Trim(), out d))
                {
                    addQuantityError.Text = "Non-Decimal \n Number input only";
                }
                else
                {
                    addQuantityError.Text = "";
                    check++;
                }

            } 
            
            if (addSellingPrice.Text.Trim() == "")
            {
                addSellingPriceError.Text = "Field Required";
            }
            else
            {
                double d;
                if (!double.TryParse(addSellingPrice.Text.Trim(), out d))
                {
                    addSellingPriceError.Text = "Number input only";
                }
                else
                {
                    addSellingPriceError.Text = "";
                    check++;
                }

            }
            if (addBuyingPrice.Text.Trim() == "")
            {
                addBuyingPriceError.Text = "Field Required";
            }
            else
            {
                double d;
                if (!double.TryParse(addBuyingPrice.Text.Trim(), out d))
                {
                    addBuyingPriceError.Text = "Number input only";
                }
                else
                {
                    addBuyingPriceError.Text = "";
                    check++;
                }
            }
            if (check == 7)
            {
                String newMedicineID = addMedicineID.Text;
                String newMedicineName = addMedicineName.Text;
                String newCategory = addCategory.Text;
                int newQuantity = Convert.ToInt32(addQuantity.Text);
                String newManufacturer = addManufacturer.Text;
                DateTime newEntryDate = DateTime.Now;
                DateTime newProductionDate = Convert.ToDateTime(addProductionDate.Text);
                DateTime newExpiryDate = Convert.ToDateTime(addExpiryDate.Text);
                double newSellingPrice = Math.Round(Convert.ToDouble(addSellingPrice.Text),2);
                double newBuyingPrice = Math.Round(Convert.ToDouble(addBuyingPrice.Text), 2);
             
                 
                using (DataClasses1DataContext context = new DataClasses1DataContext())
                {

                    MedicineTable newMedicine = new MedicineTable
                    {
                        MedicineID = newMedicineID,
                        Medicine_Name = newMedicineName,
                        Category = newCategory,
                        Quantity = newQuantity,
                        Manufacturer = newManufacturer,
                        Entry_Date = newEntryDate,
                        Production_Date = newProductionDate,
                        Expiring_Date = newExpiryDate,
                        Selling_Price = newSellingPrice,
                        Buying_Price = newBuyingPrice
                    };
                    context.MedicineTables.InsertOnSubmit(newMedicine);
                    context.SubmitChanges();
                    clearAdd();
                    MessageBox.Show("Medicine Added Successfully");
                }

            }
        }
コード例 #7
0
        private void Finish_Click(object sender, EventArgs e)
        {
            DataClasses1DataContext context = new DataClasses1DataContext();
            String customer;

            if (buyer.Text.Trim() != "")
            {
                customer = buyer.Text;
            }
            else
            {
                customer = "customer";
            }
            IList <String>   medicineName   = new List <String>();
            IList <String>   category       = new List <String>();
            IList <String>   manufaturer    = new List <String>();
            IList <DateTime> productionDate = new List <DateTime>();
            IList <DateTime> expiryDate     = new List <DateTime>();
            IList <int>      quantity       = new List <int>();
            IList <Double>   buyingPrice    = new List <Double>();
            IList <Double>   sellingPrice   = new List <Double>();
            DateTime         dateSold       = DateTime.Now;
            IList <Double>   amountTotals   = new List <Double>();
            IList <Double>   profit         = new List <Double>();

            foreach (DataGridViewRow row in cartDataView.Rows)
            {
                medicineName.Add(row.Cells[0].Value.ToString());
                category.Add(row.Cells[1].Value.ToString());
                manufaturer.Add(row.Cells[2].Value.ToString());
                productionDate.Add(Convert.ToDateTime(row.Cells[3].Value));
                expiryDate.Add(Convert.ToDateTime(row.Cells[4].Value));
                quantity.Add(Convert.ToInt32(row.Cells[5].Value));
                sellingPrice.Add(Convert.ToDouble(row.Cells[6].Value));
                amountTotals.Add((Convert.ToInt32(row.Cells[5].Value)) * (Convert.ToDouble(row.Cells[6].Value)));
                var med = (from x in context.MedicineTables
                           where x.Medicine_Name == row.Cells[0].Value.ToString()
                           select new
                {
                    x.Buying_Price
                }).First();
                buyingPrice.Add(Convert.ToDouble(med.Buying_Price));
                profit.Add(Convert.ToDouble(row.Cells[6].Value) - Convert.ToDouble(med.Buying_Price));
            }
            for (int i = 0; i < medicineName.Count; i++)
            {
                SalesReport sale = new SalesReport
                {
                    Buyer           = customer,
                    Seller          = LoggedInUserID,
                    Medicine_Name   = medicineName[i],
                    Category        = category[i],
                    Manufacturer    = manufaturer[i],
                    Production_Date = productionDate[i],
                    Expiring_Date   = expiryDate[i],
                    Quantity        = quantity[i],
                    Selling_Price   = sellingPrice[i],
                    Buying_Price    = buyingPrice[i],
                    Profit_Gained   = profit[i],
                    Date_Of_Sale    = DateTime.Now
                };
                context.SalesReports.InsertOnSubmit(sale);
                context.SubmitChanges();
                var updateMedicine = (from x in context.MedicineTables
                                      where x.Medicine_Name == medicineName[i] && x.Manufacturer == manufaturer[i]
                                      select new{
                    x.Quantity
                }).First();
                int           update = Convert.ToInt32(updateMedicine.Quantity) - quantity[i];
                MedicineTable dd     = context.MedicineTables.SingleOrDefault(x => x.Medicine_Name == medicineName[i] &&
                                                                              x.Manufacturer == manufaturer[i]);
                dd.Medicine_Name   = medicineName[i];
                dd.Category        = category[i];
                dd.Manufacturer    = manufaturer[i];
                dd.Quantity        = update;
                dd.Entry_Date      = DateTime.Now;
                dd.Production_Date = productionDate[i];
                dd.Expiring_Date   = expiryDate[i];
                dd.Selling_Price   = sellingPrice[i];
                dd.Buying_Price    = buyingPrice[i];
                context.SubmitChanges();
            }

            PrintPreview print = new PrintPreview();

            print.Customer       = customer;
            print.MedicineName   = medicineName;
            print.Category       = category;
            print.Manufaturer    = manufaturer;
            print.ProductionDate = productionDate;
            print.ExpiryDate     = expiryDate;
            print.Quantity       = quantity;
            print.SellingPrice   = sellingPrice;
            print.BuyingPrice    = buyingPrice;
            print.AmountTotal    = amountTotals;
            print.SubTotal       = Convert.ToDouble(subTotalBox.Text);
            print.Total          = Convert.ToDouble(total.Text);

            reset();
            print.printPreview(this, "sale");
            print.Show();
        }