Ejemplo n.º 1
0
 public IActionResult Create(Models.tbls.customer.customer model)
 {
     if (ModelState.IsValid)
     {
         var x = db.TblCustomers.Find(model.Id);
         if (x == null)
         {
             x = new web_db.TblCustomer
             {
                 Id        = Guid.NewGuid(),
                 FkSalmali = User._getuserSalMaliDef(),
                 Code      = (db.TblCustomers.Where(a => a.FkSalmali == User._getuserSalMaliDef()).Max(a => (int?)a.Code) ?? 0) + 1
             };
             db.TblCustomers.Add(x);
         }
         x.Addras        = model.Addras ?? "";
         x.IdOtherSystem = model.IdOtherSystem ?? "";
         x.IsEnable      = model.IsEnable;
         x.Mob           = model.Mob ?? "";
         x.NationalCode  = model.NationalCode ?? "";
         x.Title         = model.Title;
         db.SaveChanges();
         return(RedirectToAction("Index", new { txt = "ثبت موفق" }));
     }
     return(View(model));
 }
Ejemplo n.º 2
0
        public IActionResult RePassword(string password, string newPassword, string reNewPassword)
        {
            if (newPassword != reNewPassword)
            {
                ViewBag.error = "تکرار رمز عبور اشتباه است";
                return(View());
            }

            var x = db.TblUsers.Find(User._getuserid());

            ViewBag.BalanceCode = x.BalanceCode;
            if (x.Password != password)
            {
                ViewBag.error = "رمز عبور اشتباه است";
                return(View());
            }


            x.Password = newPassword;



            db.SaveChanges();
            ViewBag.txt = "ثبت انجام شد";
            return(View());
        }
Ejemplo n.º 3
0
        public IActionResult setinjuryDef(Guid id, Guid defContract, Guid[] FkInjury, string submitall = "")
        {
            var pp = db.TblPortages.Find(id);

            if ((pp.FkSalmali != User._getuserSalMaliDef()) || (pp.IsEnd) || (pp.IsDel))
            {
                return(RedirectToAction("index"));
            }

            db.TblPortageInjuries.RemoveRange(db.TblPortageInjuries.Where(a => a.FkPortage == id));
            foreach (var item in FkInjury)
            {
                db.TblPortageInjuries.Add(new web_db._Weighing.TblPortageInjury {
                    FkPortage = id, FkInjury = item
                });
            }
            if (submitall.IsEmpty() == false)
            {
                foreach (var itemr in db.TblPortageRows.Where(a => a.FkPortage == id && a.FkContract == defContract))
                {
                    db.TblPortageRowInjuries.RemoveRange(db.TblPortageRowInjuries.Where(a => a.FkPortageRow == itemr.Id));
                    foreach (var item in FkInjury)
                    {
                        db.TblPortageRowInjuries.Add(new web_db._Weighing.TblPortageRowInjury {
                            FkPortageRow = itemr.Id, FkInjury = item
                        });
                    }
                }
            }

            db.SaveChanges();

            return(RedirectToAction("view", new { id = id, openkind = 1 }));
        }
Ejemplo n.º 4
0
        public IActionResult Create(web_db._temp.TblTemp temp)
        {
            if (ModelState.IsValid && (temp.FkuserTaiid.HasValue == false))
            {
                var xx = db.TblTemps.Any(a =>
                                         (a.Date == temp._Date.ToDate() && (a.Id != temp.Id))

                                         && a.FkSalMali == User._getuserSalMaliDef()
                                         );
                if (xx == false)
                {
                    var x = db.TblTemps.Any(a => a.Id == temp.Id);


                    if (x == false)
                    {
                        temp.Id        = Guid.NewGuid();
                        temp.FkuserAdd = User._getuserid().Value;
                        temp.FkSalMali = User._getuserSalMaliDef();
                        db.TblTemps.Add(temp);
                    }
                    else
                    {
                        db.TblTemps.Update(temp);
                    }
                    db.SaveChanges();
                    return(RedirectToAction(nameof(Index)));
                }
            }

            return(View(temp));
        }
Ejemplo n.º 5
0
        public IActionResult Create(web_db.TblGroup model)
        {
            try
            {
                var x = db.TblGroups.Find(model.Id);
                if (x == null)
                {
                    x = new web_db.TblGroup {
                        Id = Guid.NewGuid()
                    };

                    db.TblGroups.Add(x);
                }

                x.IsActive   = model.IsActive;
                x.Title      = model.Title;
                x.Fklocation = model.Fklocation;
                x.Class      = model.Class;

                db.SaveChanges();
                ViewBag.txt          = "ثبت انجام شد";
                Models.cl._ListGroup = db.TblGroups.OrderBy(a => a.Title).ToList();
                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                ViewBag.error = "ثبت انجام نشد";
            }
            return(View(model));
        }
Ejemplo n.º 6
0
        public IActionResult SyncDoc()
        {
            {
                using (var dbdoc = new web_dbDocument.db_Context())
                {
                    using (var db = new web_db.sardweb_Context())
                    {
                        foreach (var item in db.TblDocuments.Take(100))
                        {
                            dbdoc.TblDocuments.Add(new web_dbDocument.TblDocument
                            {
                                Date      = item.Date,
                                FkP       = item.FkP,
                                FkPortage = item.FkPortage,
                                fkuser    = item.fkuser,
                                Format    = item.Format,
                                Id        = item.Id,
                                Image     = item.Image,
                                Kind      = item.Kind
                            });
                            db.Remove(item);
                        }

                        db.SaveChanges();
                        dbdoc.SaveChanges();
                    }
                }
            }



            return(RedirectToAction("Index"));
        }
Ejemplo n.º 7
0
        public static bool RemoveFullPortage(Guid id, web_db.sardweb_Context db)
        {
            var portage = db.TblPortages.Find(id);


            var contypeclone = db.TblContractTypes.Single(a => a.Id == portage.FkContracttype);


            #region rem PortageRows


            foreach (var item in db.TblPortageRows.Where(a => a.FkPortage == portage.Id))
            {
                db.TblPortageRowInjuries.RemoveRange(db.TblPortageRowInjuries.Where(a => a.FkPortageRow == item.Id));
                db.TblPortageRows.Remove(item);
            }


            #endregion


            #region rem images
            var dbdoc = new web_dbDocument.db_Context();
            dbdoc.TblDocuments.RemoveRange(dbdoc.TblDocuments.Where(a => a.FkPortage == portage.Id));
            db.TblPortages.Remove(portage);
            #endregion
            db.SaveChanges();
            dbdoc.SaveChanges();



            return(true);
        }
Ejemplo n.º 8
0
        public IActionResult Acc(Guid fktype, bool refresh = false)
        {
            var sal   = User._getuserSalMaliDef();
            var ctype = db.TblContractTypes.Find(fktype);

            if (refresh)
            {
                //using (var scope = new TransactionScope(TransactionScopeOption.Required,
                //                       new System.TimeSpan(0, 15, 0)))
                //{  scope.Complete();
                //}
                foreach (var item in db.TblPortages.Where(a => a.FkSalmali == User._getuserSalMaliDef() && a.FkContracttype == fktype))
                {
                    Models.cl.refPortageAccMoney(db, item.Id);
                }
                db.SaveChanges();
            }
            var x = from n in db.TblCustomers.Include(a => a.TblPortageMoneys)
                    where n.FkSalmali == sal

                    let bascul = n.TblPortageMoneys.Where(a => a.FkContractType == fktype && a.Kind == "bascul").Sum(a => (decimal?)a.PriceSum)
                                 let kargar = n.TblPortageMoneys.Where(a => a.FkContractType == fktype && a.Kind == "kargar").Sum(a => (decimal?)a.PriceSum)
                                              let packing = n.TblPortageMoneys.Where(a => a.FkContractType == fktype && a.Kind == "packing").Sum(a => (decimal?)a.PriceSum)
                                                            let product = n.TblPortageMoneys.Where(a => a.FkContractType == fktype && a.Kind == "product").Sum(a => (decimal?)a.PriceSum)
                                                                          select new Models.customerAcc(n, db)
            {
                bascul  = bascul,
                kargar  = kargar,
                packing = packing,
                product = product,
            };

            ViewBag.ctype = ctype;
            return(View(x.ToList()));
        }
