Beispiel #1
0
        public ActionResult Export(long RowID, Driver driver, int Packaging_Price = 0, int Inventory_price = 0)
        {
            if (!Permission(new int[] { RolesInt.Anbar }))
            {
                return(Return());
            }
            if (RowID < 0 || driver == null)
            {
                ModelState.AddModelError(string.Empty, "مقدار  توکت را وارد نمایید.");
                return(View());
            }
            var row = db.Rows.Where(i => i.RowID.Equals(RowID) && i.WherHouseID.Equals(Members.User.ID) && i.invoiceID > 0).FirstOrDefault();

            if (row == null)
            {
                return(Return());
            }
            List <string> Errorlist = driver.Validate();

            if (!Errorlist.Any())
            {
                if (!db.Drivers.Any(i => i.ID.Equals(driver.ID, StringComparison.OrdinalIgnoreCase)))
                {
                    driver.Date = DateTime.Now;
                    db.Drivers.Add(driver);
                    db.SaveChanges();
                }
                row.Packaging_Price = Packaging_Price;
                row.Inventory_price = Inventory_price;
                row.DriverID        = driver.ID;
                db.SaveChanges();
                db.Dispose();
                db  = new AnbariiEntities();
                row = db.Rows.Where(i => i.RowID.Equals(row.RowID) && i.WherHouseID.Equals(row.WherHouseID)).FirstOrDefault();
                return(View(SExportPrint, row));
            }
            else
            {
                foreach (string item in Errorlist)
                {
                    ModelState.AddModelError(item, item);
                }
            }
            return(View());
        }
Beispiel #2
0
 public static void UpdateUser()
 {
     db.Dispose();
     db   = new AnbariiEntities();
     User = db.Users.Where(i => i.ID.Equals(User.ID)).FirstOrDefault();
 }
Beispiel #3
0
        public ActionResult Row(Row Input, long DestinationID)
        {
            if (!Permission(new int[] { RolesInt.Tajer }))
            {
                return(Return());
            }
            if (Input == null && DestinationID < 0)
            {
                ModelState.AddModelError(string.Empty, "مقادیر اجباری فرم را وارد نمایید.");
                return(View());
            }
            if (DestinationID.Equals(0))
            {
                DestinationID = Members.User.ID;
            }

            List <string> Errorlist = Input.Validate();

            Errorlist.Union(DestinationID.ValidateDestination());
            if (!Errorlist.Any())
            {
                List <RowInput> rowInputs = (List <RowInput>)Session["RowInput"];
                var             WID       = (long)TempData["WherHouseID"];
                Input.RowID       = (db.Rows.Where(i => i.WherHouseID.Equals(WID)).Max(i => (long?)i.RowID) ?? default(long)) + 1;
                Input.WherHouseID = WID;
                Input.Date        = DateTime.Now;
                Input.invoiceID   = 0;
                Input.Year        = Members.Year;
                if (string.IsNullOrEmpty(Input.Name))
                {
                    Input.Name = string.Empty;
                }
                db.Rows.Add(Input);
                foreach (var item in rowInputs)
                {
                    Load Source      = db.Loads.Where(i => i.ID.Equals(item.ID)).First();
                    Load Destination = Source;
                    if (!DestinationID.Equals(Members.User.ID))
                    {
                        Members.UpdateUser();
                        Destination = db.Loads
                                      .Where(i => i.Name.Equals(Source.Name, StringComparison.OrdinalIgnoreCase) && i.Load_TypeID.Equals(Source.Load_TypeID) && i.OwnerID.Equals(DestinationID)).FirstOrDefault();
                        if (Destination == null)
                        {
                            Destination = new Load
                            {
                                Add_Date        = DateTime.Now,
                                Change_date     = DateTime.Now,
                                Count           = item.Count,
                                Input_Name      = Source.Name,
                                Name            = Source.Name,
                                Details         = Source.Details,
                                Inventory_price = 0,
                                Load_TypeID     = Source.Load_TypeID,
                                OwnerID         = DestinationID,
                                Packaging_Price = 0,
                                Pic1            = Source.Pic1,
                                Pic2            = Source.Pic2,
                                Pic3            = Source.Pic3,
                                Pic4            = Source.Pic4,
                                Pic5            = Source.Pic5,
                                Weight          = Source.Weight,
                                Weight_Type     = Source.Weight_Type,
                                WherhouseID     = Input.WherHouseID,
                            };
                            db.Loads.Add(Destination);
                        }
                        else
                        {
                            Destination.Change_date = DateTime.Now;
                            Destination.Count      += item.Count;
                        }
                    }
                    else
                    {
                        Input.invoiceID = db.Rows.Where(i => i.WherHouseID.Equals(Input.WherHouseID)).Max(i => i.invoiceID) + 1;
                    }
                    Source.Count -= item.Count;
                    db.SaveChanges();
                    db.RowDetails.Add(new RowDetail
                    {
                        Count              = item.Count,
                        Details            = Input.Name,
                        ID                 = Input.RowID,
                        WherHouseID        = Input.WherHouseID,
                        LoadID_Destination = Destination.ID,
                        LoadID_Source      = Source.ID,
                        Load_TypeID        = Source.Load_TypeID,
                        Weight             = Source.Weight,
                        WeightType         = Source.Weight_Type,
                    });
                    db.SaveChanges();
                }
                db.Dispose();
                db    = new AnbariiEntities();
                Input = db.Rows.Where(i => i.RowID.Equals(Input.RowID) && i.WherHouseID.Equals(Input.WherHouseID)).FirstOrDefault();
                return(View(SRowPrint, Input));
            }
            else
            {
                foreach (string item in Errorlist)
                {
                    ModelState.AddModelError(item, item);
                }
            }

            return(View(Input));
        }
