Exemplo n.º 1
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          = Userid,
                    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.printPreviewAdmin(this, Userid, "admin");
            print.Show();
        }
Exemplo n.º 2
0
        private void medicineNameComboBox_SelectedValueChanged(object sender, EventArgs e)
        {
            String selectedMedicine = medicineNameComboBox.Text;
            double amountRequested  = 1;

            if (amountWanted.Text.Trim() != "")
            {
                int d;
                if (int.TryParse(amountWanted.Text.Trim(), out d))
                {
                    amountRequested = Convert.ToInt32(amountWanted.Text);
                }
            }

            if (selectedMedicine.Trim() != "")
            {
                if (quantityError.Text.Trim() == "Amount Insufficent")
                {
                    addSelectedMedicine.Enabled = true;
                }
                DataClasses1DataContext context = new DataClasses1DataContext();
                var quantity = from m in context.MedicineTables
                               where m.MedicineID == selectedMedicine
                               select m.Quantity;
                var prices = from m in context.MedicineTables
                             where m.MedicineID == selectedMedicine
                             select m.Selling_Price;
                var selectedMedicineName = (from m in context.MedicineTables
                                            where m.MedicineID == selectedMedicine
                                            select new
                {
                    m.Medicine_Name
                }).First();
                foreach (int x in quantity)
                {
                    double avail = 0;
                    if (cartDataView.Rows.Count > 0)
                    {
                        foreach (DataGridViewRow rows in cartDataView.Rows)
                        {
                            if (selectedMedicineName.Medicine_Name == rows.Cells[0].Value.ToString())
                            {
                                avail += Convert.ToDouble(rows.Cells[5].Value);
                            }
                        }
                    }
                    avail = x - avail;
                    availableAmount.Text = avail.ToString();
                }
                foreach (double y in prices)
                {
                    price.Text = y.ToString();
                    if (Convert.ToInt32(availableAmount.Text) < amountRequested)
                    {
                        addSelectedMedicine.Enabled = false;
                        quantityError.Text          = "Amount Insufficent";
                    }
                    else
                    {
                        quantityError.Text          = "";
                        addSelectedMedicine.Enabled = true;
                    }
                    amountTotal.Text = (y * amountRequested).ToString();
                }
            }
            else
            {
                availableAmount.Clear();
                price.Clear();
                amountTotal.Clear();
                quantityError.Text          = "";
                addSelectedMedicine.Enabled = false;
            }
        }
Exemplo n.º 3
0
        private void addUser_Click(object sender, EventArgs e)
        {
            int check = 0;

            if (addUserID.Text.Trim() == "")
            {
                userIDError.Text = "Field Required";
            }
            else
            {
                using (DataClasses1DataContext context = new DataClasses1DataContext())
                {
                    var newUser = from d in context.Users
                                  where d.UserID == addUserID.Text
                                  select d;

                    if (newUser.Any())
                    {
                        userIDError.Text = "Id Already Exists";
                    }
                    else
                    {
                        userIDError.Text = "";
                        check++;
                    }
                }
            }
            if (addFirstName.Text.Trim() == "")
            {
                firstNameError.Text = "Field Required";
            }
            else
            {
                firstNameError.Text = "";
                check++;
            }
            if (addLastName.Text.Trim() == "")
            {
                lastNameError.Text = "Field Required";
            }
            else
            {
                lastNameError.Text = "";
                check++;
            }
            if (addPassword1.Text.Trim() == "")
            {
                password1Error.Text = "Field Required";
            }
            else
            {
                password1Error.Text = "";
                check++;
            }
            if (addPassword2.Text.Trim() == "")
            {
                password2Error.Text = "Field Required";
            }
            else
            {
                password2Error.Text = "";
                check++;
            }
            if (addPassword1.Text.Trim() != "" && addPassword2.Text.Trim() != "")
            {
                if (addPassword1.Text.Trim() != addPassword2.Text.Trim())
                {
                    password2Error.Text = "Passwords Do not Match";
                }
                else
                {
                    password2Error.Text = "";
                    check++;
                }
            }

            if (check == 6)
            {
                String userID    = addUserID.Text;
                String firstName = addFirstName.Text;
                String lastName  = addLastName.Text;
                String password  = addPassword1.Text;
                String role      = roleComboBox.Text;

                DataClasses1DataContext context = new DataClasses1DataContext();
                User newUser = new User
                {
                    UserID     = userID,
                    First_Name = firstName,
                    Last_Name  = lastName,
                    User_Type  = role,
                    Password   = password
                };
                context.Users.InsertOnSubmit(newUser);
                context.SubmitChanges();
                clearAdd();
                MessageBox.Show("User Added Successfully");
            }
        }