Example #1
0
        public static List <SysEnumInfo> GetList()
        {
            SysEnum bll = new SysEnum();

            if (!enableCaching)
            {
                return(bll.GetList());
            }

            string             key  = "sysEnum_list";
            List <SysEnumInfo> data = (List <SysEnumInfo>)HttpRuntime.Cache[key];

            if (data == null)
            {
                data = bll.GetList();

                AggregateCacheDependency cd = DependencyFacade.GetSysEnumDependency();
                HttpRuntime.Cache.Add(key, data, cd, DateTime.Now.AddHours(sysEnumTimeout), Cache.NoSlidingExpiration, CacheItemPriority.High, null);
            }

            return(data);
        }
Example #2
0
        public static List <SysEnumInfo> GetList(string parentName)
        {
            SysEnum bll = new SysEnum();

            SqlParameter parm = new SqlParameter("@EnumName", parentName);

            if (!enableCaching)
            {
                return(bll.GetList(1, 100000, "and t2.EnumName = @EnumName", parm));
            }

            string             key  = "sysEnum_list_" + parentName + "";
            List <SysEnumInfo> data = (List <SysEnumInfo>)HttpRuntime.Cache[key];

            if (data == null)
            {
                data = bll.GetList(1, 100000, "and t2.EnumName = @EnumName", parm);

                AggregateCacheDependency cd = DependencyFacade.GetSysEnumDependency();
                HttpRuntime.Cache.Add(key, data, cd, DateTime.Now.AddHours(sysEnumTimeout), Cache.NoSlidingExpiration, CacheItemPriority.High, null);
            }

            return(data);
        }
        /// <summary>
        /// 绑定运输环节
        /// </summary>
        private void BindTranNode()
        {
            SysEnum seBll      = new SysEnum();
            var     list       = seBll.GetList("and t2.EnumCode = 'SendReceiveType' ");
            string  itemAppend = "";

            foreach (var item in list)
            {
                itemAppend += "{\"id\":\"" + item.EnumCode + "\",\"text\":\"" + item.EnumValue + "\"},";
            }
            itemAppend  = itemAppend.Trim(',');
            htmlAppend += "<div id=\"myDataForTranNode\" style=\"display:none;\">[";

            htmlAppend += itemAppend;

            htmlAppend += "]</div>";
        }
        /// <summary>
        /// 获取模板参数并绑定到前端控件
        /// </summary>
        private void BindTemplateParams()
        {
            htmlAppend += "<div id=\"myDataForSmsParam\" style=\"display:none;\">[";

            SysEnum seBll      = new SysEnum();
            string  itemAppend = "";
            var     list       = seBll.GetList("and t2.EnumCode = 'SmsParam'", null);

            if (list != null && list.Count > 0)
            {
                foreach (var item in list)
                {
                    itemAppend += "{\"EnumCode\":\"" + item.EnumCode + "\",\"EnumValue\":\"" + item.EnumValue + "\",\"ParamsValue\":\"\",\"status\":\"否\"},";
                }

                itemAppend  = itemAppend.Trim(',');
                htmlAppend += itemAppend;
            }

            htmlAppend += "]</div>";
        }
        /// <summary>
        /// 新增PDA扫描数据
        /// </summary>
        /// <param name="opType">操作类型</param>
        /// <param name="barCode">单号条码</param>
        /// <param name="scanTime">扫描时间</param>
        /// <param name="userName">用户名</param>
        /// <returns>返回:包含“成功”,则调用成功,否则返回调用失败原因</returns>
        public string Insert(string opType, string barCode, DateTime scanTime, string userName)
        {
            #region 参数合法性检查

            if (string.IsNullOrEmpty(opType))
            {
                return("操作类型不能为空");
            }
            opType = opType.Trim();
            if (string.IsNullOrEmpty(barCode))
            {
                return("单号条码不能为空");
            }
            barCode = barCode.Trim();
            //if (barCode.Length != 13)
            //{
            //    return "单号条码不正确";
            //}

            if (scanTime == DateTime.MinValue)
            {
                return("扫描时间格式不正确");
            }

            if (string.IsNullOrEmpty(userName))
            {
                return("用户不能为空");
            }

            #endregion

            try
            {
                MembershipUser user = Membership.GetUser(userName);
                if (user == null)
                {
                    return("不存在用户:" + userName);
                }

                SysEnum seBll  = new SysEnum();
                var     seList = seBll.GetList("and t2.EnumCode = 'SendReceiveType'", null);
                if (seList == null || seList.Count == 0)
                {
                    return("服务端的操作类型未设定,请先完成设定");
                }

                var firstModel  = seList.OrderBy(m => m.Sort).First();
                var currSeModel = seList.Find(m => m.EnumValue.Trim() == opType);
                if (currSeModel == null)
                {
                    return("当前操作类型“" + opType + "”不存在");
                }

                object nextNodeId  = Guid.Empty;
                var    nextSeModel = seList.FindAll(m => m.Sort > currSeModel.Sort).OrderBy(m => m.Sort).FirstOrDefault();
                if (nextSeModel == null)
                {
                    nextNodeId = currSeModel.Id;
                }
                else
                {
                    nextNodeId = nextSeModel.Id;
                }

                bool isOsdExists = false;

                PDAOrderScanInfo currOsModel = new PDAOrderScanInfo();
                currOsModel.OrderCode       = barCode;
                currOsModel.CurrNodeId      = currSeModel.Id;
                currOsModel.NextNodeId      = nextNodeId;
                currOsModel.IsFinish        = false;
                currOsModel.LastUpdatedDate = DateTime.Now;

                PDAOrderScanDetailInfo currOsdModel = new PDAOrderScanDetailInfo();
                currOsdModel.OrderCode       = barCode;
                currOsdModel.CurrNodeId      = currOsModel.CurrNodeId;
                currOsdModel.ScanTime        = scanTime;
                currOsdModel.UserId          = user.ProviderUserKey;
                currOsdModel.LastUpdatedDate = currOsModel.LastUpdatedDate;

                Order              oBll   = new Order();
                PDAOrderScan       osBll  = new PDAOrderScan();
                PDAOrderScanDetail osdBll = new PDAOrderScanDetail();
                TyUser             tyuBll = new TyUser();
                SmsSend            smsBll = new SmsSend();

                string     sRemark  = "";
                TyUserInfo tyuModel = tyuBll.GetModelByUser(user.UserName);
                if (tyuModel != null && !string.IsNullOrWhiteSpace(tyuModel.OrganizationName))
                {
                    sRemark = string.Format(currSeModel.Remark, tyuModel.OrganizationName);
                }
                else
                {
                    sRemark = currSeModel.Remark.Replace(@"{0}", "");
                }
                sRemark = currSeModel.EnumValue + ":" + sRemark;

                currOsdModel.Remark = sRemark;

                if (opType == "干线发运" || opType == "干线到达")
                {
                    var orders = oBll.GetOrderByCarcode(barCode);
                    if (orders == null || orders.Count() == 0)
                    {
                        return("操作类型:" + barCode + "找不到订单号,有错误");
                    }

                    foreach (var currOrderCode in orders)
                    {
                        currOsModel.OrderCode  = currOrderCode;
                        currOsdModel.OrderCode = currOrderCode;

                        var oldOsdList = osdBll.GetList(currOrderCode);
                        if (oldOsdList != null)
                        {
                            isOsdExists = oldOsdList.Exists(m => m.CurrNodeId.Equals(currSeModel.Id));
                        }

                        if (isOsdExists)
                        {
                            return("订单号:" + currOrderCode + " 操作类型:" + opType + "已存在,不能重复提交");
                        }

                        //发短信
                        SmsSendInfo ssiModel = new SmsSendInfo();
                        ssiModel.OrderCode    = currOrderCode;
                        ssiModel.TranNode     = currSeModel.EnumCode;
                        ssiModel.TranNodeText = currSeModel.EnumValue;

                        using (TransactionScope scope = new TransactionScope())
                        {
                            if (osBll.GetModel(currOrderCode) == null)
                            {
                                osBll.Insert(currOsModel);
                            }
                            else
                            {
                                osBll.Update(currOsModel);
                            }

                            osdBll.Insert(currOsdModel);

                            scope.Complete();
                        }

                        smsBll.InsertByStrategy(ssiModel);
                    }
                }

                else if (currSeModel.Sort == firstModel.Sort)
                {
                    var oldOsModel = osBll.GetModel(barCode);
                    if (oldOsModel != null)
                    {
                        return("订单号:" + barCode + ",操作类型:" + opType + "已存在,不能重复提交");
                    }

                    SmsSendInfo ssiModel = new SmsSendInfo();
                    ssiModel.OrderCode    = barCode;
                    ssiModel.TranNode     = currSeModel.EnumCode;
                    ssiModel.TranNodeText = currSeModel.EnumValue;

                    using (TransactionScope scope = new TransactionScope())
                    {
                        osBll.Insert(currOsModel);
                        osdBll.Insert(currOsdModel);

                        scope.Complete();
                    }

                    smsBll.InsertByStrategy(ssiModel);
                }
                else
                {
                    var oldOsModel = osBll.GetModel(barCode);
                    if (oldOsModel == null)
                    {
                        return("订单号:" + barCode + ",操作类型:" + opType + "未取货,有错误");
                    }

                    var oldOsdList = osdBll.GetList(barCode);
                    if (oldOsdList != null)
                    {
                        isOsdExists = oldOsdList.Exists(m => m.CurrNodeId.Equals(currSeModel.Id));

                        currOsModel.IsFinish = oldOsdList.Count == 5;
                    }

                    if (currOsModel.IsFinish)
                    {
                        return("订单号:" + barCode + "已完成所有操作");
                    }

                    if (isOsdExists)
                    {
                        return("订单号:" + barCode + ",操作类型:" + opType + "已存在,不能重复提交");
                    }

                    SmsSendInfo ssiModel = new SmsSendInfo();
                    ssiModel.OrderCode    = barCode;
                    ssiModel.TranNode     = currSeModel.EnumCode;
                    ssiModel.TranNodeText = currSeModel.EnumValue;

                    using (TransactionScope scope = new TransactionScope())
                    {
                        osBll.Update(currOsModel);

                        osdBll.Insert(currOsdModel);

                        scope.Complete();
                    }

                    smsBll.InsertByStrategy(ssiModel);
                }

                Console.WriteLine("request: opType:{0},barCode:{1},scanTime:{3},user:{2}", opType, barCode, scanTime, userName);

                return("保存成功");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
        /// <summary>
        /// 批量提交PDA扫描数据
        /// </summary>
        /// <param name="dt">应包含opType、barCode、scanTime、userName等列</param>
        /// <returns>返回:包含“成功”,则调用成功,否则返回调用失败原因</returns>
        public string InsertByBatch(DataTable dt)
        {
            if (dt == null || dt.Rows.Count == 0)
            {
                return("无任何可保存的数据");
            }

            string[] colNames = { "opType", "barCode", "scanTime", "userName" };

            DataColumnCollection cols = dt.Columns;

            foreach (DataColumn col in cols)
            {
                if (!colNames.Contains(col.ColumnName))
                {
                    return("检测到提交的数据集中未包含" + col.ColumnName + "列");
                }
            }

            DataRowCollection rows = dt.Rows;

            List <PDAOrderScanDetailInfo> osdList = new List <PDAOrderScanDetailInfo>();

            //定义非重复的用户名、用户ID
            Dictionary <string, object> dicUser = new Dictionary <string, object>();

            try
            {
                SysEnum seBll  = new SysEnum();
                var     seList = seBll.GetList("and t2.EnumCode = 'SendReceiveType'", null);
                if (seList == null || seList.Count == 0)
                {
                    return("服务端的操作类型未设定,请先完成设定");
                }
                var firstModel = seList.OrderBy(m => m.Sort).First();

                foreach (DataRow row in rows)
                {
                    string opType = "";
                    if (row["opType"] != DBNull.Value)
                    {
                        opType = row["opType"].ToString();
                    }
                    else
                    {
                        return("操作类型不能为空");
                    }

                    var seModel = seList.Find(m => m.EnumValue.Trim() == opType.Trim());
                    if (seModel == null)
                    {
                        return("不存在操作类型:" + opType);
                    }

                    string barCode = "";
                    if (row["barCode"] != DBNull.Value)
                    {
                        barCode = row["barCode"].ToString();
                    }
                    DateTime scanTime = DateTime.MinValue;
                    if (row["scanTime"] != DBNull.Value)
                    {
                        DateTime.TryParse(row["scanTime"].ToString(), out scanTime);
                    }
                    if (scanTime == DateTime.MinValue)
                    {
                        return("数据集中包含不合法数据:scanTime值格式不正确");
                    }

                    string userName = "";
                    if (row["userName"] != DBNull.Value)
                    {
                        userName = row["userName"].ToString();
                    }
                    if (string.IsNullOrEmpty(userName))
                    {
                        return("数据集中包含用户名为空");
                    }

                    if (!dicUser.ContainsKey(userName))
                    {
                        dicUser.Add(userName, Guid.Empty);
                    }

                    osdList.Add(new PDAOrderScanDetailInfo {
                        OrderCode = barCode, CurrNodeId = seModel.Id, ScanTime = scanTime, Remark = seModel.Remark, Sort = seModel.Sort, LastUpdatedDate = DateTime.Now, UserName = userName, SysEnumValue = opType
                    });
                }

                TyUser tyuBll = new TyUser();

                foreach (KeyValuePair <string, object> kvp in dicUser)
                {
                    MembershipUser user = Membership.GetUser(kvp.Key, false);
                    if (user == null)
                    {
                        return("不存在用户:" + kvp.Key);
                    }

                    TyUserInfo tyuModel = tyuBll.GetModelByUser(user.UserName);

                    var currList = osdList.FindAll(m => m.UserName == kvp.Key);
                    foreach (var item in currList)
                    {
                        item.UserId = user.ProviderUserKey;

                        string sRemark = "";
                        if (tyuModel != null && !string.IsNullOrWhiteSpace(tyuModel.OrganizationName))
                        {
                            sRemark = string.Format(item.Remark, tyuModel.OrganizationName);
                        }
                        else
                        {
                            sRemark = item.Remark.Replace(@"{0}", "");
                        }
                        sRemark = item.SysEnumValue + ":" + sRemark;

                        item.Remark = sRemark;
                    }
                }

                PDAOrderScan       osBll  = new PDAOrderScan();
                PDAOrderScanDetail osdBll = new PDAOrderScanDetail();
                Order   oBll   = new Order();
                SmsSend smsBll = new SmsSend();

                var q = osdList.OrderBy(m => m.Sort);
                foreach (var item in q)
                {
                    object nextNodeId  = Guid.Empty;
                    var    currSeModel = seList.Find(m => m.EnumValue.Trim() == item.SysEnumValue);
                    var    nextSeModel = seList.FindAll(m => m.Sort > item.Sort).OrderBy(m => m.Sort).FirstOrDefault();
                    if (nextSeModel == null)
                    {
                        nextNodeId = item.CurrNodeId;
                    }
                    else
                    {
                        nextNodeId = nextSeModel.Id;
                    }
                    var  lastSeModel = seList.OrderByDescending(m => m.Sort).First();
                    bool isFinish    = lastSeModel.EnumValue.Trim() == item.SysEnumValue;

                    bool isOsdExists = false;

                    PDAOrderScanInfo currOsModel = new PDAOrderScanInfo();
                    currOsModel.OrderCode       = item.OrderCode;
                    currOsModel.CurrNodeId      = item.CurrNodeId;
                    currOsModel.NextNodeId      = nextNodeId;
                    currOsModel.IsFinish        = isFinish;
                    currOsModel.LastUpdatedDate = DateTime.Now;

                    PDAOrderScanDetailInfo currOsdModel = new PDAOrderScanDetailInfo();
                    currOsdModel.OrderCode       = item.OrderCode;
                    currOsdModel.CurrNodeId      = item.CurrNodeId;
                    currOsdModel.ScanTime        = item.ScanTime;
                    currOsdModel.UserId          = item.UserId;
                    currOsdModel.LastUpdatedDate = currOsModel.LastUpdatedDate;
                    currOsdModel.Remark          = item.Remark;

                    if (item.SysEnumValue == "干线发运" || item.SysEnumValue == "干线到达")
                    {
                        var orders = oBll.GetOrderByCarcode(item.OrderCode);
                        if (orders == null || orders.Count() == 0)
                        {
                            return("操作类型:" + item.SysEnumValue + "找不到订单号,有错误");
                        }

                        foreach (var currOrderCode in orders)
                        {
                            currOsModel.OrderCode  = currOrderCode;
                            currOsdModel.OrderCode = currOrderCode;

                            var oldOsdList = osdBll.GetList(currOrderCode);
                            if (oldOsdList != null)
                            {
                                isOsdExists = oldOsdList.Exists(m => m.CurrNodeId.Equals(item.CurrNodeId));
                            }

                            if (!isOsdExists)
                            {
                                SmsSendInfo ssiModel = new SmsSendInfo();
                                ssiModel.OrderCode    = currOrderCode;
                                ssiModel.TranNode     = currSeModel.EnumCode;
                                ssiModel.TranNodeText = currSeModel.EnumValue;

                                using (TransactionScope scope = new TransactionScope())
                                {
                                    if (osBll.GetModel(currOrderCode) == null)
                                    {
                                        osBll.Insert(currOsModel);
                                    }
                                    else
                                    {
                                        osBll.Update(currOsModel);
                                    }

                                    osdBll.Insert(currOsdModel);

                                    scope.Complete();
                                }

                                smsBll.InsertByStrategy(ssiModel);
                            }
                        }
                    }
                    else if (item.Sort == firstModel.Sort)
                    {
                        var oldOsModel = osBll.GetModel(item.OrderCode);
                        if (oldOsModel == null)
                        {
                            SmsSendInfo ssiModel = new SmsSendInfo();
                            ssiModel.OrderCode    = item.OrderCode;
                            ssiModel.TranNode     = currSeModel.EnumCode;
                            ssiModel.TranNodeText = currSeModel.EnumValue;

                            using (TransactionScope scope = new TransactionScope())
                            {
                                osBll.Insert(currOsModel);
                                osdBll.Insert(currOsdModel);

                                scope.Complete();
                            }

                            smsBll.InsertByStrategy(ssiModel);
                        }
                    }
                    else
                    {
                        var oldOsModel = osBll.GetModel(item.OrderCode);
                        if (oldOsModel == null)
                        {
                            return("订单号:" + item.OrderCode + ",操作类型:" + item.SysEnumValue + "未取货,有错误");
                        }

                        var oldOsdList = osdBll.GetList(item.OrderCode);
                        if (oldOsdList != null)
                        {
                            isOsdExists = oldOsdList.Exists(m => m.CurrNodeId.Equals(item.CurrNodeId));

                            currOsModel.IsFinish = oldOsdList.Count == 5;
                        }

                        if (currOsModel.IsFinish)
                        {
                            continue;
                        }

                        if (!isOsdExists)
                        {
                            SmsSendInfo ssiModel = new SmsSendInfo();
                            ssiModel.OrderCode    = currOsModel.OrderCode;
                            ssiModel.TranNode     = currSeModel.EnumCode;
                            ssiModel.TranNodeText = currSeModel.EnumValue;

                            using (TransactionScope scope = new TransactionScope())
                            {
                                osBll.Update(currOsModel);

                                osdBll.Insert(currOsdModel);

                                scope.Complete();
                            }

                            smsBll.InsertByStrategy(ssiModel);
                        }
                    }

                    Console.WriteLine("request: opType:{0},barCode:{1},scanTime:{3},user:{2}", item.SysEnumValue, item.OrderCode, item.ScanTime, item.UserName);
                }

                return("保存成功");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
        private static void WorkProcessor()
        {
            Random   rnd         = new Random();
            bool     isPassNight = false;             //是否已到深夜0点
            DateTime startTime   = DateTime.MinValue; //开始时间
            DateTime endTime     = DateTime.MinValue; //结束时间

            try
            {
                TyUser  bll   = new TyUser();
                SysEnum seBll = new SysEnum();

                while (true)
                {
                    if (!isPassNight)
                    {
                        if (DateTime.Now.Hour == 0)
                        {
                            isPassNight = true;
                        }
                    }

                    List <SysEnumInfo> seList     = seBll.GetList("and t2.EnumCode = 'UserProcessor'");
                    double             runTimeout = 0;
                    double.TryParse(seList.Find(m => m.EnumCode == "RunTimeout").EnumValue.Trim(), out runTimeout);
                    bool isOff = seList.Find(m => m.EnumCode == "On/Off").EnumValue.Trim().ToLower() == "off" ? true : false;
                    if (isOff)
                    {
                        Thread.Sleep(5000);
                        continue;
                    }

                    string sStartTime = seList.Find(m => m.EnumCode.Trim() == "StartTime").EnumValue;
                    string sEndTime   = seList.Find(m => m.EnumCode.Trim() == "EndTime").EnumValue;

                    if ((sStartTime.IndexOf(':') != -1) && (sEndTime.IndexOf(':') != -1))
                    {
                        DateTime currTime = DateTime.Now;
                        sStartTime = string.Format("{0} {1}", currTime.ToString("yyyy-MM-dd"), sStartTime);
                        sEndTime   = string.Format("{0} {1}", currTime.ToString("yyyy-MM-dd"), sEndTime);

                        DateTime.TryParse(sStartTime, out startTime);
                        DateTime.TryParse(sEndTime, out endTime);
                        DateTime maxTime = DateTime.Parse(string.Format("{0} {1}", currTime.ToString("yyyy-MM-dd"), "23:59:59"));

                        if ((startTime != DateTime.MinValue) && (endTime != DateTime.MinValue))
                        {
                            if (currTime >= endTime || currTime <= startTime)
                            {
                                Thread.Sleep(5000);
                                continue;
                            }
                        }
                    }

                    #region  步用户表开始

                    TyUser tyuserBll = new TyUser();

                    List <string>     newUsers = new List <string>();
                    string[]          oldUsers = tyuserBll.GetTyUsers();
                    List <TyUserInfo> userList = tyuserBll.GetList();

                    foreach (string userName in oldUsers)
                    {
                        if (!userList.Exists(m => m.UserName == userName))
                        {
                            newUsers.Add(userName);
                        }
                    }

                    if (newUsers.Count > 0)
                    {
                        using (TransactionScope scope = new TransactionScope())
                        {
                            foreach (string userName in newUsers)
                            {
                                string psw = (rnd.NextDouble() * Int32.MaxValue).ToString().PadLeft(6, '0').Substring(0, 6);
                                Membership.CreateUser(userName, psw, "" + userName + "@tygaweb.com");
                                Roles.AddUserToRole(userName, "Users");
                                tyuserBll.Insert(new TyUserInfo {
                                    UserName = userName, Password = psw, IsEnable = true, LastUpdatedDate = DateTime.Now
                                });
                            }

                            scope.Complete();
                        }
                    }

                    #endregion

                    if (runTimeout > 0)
                    {
                        TimeSpan ts = DateTime.Now.AddMinutes(runTimeout) - DateTime.Now;
                        Thread.Sleep(ts);
                    }
                    else
                    {
                        Thread.Sleep(5000);
                    }
                }
            }
            catch (Exception ex)
            {
                WriteLog log = new WriteLog();
                log.Write(ex.Message);
            }
        }