Ejemplo n.º 9
0
        public IActionResult Create(web_db._Weighing.TblCar model, IFormFile file)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.error = "ثبت انجام نشد - فیلد ها را درست پر کنید";
                return(View(model));
            }
            try
            {
                var x = db.TblCars.Find(model.Id);
                if (x == null)
                {
                    x = new web_db._Weighing.TblCar {
                        Id = model.Id, PriceTowBascol = 0
                    };

                    db.TblCars.Add(x);
                }



                x.Title          = model.Title;
                x.IsDel          = model.IsDel;
                x.PriceTowBascol = model.PriceTowBascol;
                var dbdoc = new web_dbDocument.db_Context();

                if (file != null)
                {
                    var r = dbdoc.TblDocuments.FirstOrDefault(a => a.FkP == x.Id);
                    if (r == null)
                    {
                        r = new web_dbDocument.TblDocument
                        {
                            Date   = DateTime.Now,
                            FkP    = x.Id,
                            fkuser = User._getuserid(),
                            Id     = Guid.NewGuid(),
                            Kind   = "Image"
                        };
                        dbdoc.TblDocuments.Add(r);
                    }
                    r.Image = file.ToByteArray().imgTosmall();
                }



                db.SaveChanges();
                dbdoc.SaveChanges();
                ViewBag.txt        = "ثبت انجام شد";
                Models.cl._ListCar = db.TblCars.OrderBy(a => a.Title).ToList();
                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                ViewBag.error = "ثبت انجام نشد";
            }
            return(View(model));
        }
Ejemplo n.º 10
0
        public static void _refstoreOne(web_db.sardweb_Context db, Guid fkportage)
        {
            var x       = db.TblPortageRows.Where(a => a.FkPortage == fkportage);
            var por     = db.TblPortages.Find(fkportage);
            var contype = web_sard.Models.cl._ListContractType(por.FkSalmali).Single(a => a.Id == por.FkContracttype);

            por.WeightNet = (por.Weight1 - por.Weight2).gadrmotlagh();
            if (Models.tbls.portage.kindPortage.listkindcontract.Single(a => a.code == por.KindCode).Manfi)
            {
                por.WeightNet = -por.WeightNet;
            }

            por.PackingCount = x.Sum(a => a.Count);

            por.PackingOfWeight = (double?)(por.WeightNet / por.PackingCount).gadrmotlagh();



            por.OtcodeResid = "";
            db.TblPortageMoneys.RemoveRange(db.TblPortageMoneys.Where(a => a.FkPortage == por.Id));


            decimal ss = 0;

            foreach (var item in x)
            {
                var sc = Models.cl.getWeightScale(item.FkProduct, item.FkPacking);


                item.WeightOne = sc * por.PackingOfWeight;
                if (item.WeightOne.HasValue)
                {
                    ss += (decimal)item.WeightOne * item.Count;
                }
            }


            foreach (var item in x)
            {
                if (item.WeightOne.HasValue)
                {
                    item.WeightOne = item.WeightOne * (double)(por.WeightNet / ss);
                }
            }



            db.SaveChanges();
            _refstoreTow(db, fkportage);
        }
Ejemplo n.º 11
0
 public static bool RemoveFullContract(Guid id, web_db.sardweb_Context db)
 {
     try
     {
         db.TblContractPackings.RemoveRange(db.TblContractPackings.Where(a => a.FkContract == id));
         db.TblContractProducts.RemoveRange(db.TblContractProducts.Where(a => a.FkContract == id));
         db.TblContracts.Remove(db.TblContracts.Find(id));
         db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 12
0
        public IActionResult Create(web_db._Weighing.TblPacking model, List <web_db._Weighing.TblContractType.KindCotractTypeEnum> _ForContractType)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.txt = "ثبت انجام نشد - فیلد ها را درست پر کنید";
                return(View(model));
            }
            try
            {
                var x = db.TblPackings.Find(model.Id);
                if (x == null)
                {
                    x = new web_db._Weighing.TblPacking {
                        Id = model.Id
                    };

                    db.TblPackings.Add(x);
                }
                x.Code       = model.Code;
                x.IsActive   = model.IsActive;
                x.Title      = model.Title;
                x.WightEmpty = model.WightEmpty;
                x.WightFull  = model.WightFull;
                x.ForContractType(_ForContractType);
                x.WightScale           = model.WightScale;
                x.WightScale           = x.WightScale == 0 ? null : x.WightScale;
                x.OtcodeKala           = model.OtcodeKala;
                x.OtcodeVahedShomaresh = model.OtcodeVahedShomaresh;
                x.OtcodeKalaAcc        = model.OtcodeKalaAcc;
                x.IsNotAc = model.IsNotAc;

                db.SaveChanges();
                ViewBag.txt            = "ثبت انجام شد";
                Models.cl._ListPacking = db.TblPackings.OrderBy(a => a.Code).ToList();

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                ViewBag.error = "ثبت انجام نشد";
            }
            return(View(model));
        }
Ejemplo n.º 13
0
        //public static bool RemoveFullPortage(Guid id, web_db.sardweb_Context db)
        //{
        //    var portage = db.TblPortages.Find(id);


        //    var contypeclone = db.TblContractTypes.Single(a => a.Id == portage.FkContracttype);


        //    #region rem PortageRows


        //    foreach (var item in db.TblPortageRows.Where(a => a.FkPortage == portage.Id))
        //    {
        //        db.TblPortageRowInjuries.RemoveRange(db.TblPortageRowInjuries.Where(a => a.FkPortageRow == item.Id));
        //        db.TblPortageRows.Remove(item);

        //    }


        //    #endregion


        //    #region rem images

        //    db.TblDocuments.RemoveRange(db.TblDocuments.Where(a => a.FkPortage == portage.Id));
        //    db.TblPortages.Remove(portage);
        //    #endregion
        //    db.SaveChanges();

        //    if (contypeclone.KindCotractType == web_db._Weighing.TblContractType.KindCotractTypeEnum.ASardKhane)
        //    {
        //        var x = db.TblPortageRows.Where(a => a.FkPortage == portage.Id);
        //        foreach (var item in x.Select(a => a.FkContract).Distinct())
        //        {
        //            Models.cl.refTblStoreLogcontractSardKhane(item.Value, db);
        //        }
        //    }

        //    else if (contypeclone.KindCotractType == web_db._Weighing.TblContractType.KindCotractTypeEnum.ASabad)

        //    {
        //        Models.cl.refTblStoreLogcontractTypeSabad(contypeclone.Id , db);

        //    }


        //    return true;
        //}
        //public static bool RemoveFullContract(Guid id, web_db.sardweb_Context db)
        //{
        //    try
        //    {
        //        db.TblContractPackings.RemoveRange(db.TblContractPackings.Where(a => a.FkContract == id));
        //        db.TblContractProducts.RemoveRange(db.TblContractProducts.Where(a => a.FkContract == id));
        //        db.TblContracts.Remove(db.TblContracts.Find(id));
        //        db.SaveChanges();
        //        return true;
        //    }
        //    catch
        //    {
        //        return false;
        //    }


        //}

        public static async Task <Guid?> AddPayvastCustomerAsync(web_db.sardweb_Context db, string CellPhone, int sal)
        {
            var Mali_KindOT = (Models.cl._conf.SingleOrDefault(a => a.Key == web_db.TblConf.KeyEnum.Mali_KindOT) ?? new web_db.TblConf()).Value;
            var Mali_UrlOT  = (Models.cl._conf.SingleOrDefault(a => a.Key == web_db.TblConf.KeyEnum.Mali_UrlOT) ?? new web_db.TblConf()).Value;
            var Mali_UserOT = (Models.cl._conf.SingleOrDefault(a => a.Key == web_db.TblConf.KeyEnum.Mali_UserOT) ?? new web_db.TblConf()).Value;
            var Mali_PassOT = (Models.cl._conf.SingleOrDefault(a => a.Key == web_db.TblConf.KeyEnum.Mali_PassOT) ?? new web_db.TblConf()).Value;


            ApiPaivast.AccountingServiceSoapClient vv = new AccountingServiceSoapClient(AccountingServiceSoapClient.EndpointConfiguration.AccountingServiceSoap, Mali_UrlOT);
            var c = await vv.GetCustomerIdByCellPhoneAsync(CellPhone : CellPhone);

            var idc = c;

            var cid = await vv.GetCustomerInfoAsync(idc, Mali_UserOT, Mali_PassOT);

            if (cid != null)
            {
                string txt = "ثبت موفق";
                var    row = db.TblCustomers.FirstOrDefault(a => a.FkSalmali == sal && a.IdOtherSystem == cid.Id.ToString());
                if (row == null)
                {
                    row = new web_db.TblCustomer
                    {
                        Id            = Guid.NewGuid(),
                        FkSalmali     = sal,
                        IdOtherSystem = cid.Id.ToString(),
                        IsEnable      = true,
                        Code          = (db.TblCustomers.Where(a => a.FkSalmali == sal).Max(a => (int?)a.Code) ?? 0) + 1,
                    };
                    db.TblCustomers.Add(row);
                    txt = "بروزرسانی موفق";
                }
                row.IsEnable     = true;
                row.Addras       = "";
                row.Mob          = CellPhone;
                row.NationalCode = cid.NationalCode;
                row.Title        = cid.Name.ToPersianChars();
                db.SaveChanges();
                return(row.Id);
            }
            return(null);
        }
