partial void DeleteSalesReport(SalesReport instance);
 partial void InsertSalesReport(SalesReport instance);
 partial void UpdateSalesReport(SalesReport instance);
예제 #4
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();
        }