Пример #1
0
    void placeOrder(string name, string quantity)
    {
        int?   MedicineCompanyID   = 0;
        string MedicineCompanyName = ddlMedicineCompany.SelectedItem.Text;
        int?   MedicineID          = 0;

        dc.GetMedicineID(name, ref MedicineID);
        dc.GetMedicineCompanyID(MedicineCompanyName, ref MedicineCompanyID);
        if (chk1 == 1)
        {
            var username = (from a in dc.Users
                            where a.UserId == Convert.ToInt32(Session["AdminUserID"])
                            select a.Username).Single();
            Order_To_Medicine_Company obms = new Order_To_Medicine_Company
            {
                MedicineCompanyID = MedicineCompanyID,
                Due_Date          = Convert.ToDateTime(txtDueDate.Text),
                Order_Date        = DateTime.Now,
                Placed_By         = Convert.ToString(username),
                Status            = "Pending"
            };
            dc.Order_To_Medicine_Companies.InsertOnSubmit(obms);
            dc.SubmitChanges();
        }
        var s = dc.Order_To_Medicine_Companies
                .OrderByDescending(m => m.OrderIDToMC)
                .FirstOrDefault();
        Order_To_Medicine_Company_Per_Medicine obmsm = new Order_To_Medicine_Company_Per_Medicine
        {
            MedicineID  = MedicineID,
            Amount      = Convert.ToInt32(quantity),
            OrderIDToMC = Convert.ToDecimal(s.OrderIDToMC)
        };

        dc.Order_To_Medicine_Company_Per_Medicines.InsertOnSubmit(obmsm);
        dc.SubmitChanges();
    }