Ejemplo n.º 14
0
        public static bool RemoveFullPortage(Guid id, web_db.sardweb_Context db)
        {
            var portage = db.TblPortages.Find(id);


            var contypeclone = db.TblContractTypes.Single(a => a.Id == portage.FkContracttype);


            #region rem PortageRows


            foreach (var item in db.TblPortageRows.Where(a => a.FkPortage == portage.Id))
            {
                db.TblPortageRowInjuries.RemoveRange(db.TblPortageRowInjuries.Where(a => a.FkPortageRow == item.Id));
                db.TblPortageRows.Remove(item);
            }


            #endregion


            #region rem images
            var dbdoc = new web_dbDocument.db_Context();

            dbdoc.TblDocuments.RemoveRange(dbdoc.TblDocuments.Where(a => a.FkPortage == portage.Id));
            db.TblPortages.Remove(portage);
            #endregion
            db.SaveChanges();
            dbdoc.SaveChanges();

            if (contypeclone.KindCotractType == web_db._Weighing.TblContractType.KindCotractTypeEnum.ASardKhane)
            {
                var x = db.TblPortageRows.Where(a => a.FkPortage == portage.Id);
                foreach (var item in x.Select(a => a.FkContract).Distinct())
                {
                    Models.cl.refTblStoreLogcontractSardKhane(item.Value, db);
                }
            }


            return(true);
        }
Ejemplo n.º 15
0
 public IActionResult Create(web_db._temp.TblTempRow temp)
 {
     if (ModelState.IsValid)
     {
         var x = db.TblTempRows.Any(a => a.Id == temp.Id);
         if (x == false)
         {
             temp.Id      = Guid.NewGuid();
             temp.DateAdd = DateTime.Now;
             db.TblTempRows.Add(temp);
         }
         else
         {
             db.TblTempRows.Update(temp);
         }
         db.SaveChanges();
         return(RedirectToAction(nameof(Index)));
     }
     return(View(temp));
 }
Ejemplo n.º 16
0
        public static void _refstoreTow(web_db.sardweb_Context db, Guid fkportage)
        {
            var x   = db.TblPortageRows.Where(a => a.FkPortage == fkportage);
            var por = db.TblPortages.Find(fkportage);

            por.WeightNet = (por.Weight1 - por.Weight2).gadrmotlagh();
            if (Models.tbls.portage.kindPortage.listkindcontract.Single(a => a.code == por.KindCode).Manfi)
            {
                por.WeightNet = -por.WeightNet;
            }
            var contype = web_sard.Models.cl._ListContractType(por.FkSalmali).Single(a => a.Id == por.FkContracttype);

            if (contype.KindCotractType == web_db._Weighing.TblContractType.KindCotractTypeEnum.ASabad)
            {
                Models.cl.refTblStoreLogcontractTypeSabad(contype.Id, db);
            }



            db.SaveChanges();
        }
Ejemplo n.º 17
0
        public IActionResult Create(web_db._Weighing.TblInjury model, List <web_db._Weighing.TblContractType.KindCotractTypeEnum> _ForContractType)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.txt = "ثبت انجام نشد - فیلد ها را درست پر کنید";
                return(View(model));
            }
            try
            {
                var x = db.TblInjuries.Find(model.Id);
                if (x == null)
                {
                    x = new web_db._Weighing.TblInjury {
                        Id = model.Id
                    };

                    db.TblInjuries.Add(x);
                }

                x.IsActive = model.IsActive;
                x.Title    = model.Title;
                x.forIn    = model.forIn;
                x.forOut   = model.forOut;
                x.ForContractType(_ForContractType);

                db.SaveChanges();
                ViewBag.txt           = "ثبت انجام شد";
                Models.cl._ListInjury = db.TblInjuries.OrderBy(a => a.Ord).ToList();
                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                ViewBag.error = "ثبت انجام نشد";
            }
            return(View(model));
        }
Ejemplo n.º 18
0
        public IActionResult Create(Models.tbls.contract.contract model, bool sendSMS)
        {
            var sal          = User._getuserSalMaliDef();
            var ContractType = db.TblContractTypes.Find(model.FkContractType);

            var x = db.TblContracts.Find(model.Id);



            if (ContractType.KindCotractType == web_db._Weighing.TblContractType.KindCotractTypeEnum.ASabad)
            {
                var conf = ContractType.ConfigASabad();


                ModelState.Remove("WeightMaxIn");

                ModelState.Remove("WeightMaxOut");

                ModelState.Remove("prodoctsId");



                if (conf.IsEntry == false)
                {
                    ModelState.Remove("CountMaxIn");
                }
                if (conf.IsExit == false)
                {
                    ModelState.Remove("CountMaxOut");
                }

                {
                    ModelState.Remove("WeightMaxOut");
                    ModelState.Remove("PercentForOut");
                }


                if (ModelState.IsValid)
                {
                    {
                        var x2 = db.TblContracts.Where(a => a.Code == model.Code && a.FkSalmali == sal);
                        if (x2.Any() && x2.Single().Id != x.Id)
                        {
                            x.Code = Convert.ToInt64((db.TblContracts.Where(a => a.FkSalmali == sal).Max(a => (long?)a.Code) ?? 0) + 1);
                        }
                    }

                    if (x == null)
                    {
                        x = new web_db._Weighing.TblContract
                        {
                            Date = DateTime.Now.Date,

                            Dateadd        = DateTime.Now,
                            FkContractType = model.FkContractType,
                            FkSalmali      = User._getuserSalMaliDef(),
                            FkUsAdd        = User._getuserid().Value,
                            Id             = Guid.NewGuid(),
                            FkCustomer     = model.FkCustomer
                        };
                        db.TblContracts.Add(x);
                    }
                    else
                    {
                        x.FkUsEdit = User._getuserid();
                        x.Dateedit = DateTime.Now;
                    }
                    x.Code        = model.Code;
                    x.Azdate      = model.Azdate.ToDate();
                    x.Tadate      = model.Tadate.ToDate();
                    x.WeightMaxIn = model.WeightMaxIn;
                    x.CountMaxIn  = model.CountMaxIn;

                    x.WeightMaxOut  = model.WeightMaxOut;
                    x.CountMaxOut   = model.CountMaxOut;
                    x.PercentForOut = model.PercentForOut;


                    x.IsEndVrud = model.isEndVrud;
                    x.IsEndXroj = model.isEndXroj;

                    x.Txt = model.Txt ?? "";

                    x.PriceOfBoxIn   = model.PriceOfBoxIn ?? 0;
                    x.PriceOfBoxOut  = model.PriceOfBoxOut ?? 0;
                    x.PriceOfKiloIn  = model.PriceOfKiloIn ?? 0;
                    x.PriceOfKiloOut = model.PriceOfKiloOut ?? 0;

                    db.TblContractPackings.RemoveRange(db.TblContractPackings.Where(a => a.FkContract == x.Id));
                    foreach (var item in model.packingsId)
                    {
                        db.TblContractPackings.Add(new web_db._Weighing.TblContractPacking {
                            FkContract = x.Id, FkPacking = item
                        });
                    }


                    if (sendSMS)
                    {
                        x.SendSms = true;
                    }
                    db.SaveChanges();
                    ViewBag.txt = "ثبت انجام شد";
                    return(RedirectToAction(nameof(Index), new { idtype = model.FkContractType }));
                }

                ViewData["listcustumer"] = db.TblCustomers.Include(a => a.TblContracts).Where(a => a.FkSalmali == User._getuserSalMaliDef() && a.IsEnable).OrderBy(a => a.Code).Select(a => new web_sard.Models.tbls.customer.customer(a, db, web_db._Weighing.TblContractType.KindCotractTypeEnum.ASabad, true)).ToList();

                ViewData["type"] = ContractType;
                ViewBag.error    = "لطفا موارد را درست پر کنید";
                return(View(model));
            }


            return(null);
        }
