/// <summary>
        /// 生成指定实体文件
        /// </summary>
        /// <param name="TableInfo">表信息集合</param>
        /// <param name="s">文件输出流</param>
        public static void QuickCode(IEnumerable <dynamic> TableInfo, Stream os)
        {
            var    group        = TableInfo.GroupBy(e => e.TableName);
            string templatePath = FileHelper.GetAbsolutePath("/Template/Entity.vm");

            using (ZipOutputStream s = new ZipOutputStream(os))
            {
                foreach (var columnList in group)
                {
                    var newColumnList = columnList.OrderBy(e => e.FieldSequence).ToList();

                    string    tableName     = newColumnList[0].TableName;
                    string    tableNameDesc = newColumnList[0].TableNameDesc;
                    string    entityName    = tableName.Substring(tableName.IndexOf("_") + 1).Replace("_", "");
                    Hashtable htArgs        = new Hashtable();
                    htArgs["ColumnList"]    = newColumnList;
                    htArgs["TableName"]     = tableName;
                    htArgs["EntityName"]    = entityName;
                    htArgs["TableNameDesc"] = tableNameDesc;
                    htArgs["ConvertType"]   = new ConvertType();
                    var      codeText = FileGen.GetFileText(templatePath, htArgs).ToString();
                    byte[]   m_buffer = Encoding.UTF8.GetBytes(codeText);
                    ZipEntry entry    = new ZipEntry(entityName + ".cs");
                    entry.DateTime = DateTime.Now;
                    s.PutNextEntry(entry);
                    s.Write(m_buffer, 0, m_buffer.Count());
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// 根据读取的表信息导出HTML文档
        /// </summary>
        /// <param name="list">表信息集合</param>
        /// <param name="strExportPath">导出路径</param>
        public static void CreateHtml(List <TableInfo> list, string strExportPath, string strDBName)
        {
            Hashtable param = null;
            string    tPath = AppDomain.CurrentDomain.BaseDirectory + @"Common\html.vm";

            param = new Hashtable();
            param.Add("TableList", list);
            param.Add("DBName", strDBName);
            FileGen.GetFile(tPath, param, strExportPath);
        }
Beispiel #3
0
        public void Init(string inputFileName, string fileName)
        {
            _fileName = fileName;
            className = NameResolver.ToPascalCase(Path.GetFileNameWithoutExtension(inputFileName));
            _scopes   = new List <Scope>
            {
                new Scope()
            };

            _dependencies     = new HashSet <string>();
            _dependenciesDict = new Dictionary <string, string>();

            fileGen = new FileGen(_fileName);

            typeGen = fileGen.Class();

            codeGen = typeGen.GetCodeGen();
        }
Beispiel #4
0
        /// <summary>
        /// 生成表的SQL
        /// </summary>
        private Result GenSQL(TableInfo t)
        {
            Hashtable param = null;

            string tPath = GetTemplatePath(t);

            try
            {
                param = new Hashtable();
                param.Add("T", t);
                param.Add("V", softVerion);
                FileGen.GetFile(tPath, param, txtOutPutPath.Text.Trim() + @"\" + t.Code + ".sql");
                return(new Result(Level.Success, t.Code));
            }
            catch (Exception ex)
            {
                return(new Result(Level.Execption, ex.Message));
            }
        }
Beispiel #5
0
        /// <summary>
        /// 解析快递信息
        /// </summary>
        /// <param name="json">服务器返回json数据</param>
        /// <param name="ExpressInfo">快递单号信息</param>
        /// <returns>是否成功</returns>
        private static bool ParseExpressInfo(string json, ExpressInfo ExpressInfo)
        {
            try
            {
                JObject jo    = JObject.Parse(json);
                JToken  value = null;

                //快递单当前的状态
                int state = -1;
                if (jo.TryGetValue("state", out value))
                {
                    if (!Int32.TryParse(value.ToString(), out state))
                    {
                        return(false);
                    }
                }

                //查询结果状态
                if (jo.TryGetValue("status", out value))
                {
                    if (value.ToString().Equals("200"))
                    {
                        //快递单号
                        string ExpressNo = string.Empty;

                        if (jo.TryGetValue("nu", out value))
                        {
                            ExpressNo = value.ToString();
                        }
                        if (string.IsNullOrEmpty(ExpressNo))
                        {
                            return(false);
                        }
                        if (state == 3 || state == 4 || state == 6)
                        {
                            //3:签收,收件人已签收;4:退签,即货物由于用户拒签、超区等原因退回,而且发件人已经签收;
                            //6:退回,货物正处于退回发件人的途中;
                            //快递周期已结束,则将当前快递单号移入到历史表中,不在产生任何短信信息
                            SaveExpressHistoryInfo(ExpressNo, state);
                        }

                        if (jo.TryGetValue("data", out value))
                        {
                            List <ExpressProcessDetail> list = JsonConvert.DeserializeObject <List <ExpressProcessDetail> >(value.ToString());
                            if (list != null && list.Count > 0)
                            {
                                list.Reverse();
                                int length                = list.Count;
                                int maxGroupNo            = GetExpressDetailMaxGroupNo(ExpressNo);
                                ExpressProcessDetail item = null;
                                for (int i = maxGroupNo; i < length; i++)
                                {
                                    item           = list[i];
                                    item.ExpressNo = ExpressNo;
                                    item.GroupNo   = i + 1;
                                    //相对准确,但不是完全准确的一个状态
                                    item.State = GetExpressDetailState(item, maxGroupNo == 0 && i == 0);
                                }


                                //产生了新的快递进度信息,准备发送短信通知
                                if (length > maxGroupNo)
                                {
                                    var saveList = list.Where(e => e.GroupNo > maxGroupNo).ToList();
                                    //保存新的进度信息
                                    SQLHelper.BatchSaveData(saveList, "p_ExpressProcessDetail");
                                    //插入短信通知,等待任务轮训时发送短信
                                    var      lastDetail = list[length - 1];
                                    string[] Receivers  = ExpressInfo.Receiver.Split(new char[] { ',' });
                                    foreach (string Receiver in Receivers)
                                    {
                                        if (RegexHelper.IsMobile(Receiver))
                                        {
                                            //短信最大长度为40字节,20汉字
                                            string content = string.Format("亲快件*{0}!{1}", ExpressNo.Substring(ExpressNo.Length - 4 > 0 ? ExpressNo.Length - 4 : 0), lastDetail.Context.Replace(" ", ""));
                                            //由于短信接口只有20条免费短信的限制,所以改为邮件提醒
                                            //MessageHelper.AddMessage(Receiver, content.FormatStringLength(40), "");
                                        }
                                        else if (RegexHelper.IsEmail(Receiver))
                                        {
                                            bool isAddMessage = false;
                                            //修改消息添加规则,有变更就添加可能一天收很多邮件,让人厌烦
                                            //现在规则修改为快递状态为1:揽件 3:签收 5:派件 这几种状态必发
                                            //然后每天其它状态的最多发送一条
                                            var importantDetail = saveList.Where(e => e.State == 1 || e.State == 3 || e.State == 5);
                                            if (importantDetail != null && importantDetail.Count() > 0)
                                            {
                                                isAddMessage = true;
                                            }
                                            else
                                            {
                                                if (!HasSendMessage(ExpressInfo.ExpressGUID))
                                                {
                                                    isAddMessage = true;
                                                }
                                            }
                                            if (isAddMessage)
                                            {
                                                Hashtable             ht = new Hashtable();
                                                List <ExpressCompany> listExpressCompany = GetAllExpressCompany();
                                                string ExpressCompany = listExpressCompany.FirstOrDefault(e => e.CompanyCode == ExpressInfo.ExpressCompanyCode).CompanyName;
                                                ht["TotalTime"]      = lastDetail.Time.GetDayAndHours(list[0].Time);
                                                ht["T"]              = list;
                                                ht["V"]              = ExpressInfo;
                                                ht["ExpressCompany"] = ExpressCompany;
                                                ht["Status"]         = state;
                                                string content = FileGen.GetFileText(FileHelper.GetAbsolutePath("Temples/ExpressDetail.vm"), ht).ToString();
                                                //添加邮件消息提醒
                                                MessageHelper.AddMessage(Receiver, content, "快递进度变更", "快递进度", ExpressInfo.ExpressGUID, MessageType.EMAIL);
                                            }
                                        }
                                        else
                                        {
                                            TaskLog.ExpressProgressLogInfo.WriteLogE(string.Format("快递单号“{0}”的接收人“{1}”无法识别,不为邮件/手机号任何一种,请检查!", ExpressInfo.ExpressNo, ExpressInfo.Receiver));
                                        }
                                    }
                                }
                            }
                        }
                        return(true);
                    }
                }
                return(false);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #6
0
        /// <summary>
        /// 解析快递信息
        /// </summary>
        /// <param name="json">服务器返回json数据</param>
        /// <param name="ExpressInfo">快递单号信息</param>
        /// <returns>是否成功</returns>
        private static bool ParseExpressInfo(string json, ExpressInfo ExpressInfo)
        {
            try
            {
                JObject jo    = JObject.Parse(json);
                JToken  value = null;

                //快递单当前的状态
                string state = string.Empty;
                if (jo.TryGetValue("state", out value))
                {
                    state = value.ToString();
                }

                //查询结果状态
                if (jo.TryGetValue("status", out value))
                {
                    if (value.ToString().Equals("200"))
                    {
                        //快递单号
                        string ExpressNo = string.Empty;

                        if (jo.TryGetValue("nu", out value))
                        {
                            ExpressNo = value.ToString();
                        }
                        if (string.IsNullOrEmpty(ExpressNo))
                        {
                            return(false);
                        }
                        if (state.Equals("3") || state.Equals("4") || state.Equals("6"))
                        {
                            //3:签收,收件人已签收;4:退签,即货物由于用户拒签、超区等原因退回,而且发件人已经签收;
                            //6:退回,货物正处于退回发件人的途中;
                            //快递周期已结束,则将当前快递单号移入到历史表中,不在产生任何短信信息
                            SaveExpressHistoryInfo(ExpressNo, state);
                        }

                        if (jo.TryGetValue("data", out value))
                        {
                            List <ExpressProcessDetail> list = JsonConvert.DeserializeObject <List <ExpressProcessDetail> >(value.ToString());
                            if (list != null && list.Count > 0)
                            {
                                list.Reverse();
                                int length                = list.Count;
                                int maxGroupNo            = GetExpressDetailMaxGroupNo(ExpressNo);
                                ExpressProcessDetail item = null;
                                for (int i = maxGroupNo; i < length; i++)
                                {
                                    item           = list[i];
                                    item.ExpressNo = ExpressNo;
                                    item.GroupNo   = i + 1;
                                }


                                //产生了新的快递进度信息,准备发送短信通知
                                if (length > maxGroupNo)
                                {
                                    //保存新的进度信息
                                    SQLHelper.BatchSaveData(list.Where(e => e.GroupNo > maxGroupNo).ToList(), "p_ExpressProcessDetail");
                                    //插入短信通知,等待任务轮训时发送短信
                                    var      lastDetail = list[length - 1];
                                    string[] Receivers  = ExpressInfo.Receiver.Split(new char[] { ',' });
                                    foreach (string Receiver in Receivers)
                                    {
                                        if (RegexHelper.IsMobile(Receiver))
                                        {
                                            //短信最大长度为40字节,20汉字
                                            string content = string.Format("亲快件*{0}!{1}", ExpressNo.Substring(ExpressNo.Length - 4 > 0 ? ExpressNo.Length - 4 : 0), lastDetail.Context.Replace(" ", ""));
                                            //由于短信接口只有20条免费短信的限制,所以改为邮件提醒
                                            //MessageHelper.AddMessage(Receiver, content.FormatStringLength(40), "");
                                        }
                                        else if (RegexHelper.IsEmail(Receiver))
                                        {
                                            Hashtable             ht = new Hashtable();
                                            List <ExpressCompany> listExpressCompany = GetAllExpressCompany();
                                            string ExpressCompany = listExpressCompany.FirstOrDefault(e => e.CompanyCode == ExpressInfo.ExpressCompanyCode).CompanyName;
                                            ht["TotalTime"]      = lastDetail.Time.GetDayAndHours(list[0].Time);
                                            ht["T"]              = list;
                                            ht["V"]              = ExpressInfo;
                                            ht["ExpressCompany"] = ExpressCompany;
                                            ht["Status"]         = state;
                                            string content = FileGen.GetFileText(FileHelper.GetAbsolutePath("Temples/ExpressDetail.vm"), ht).ToString();
                                            //添加邮件消息提醒
                                            MessageHelper.AddMessage(Receiver, content, "快递进度变更", MessageType.EMAIL);
                                        }
                                    }
                                }
                            }
                        }
                        return(true);
                    }
                }
                return(false);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }