Ejemplo n.º 1
0
    private void Generate()
    {
#if USING_XML
        XmlSerializer      ser = new XmlSerializer(typeof(ZConfig));
        List <GroupConfig> group;
        using (Stream stream = File.OpenRead(Path))
        {
            ZConfig config = ser.Deserialize(stream) as ZConfig;
            group = config.groups;
        }
#else
        string             json  = File.ReadAllText(Path);
        List <GroupConfig> group = JsonMapper.ToObject <List <GroupConfig> >(json);
#endif

        if (group == null)
        {
            return;
        }

        IEnumerable <ResourceConfig> res = group.SelectMany(g => g.resources);

        GameObject asset = new GameObject("ZResources");
        asset.AddComponent <ZResource>().resources = res.Select(r => r.ToZResource()).ToArray();
        AssetDatabase.DeleteAsset("Assets/Resources/ZResources");
        PrefabUtility.CreatePrefab("Assets/Resources/ZResources.prefab", asset);
        DestroyImmediate(asset);

        EditorUtility.DisplayDialog("GENERATE", "ZResources successfully generated!", "OK");
        AssetDatabase.Refresh();
        AssetDatabase.SaveAssets();
    }
Ejemplo n.º 2
0
    private void Save()
    {
        if (_groups == null)
        {
            return;
        }
        if (!_groups.TrueForAll(g => g.resources != null && g.resources.TrueForAll(CheckKey)))
        {
            return;
        }
#if USING_XML
        ZConfig config = new ZConfig();
        config.selections = _selections;
        config.groups     = _groups;
        XmlSerializer ser = new XmlSerializer(typeof(ZConfig));

        using (StreamWriter sw = File.CreateText(Path))
        {
            ser.Serialize(sw, config);
        }
#else
        string json = JsonMapper.ToJson(_groups);
        File.WriteAllText(Path, json);

        string groupJson = JsonMapper.ToJson(_selections);
        File.WriteAllText(GroupInfoPath, groupJson);
#endif

        EditorUtility.DisplayDialog("SAVE", "File successfully saved!", "OK");
        AssetDatabase.Refresh();
    }
Ejemplo n.º 3
0
        // GET api/menu
        public IEnumerable <dynamic> Get()
        {
            var UserCode = SysHelper.GetUserCode();
            var TenantId = SysHelper.GetTenantId();

            dynamic result = ZCache.GetCache("MenuData");

            if (result == null && !string.IsNullOrEmpty(UserCode) && !string.IsNullOrEmpty(TenantId))
            {
                var postdata = new
                {
                    AppCode        = "EPS",
                    ApiCode        = "GetUserMenuData",
                    TenantId       = TenantId,
                    UserCode       = UserCode,
                    RequestAppCode = "MiniMES"
                };

                result = HttpHelper.PostWebApi(ZConfig.GetConfigString("APIGatewayUrl"), JsonConvert.SerializeObject(postdata), 18000);

                ZCache.SetCache("MenuData", result);
            }

            return(result);
        }
Ejemplo n.º 4
0
        public ActionResult Logout()
        {
            FormsAuth.SingOut();

            var result = Redirect(ZConfig.GetConfigString("GatewayServer") + "/Login");

            return(result);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 连接串
        /// </summary>
        /// <returns></returns>
        public ConfigurationOptions Conn()
        {
            var options = ConfigurationOptions.Parse(ZConfig.GetConfigString("redispath"));

            options.SyncTimeout = int.MaxValue;
            options.AllowAdmin  = true;
            options.Password    = ZConfig.GetConfigString("redispwd");
            return(options);
        }
Ejemplo n.º 6
0
        public ActionResult Index()
        {
            ViewBag.CnName = "STD MiniMES系统";
            ViewBag.EnName = "STD MiniMES System";

            var Token = Request["Token"];

            if (!string.IsNullOrEmpty(Token))
            {
                string APIGatewayUrl = ZConfig.GetConfigString("APIGatewayUrl");
                var    data          = new
                {
                    AppCode = "EPS",
                    ApiCode = "PostValidateToken",
                    Token   = Token
                };

                var result = HttpHelper.PostWebApi(APIGatewayUrl, JsonConvert.SerializeObject(data), 18000);
                if (result != null)
                {
                    if (result.status == true)
                    {
                        var UserInfo = result.UserInfo;

                        //调用框架中的登录机制
                        var loginer = new LoginerBase
                        {
                            UserId   = UserInfo.UserId,
                            UserType = "2",
                            TenantId = UserInfo.TenantId,
                            UserCode = UserInfo.UserCode,
                            UserName = UserInfo.UserName,
                            ShiftId  = UserInfo.ShiftId
                        };

                        var effectiveHours = ZConfig.GetConfigInt("LoginEffectiveHours");
                        FormsAuth.SignIn(loginer.UserCode, loginer, 60 * effectiveHours);

                        ZCache.SetCache("MenuData", result.MenuData);

                        return(Redirect("Home"));
                    }
                }

                //return View("授权Token验证失败!单击<a href='" + ZConfig.GetConfigString("GatewayServer") + "'>这里</a>返回登录页面。");
                return(Redirect(ZConfig.GetConfigString("GatewayServer") + "/Login"));
            }
            else
            {
                //return View("授权参数错误!单击<a href='" + ZConfig.GetConfigString("GatewayServer") + "'>这里</a>返回登录页面。");
                //return View();
                return(Redirect(ZConfig.GetConfigString("GatewayServer") + "/Login"));
            }
        }
Ejemplo n.º 7
0
        public object Login(JObject request)
        {
            var UserCode = request.Value <string>("usercode");
            var Password = request.Value <string>("password");

            //用户名密码检查
            if (String.IsNullOrEmpty(UserCode) || String.IsNullOrEmpty(Password))
            {
                return new { status = "error", message = "用户名或密码不能为空!" }
            }
            ;

            //用户名密码验证
            var result = this.GetModel(ParamQuery.Instance()
                                       .AndWhere("UserCode", UserCode)
                                       .AndWhere("Password", Password)
                                       .AndWhere("IsEnable", true));

            if (result == null || String.IsNullOrEmpty(result.UserCode))
            {
                return new { status = "error", message = "用户名或密码不正确!" }
            }
            ;

            //调用框架中的登陆机制
            var loginer = new LoginerBase {
                UserCode = result.UserCode, UserName = result.UserName
            };

            var effectiveHours = ZConfig.GetConfigInt("LoginEffectiveHours");

            FormsAuth.SignIn(loginer.UserCode, loginer, 60 * effectiveHours);

            //登陆后处理
            this.UpdateUserLoginCountAndDate(UserCode); //更新用户登陆次数及时间
            this.AppendLoginHistory(request);           //添加登陆履历
            MmsService.LoginHandler(request);           //MMS系统的其它的业务处理

            //返回登陆成功
            return(new { status = "success", message = "登陆成功!" });
        }
Ejemplo n.º 8
0
        protected override void Seed(EfDbContext context)
        {
            try
            {
                //context.Set<CityArea>().AddRange(new List<CityArea> {
                //new CityArea { Name = "厦门", Pinyin = "xiamen", CityId = 0, IsEdit = false, Sort = 1, State = 1, CreateTime = DateTime.Now },
                //new CityArea { Name = "深圳", Pinyin = "shenzhen", CityId = 0, IsEdit = false, Sort = 1, State = 0, CreateTime = DateTime.Now },
                //new CityArea { Name = "福州", Pinyin = "fuzhou", CityId = 0, IsEdit = false, Sort = 1, State = 0, CreateTime = DateTime.Now },
                //new CityArea { Name = "泉州", Pinyin = "quanzhou", CityId = 0, IsEdit = false, Sort = 1, State = 0, CreateTime = DateTime.Now },
                //new CityArea { Name = "龙岩", Pinyin = "longyan", CityId = 0, IsEdit = false, Sort = 1, State = 0, CreateTime = DateTime.Now },
                //new CityArea { Name = "武汉", Pinyin = "wuhan", CityId = 0, IsEdit = false, Sort = 1, State = 0, CreateTime = DateTime.Now },
                //new CityArea { Name = "重庆", Pinyin = "chongqing", CityId = 0, IsEdit = false, Sort = 1, State = 0, CreateTime = DateTime.Now }});
                //context.SaveChanges();

                //ProductCategory productCategory = new ProductCategory { Name = "其他", CreateTime = DateTime.Now, State = DelStateEnum.正常 };
                //context.Set<ProductCategory>().Add(productCategory);
                //context.SaveChanges();
                //context.Set<Product>().Add(new Product { Name = "其他", ProductCategoryId = productCategory.Id, State = DelStateEnum.正常, CreateTime = DateTime.Now });
                //context.SaveChanges();

                var filePath = ZConfig.GetConfigString("InitSqlFile");
                if (string.IsNullOrEmpty(filePath))
                    throw new Exception("初始化数据文件不能为空!");
                if (filePath.StartsWith("~"))
                {
                    filePath = filePath.Substring(2);
                    filePath = $"{AppDomain.CurrentDomain.BaseDirectory}{filePath}";
                }
                var sql = File.ReadAllText(filePath);
                context.Database.ExecuteSqlCommand(sql);
                base.Seed(context);
            }
            catch (Exception ex)
            {
                NLogger.Error(ex);
            }

        }
Ejemplo n.º 9
0
    private void Load()
    {
        if (File.Exists(Path))
        {
#if USING_XML
            XmlSerializer ser = new XmlSerializer(typeof(ZConfig));
            using (Stream stream = File.OpenRead(Path))
            {
                ZConfig config = ser.Deserialize(stream) as ZConfig;
                _groups     = config.groups;
                _selections = config.selections;
            }
#else
            string json      = File.ReadAllText(Path);
            string groupJson = File.ReadAllText(GroupInfoPath);
            _groups     = JsonMapper.ToObject <List <GroupConfig> >(json);
            _selections = JsonMapper.ToObject <List <GroupSelection> >(groupJson);
#endif
        }

        if (_groups == null)
        {
            _groups = new List <GroupConfig>();
            GroupConfig group = new GroupConfig();
            group.Initialize();
            _groups.Add(group);
        }
        if (_selections == null)
        {
            _selections = new List <GroupSelection>();
            GroupSelection sel = new GroupSelection {
                name = "Default", desc = "Default group"
            };
            _selections.Add(sel);
        }
    }
Ejemplo n.º 10
0
        /// <summary>
        /// 主键key查找
        /// </summary>
        /// <param name="key">关键字</param>
        public static List <string> GetByKey(string key)
        {
            List <string> result = new List <string>();

            try
            {
                using (ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(GetConn.GetInstance().Conn()))
                {
                    string host   = ZConfig.GetConfigString("redispath");
                    var    server = redis.GetServer(host);

                    foreach (var item in server.Keys(pattern: key))
                    {
                        result.Add(item);
                    }
                    return(result);
                }
            }
            catch (Exception ex)
            {
                NLogger.Error(ex.ToString(), "Cache");
                return(new List <string>());
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 添加溢出值
        /// </summary>
        public void AddInventoryOver()
        {
            int Stockdate = ZConvert.StrToInt(ZConfig.GetConfigString("Stockdate"));


            DateTime Time = DateTime.Now;

            for (int z = 0; z < Stockdate; z++)
            {
                int t = z == 0 ? 0 : 1;
                Time = Time.AddDays(t);
                var InventoryHistory = InventoryOverHistoryBLL.GetInstance().TableNoTracking().Where(o => o.CreTime == Time.Date).FirstOrDefault();
                if (InventoryHistory == null)
                {
                    // 添加记录
                    InventoryOverHistory obj = new InventoryOverHistory();
                    obj.CreTime = Time.Date;
                    InventoryOverHistoryBLL.GetInstance().Add(obj);
                    var store                 = StoreBll.GetInstance().TableNoTracking().Where(o => o.State == (int)StoreState.线中).ToList();
                    var ProductCategory       = ProductCategoryBll.GetInstance().TableNoTracking().ToList();
                    var ProductCategoryidlist = ProductCategory.Select(o => o.Id).ToList();
                    ProductCategoryidlist.Add(0);

                    var Productlist   = ProductBll.GetInstance().TableNoTracking().Where(o => ProductCategoryidlist.Contains(o.ProductCategoryId) && o.State == ProductStateEnum.架).ToList();
                    var Productidlist = Productlist.Select(o => o.Id).ToList();
                    Productidlist.Add(0);
                    var StockSettinglist = StockSettingBLL.GetInstance().TableNoTracking().Where(o => Productidlist.Contains(o.ProductId)).ToList();

                    if (store != null && store.Count > 0)
                    {
                        foreach (var itemstore in store)
                        {
                            if (ProductCategory != null && ProductCategory.Count > 0)
                            {
                                foreach (var itemProductCategory in ProductCategory)
                                {
                                    #region MyRegion
                                    ////    //店铺   分类下  当天的总库存
                                    List <StockOutInView> StockOutInViewlist = InventoryBLL.GetInstance().GetStockTotal(itemstore.Id, itemProductCategory.Id, Time);

                                    List <Product> ProductList = Productlist.Where(o => o.ProductCategoryId == itemProductCategory.Id).ToList();
                                    if (ProductList != null)
                                    {
                                        foreach (var item in ProductList)
                                        {
                                            string sql = "  INSERT INTO [InventoryOver]  ([StoreId]   ,[ProductId]    ,[CreTime]   ";
                                            sql += "      ,[Time1] ,[Time2]  ,[Time3]  ,[Time4]  ,[Time5]   ,[Time6]   ,[Time7]  ,[Time8]  ,[Time9]  ,[Time10]  ,[Time11] ,[Time12]  ,[Time13]  ,[Time14] ,[Time15]  ";
                                            sql += "       ,[Time16]   ,[Time17]   ,[Time18]   ,[Time19]   ,[Time20]   ,[Time21]    ,[Time22]    ,[Time23]  ";
                                            sql += "       ,[Time24]  ,[Time25]   ,[Time26]  ,[Time27]   ,[Time28] ,[Time29] ,[Time30]  ,[Time31]    ,[Time32]  ,[Time33]  ";
                                            sql += "        ,[Time34]  ,[Time35]  ,[Time36]  ,[Time37]    ,[Time38]   ,[Time39]    ,[Time40]  ,[Time41]  ,[Time42] ,[Time43]   ,[Time44] ,[Time45]  ,[Time46]  ,[Time47] ,[Time48]  ";
                                            sql += "        )  ";
                                            sql += "      VALUES  ";
                                            sql += "         (" + itemstore.Id + "," + item.Id + ",'" + Time.Date + "'  ";
                                            int i = 1;
                                            #region 循环

                                            while (i < 49)
                                            {
                                                //分类下
                                                var EmployeeProductViewModellistitem = new List <StockOutInView>();


                                                #region MyRegion
                                                if (i == 1)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time1 != null).ToList();
                                                }
                                                else
                                                if (i == 2)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time2 != null).ToList();
                                                }
                                                else
                                                if (i == 3)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time3 != null).ToList();
                                                }

                                                else
                                                if (i == 4)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time4 != null).ToList();
                                                }

                                                else
                                                if (i == 5)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time5 != null).ToList();
                                                }

                                                else
                                                if (i == 6)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time6 != null).ToList();
                                                }
                                                else
                                                if (i == 7)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time7 != null).ToList();
                                                }
                                                else
                                                if (i == 8)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time8 != null).ToList();
                                                }


                                                else
                                                if (i == 9)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time9 != null).ToList();
                                                }


                                                else
                                                if (i == 10)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time10 != null).ToList();
                                                }


                                                else
                                                if (i == 11)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time11 != null).ToList();
                                                }

                                                else
                                                if (i == 12)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time12 != null).ToList();
                                                }


                                                else
                                                if (i == 13)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time13 != null).ToList();
                                                }



                                                else
                                                if (i == 14)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time14 != null).ToList();
                                                }


                                                else
                                                if (i == 15)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time15 != null).ToList();
                                                }


                                                else
                                                if (i == 16)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time16 != null).ToList();
                                                }

                                                else
                                                if (i == 17)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time17 != null).ToList();
                                                }

                                                else
                                                if (i == 18)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time18 != null).ToList();
                                                }

                                                else
                                                if (i == 19)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time19 != null).ToList();
                                                }

                                                else
                                                if (i == 20)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time20 != null).ToList();
                                                }

                                                else
                                                if (i == 21)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time21 != null).ToList();
                                                }


                                                else
                                                if (i == 22)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time22 != null).ToList();
                                                }


                                                else
                                                if (i == 23)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time23 != null).ToList();
                                                }

                                                else
                                                if (i == 24)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time24 != null).ToList();
                                                }


                                                else
                                                if (i == 25)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time25 != null).ToList();
                                                }


                                                else
                                                if (i == 26)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time26 != null).ToList();
                                                }

                                                else
                                                if (i == 27)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time27 != null).ToList();
                                                }



                                                else
                                                if (i == 28)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time28 != null).ToList();
                                                }


                                                else
                                                if (i == 29)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time29 != null).ToList();
                                                }

                                                else
                                                if (i == 30)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time30 != null).ToList();
                                                }


                                                else
                                                if (i == 31)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time31 != null).ToList();
                                                }



                                                else
                                                if (i == 32)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time32 != null).ToList();
                                                }


                                                else
                                                if (i == 33)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time33 != null).ToList();
                                                }

                                                else
                                                if (i == 34)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time34 != null).ToList();
                                                }

                                                else
                                                if (i == 35)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time35 != null).ToList();
                                                }

                                                else
                                                if (i == 36)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time36 != null).ToList();
                                                }


                                                else
                                                if (i == 37)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time37 != null).ToList();
                                                }
                                                else
                                                if (i == 38)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time38 != null).ToList();
                                                }
                                                else
                                                if (i == 39)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time39 != null).ToList();
                                                }
                                                else
                                                if (i == 40)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time40 != null).ToList();
                                                }

                                                else
                                                if (i == 41)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time41 != null).ToList();
                                                }

                                                else
                                                if (i == 42)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time42 != null).ToList();
                                                }
                                                else
                                                if (i == 43)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time43 != null).ToList();
                                                }
                                                else
                                                if (i == 44)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time44 != null).ToList();
                                                }

                                                else
                                                if (i == 45)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time45 != null).ToList();
                                                }


                                                else
                                                if (i == 46)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time46 != null).ToList();
                                                }

                                                else
                                                if (i == 47)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time47 != null).ToList();
                                                }

                                                else
                                                if (i == 48)
                                                {
                                                    EmployeeProductViewModellistitem = StockOutInViewlist.Where(o => o.PrdouctId == item.Id && o.Time48 != null).ToList();
                                                }



                                                #endregion


                                                //产品下的总库存
                                                int TotalInventory = EmployeeProductViewModellistitem.Select(o => o.EmployeeId).Distinct().Count();


                                                //百分比计算

                                                var StockSetting = StockSettinglist.Where(o => o.ProductId == item.Id).FirstOrDefault();
                                                if (StockSetting != null)
                                                {
                                                    TotalInventory = ZConvert.StrToInt(TotalInventory * ((StockSetting.OverflowValue - 100) / 100));
                                                }
                                                else
                                                {
                                                    TotalInventory = 0;
                                                }



                                                sql += "  ," + TotalInventory + " ";



                                                i++;
                                            }
                                            #endregion

                                            sql += "   )";

                                            ExecuteSqlCommand(sql, null);
                                        }
                                    }
                                    #endregion
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 12
0
        public static IDbContext Context(string connName)
        {
            var setting = ConfigurationManager.ConnectionStrings[connName];
            var db      = new DbContext().ConnectionString(setting.ConnectionString, Provider(setting.ProviderName));

            if (ZConfig.GetConfigString("SqlLog") == "1")
            {
                db.OnExecuting(x =>
                {
                    //if (APP.OnDbExecuting != null) APP.OnDbExecuting(x);
                    var sql = x.Command.CommandText;
                    for (int i = x.Command.Parameters.Count - 1; i >= 0; i--)
                    {
                        var item = x.Command.Parameters[i] as IDataParameter;
                        sql      = sql.Replace(item.ParameterName, string.Format("'{0}'", item.Value));
                    }
                    log.Debug(sql);
                });
            }

            db.OnError(e =>
            {
                var log = LogManager.GetLogger(connName);
                var ex  = e.Exception as SqlException;
                if (ex != null)
                {
                    var error = "";
                    switch (ex.Number)
                    {
                    case -2:
                        error = "超时时间已到。在操作完成之前超时时间已过或服务器未响应";
                        break;

                    case 4060:
                        // Invalid Database
                        error = "数据库不可用,请检查系统设置后重试!";
                        break;

                    case 18456:
                        // Login Failed
                        error = "登陆数据库失败!";
                        break;

                    case 547:
                        // ForeignKey Violation
                        error = "数据已经被引用,更新失败,请先删除引用数据并重试!";
                        break;

                    case 2627:
                        // Unique Index/Constriant Violation
                        error = "主键重复,更新失败!";
                        break;

                    case 2601:
                        // Unique Index/Constriant Violation
                        break;
                        // throw a general DAL Exception
                    }
                    if (!string.IsNullOrEmpty(error))
                    {
                        throw new Exception(error);
                    }

                    log.Error(ex.Message);
                }
            });

            return(db);
        }