Ejemplo n.º 19
0
        public IActionResult Add(web_db._note.TblNote model, _UserRol._Rolls[] roll, Guid[] us, string delete, string date = "")
        {
            var row = db.TblNotes.Find(model.Id);

            if (delete.IsEmpty() == false)
            {
                if (row != null)
                {
                    if (User._getRolAny(_UserRol._Rolls.TempAdmin))
                    {
                        db.TblNoteRows.RemoveRange(db.TblNoteRows.Where(a => a.FkTblNote == row.Id));
                        db.TblNoteDates.RemoveRange(db.TblNoteDates.Where(a => a.FkTblNote == row.Id));
                        db.TblNoteRolls.RemoveRange(db.TblNoteRolls.Where(a => a.FkTblNote == row.Id));
                        db.TblNotes.Remove(row);
                        db.SaveChanges();
                    }
                }
                return(Redirect(Request.UrlReferer()));
            }
            if (row == null)
            {
                row = new web_db._note.TblNote
                {
                    Id        = Guid.NewGuid(),
                    DateAdd   = DateTime.Now,
                    FkuserAdd = User._getuserid().Value,
                };
                db.TblNotes.Add(row);
            }

            if ((row.FkuserAdd != User._getuserid()) && User._getRolAny(_UserRol._Rolls.TempAdmin) == false)
            {
                return(Redirect(Request.UrlReferer()));
            }

            row.Txt     = model.Txt.Trim();
            row.Caption = model.Caption.Trim();

            db.TblNoteRows.RemoveRange(db.TblNoteRows.Where(a => a.FkTblNote == row.Id));
            db.TblNoteDates.RemoveRange(db.TblNoteDates.Where(a => a.FkTblNote == row.Id));
            db.TblNoteRolls.RemoveRange(db.TblNoteRolls.Where(a => a.FkTblNote == row.Id));


            List <web_db._note.TblNoteRoll> rols = new List <web_db._note.TblNoteRoll>();

            if (User._getRolAny(_UserRol._Rolls.NoteAdmin))
            {
                foreach (var item in roll)
                {
                    var z = new web_db._note.TblNoteRoll
                    {
                        ForUserroll = item.ToString(),
                        Id          = Guid.NewGuid(),
                        FkTblNote   = row.Id
                    };
                    db.TblNoteRolls.Add(z);
                    rols.Add(z);
                }
                foreach (var item in us)
                {
                    var z = new web_db._note.TblNoteRoll
                    {
                        ForUserId = item,
                        Id        = Guid.NewGuid(),
                        FkTblNote = row.Id
                    };
                    db.TblNoteRolls.Add(z);
                    rols.Add(z);
                }
            }
            if (User._getRolAny(_UserRol._Rolls.NoteAdmin) == false || ((roll.Any() == false) && (us.Any() == false)))
            {
                var z = new web_db._note.TblNoteRoll
                {
                    ForUserId = User._getuserid(),
                    Id        = Guid.NewGuid(),
                    FkTblNote = row.Id
                };
                db.TblNoteRolls.Add(z); rols.Add(z);
            }


            foreach (var itemd in model.TblNoteDates)
            {
                if (itemd._ToDate.IsEmpty() || itemd._FromDate.IsEmpty())
                {
                    break;
                }
                itemd.FromDate = itemd._FromDate.ToDate();
                itemd.ToDate   = itemd._ToDate.ToDate();
                db.TblNoteDates.Add(new web_db._note.TblNoteDate
                {
                    Id          = Guid.NewGuid(),
                    FromDate    = itemd.FromDate,
                    SendSms     = itemd.SendSms,
                    KindBesorat = itemd.KindBesorat,
                    ToDate      = itemd.ToDate,
                    FkTblNote   = row.Id
                });



                List <DateTime> dates = new List <DateTime>();
                var             d     = itemd.FromDate.Value;
                while (itemd.ToDate >= d)
                {
                    dates.Add(d);

                    switch (itemd.KindBesorat)
                    {
                    case web_db._note.TblNoteDate.Kind.Harroz:
                        d = d.AddDays(1);
                        break;

                    case web_db._note.TblNoteDate.Kind.HarHafte:
                        d = d.AddDays(7);
                        break;

                    case web_db._note.TblNoteDate.Kind.Har2Hafte:
                        d = d.AddDays(7);
                        break;

                    case web_db._note.TblNoteDate.Kind.Har4Week:
                        d = d.AddDays(7 * 4);
                        break;

                    case web_db._note.TblNoteDate.Kind.HarMah:
                        d = d.ToPersianAddMonths(1);
                        break;

                    default:
                        break;
                    }
                }

                foreach (var item in dates)
                {
                    foreach (var itemr in rols)
                    {
                        db.TblNoteRows.Add(new web_db._note.TblNoteRows
                        {
                            Date        = item,
                            ForUserId   = itemr.ForUserId,
                            ForUserroll = itemr.ForUserroll,
                            Id          = Guid.NewGuid(),
                            FkTblNote   = row.Id,
                            SendSms     = itemd.SendSms,
                        });
                    }
                }
            }
            db.SaveChanges();


            return(Redirect(Request.UrlReferer()));
        }