Пример #2
0
    void placeOrder(string name, string quantity, string discount)
    {
        //List<int> dlist = new List<int>();
        Dictionary <int, decimal> ddictionary = new Dictionary <int, decimal>();
        int? MedicalStoreID            = 0;
        bool requiredMedicineAvailable = false;

        string MedicalStoreName = ddlMedicalStore.SelectedItem.Text;
        var    samename         = from a in dc.Medicine_In_Stocks
                                  where a.MedicineName == name
                                  select a;

        foreach (Medicine_In_Stock mediamount in samename)
        {
            if (mediamount.Amount - Convert.ToDecimal(quantity) >= 0)
            {
                decimal df = Convert.ToDecimal((mediamount.Amount - Convert.ToDecimal(quantity)));
                ddictionary.Add(Convert.ToInt32(mediamount.MedicineID), df);
                requiredMedicineAvailable = true;
            }
        }
        if (requiredMedicineAvailable == true)   // Stock Available for to be delivered
        {
            var getleastkey = (from a in ddictionary
                               orderby a.Value
                               select a.Key).First();
            var getleastvalue = (from a in ddictionary
                                 orderby a.Value
                                 select a.Value).First();
            //var getBatch = (from a in dc.Medicine_In_Stocks
            //                   where a.MedicineID==getleastkey
            //                   orderby a.ExpiryDate

            //                   select a.BatchNo).First();
            // int? MedicineID = 0;
            // dc.GetMedicineID(name, ref MedicineID);
            // dc.GetMedicineIDByBatch(getBatch, ref MedicineID);
            dc.GetMedicalStoreID(MedicalStoreName, ref MedicalStoreID);
            if (chk1 == 1)
            {
                Order_By_Medical_Store obms = new Order_By_Medical_Store
                {
                    MedicalStoreID = MedicalStoreID,
                    Due_Date       = Convert.ToDateTime(txtDueDate.Text),
                    Order_Date     = DateTime.Now,
                    Placed_By      = txtName.Text,
                    Status         = "Pending"
                };
                dc.Order_By_Medical_Stores.InsertOnSubmit(obms);
                dc.SubmitChanges();
            }
            var s = dc.Order_By_Medical_Stores
                    .OrderByDescending(m => m.OrderIDByMS)
                    .FirstOrDefault();

            Order_by_Medical_Store_Per_Medicine obmsm = new Order_by_Medical_Store_Per_Medicine
            {
                MedicineID = getleastkey,
                Amount     = Convert.ToInt32(quantity),
                Discount   = Convert.ToInt32(discount),
                // DiscountAmount=(price*Convert.ToInt32 (discount))/100,
                //NetAmount=price-((price*Convert.ToInt32 (discount))/100),
                OrderIDByMS = Convert.ToDecimal(s.OrderIDByMS)
            };
            dc.Order_by_Medical_Store_Per_Medicines.InsertOnSubmit(obmsm);
            dc.SubmitChanges();


            var price = (from a in dc.Medicine_In_Stocks
                         join b in dc.Order_by_Medical_Store_Per_Medicines on a.MedicineID equals b.MedicineID
                         where b.OrderIDByMS == s.OrderIDByMS && a.MedicineID == Convert.ToInt32(getleastkey)
                         select a.Price).Single();
            var orpm = from a in dc.Order_by_Medical_Store_Per_Medicines
                       where a.OrderIDByMS == Convert.ToDecimal(s.OrderIDByMS) && a.MedicineID == Convert.ToInt32(getleastkey)
                       select a;
            foreach (Order_by_Medical_Store_Per_Medicine orp in orpm)
            {
                orp.DiscountAmount = ((price * orp.Amount) * Convert.ToInt32(discount)) / 100;
                orp.NetAmount      = (price * orp.Amount) - (((price * orp.Amount) * Convert.ToInt32(discount)) / 100);
            }
            ;
            try
            {
                dc.SubmitChanges();
            }
            catch (Exception ex)
            {
                // lblerr.Text = ex.ToString();
            }
            var sub = dc.Medicine_In_Stocks
                      .Where(m => m.MedicineID == getleastkey)
                      .FirstOrDefault();
            int q = Convert.ToInt32(sub.Amount);
            q = q - Convert.ToInt32(quantity);
            // int.TryParse(quantity, out q);
            var medi = from m in dc.Medicine_In_Stocks
                       where m.MedicineID == getleastkey
                       select m;
            foreach (Medicine_In_Stock mis in medi)
            {
                if (q < 20)
                {
                    Notification nf = new Notification
                    {
                        UserID      = Convert.ToInt32(Session["SaleUserID"]),
                        Message     = "New Order You have less of: " + mis.MedicineName + "having Batch#  " + mis.BatchNo,
                        Type        = "Warning",
                        Status      = "Unseen",
                        OrderNumber = s.OrderIDByMS
                    };
                    dc.Notifications.InsertOnSubmit(nf);
                    dc.SubmitChanges();
                }
                else
                {
                    Notification nf = new Notification
                    {
                        UserID      = Convert.ToInt32(Session["SaleUserID"]),
                        Message     = "You have new Order",
                        Type        = "Order Placed",
                        Status      = "Unseen",
                        OrderNumber = s.OrderIDByMS
                    };
                    dc.Notifications.InsertOnSubmit(nf);
                    dc.SubmitChanges();
                }
                mis.Amount = q;

                try
                {
                    dc.SubmitChanges();
                }
                catch (Exception ex)
                {
                    // lblerr.Visible = false;
                    //lblerr.Text = ex.ToString();
                }
            }
            ;
        }
        else
        {
            int?MedicineID = 0;
            dc.GetMedicineID(name, ref MedicineID);

            var medi = from m in dc.Medicine_In_Stocks
                       where m.MedicineID == MedicineID
                       select m;
            dc.GetMedicalStoreID(MedicalStoreName, ref MedicalStoreID);
            if (chk1 == 1)
            {
                Order_By_Medical_Store obms = new Order_By_Medical_Store
                {
                    MedicalStoreID = MedicalStoreID,
                    Due_Date       = Convert.ToDateTime(txtDueDate.Text),
                    Order_Date     = DateTime.Now,
                    Placed_By      = txtName.Text,
                    Status         = "Pending"
                };
                dc.Order_By_Medical_Stores.InsertOnSubmit(obms);
                dc.SubmitChanges();
            }
            var s = dc.Order_By_Medical_Stores
                    .OrderByDescending(m => m.OrderIDByMS)
                    .FirstOrDefault();

            Order_by_Medical_Store_Per_Medicine obmsm = new Order_by_Medical_Store_Per_Medicine
            {
                MedicineID = MedicineID,
                Amount     = Convert.ToInt32(quantity),
                Discount   = Convert.ToInt32(discount),
                // DiscountAmount=(price*Convert.ToInt32 (discount))/100,
                //NetAmount=price-((price*Convert.ToInt32 (discount))/100),
                OrderIDByMS = Convert.ToDecimal(s.OrderIDByMS)
            };
            dc.Order_by_Medical_Store_Per_Medicines.InsertOnSubmit(obmsm);
            dc.SubmitChanges();


            var price = (from a in dc.Medicine_In_Stocks
                         join b in dc.Order_by_Medical_Store_Per_Medicines on a.MedicineID equals b.MedicineID
                         where b.OrderIDByMS == s.OrderIDByMS && a.MedicineID == Convert.ToInt32(MedicineID)
                         select a.Price).Single();
            var orpm = from a in dc.Order_by_Medical_Store_Per_Medicines
                       where a.OrderIDByMS == Convert.ToDecimal(s.OrderIDByMS) && a.MedicineID == Convert.ToInt32(MedicineID)
                       select a;
            foreach (Order_by_Medical_Store_Per_Medicine orp in orpm)
            {
                orp.DiscountAmount = ((price * orp.Amount) * Convert.ToInt32(discount)) / 100;
                orp.NetAmount      = (price * orp.Amount) - (((price * orp.Amount) * Convert.ToInt32(discount)) / 100);
            }
            ;
            try
            {
                dc.SubmitChanges();
            }
            catch (Exception ex)
            {
                // lblerr.Text = ex.ToString();
            }
            foreach (Medicine_In_Stock mis in medi)
            {
                // mis.Amount = 0;
                Notification nf = new Notification
                {
                    UserID      = Convert.ToInt32(Session["SaleUserID"]),
                    Message     = "Medicine finished " + mis.MedicineName,
                    Type        = "Stock Ended",
                    Status      = "Unseen",
                    OrderNumber = s.OrderIDByMS
                };
                dc.Notifications.InsertOnSubmit(nf);
                dc.SubmitChanges();
                try
                {
                    dc.SubmitChanges();
                }
                catch (Exception ex)
                {
                    // lblerr.Visible = false;
                    //lblerr.Text = ex.ToString();
                }
            }
            ;
        }
    }