Beispiel #4
0
 public ActionResult AddProduct(Receipt receipt, long OwnerID)
 {
     if (!Permission(new int[] { RolesInt.Admin, RolesInt.Anbar }))
     {
         return(Return());
     }
     if (receipt == null || OwnerID <= 0)
     {
         ModelState.AddModelError(string.Empty, "مقادیر اجباری فرم را وارد نمایید.");
         return(View(new Load()));
     }
     else
     {
         List <string> Errorlist = receipt.Validate();
         Errorlist.Union(receipt.Driver.Validate());
         Errorlist.Union(OwnerID.ValidateDestination());
         if (!Errorlist.Any())
         {
             receipt.DriverID = receipt.Driver.ID;
             if (!db.Drivers.Where(i => i.ID.Equals(receipt.Driver.ID, StringComparison.OrdinalIgnoreCase)).Any())
             {
                 receipt.Driver.Date = DateTime.Now;
             }
             else
             {
                 receipt.Driver = null;
             }
             receipt.ID          = (db.Receipts.Where(i => i.WherHouseID.Equals(Members.User.ID)).Max(i => (long?)i.ID) ?? default(long)) + 1;
             receipt.WherHouseID = Members.User.ID;
             receipt.Date        = DateTime.Now;
             receipt.Year        = Members.Year;
             foreach (var item in receipt.ReceiptDetails)
             {
                 Load load = db.Loads
                             .Where(i => i.Name.Equals(item.Details, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                 if (load == null)
                 {
                     load = new Load()
                     {
                         Change_date     = DateTime.Now,
                         Weight          = item.Weight,
                         Count           = item.Count,
                         Add_Date        = DateTime.Now,
                         Details         = item.Details,
                         ID              = receipt.ID,
                         Input_Name      = item.Details,
                         Inventory_price = 0,
                         Load_TypeID     = item.Load_TypeID,
                         Name            = item.Details,
                         OwnerID         = OwnerID,
                         Packaging_Price = 0,
                         Pic1            = Strings.ImageEmpty,
                         Pic2            = Strings.ImageEmpty,
                         Pic3            = Strings.ImageEmpty,
                         Pic4            = Strings.ImageEmpty,
                         Pic5            = Strings.ImageEmpty,
                         Weight_Type     = item.WeightType,
                         WherhouseID     = receipt.WherHouseID
                     };
                     db.Loads.Add(load);
                 }
                 else
                 {
                     load.Count      += item.Count;
                     load.Weight      = item.Weight;
                     load.Change_date = DateTime.Now;
                 }
                 item.Load        = load;
                 item.ID          = receipt.ID;
                 item.WherHouseID = receipt.WherHouseID;
             }
             db.Receipts.Add(receipt);
             db.SaveChanges();
             db.Dispose();
             db      = new AnbariiEntities();
             receipt = db.Receipts.Where(i => i.ID.Equals(receipt.ID) && i.WherHouseID.Equals(receipt.WherHouseID)).FirstOrDefault();
             return(View(SReceiptPrint, receipt));
         }
         else
         {
             foreach (string item in Errorlist)
             {
                 ModelState.AddModelError(item, item);
             }
         }
         return(View(receipt));
     }
 }