Ejemplo n.º 20
0
        public IActionResult CreateIN(Guid idtype, int kindPortage, Models.tbls.portage.portage model)
        {
            ModelState.Remove("Weight2");
            ModelState.Remove("Date2date");
            ModelState.Remove("Date2time");
            ModelState.Remove("Customer.Mob");
            ModelState.Remove("Customer.NationalCode");
            ModelState.Remove("Customer.Code");
            ModelState.Remove("Customer.Title");
            ModelState.Remove("Customer.Id");
            ModelState.Remove("FkCarTbl");


            var kindPortageenum = (web_sard.Areas.ASurting.Models.tbls.portage.kindPortage.kindPortageEnum)kindPortage;

            if (kindPortageenum == Models.tbls.portage.kindPortage.kindPortageEnum.InFromSardkhane || kindPortageenum == Models.tbls.portage.kindPortage.kindPortageEnum.OutToSardkhane ||
                kindPortageenum == Models.tbls.portage.kindPortage.kindPortageEnum.InFromAnbar || kindPortageenum == Models.tbls.portage.kindPortage.kindPortageEnum.OutToAnbar)
            {
                ModelState.Remove("CarShMashin");
                ModelState.Remove("FkCar");
                ModelState.Remove("CarRanande");
                ModelState.Remove("CarTell");
                ModelState.Remove("Weight1IsBascul");
                ModelState.Remove("Weight1");
            }

            var typecontract = db.TblContractTypes.Find(idtype);


            if (typecontract.KindCotractType == web_db._Weighing.TblContractType.KindCotractTypeEnum.ASurting)
            {
                var conf = typecontract.ConfigASurting();

                if (ModelState.IsValid)
                {
                    var x = db.TblPortages.Find(model.Id);
                    if (x == null)
                    {
                        model.Code = (db.TblPortages.Where(a => a.FkSalmali == User._getuserSalMaliDef() && a.FkContracttype == idtype && a.KindCode == kindPortage).Max(a => (long?)a.Code) ?? 0) + 1;



                        x = new web_db._Weighing.TblPortage
                        {
                            FkSalmali      = User._getuserSalMaliDef(),
                            Code           = model.Code,
                            Dateadd1       = DateTime.Now,
                            FkContracttype = idtype,
                            FkUsAdd1       = User._getuserid().Value,
                            Id             = model.Id,
                            KindCode       = kindPortage,
                            KindTitle      = Models.tbls.portage.kindPortage.listkindcontract.Find(a => a.code == kindPortage).txt,
                        };
                        db.TblPortages.Add(x);
                    }
                    else
                    {
                        x.Dateedit1 = DateTime.Now;
                        x.FkUsEdit1 = User._getuserid().Value;
                    }

                    x.CarMashin   = model.CarMashin ?? "";
                    x.CarRanande  = model.CarRanande ?? "";
                    x.CarShMashin = model.CarShMashin ?? "";
                    x.CarTell     = model.CarTell ?? "";
                    x.FkCar       = model.FkCar;
                    x.CarMashin   = (web_sard.Models.cl._ListCar.SingleOrDefault(a => a.Id == model.FkCar) ?? new web_db._Weighing.TblCar()).Title;


                    x._FkContractMain = model._FkContractMain;

                    x.FkCustomer = db.TblContracts.Find(model._FkContractMain).FkCustomer;


                    x.Weight1         = model.Weight1;
                    x.Weight1IsBascul = model.Weight1IsBascul;
                    x.Txt             = model.Txt;
                    x.Date1           = model.Date1date.ToDate().AddHours(model.Date1time.Hours).AddMinutes(model.Date1time.Minutes);
                    x.IsDel           = false;
                    x.IsPermitOk      = null;
                    x.FkUsPermit      = null;
                    x.TxtPermit       = "";

                    var dbdoc = new web_dbDocument.db_Context();

                    #region captureDorbinBaskul
                    if (kindPortageenum == Models.tbls.portage.kindPortage.kindPortageEnum.In || kindPortageenum == Models.tbls.portage.kindPortage.kindPortageEnum.Out)
                    {
                        if (x.Weight1 != model.Weight1)
                        {
                            var z = web_sard.Models.cl.captureDorbinBaskul();
                            if (z != null)
                            {
                                dbdoc.TblDocuments.Add(new web_dbDocument.TblDocument
                                {
                                    Date = DateTime.Now,
                                    FkP  = x.Id,
                                    Id   = Guid.NewGuid(),

                                    Image  = z,
                                    Kind   = "InBaskul",
                                    Format = ""
                                });
                            }
                        }
                    }

                    #endregion



                    #region PeerSardKhane

                    if (kindPortageenum == Models.tbls.portage.kindPortage.kindPortageEnum.InFromSardkhane || kindPortageenum == Models.tbls.portage.kindPortage.kindPortageEnum.OutToSardkhane)
                    {
                        var xpkind = (kindPortageenum == Models.tbls.portage.kindPortage.kindPortageEnum.InFromSardkhane ? web_sard.Areas.ASardKhane.Models.tbls.portage.kindPortage.kindPortageEnum.OutToSurt :
                                      web_sard.Areas.ASardKhane.Models.tbls.portage.kindPortage.kindPortageEnum.InFromSurt);

                        foreach (var item in web_sard.Models.cl._ListContractType(x.FkSalmali).Where(a => a.KindCotractType == web_db._Weighing.TblContractType.KindCotractTypeEnum.ASardKhane))
                        {
                            var xp = db.TblPortages.Find(x._FkPortagePeer);

                            if (xp == null)
                            {
                                xp = new web_db._Weighing.TblPortage
                                {
                                    FkSalmali      = User._getuserSalMaliDef(),
                                    Code           = model.Code,
                                    _FkPortagePeer = x.Id,
                                    Dateadd1       = DateTime.Now,
                                    FkContracttype = item.Id,
                                    FkUsAdd1       = User._getuserid().Value,
                                    Id             = Guid.NewGuid(),
                                    KindCode       = (int)xpkind,
                                    KindTitle      = web_sard.Areas.ASardKhane.Models.tbls.portage.kindPortage.listkindcontract.Find(a => a.code == (int)xpkind).txt,
                                };
                                xp.Code = (db.TblPortages.Where(a => a.FkSalmali == User._getuserSalMaliDef() && a.FkContracttype == item.Id && a.KindCode == (int)xpkind).Max(a => (long?)a.Code) ?? 0) + 1;

                                db.TblPortages.Add(xp);



                                x._FkPortagePeer = xp.Id;
                            }
                            else
                            {
                                xp.Dateedit1 = DateTime.Now;
                                xp.FkUsEdit1 = User._getuserid().Value;
                            }



                            xp.CarMashin   = x.CarMashin ?? "";
                            xp.CarRanande  = x.CarRanande ?? "";
                            xp.CarShMashin = x.CarShMashin ?? "";
                            xp.CarTell     = x.CarTell ?? "";
                            xp.FkCar       = x.FkCar;
                            xp.CarMashin   = (web_sard.Models.cl._ListCar.SingleOrDefault(a => a.Id == model.FkCar) ?? new web_db._Weighing.TblCar()).Title;

                            xp.FkCustomer = x.FkCustomer;


                            xp.Weight1         = x.Weight1;
                            xp.Weight1IsBascul = x.Weight1IsBascul;
                            xp.Txt             = x.Txt;
                            xp.Date1           = x.Date1;
                            xp.IsDel           = false;
                            xp.IsPermitOk      = null;
                            xp.FkUsPermit      = null;
                            xp.TxtPermit       = "";
                        }
                    }



                    #endregion


                    #region PeerAnbar

                    if (kindPortageenum == Models.tbls.portage.kindPortage.kindPortageEnum.InFromAnbar || kindPortageenum == Models.tbls.portage.kindPortage.kindPortageEnum.OutToAnbar)
                    {
                        var xpkind = (kindPortageenum == Models.tbls.portage.kindPortage.kindPortageEnum.InFromAnbar ? web_sard.Areas.ASabad.Models.tbls.portage.kindPortage.kindPortageEnum.OutToSurt :
                                      web_sard.Areas.ASabad.Models.tbls.portage.kindPortage.kindPortageEnum.InFromSurt);

                        foreach (var item in web_sard.Models.cl._ListContractType(x.FkSalmali).Where(a => a.KindCotractType == web_db._Weighing.TblContractType.KindCotractTypeEnum.ASabad))
                        {
                            var xp = db.TblPortages.SingleOrDefault(a => a.FkContracttype == item.Id && a.Id == x._FkPortagePeer);

                            if (xp == null)
                            {
                                xp = new web_db._Weighing.TblPortage
                                {
                                    FkSalmali      = User._getuserSalMaliDef(),
                                    Code           = model.Code,
                                    Dateadd1       = DateTime.Now,
                                    FkContracttype = item.Id,
                                    FkUsAdd1       = User._getuserid().Value,
                                    _FkPortagePeer = x.Id,
                                    Id             = Guid.NewGuid(),
                                    KindCode       = (int)xpkind,
                                    KindTitle      = web_sard.Areas.ASabad.Models.tbls.portage.kindPortage.listkindcontract.Find(a => a.code == (int)xpkind).txt,
                                };
                                xp.Code = (db.TblPortages.Where(a => a.FkSalmali == User._getuserSalMaliDef() && a.FkContracttype == item.Id && a.KindCode == (int)xpkind).Max(a => (long?)a.Code) ?? 0) + 1;

                                db.TblPortages.Add(xp);



                                x._FkPortagePeer = xp.Id;
                            }
                            else
                            {
                                xp.Dateedit1 = DateTime.Now;
                                xp.FkUsEdit1 = User._getuserid().Value;
                            }


                            xp.CarMashin   = x.CarMashin ?? "";
                            xp.CarRanande  = x.CarRanande ?? "";
                            xp.CarShMashin = x.CarShMashin ?? "";
                            xp.CarTell     = x.CarTell ?? "";
                            xp.FkCar       = x.FkCar;
                            xp.CarMashin   = (web_sard.Models.cl._ListCar.SingleOrDefault(a => a.Id == model.FkCar) ?? new web_db._Weighing.TblCar()).Title;

                            xp.FkCustomer = x.FkCustomer;


                            xp.Weight1         = x.Weight1;
                            xp.Weight1IsBascul = x.Weight1IsBascul;
                            xp.Txt             = x.Txt;
                            xp.Date1           = x.Date1;
                            xp.IsDel           = false;
                            xp.IsPermitOk      = null;
                            xp.FkUsPermit      = null;
                            xp.TxtPermit       = "";
                        }
                    }



                    #endregion

                    ViewBag.error = checkportage(x);
                    if (((string)ViewBag.error).IsEmpty())
                    {
                        db.SaveChanges();
                        dbdoc.SaveChanges();
                        _refstoreTow(x.Id);

                        if (kindPortageenum == Models.tbls.portage.kindPortage.kindPortageEnum.InFromSardkhane || kindPortageenum == Models.tbls.portage.kindPortage.kindPortageEnum.OutToSardkhane)
                        {
                            ASardKhane.Models.cl._refstoreTow(db, x.Id);
                        }
                        if (kindPortageenum == Models.tbls.portage.kindPortage.kindPortageEnum.InFromAnbar || kindPortageenum == Models.tbls.portage.kindPortage.kindPortageEnum.OutToAnbar)
                        {
                            ASabad.Models.cl._refstoreTow(db, x.Id);
                        }


                        return(RedirectToAction("index", new { idtype = x.FkContracttype }));
                    }
                }
                ViewData["type"]        = db.TblContractTypes.Find(idtype);
                ViewData["kindPortage"] = kindPortage;



                var intosard = false;
                if ((kindPortage == (int)Models.tbls.portage.kindPortage.kindPortageEnum.InFromSardkhane) || (kindPortage == (int)Models.tbls.portage.kindPortage.kindPortageEnum.OutToSardkhane))
                {
                    intosard = true;
                }

                ViewBag.contrs = (from n in db.TblContracts.Include(a => a.FkContractTypeNavigation).Include(a => a.FkCustomerNavigation)
                                  where n.FkSalmali == typecontract.FkSalmali && n.FkContractType == idtype
                                  //&&

                                  //(intosard == false ? true : (n._FkContractPeer.HasValue))
                                  orderby n.Code ascending
                                  select n).ToList();


                return(View(model));
            }



            return(null);
        }
Ejemplo n.º 21
0
        public async Task <IActionResult> Index(int p, web_db._queu.TblQueu model, string captcha, List <Guid> Product, List <Guid> Packing)
        {
            if (model.mob.IsMobile() == false)
            {
                ViewBag.error = "شماره موبایل اشتباه است";
                p             = 0;
            }


            if (p == 0)
            {
            }
            else
            if (p == 1)
            {
                if (web_lib.stat.Captcha.CheckCaptcha(this.HttpContext, captcha) == false)
                {
                    ViewBag.error = "متن امنیتی اشتباه است";
                    var Captcha = new web_lib.stat.Captcha(this.HttpContext);
                    ViewBag.Captcha = Captcha.ImageAsBaseSrc;
                    p = 0;

                    return(View());
                }
                var row = db.TblQueus.FirstOrDefault(a => a.mob == model.mob && a.KindQueu == web_db._queu.TblQueu.QueuEnum.Empty);

                if (row == null)
                {
                    row = new web_db._queu.TblQueu
                    {
                        Id   = Guid.NewGuid(),
                        mob  = model.mob,
                        date = DateTime.Now,

                        Code        = (db.TblQueus.Max(a => (long?)a.Code) ?? 0) + 1,
                        KindQueu    = web_db._queu.TblQueu.QueuEnum.Empty,
                        Addras      = "",
                        codemeli    = "",
                        CodeMahsuls = "",
                        Weight      = 0,
                        Name        = "",
                        Txt         = "",
                    };
                    db.TblQueus.Add(row);
                }
                if (row.datecodesend.HasValue == false || (DateTime.Now - row.datecodesend.Value > TimeSpan.FromMinutes(15)))
                {
                    await sendsmsAsync(row);
                }
                db.SaveChanges();
                model = row;
            }
            else
            {
                var row = db.TblQueus.SingleOrDefault(a => a.Id == model.Id);

                var z = db.TblProducts.Where(a => Product.Contains(a.Id)).Select(a => a.Title).ToList();
                z.AddRange(db.TblPackings.Where(a => Packing.Contains(a.Id)).Select(a => a.Title).ToList());

                Product.AddRange(Packing);
                row.CodeMahsuls = Product.ToJson();


                if (row.codesend != model.codesend)
                {
                    ViewBag.error = "کد ارسالی به موبایل اشتباه است ";
                    p             = 1;
                }
                else
                {
                    row.Addras = model.Addras;


                    row.Mahsuls  = string.Join(',', z);
                    row.Weight   = model.Weight;
                    row.codemeli = model.codemeli;
                    row.KindQueu = web_db._queu.TblQueu.QueuEnum.Save;

                    row.Name = model.Name;
                    row.Txt  = model.Txt;

                    db.SaveChanges();

                    await sendsmsloginAsync(row);
                }

                model = row;
            }



            ViewBag.p      = p;
            model.codesend = null;
            if (p == 0)
            {
                var Captcha = new web_lib.stat.Captcha(this.HttpContext);
                ViewBag.Captcha = Captcha.ImageAsBaseSrc;

                return(View(model));
            }
            else
            if (p == 1)
            {
                ViewBag.listPacking = db.TblPackings.AsEnumerable().Where(a => a.ForContractType().Contains(web_db._Weighing.TblContractType.KindCotractTypeEnum.ASardKhane) && a.IsActive == true)
                                      .OrderBy(a => a.Code).ToList();
                ViewBag.listProduct = db.TblProducts.Where(a => a.IsActive).OrderBy(a => a.Ord).ToList();
                return(View("indexEdit", model));
            }
            else
            {
                return(RedirectToAction("success", new { model.Id }));
            }
        }
Ejemplo n.º 22
0
        public IActionResult SyncCusSystem()
        {
            {
                using (var dbCus = new web_CusDB.db_Context())
                {
                    using (var db = new web_db.sardweb_Context())
                    {
                        long code = (dbCus.tblReqContracts.Max(a => (long?)a.Code) ?? 0);
                        foreach (var item in db.TblQueus.Where(a => (a.KindQueu == web_db._queu.TblQueu.QueuEnum.Save) || (a.KindQueu == web_db._queu.TblQueu.QueuEnum.IsActive)).Take(100))
                        {
                            code++;

                            var con = dbCus.tblReqContracts.Find(item.Id);
                            if (con == null)
                            {
                                var cus = dbCus.TblCustomers.SingleOrDefault(a => a.Mob == item.mob && a.CodeMelli == item.codemeli);
                                if (cus == null)
                                {
                                    cus = new web_CusDB.tblCus
                                    {
                                        CodeMelli = item.codemeli,
                                        dateAdd   = item.date,
                                        Addras    = item.Addras,
                                        Id        = Guid.NewGuid(),
                                        Mob       = item.mob,
                                        Name      = item.Name,
                                    };
                                    dbCus.TblCustomers.Add(cus);
                                }



                                con = new web_CusDB.tblReqContract
                                {
                                    Code         = (code),
                                    DateAdd      = item.date,
                                    ContractId   = item.ContractID,
                                    KindContract = web_db._Weighing.TblContractType.KindCotractTypeEnum.ASardKhane,
                                    Id           = item.Id,
                                    IsEdit       = false,
                                    tblCusId     = cus.Id,
                                    DateLast     = DateTime.Now,
                                };


                                dbCus.tblReqContracts.Add(con);

                                dbCus.tblReqContractRows.Add(new web_CusDB.tblReqContractRow
                                {
                                    CodeMahsuls      = item.CodeMahsuls,
                                    Date             = item.date,
                                    Id               = Guid.NewGuid(),
                                    Vaziat           = web_CusDB.tblReqContractRow.ResEnum.Save,
                                    WeightCount      = item.Weight ?? 0,
                                    TblReqContractId = con.Id,
                                    Mahsuls          = item.Mahsuls,
                                });



                                //  db.Remove(item);
                            }
                        }

                        db.SaveChanges();
                        dbCus.SaveChanges();
                    }
                }
            }



            return(RedirectToAction("Index"));
        }
Ejemplo n.º 23
0
        public static void refTblStoreLogcontractSardKhane(Guid fkcontract, web_db.sardweb_Context db)
        {
            var rowOK = new List <Guid>();
            //Add
            {
                var contr     = db.TblContracts.Find(fkcontract);
                var contrType = db.TblContractTypes.Find(contr.FkContractType);
                var x         = db.TblPortageRows.Include(a => a.FkPortageNavigation).Where(a => a.FkContract == fkcontract && (a.FkPortage.HasValue ? (a.FkPortageNavigation.IsEnd && a.FkPortageNavigation.IsDel == false) : true)).AsEnumerable();


                contr.SumInCount  = x.Where(a => a.FkPortageNavigation.KindCode == (int)kindPortage.kindPortageEnum.In || a.FkPortageNavigation.KindCode == (int)kindPortage.kindPortageEnum.InBack).Sum(a => a.Count);
                contr.SumInWeight = x.Where(a => a.FkPortageNavigation.KindCode == (int)kindPortage.kindPortageEnum.In || a.FkPortageNavigation.KindCode == (int)kindPortage.kindPortageEnum.InBack).Sum(a => (decimal?)(a.Count * a.WeightOne));

                contr.SumOutCount  = x.Where(a => a.FkPortageNavigation.KindCode == (int)kindPortage.kindPortageEnum.Out || a.FkPortageNavigation.KindCode == (int)kindPortage.kindPortageEnum.OutBack).Sum(a => a.Count);
                contr.SumOutWeight = x.Where(a => a.FkPortageNavigation.KindCode == (int)kindPortage.kindPortageEnum.Out || a.FkPortageNavigation.KindCode == (int)kindPortage.kindPortageEnum.OutBack).Sum(a => (decimal?)(a.Count * a.WeightOne));

                if (contrType.KindCotractType == web_db._Weighing.TblContractType.KindCotractTypeEnum.ASardKhane)
                {
                    var xx = x.GroupBy(a => new { a.FkContract, a.FkLocation1, a.FkLocation2, a.FkLocation3, a.FkPacking, a.FkProduct }).ToList();

                    foreach (var item in xx)
                    {
                        var iall = db.TblStoreLogs.Where(a =>
                                                         a.FkContractType == contrType.Id &&
                                                         a.FkSalmali == contr.FkSalmali &&
                                                         a.FkContract == item.Key.FkContract &&
                                                         a.FkLocation1 == item.Key.FkLocation1 &&
                                                         a.FkLocation2 == item.Key.FkLocation2 &&
                                                         a.FkLocation3 == item.Key.FkLocation3 &&
                                                         a.FkPacking == item.Key.FkPacking &&
                                                         a.FkProduct == item.Key.FkProduct
                                                         );
                        if (iall.Count() > 1)
                        {
                            db.TblStoreLogs.RemoveRange(iall);
                            db.SaveChanges();
                        }
                        var i = db.TblStoreLogs.SingleOrDefault(a =>
                                                                a.FkContractType == contrType.Id &&
                                                                a.FkSalmali == contr.FkSalmali &&
                                                                a.FkContract == item.Key.FkContract &&
                                                                a.FkLocation1 == item.Key.FkLocation1 &&
                                                                a.FkLocation2 == item.Key.FkLocation2 &&
                                                                a.FkLocation3 == item.Key.FkLocation3 &&
                                                                a.FkPacking == item.Key.FkPacking &&
                                                                a.FkProduct == item.Key.FkProduct
                                                                );
                        if (i == null)
                        {
                            i = new web_db._Weighing.TblStoreLog
                            {
                                Id             = Guid.NewGuid(),
                                FkContract     = fkcontract,
                                FkContractType = contrType.Id,
                                FkCustomer     = contr.FkCustomer,
                                FkLocation1    = item.Key.FkLocation1,
                                FkLocation2    = item.Key.FkLocation2,
                                FkLocation3    = item.Key.FkLocation3,
                                FkPacking      = item.Key.FkPacking,
                                FkProduct      = item.Key.FkProduct,
                                FkSalmali      = contr.FkSalmali,
                            };
                            db.TblStoreLogs.Add(i);
                        }
                        i.Count          = item.Sum(a => a.Count);
                        i.Weight         = item.Sum(a => a.Count * (decimal?)a.WeightOne);
                        i.CountIn        = item.Where(a => a.FkPortage.HasValue && a.Count > 0).Sum(a => a.Count);
                        i.CountOut       = item.Where(a => a.FkPortage.HasValue && a.Count < 0).Sum(a => a.Count);
                        i.CountMovement  = item.Where(a => a.FkPortage.HasValue == false).Sum(a => a.Count);
                        i.WeightIn       = item.Where(a => a.FkPortage.HasValue && a.Count > 0).Sum(a => a.Count * (decimal?)a.WeightOne);
                        i.WeightOut      = item.Where(a => a.FkPortage.HasValue && a.Count < 0).Sum(a => a.Count * (decimal?)a.WeightOne);
                        i.WeightMovement = item.Where(a => a.FkPortage.HasValue == false).Sum(a => a.Count * (decimal?)a.WeightOne);
                        rowOK.Add(i.Id);
                    }
                }



                db.TblStoreLogs.RemoveRange(db.TblStoreLogs.Where(a => a.FkContract == fkcontract && (rowOK.Contains(a.Id) == false)));
            }
        }
Ejemplo n.º 24
0
        public async Task <IActionResult> Login(string username, string password, string Captcha, int p)
        {
            ViewBag.username = username;
            ViewBag.p        = 1;
            if (web_lib.stat.Captcha.CheckCaptcha(this.HttpContext, Captcha) == false)
            {
                ViewBag.error = "متن امنیتی اشتباه است";
                var captcha = new web_lib.stat.Captcha(this.HttpContext);
                ViewBag.Captcha = captcha.ImageAsBaseSrc;

                return(View());
            }

            if (username.IsEmpty() || username.IsCodemeli() == false)
            {
                ViewBag.error = "کد ملی اشتباه است";
                var captcha = new web_lib.stat.Captcha(this.HttpContext);
                ViewBag.Captcha = captcha.ImageAsBaseSrc;

                return(View());
            }
            // var def = db.TblConfigs.First();
            var x = db.TblCustomers.OrderByDescending(a => a.FkSalmali).FirstOrDefault(a => /*a.FkSalmali == def.SalMaliMain*/ a.NationalCode == username);

            if (x == null)
            {
                ViewBag.error = "کد ملی شما در سیستم ثبت نیست";
                var captcha = new web_lib.stat.Captcha(this.HttpContext);
                ViewBag.Captcha = captcha.ImageAsBaseSrc;
                return(View());
            }


            if (p == 1)
            {
                if (x.Datesendpassword.HasValue == false)
                {
                    await sendsmsAsync(x);

                    db.SaveChanges();
                    ViewBag.p   = 2;
                    ViewBag.txt = "رمز عبور برای شما ارسال گردید";
                }
                else
                {
                    //ViewBag.txt = "رمز عبور قبلا برای شما ارسال گردیده";
                    ViewBag.p = 2;
                    if (x.Datesendpassword.HasValue == false || ((DateTime.Now - x.Datesendpassword.Value) > TimeSpan.FromMinutes(5)))
                    {
                        await sendsmsAsync(x);

                        db.SaveChanges();
                        ViewBag.txt = "رمز عبور برای شما ارسال گردید";
                    }
                    else
                    {
                        ViewBag.error = "رمز عبور قبلا برای شما ارسال گردیده";
                    }
                }
            }



            else if (p == 2)
            {
                if (x.Password == password)
                {
                    x.Dateloginlast = DateTime.Now;
                    db.SaveChanges();

                    var claims = new List <Claim>
                    {
                        new Claim(ClaimTypes.NameIdentifier, x.NationalCode.ToString()),
                        new Claim(ClaimTypes.Name, x.NationalCode.ToString()),
                    };
                    ClaimsIdentity  userIdentity = new ClaimsIdentity(claims, "login");
                    ClaimsPrincipal principal    = new ClaimsPrincipal(userIdentity);
                    await HttpContext.SignInAsync(principal);
                    await sendsmsloginAsync(x);

                    return(Redirect("/"));
                }
                else
                {
                    ViewBag.p   = 2;
                    ViewBag.txt = "رمز عبوراشتباه است";
                }
            }

            else if (p == 3)
            {
                ViewBag.p = 2;
                if (x.Datesendpassword.HasValue == false || ((DateTime.Now - x.Datesendpassword.Value) > TimeSpan.FromMinutes(5)))
                {
                    await sendsmsAsync(x);

                    db.SaveChanges();
                    ViewBag.txt = "رمز عبور برای شما ارسال گردید";
                }
                else
                {
                    ViewBag.error = "رمز عبور قبلا برای شما ارسال گردیده";
                }
            }


            return(View());
        }
Ejemplo n.º 25
0
        public IActionResult Create(Models.tbls.location.location model)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.error = "ثبت انجام نشد - فیلد ها را درست پرکنید";
                return(View(model));
            }
            try
            {
                var row = db.TblLocations.Find(model.Id);



                if (row == null)
                {
                    row = new web_db._Weighing.TblLocation();
                    if (model.FkP != null)
                    {
                        row.Kind = db.TblLocations.Find(model.FkP).Kind + 1;
                    }
                    else
                    {
                        row.Kind = 1;
                    }
                    row.Id  = Guid.NewGuid();
                    row.FkP = model.FkP;
                    /**/


                    //row.Code = (db.TblLocations.Where(a => (a.FkP ?? Guid.Empty) == idp).Max(a => (int?)a.Code) ?? 0) + 1;

                    db.TblLocations.Add(row);
                }
                row.Code = model.Code;
                // row.ord = 0;


                row.Title  = model.Title;
                row.Isdell = false;
                row.Wight  = model.wight;

                row.ForProduct  = model.ForProduct;
                row.OtcodeAnbar = model.OtcodeAnbar;
                if (row.Wight == 0)
                {
                    row.Wight = null;
                }

                //     row.CodeFull = row.Code.ToString();

                {
                    var z = db.TblLocations.FirstOrDefault(a => a.CodeFull == row.CodeFull);
                    if (z != null && z.Id != row.Id)
                    {
                        ViewBag.error = "ثبت انجام نشد - کد تکراری میباشد  ";
                        return(View(model));
                    }
                }
                {
                    row.CodeFull = row.Code.ToString();

                    var rowp = db.TblLocations.Find(row.FkP);
                    if (rowp != null)
                    {
                        row.CodeFull = rowp.Code + "-" + row.CodeFull;
                        if (rowp != null)
                        {
                            var rowpp = db.TblLocations.Find(rowp.FkP);
                            if (rowpp != null)
                            {
                                row.CodeFull = rowpp.Code + "-" + row.CodeFull;
                            }
                        }
                    }
                }


                db.SaveChanges();
                Models.cl._ListLocation = db.TblLocations.OrderBy(a => a.Code).ToList();

                ViewBag.txt = "ثبت انجام شد  ";
                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception e)
            {
            }
            ViewBag.error = "ثبت انجام نشد  ";
            return(View(model));
        }
Ejemplo n.º 26
0
        public IActionResult CreateIN(Guid idtype, int kindPortage, Models.tbls.portage.portage model)
        {
            ModelState.Remove("Weight2");
            ModelState.Remove("Date2date");
            ModelState.Remove("Date2time");
            ModelState.Remove("Customer.Mob");
            ModelState.Remove("Customer.NationalCode");
            ModelState.Remove("Customer.Code");
            ModelState.Remove("Customer.Title");
            ModelState.Remove("Customer.Id");
            ModelState.Remove("FkCarTbl");

            var typecontract = db.TblContractTypes.Find(idtype);



            if (typecontract.KindCotractType == web_db._Weighing.TblContractType.KindCotractTypeEnum.ASabad)
            {
                ModelState.Remove("Weight1");


                var conf = typecontract.ConfigASabad();


                if (ModelState.IsValid)
                {
                    var x = db.TblPortages.Find(model.Id);
                    if (x == null)
                    {
                        model.Code = (db.TblPortages.Where(a => a.FkSalmali == User._getuserSalMaliDef() && a.FkContracttype == idtype && a.KindCode == kindPortage).Max(a => (long?)a.Code) ?? 0) + 1;



                        x = new web_db._Weighing.TblPortage
                        {
                            FkSalmali      = User._getuserSalMaliDef(),
                            Code           = model.Code,
                            Dateadd1       = DateTime.Now,
                            FkContracttype = idtype,
                            FkUsAdd1       = User._getuserid().Value,
                            Id             = model.Id,
                            KindCode       = kindPortage,
                            KindTitle      = Models.tbls.portage.kindPortage.listkindcontract.Find(a => a.code == kindPortage).txt,
                        };
                        db.TblPortages.Add(x);
                    }
                    else
                    {
                        x.Dateedit1 = DateTime.Now;
                        x.FkUsEdit1 = User._getuserid().Value;
                    }



                    x.CarMashin   = model.CarMashin;
                    x.CarRanande  = model.CarRanande;
                    x.CarShMashin = model.CarShMashin;
                    x.CarTell     = model.CarTell;
                    x.FkCar       = model.FkCar;
                    x.CarMashin   = cl._ListCar.Single(a => a.Id == model.FkCar).Title;

                    x.FkCustomer = model.FkCustomer;
                    var dbdoc = new web_dbDocument.db_Context();

                    if (x.Weight1 != model.Weight1)
                    {
                        var z = cl.captureDorbinBaskul();
                        if (z != null)
                        {
                            dbdoc.TblDocuments.Add(new web_dbDocument.TblDocument
                            {
                                Date = DateTime.Now,
                                FkP  = x.Id,
                                Id   = Guid.NewGuid(),

                                Image  = z,
                                Kind   = "InBaskul",
                                Format = ""
                            });
                        }
                    }
                    x.Weight1         = model.Weight1;
                    x.Weight1IsBascul = model.Weight1IsBascul;
                    x.Txt             = model.Txt;
                    x.Date1           = model.Date1date.ToDate().AddHours(model.Date1time.Hours).AddMinutes(model.Date1time.Minutes);
                    x.IsDel           = false;
                    x.IsPermitOk      = null;
                    x.FkUsPermit      = null;
                    x.TxtPermit       = "";

                    ViewBag.error = checkportage(x);
                    if (((string)ViewBag.error).IsEmpty())
                    {
                        db.SaveChanges();
                        dbdoc.SaveChanges();
                        Models.cl._refstoreTow(db, x.Id);
                        return(RedirectToAction("index", new { idtype = x.FkContracttype }));
                    }
                }
                ViewData["type"]         = db.TblContractTypes.Find(idtype);
                ViewData["kindPortage"]  = kindPortage;
                ViewData["listcustumer"] = cus(typecontract, model);


                return(View(model));
            }


            return(null);
        }
Ejemplo n.º 27
0
        public IActionResult Create(Models.tbls.user.user model)
        {
            var x = db.TblUsers.Find(model.Id);

            if (x != null)
            {
                ModelState.Remove("Password");
            }

            if (!ModelState.IsValid)
            {
                ViewBag.error = "ثبت انجام نشد";
                return(View(model));
            }
            if (x == null)
            {
                x = new web_db.TblUser {
                    Id = model.Id, IsDel = false, Salmalidef = User._getuserSalMaliDef()
                };
                db.TblUsers.Add(x);
            }
            try
            {
                x.Mob = model.Mob;
                if (model.Password.IsEmpty() == false)
                {
                    x.Password = model.Password;
                }
                x.Roles    = string.Join(',', model.Roles);
                x.Title    = model.Title;
                x.Username = model.Username;
                x.IsActive = model.isActive;

                foreach (var item in model.Permis)
                {
                    var z = db.TblUserPermis.SingleOrDefault(a => a.FkUser == x.Id && a.FkPortageType == item.FkPortageType);
                    if (z == null)
                    {
                        z = new web_db.TblUserPermi {
                            FkPortageType = item.FkPortageType, FkUser = x.Id
                        };
                        db.TblUserPermis.Add(z);
                    }
                    z.IsIn      = item.IsIn;
                    z.IsInBack  = item.IsInBack;
                    z.IsOut     = item.IsOut;
                    z.IsOutBack = item.IsOutBack;
                    z.IsReport  = item.IsReport;
                    z.IsType    = z.IsIn || z.IsInBack || z.IsOut || z.IsOutBack;
                }

                try
                {
                    db.SaveChanges(); ViewBag.txt = "ثبت انجام شد";
                    return(RedirectToAction(nameof(ListUser)));
                }
                catch (Exception e)
                {
                    ViewBag.error = e.Message;
                }
            }
            catch { }
            return(View(model));
        }