示例#1
0
        public List <SmsMobileModel> GetUnknowList(string eprid, string userid, string y, string m, string d)
        {
            List <SmsMobileModel> list = new List <SmsMobileModel>();

            try
            {
                DateTime dt        = DateTime.Now;
                string   begintime = y + "-" + m + "-" + d;   //开始时间
                string   endtime   = begintime + " 23:59:59"; //结果时间
                object[] obj       = { begintime, endtime, eprid, userid };
                string   sql       = string.Format("select Id, [CLIENTMSGID] from TBL_SMS_MOBILES where    SendTime SENDTIME '{0}' and '{1}' and EprId={2}  and UserId='{3}' and [RESULT]=1 and [STATUS]=3 order by Id ", obj);
                using (MySqlDataReader sdr = MySqlHelper.ExecuteReader(MySqlHelper.ConnectionstringLocalTransaction, CommandType.Text, sql, null))
                {
                    while (sdr.Read())
                    {
                        SmsMobileModel smm = new SmsMobileModel();
                        smm.id          = sdr.GetInt32(0);
                        smm.clientMsgId = sdr.GetString(1);
                        list.Add(smm);
                    }
                }
                MyDelegateFunc.WriteFmLog("SmsMobileDAL=>GetUnknowList:SQL:" + sql + ",耗时:" + (DateTime.Now - dt).TotalMilliseconds + "毫秒");
            }
            catch (Exception ex)
            {
                MyDelegateFunc.WriteFmLog("SmsMobileDAL=>GetUnknowList:Exception:" + ex.ToString());
            }

            return(list);
        }
示例#2
0
        public List <SmsMobileModel> GetListByYYMMDD(int eprId, int yy, int mm, int dd)
        {
            string   sql = "";
            DateTime dt  = DateTime.Now;

            try
            {
                string begintime           = yy + "-" + mm + "-" + dd; //开始时间
                string endtime             = begintime + " 23:59:59";  //结果时间
                List <SmsMobileModel> list = new List <SmsMobileModel>();
                sql = "Select Mobile,SmsCount,SendTime from t_smsmobile_t where EprId='" + eprId + "' and  SendTime between '" + begintime + "' and '" + endtime + "'   and SubmitStatus='1' and ReportStatus<>-1 and GatewayNum<40001 ";
                // string sql = "Select Mobile,SmsCount,SendTime from t_smsmobile_t where EprId='" + eprId + "' ";
                using (SqlDataReader sdr = SqlHelper.ExecuteReader(lp.SqlConnStr, CommandType.Text, sql, null))
                {
                    while (sdr.Read())
                    {
                        list.Add(FillData(sdr));
                    }
                }
                MyDelegateFunc.WriteFmLog("SmsMobileDAL=>GetListByYYMMDD:SQL:" + sql + ",耗时:" + (DateTime.Now - dt).TotalMilliseconds + "毫秒");
                return(list);
            }
            catch (Exception ex)
            {
                MyDelegateFunc.WriteFmLog("SmsMobileDAL=>GetListByYYMMDD:ExceptionSQL:" + sql);
                MyDelegateFunc.WriteFmLog("SmsMobileDAL=>GetListByYYMMDD:Exception:" + ex.ToString());
            }

            return(null);
        }
示例#3
0
        public Dictionary <int, int> GetSumSMScountByDay(int y, int m, int d)
        {
            DateTime dt        = DateTime.Now;
            string   begintime = y + "-" + m + "-" + d;   //开始时间
            string   endtime   = begintime + " 23:59:59"; //结果时间
            string   sql       = string.Format("Select EprId,Sum(MSGCOUNT) From TBL_SMS_MOBILES Where SendTime between '{0}' and '{1}'  and [STATUS]=3 and ([RESULT]=1 or [RESULT] is null or [RESULT]='' ) and EPRID>0 and [GATEWAY]<50000000  group by EprId", begintime, endtime);

            //string sql = "Select EprId,Sum(SmsCount) From t_smsmobile_t   group by EprId";

            try
            {
                Dictionary <int, int> re = new Dictionary <int, int>();
                using (SqlDataReader sdr = SqlHelper.ExecuteReader(lp.SqlConnStr, CommandType.Text, sql, null))
                {
                    while (sdr.Read())
                    {
                        int eprId = sdr.GetInt32(0);
                        int count = sdr.GetInt32(1);
                        //("getSumSMScount==>eprId=" + eprId + ",count=" + count);
                        re.Add(eprId, count);
                    }
                }
                MyDelegateFunc.WriteFmLog("SmsMobileDAL=>GetSumSMScountByDay:SQL:" + sql + ",耗时:" + (DateTime.Now - dt).TotalMilliseconds + "毫秒");
                return(re);
            }
            catch (Exception ex)
            {
                MyDelegateFunc.WriteFmLog("SmsMobileDAL=>GetSumSMScountByDay:ExceptionSQL:" + sql);
                MyDelegateFunc.WriteFmLog("SmsMobileDAL=>GetSumSMScountByDay:Exception:" + ex.ToString());
            }

            return(null);
        }
示例#4
0
        /// <summary>
        /// 取企业发送量统计
        /// </summary>
        /// <param name="eprIds">企业ID LIST</param>
        /// <param name="y">年</param>
        /// <param name="m">月</param>
        /// <param name="d">日</param>
        /// <returns></returns>
        public Dictionary <int, MobileTypeCountModel> GetSumSMScountByDay(List <int> eprIds, int y, int m, int d)
        {
            string   sql = "";
            DateTime dt  = DateTime.Now;

            // MobileType:1 联通  2移动 3电信  4 未知
            try
            {
                string begintime = y + "-" + m + "-" + d;   //开始时间
                string endtime   = begintime + " 23:59:59"; //结果时间
                Dictionary <int, MobileTypeCountModel> re = new Dictionary <int, MobileTypeCountModel>();
                //foreach (int eprid in eprIds)
                //{
                //sql = string.Format("select Sum(tmp.ct),Sum(tmp.cm) from (select IFNULL((case when MobileType<3 then Sum(SmsCount) end),0) as 'ct',IFNULL((case when MobileType=3 then Sum(SmsCount) end),0) as 'cm' From t_smsmobile_t where  SendTime between '{0}' and '{1}' and EprId='{2}' and SubmitStatus='1' and ReportStatus > -1 and GatewayNum<40001 Group by MobileType) as tmp;", begintime,endtime, eprid);
                //StringBuilder sb = new StringBuilder();
                //sb.Append("select EprId ,Sum(tmp.ct),Sum(tmp.cm) from ( select EprId, IFNULL((case when MobileType<3 then Sum(SmsCount) end),0) as 'ct',IFNULL((case when MobileType=3 then Sum(SmsCount) end),0) as 'cm' From t_smsmobile_t sms");
                //sb.Append(" INNER JOIN t_eprinfo epr on sms.EprId=epr.Id");
                //sb.Append(string.Format(" where  sms.SendTime between '{0}' and '{1}'  and sms.SubmitStatus='1' and sms.ReportStatus > -1 and sms.GatewayNum<40001 Group by sms.MobileType,sms.EprId) as tmp GROUP BY EprId", begintime, endtime));
                //sql = sb.ToString();

                sql = string.Format("select EprId ,Sum(tmp.ct),Sum(tmp.cm) from (select EprId, ISNULL((case when ISNULL(MobileType,1)<3 then Sum([MSGCOUNT]) end),0) as 'ct',ISNULL((case when MobileType=3 then Sum([MSGCOUNT]) end),0) as 'cm' From [TBL_SMS_MOBILES] WHERE SENDTIME BETWEEN '{0}' AND  '{1}'  AND EPRID>0  AND [STATUS]=3 AND ISNULL(RESULT,1)<>0 and RESEND<2 AND [GATEWAY]<50000000 GROUP BY EPRID,MobileType) as tmp GROUP BY EprId", begintime, endtime);
                using (SqlDataReader sdr = SqlHelper.ExecuteReader(lp.SqlConnStr, CommandType.Text, sql, null))
                {
                    while (sdr.Read())
                    {
                        MobileTypeCountModel mtcm = new MobileTypeCountModel();
                        int eprid = sdr.GetInt32(0);
                        if (!sdr.IsDBNull(1))
                        {
                            mtcm.CTcount = sdr.GetInt32(1);
                        }
                        else
                        {
                            mtcm.CTcount = 0;
                        }
                        if (!sdr.IsDBNull(2))
                        {
                            mtcm.CMcount = sdr.GetInt32(2);
                        }
                        else
                        {
                            mtcm.CMcount = 0;
                        }
                        re.Add(eprid, mtcm);
                    }
                }
                //}
                MyDelegateFunc.WriteFmLog("SmsMobileDAL=>GetSumSMScountByDay:LastSQL:" + sql + "\n耗时:" + (DateTime.Now - dt).TotalMilliseconds + "毫秒");
                return(re);
            }
            catch (Exception ex)
            {
                MyDelegateFunc.WriteFmLog("SmsMobileDAL=>GetSumSMScountByDay:ExceptionSQL:" + sql);
                MyDelegateFunc.WriteFmLog("SmsMobileDAL=>GetSumSMScountByDay:Exception:" + ex);
            }

            return(null);
        }
示例#5
0
        public static void SimpleExample()
        {
            // Instantiate the delegate using an anonymous method.
            MyDelegateFunc d1 = delegate(int k) { return(k * k); };

            // can also be written as an "anonymous delegate" as:
            MyDelegateFunc d2 = (int k) => { return(k * k); };

            // or even simpler as: since the type and return value is inferred from the method signature
            MyDelegateFunc d3 = (k) => (k * k);
        }
示例#6
0
 /// <summary>
 /// 初始套餐
 /// </summary>
 /// <returns></returns>
 public bool InitTaocanId()
 {
     try
     {
         string sql = "update JY15.gdkltx.dbo.t_eprinfo set TaocanId=ModifyTaocanId";
         int    re  = MySqlHelper.ExecuteNonQuery(MySqlHelper.ConnectionstringLocalTransaction, CommandType.Text, sql, null);
         MyDelegateFunc.WriteFmLog("EprInfoDAL=>InitTaocanId re:" + re);
         return(true);
     }catch (Exception ex)
     {
         MyDelegateFunc.WriteFmLog("EprInfoDAL=>InitTaocanId Exception:" + ex.ToString());
     }
     return(false);
 }
示例#7
0
        public void Execute(IJobExecutionContext context)
        {
            //先更新帐单
            EprInfoDAL eprinfoDAL = new EprInfoDAL();
            bool       b          = eprinfoDAL.InitTaocanId();

            MyDelegateFunc.WriteFmLog("CreateTaoCanBillJob=>初始化套餐reslt=" + b);

            ProductId = GlobalParams.ProductId;
            FactoryNo = GlobalParams.FactoryNo;
            DateTime dt = DateTime.Now;

            Work(dt, true);
        }
示例#8
0
        /// <summary>
        /// 取企业月发送量统计
        /// </summary>
        /// <param name="eprIds">企业ID LIST</param>
        /// <param name="begintime">开始时间</param>
        /// <param name="endtime">结束</param>
        /// <returns></returns>
        public Dictionary <int, MobileTypeCountModel> GetSumSMScountByMomth(List <int> eprIds, string begintime, string endtime)
        {
            string   sql = "";
            DateTime dt  = DateTime.Now;

            try
            {
                Dictionary <int, MobileTypeCountModel> re = new Dictionary <int, MobileTypeCountModel>();
                foreach (int eprid in eprIds)
                {
                    // sql = string.Format("select Sum(tmp.ct),Sum(tmp.cm) from (select IFNULL((case when MobileType<3 then Sum(SmsCount) end),0) as 'ct',IFNULL((case when MobileType=3 then Sum(SmsCount) end),0) as 'cm' From t_smsmobile_t where  SendTime between '{0}' and '{1}' and EprId={2} and SubmitStatus='1' and ReportStatus > -1 and GatewayNum<40001 Group by MobileType) as tmp;", begintime, endtime, eprid);
                    // sql = string.Format("  select EprId ,Sum(tmp.ct),Sum(tmp.cm) from (select EprId, ISNULL((case when MobileType<3 then Sum([MSGCOUNT]) end),0) as 'ct',ISNULL((case when MobileType=3 then Sum([MSGCOUNT]) end),0) as 'cm' From [TBL_SMS_MOBILES] WHERE SENDTIME BETWEEN '{0}' AND  '{1}'  AND EPRID={2} AND [GATEWAY]<50000000 GROUP BY EPRID,MobileType) as tmp GROUP BY EprId",begintime, endtime, eprid);
                    sql = string.Format("select EprId ,Sum(tmp.ct),Sum(tmp.cm) from (select EprId, ISNULL((case when ISNULL(MobileType,1)<3 then Sum([MSGCOUNT]) end),0) as 'ct',ISNULL((case when MobileType=3 then Sum([MSGCOUNT]) end),0) as 'cm' From [TBL_SMS_MOBILES] WHERE SENDTIME BETWEEN '{0}' AND  '{1}'  AND EPRID={2}  AND [STATUS]=3 AND ISNULL(RESULT,1)<>0 AND [GATEWAY]<50000000 GROUP BY EPRID,MobileType) as tmp GROUP BY EprId", begintime, endtime, eprid);
                    using (SqlDataReader sdr = SqlHelper.ExecuteReader(lp.SqlConnStr, CommandType.Text, sql, null))
                    {
                        if (sdr.Read())
                        {
                            MobileTypeCountModel mtcm = new MobileTypeCountModel();
                            if (!sdr.IsDBNull(0))
                            {
                                mtcm.CTcount = sdr.GetInt32(0);
                            }
                            else
                            {
                                mtcm.CTcount = 0;
                            }
                            if (!sdr.IsDBNull(1))
                            {
                                mtcm.CMcount = sdr.GetInt32(1);
                            }
                            else
                            {
                                mtcm.CMcount = 0;
                            }
                            mtcm.TotalCount = mtcm.CTcount + mtcm.CMcount;
                            re.Add(eprid, mtcm);
                        }
                    }
                }
                MyDelegateFunc.WriteFmLog("SmsMobileDAL=>GetSumSMScountByDay:LastSQL:" + sql + ",耗时:" + (DateTime.Now - dt).TotalMilliseconds + "毫秒");
                return(re);
            }
            catch (Exception ex)
            {
                MyDelegateFunc.WriteFmLog("SmsMobileDAL=>GetSumSMScountByDay2:ExceptionSQL:" + sql);
                MyDelegateFunc.WriteFmLog("SmsMobileDAL=>GetSumSMScountByDay2:Exception:" + ex.ToString());
            }

            return(null);
        }
示例#9
0
 public bool UpdateUnknowReportStatus(List <string> list)
 {
     try
     {
         List <string> failList = SqlHelper.BatchExec(lp.SqlConnStr, list);
         if (failList == null || failList.Count == 0)
         {
             return(true);
         }
     }
     catch (Exception ex)
     {
         MyDelegateFunc.WriteFmLog("SmsMobileDAL=>UpdateUnknowReportStatus:Exception:" + ex.ToString());
     }
     return(false);
 }
示例#10
0
        public bool UpdateUnknowReportStatus(int id, string eprId)
        {
            try
            {
                string sql = string.Format("update TBL_SMS_MOBILES set [RESULT]=NULL where Id={0} and EprId='{1}'", id, eprId);

                int re = SqlHelper.ExecuteNonQuery(lp.SqlConnStr, CommandType.Text, sql, null);
                if (re > 0)
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                MyDelegateFunc.WriteFmLog("SmsMobileDAL=>UpdateUnknowReportStatus:Exception:" + ex.ToString());
            }
            return(false);
        }
        [TestMethod] // -----------------------------------------------------------------------
        public void TestMethod2()
        {
            // Original delegate syntax required
            // initialization with a named method.
            MyDelegateFunc testDelA = new MyDelegateFunc(functionImpl); // need functio & type name, implement at top. no need functionImpl()

            // C# 2.0: A delegate can be initialized with
            // inline code, called an "anonymous method." This
            // method takes a string as an input parameter.
            MyDelegateFunc testDelB = delegate(string s) { HLog.print(s); };  // no funciton name, direct implement at here!

            // C# 3.0. A delegate can be initialized with
            // a lambda expression. The lambda also takes a string
            // as an input parameter (x). The type of x is inferred by the compiler.
            MyDelegateFunc testDelC = (x) => { HLog.print(x); }; // no function & type name, direct implement at here!

            // Invoke the delegates.
            testDelA("Hello. My name is M and I write lines.");
            testDelB("That's nothing. I'm anonymous and ");
            testDelC("I'm a famous author.");
        }
示例#12
0
        private TaoCanInfoModel FillData(MySqlDataReader sdr)
        {
            TaoCanInfoModel model = null;

            try
            {
                model                = new TaoCanInfoModel();
                model.Id             = sdr.GetInt32(0);
                model.TCName         = sdr.GetString(1);
                model.TCPrice        = sdr.GetString(2);
                model.TCNumber       = sdr.GetInt32(3);
                model.TCOutsidePrice = sdr.GetString(4);
                model.Billprice      = sdr.GetString(5);
                model.Billnumber     = sdr.GetInt32(6);
            }
            catch (Exception ex)
            {
                MyDelegateFunc.WriteFmLog("TaoCanInfoDAL=>FillData Exception:" + ex.ToString());
            }

            return(model);
        }
示例#13
0
 private static readonly log4net.ILog logger = log4net.LogManager.GetLogger(typeof(CreateJob));//log4net 日志
 public IScheduler CreateSched(string cronExpression, string trigger_str, string group_str, Type ijob)
 {
     try
     {
         CronScheduleBuilder csb     = CronScheduleBuilder.CronSchedule(cronExpression);
         ITrigger            trigger = TriggerBuilder.Create().WithIdentity(trigger_str, group_str).WithSchedule(csb).Build();
         IJobDetail          job     = JobBuilder.Create(ijob).Build();
         ISchedulerFactory   sf      = new StdSchedulerFactory();
         IScheduler          sched   = sf.GetScheduler();
         sched.ScheduleJob(job, trigger);
         string info = string.Format("[{0}],创建成功", cronExpression);
         logger.Info(info);
         MyDelegateFunc.WriteFmLog(info);
         return(sched);
     }
     catch (Exception ex)
     {
         logger.Error(ex.Message);
         MyDelegateFunc.WriteFmLog(ex.Message);
     }
     return(null);
 }
示例#14
0
        public int GetUnknowCount(string eprid, string userid, string y, string m, string d)
        {
            int result = 0;

            try
            {
                DateTime dt        = DateTime.Now;
                string   begintime = y + "-" + m + "-" + d;   //开始时间
                string   endtime   = begintime + " 23:59:59"; //结果时间
                object[] obj       = { eprid, begintime, endtime, userid };
                string   sql       = string.Format("select count(1) from TBL_SMS_MOBILES where EprId={0} and [SENDTIME] between '{1}' and '{2}'  and UserId='{3}' and [RESULT]=NULL and [STATUS]=3 ", obj);
                object   re        = SqlHelper.ExecuteScalar(lp.SqlConnStr, CommandType.Text, sql, null);
                if (re != null)
                {
                    int.TryParse(re.ToString(), out result);
                }
                MyDelegateFunc.WriteFmLog("SmsMobileDAL=>GetUnknowList:SQL:" + sql + ",耗时:" + (DateTime.Now - dt).TotalMilliseconds + "毫秒");
            }
            catch (Exception ex)
            {
                MyDelegateFunc.WriteFmLog("SmsMobileDAL=>GetUnknowCount:Exception:" + ex.ToString());
            }
            return(result);
        }
示例#15
0
        /// <summary>
        /// 用执行的数据库连接执行一个返回数据集的sql命令
        /// </summary>
        /// <remarks>
        /// 举例:
        ///  MySqlDataReader r = ExecuteReader(connstring, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
        /// </remarks>
        /// <param name="connectionstring">一个有效的连接字符串</param>
        /// <param name="commandType">命令类型(存储过程, 文本, 等等)</param>
        /// <param name="commandText">存储过程名称或者sql命令语句</param>
        /// <param name="commandParameters">执行命令所用参数的集合</param>
        /// <returns>包含结果的读取器</returns>
        public static MySqlDataReader ExecuteReader(string connectionstring, CommandType cmdType, string cmdText, params MySqlParameter[] commandParameters)
        {
            //创建一个MySqlCommand对象
            MySqlCommand cmd = new MySqlCommand();
            //创建一个MySqlConnection对象
            MySqlConnection conn = null;

            try
            {
                conn = new MySqlConnection(connectionstring);
            }catch (Exception ex)
            {
                MyDelegateFunc.WriteFmLog("MysqlHelper=>MySqlDataReader:con:" + connectionstring + "Exception:" + ex);
            }

            //在这里我们用一个try/catch结构执行sql文本命令/存储过程,因为如果这个方法产生一个异常我们要关闭连接,因为没有读取器存在,
            //因此commandBehaviour.CloseConnection 就不会执行
            try
            {
                //调用 PrepareCommand 方法,对 MySqlCommand 对象设置参数
                PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
                //调用 MySqlCommand  的 ExecuteReader 方法
                MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                //清除参数
                cmd.Parameters.Clear();
                // conn.Close();
                return(reader);
            }
            catch (Exception ex)
            {
                MyDelegateFunc.WriteFmLog("MysqlHelper=>PrepareCommand:con:" + connectionstring + "Exception:" + ex);
                //关闭连接,抛出异常
                conn.Close();
                throw ex;
            }
        }
示例#16
0
        public void Work(DateTime dtnow, bool isupload)
        {
            DateTime dt = DateTime.Now;
            int      yy = dtnow.Year;  // 得到年
            int      mm = dtnow.Month; // 得到月
            int      dd = dtnow.Day;   // 日
            int      hh = dtnow.Hour;  // 小时

            try
            {
                string        strmm  = mm > 9 ? mm + "" : "0" + mm;
                string        strdd  = dd > 9 ? dd + "" : "0" + dd;
                string        strhh  = hh > 9 ? hh + "" : "0" + hh;
                string        ftpdir = yy + strmm + strdd;// ftp上的每天一个文件夹
                string        dir    = Application.StartupPath + "\\" + FactoryNo;
                DirectoryInfo dim    = new DirectoryInfo(dir);
                if (!dim.Exists)
                {
                    dim.Create();
                }
                dir += "\\" + yy + strmm + strdd;// 文件夹(厂家编号/yyyyMMdd)
                DirectoryInfo di = new DirectoryInfo(dir);
                if (!di.Exists)
                {
                    di.Create();
                }
                //深圳23点
                string fileName      = ProductId + "_" + yy + strmm + strdd + strhh + "0001.txt.sending"; // 文件名
                string filePath      = dir + "\\" + fileName;
                string szftpfilename = ProductId + "_" + yy + strmm + strdd + strhh + "0001.txt";         // ftp保存文件名
                try
                {
                    if (File.Exists(szftpfilename))
                    {
                        File.Delete(szftpfilename);
                    }
                }
                catch { }

                //东莞22点
                string strdghh       = "22";                                                                // hh - 1 > 9 ? hh - 1 + "" : "0" + (hh - 1);//东莞
                string dgfileName    = ProductId + "_" + yy + strmm + strdd + strdghh + "0001.txt.sending"; // 文件名
                string dgfilePath    = dir + "\\" + dgfileName;
                string dgftpfilename = ProductId + "_" + yy + strmm + strdd + strdghh + "0001.txt";         // ftp保存的文件名

                try
                {
                    if (File.Exists(dgftpfilename))
                    {
                        File.Delete(dgftpfilename);
                    }
                }
                catch { }

                //中山21点
                string strzshh       = "21";                                                                // hh - 2 > 9 ? hh - 2 + "" : "0" + (hh - 2);//中山
                string zsfileName    = ProductId + "_" + yy + strmm + strdd + strzshh + "0001.txt.sending"; // 文件名
                string zsfilePath    = dir + "\\" + zsfileName;
                string zsftpfilename = ProductId + "_" + yy + strmm + strdd + strzshh + "0001.txt";         // ftp保存的文件名
                try
                {
                    if (File.Exists(zsftpfilename))
                    {
                        File.Delete(zsftpfilename);
                    }
                }
                catch { }

                //潮洲19点
                string strczhh       = "19";                                                                // hh - 4 > 9 ? hh - 4 + "" : "0" + (hh - 4);//潮洲
                string czfileName    = ProductId + "_" + yy + strmm + strdd + strczhh + "0001.txt.sending"; // 文件名
                string czfilePath    = dir + "\\" + zsfileName;
                string czftpfilename = ProductId + "_" + yy + strmm + strdd + strczhh + "0001.txt";         // ftp保存的文件名
                try
                {
                    if (File.Exists(czftpfilename))
                    {
                        File.Delete(czftpfilename);
                    }
                }
                catch { }

                EprInfoDAL   eprDAO    = new EprInfoDAL();
                SmsMobileDAL mobileDAO = new SmsMobileDAL();
                BnetInfoDAL  bnetDAO   = new BnetInfoDAL();

                //查出所有企业信息和bnet信息
                Dictionary <int, EprInfoModel>     dicEprInfo  = eprDAO.GetEprInfoAll();
                Dictionary <string, BnetInfoModel> dicBnetInfo = bnetDAO.GetAll();

                //帐单
                List <string> szbillList  = new List <string>();                                                                           // 深圳帐单
                List <string> dgbillList  = new List <string>();                                                                           //东莞帐单
                List <string> zsbillList  = new List <string>();                                                                           //中山帐单
                List <string> czbillList  = new List <string>();                                                                           //潮洲帐单
                List <string> daystatlist = new List <string>();                                                                           //帐号报表
                Dictionary <int, MobileTypeCountModel> eprSendCount = mobileDAO.GetSumSMScountByDay(dicEprInfo.Keys.ToList(), yy, mm, dd); //查出企业发送量
                Dictionary <int, MobileTypeCountModel> billCount    = new Dictionary <int, MobileTypeCountModel>();                        //打折后企业的发送量
                foreach (int key in eprSendCount.Keys)
                {
                    try
                    {
                        MobileTypeCountModel mtcm    = null;
                        EprInfoModel         eprinfo = null;
                        try
                        {
                            mtcm    = eprSendCount[key];
                            eprinfo = dicEprInfo[key];
                            if (eprinfo != null && eprinfo.taocanId > 0)
                            {
                                continue;//套餐的不处理
                            }
                        }
                        catch (Exception ex)
                        {
                            MyDelegateFunc.WriteFmLog("打折异常[eprinfo]:" + ex.ToString());
                        }

                        if (eprinfo != null && (mtcm.CTcount > 0 || mtcm.CMcount > 0))
                        {
                            if (string.IsNullOrEmpty(eprinfo.bnetId) || eprinfo.bnetId.Equals("888"))
                            {
                                continue;
                            }

                            double        dprice = 10.00;
                            int           billct = mtcm.CTcount;
                            int           billcm = mtcm.CMcount;
                            BnetInfoModel bnetf  = null;
                            try
                            {
                                bnetf = dicBnetInfo[eprinfo.bnetId];
                            }
                            catch (Exception ex)
                            {
                                MyDelegateFunc.WriteFmLog("打折异常[bnetf]:" + ex.ToString());
                            }

                            if (bnetf != null)
                            {
                                //中山
                                if (bnetf.BnetAccount.StartsWith("760"))//eprinfo.areaId == 17
                                {
                                    billCount.Add(key, mtcm);
                                    continue;
                                }

                                string tprice = bnetf.Price;
                                if (!string.IsNullOrEmpty(tprice))
                                {
                                    bool b = double.TryParse(tprice, out dprice);
                                    if (dprice <= 0.00 || !b)
                                    {
                                        dprice = 10.00;
                                    }
                                }
                                MobileTypeCountModel mtcm_bill = new MobileTypeCountModel();

                                //double bcount_ct = billct * (dprice / 10);
                                mtcm_bill.CTcount = (int)(billct * (dprice / 10));// (int)Math.Ceiling(billct * (dprice / 10));

                                //  double bcount_cm = billcm * (dprice / 10);
                                mtcm_bill.CMcount    = (int)(billcm * (dprice / 10));// (int)Math.Ceiling(billcm * (dprice / 10));
                                mtcm_bill.Pirce      = dprice + "";
                                mtcm_bill.InitialNum = billct + billcm;
                                string inf = string.Format("INFO CreateBillJob==>企业id:{0},清单数量:{1},帐单数量:{2},单价:{3}", key, billcm + billct, mtcm_bill.CMcount + mtcm_bill.CTcount, tprice);
                                logger.Info(inf);
                                MyDelegateFunc.WriteFmLog(inf);
                                billCount.Add(key, mtcm_bill);
                            }//BnetInfo
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error("CreateBillJob==>计算账单条数异常:" + ex.Message);
                    }
                }//foreach eprCount


                //移动联通,电信
                foreach (int key in billCount.Keys)
                {
                    EprInfoModel         eprinfo     = eprDAO.GetEprInfo(key);
                    string               bnetId      = eprinfo.bnetId;
                    string               bnetAccount = eprinfo.bnetAccount;
                    MobileTypeCountModel mtcm        = billCount[key];//帐单数量

                    try
                    {
                        //生成sql
                        object[] obj = { eprinfo.id, bnetId, bnetAccount, mtcm.CTcount, mtcm.CUcount, mtcm.CMcount, yy, mm, dd, eprinfo.areaId, mtcm.Pirce, mtcm.InitialNum, mtcm.TotalCount };
                        string   sql = string.Format("Insert into JY15.gdkltx.dbo.t_billdaystat(EprId,BnetId,BnetAccount,CTcount,CUcount,CMcount,YY,MM,DD,AreaId,Price,InitialNum,TaoCanType) values({0},'{1}','{2}',{3},{4},{5},{6},{7},{8},{9},'{10}',{11},'{12}')", obj);
                        logger.Info(sql);
                        daystatlist.Add(sql);
                    }
                    catch (Exception ex)
                    {
                        MyDelegateFunc.WriteFmLog("CreateBillJob==>保存sqlList失败:" + ex.ToString());
                    }
                    for (int i = 0; i < mtcm.CTcount; i++)
                    {
                        StringBuilder sbstr = new StringBuilder();
                        sbstr.Append(bnetId);
                        sbstr.Append("|");
                        sbstr.Append(bnetAccount);
                        sbstr.Append("|");
                        sbstr.Append("0|1|0|0|");
                        sbstr.Append(dtnow.ToString("yyyy/MM/dd H:mm:ss", DateTimeFormatInfo.InvariantInfo));
                        szbillList.Add(sbstr.ToString());

                        /*
                         * if (bnetAccount.StartsWith("755"))//深圳
                         * {
                         *  szbillList.Add(sbstr.ToString());
                         * }
                         * else if (bnetAccount.StartsWith("769"))//东莞
                         * {
                         *  dgbillList.Add(sbstr.ToString());
                         * }
                         * else if (bnetAccount.StartsWith("760"))//中山
                         * {
                         *  zsbillList.Add(sbstr.ToString());
                         * }
                         * else if (bnetAccount.StartsWith("0768"))//潮洲
                         * {
                         *  czbillList.Add(sbstr.ToString());
                         * }
                         * */
                    }

                    //电信
                    for (int j = 0; j < mtcm.CMcount; j++)
                    {
                        StringBuilder sbstr = new StringBuilder();
                        sbstr.Append(bnetId);
                        sbstr.Append("|");
                        sbstr.Append(bnetAccount);
                        sbstr.Append("|");
                        sbstr.Append("0|0|1|0|");
                        sbstr.Append(dtnow.ToString("yyyy/MM/dd H:mm:ss", DateTimeFormatInfo.InvariantInfo));
                        szbillList.Add(sbstr.ToString());

                        /*
                         * if (bnetAccount.StartsWith("755"))//深圳
                         * {
                         *  szbillList.Add(sbstr.ToString());
                         * }
                         * else if (bnetAccount.StartsWith("769"))//东莞
                         * {
                         *  dgbillList.Add(sbstr.ToString());
                         * }
                         * else if (bnetAccount.StartsWith("760"))//中山
                         * {
                         *  zsbillList.Add(sbstr.ToString());
                         * }
                         * else if (bnetAccount.StartsWith("0768") || bnetAccount.StartsWith("768"))//潮洲
                         * {
                         *  czbillList.Add(sbstr.ToString());
                         * }
                         * */
                    }
                }//foreach billCount

                try
                {
                    if (daystatlist != null && daystatlist.Count > 0)
                    {
                        int result = SQLbll.BatchExec(daystatlist);
                        MyDelegateFunc.WriteFmLog("CreateBillJob==>保存sql fail:" + result);
                    }
                }
                catch (Exception ex)
                {
                    MyDelegateFunc.WriteFmLog("CreateBillJob==>保存sql失败:" + daystatlist[0]);
                    MyDelegateFunc.WriteFmLog("CreateBillJob==>保存sql失败:" + ex.Message);
                }


                //生成文件,上传

                FtpClient   ftp  = new FtpClient();
                LocalParams lp   = new LocalParams();
                HttpHelper  http = new HttpHelper();
                //深圳账单
                if (szbillList != null)
                {
                    bool bsz = MyFileOptions.WriteFileTXT(szbillList, filePath);
                    MyDelegateFunc.WriteFmLog("CreateBillJob==>生成sz文件[" + szftpfilename + "]结果:" + bsz);
                    if (bsz && isupload)
                    {
                        bool boolf = false;
                        int  i     = 0;
                        do
                        {
                            boolf = ftp.Upload(ftpdir, szftpfilename, filePath);
                            i++;
                        } while (!boolf && i < 3);
                        MyDelegateFunc.WriteFmLog("CreateBillJob==>上传sz账单[" + szftpfilename + "]结果:" + boolf);
                        if (boolf)
                        {
                            try
                            {
                                File.Move(filePath, dir + "\\" + szftpfilename);
                            }
                            catch (Exception ex)
                            {
                                MyDelegateFunc.WriteFmLog("CreateBillJob==>修改sz文件名[" + filePath + "]to[" + szftpfilename + "]失败:" + ex.Message);
                                logger.Error("CreateBillJob==>修改sz文件名[" + filePath + "]to[" + szftpfilename + "]失败:" + ex.Message);
                            }
                        }
                        else
                        {
                            string sendresult = http.Send(lp.UID, lp.PWD, "18002579031", 111, "上传sz文件[" + filePath + "]失败【嘉盈资讯】");
                            MyDelegateFunc.WriteFmLog("CreateBillJob==>上传sz文件[" + filePath + "]失败,发送短信结果:" + sendresult);
                            logger.Error("CreateBillJob==>上传sz文件[" + filePath + "]失败");
                        }
                    }
                    else
                    {
                        string sendresult = http.Send(lp.UID, lp.PWD, "18002579031", 111, "生成sz文件[" + filePath + "]失败【嘉盈资讯】");
                        MyDelegateFunc.WriteFmLog("CreateBillJob==>生成sz文件[" + filePath + "]失败,发送短信结果:" + sendresult);
                        logger.Error("CreateBillJob==>生成sz文件[" + filePath + "]失败");
                    }
                }
                else
                {
                    string sendresult = http.Send(lp.UID, lp.PWD, "18002579031", 111, "szbillList null【嘉盈资讯】");
                    MyDelegateFunc.WriteFmLog("CreateBillJob=FTP=>文件szbillList null,发送短信结果:" + sendresult);
                }

                //东莞账单
                if (dgbillList != null)
                {
                    bool bdg = MyFileOptions.WriteFileTXT(dgbillList, dgfilePath);
                    if (bdg && isupload)
                    {
                        bool booldg = ftp.Upload(ftpdir, dgftpfilename, dgfilePath);
                        MyDelegateFunc.WriteFmLog("CreateBillJob==>上传东莞账单[" + dgfilePath + "]结果:" + booldg);
                        if (booldg)
                        {
                            try
                            {
                                File.Move(dgfilePath, dir + "\\" + dgftpfilename);
                            }
                            catch (Exception ex)
                            {
                                logger.Error("CreateBillJob==>修改东莞文件名[" + dgfilePath + "]to[" + dgftpfilename + "]失败:" + ex.Message);
                            }
                        }
                    }
                    else
                    {
                        logger.Error("CreateBillJob==>生成dg文件[" + dgfilePath + "]失败");
                    }
                }



                //中山账单
                if (zsbillList != null)
                {
                    bool zsb = MyFileOptions.WriteFileTXT(zsbillList, zsfilePath);
                    if (zsb && isupload)
                    {
                        bool booldg = ftp.Upload(ftpdir, zsftpfilename, zsfilePath);
                        MyDelegateFunc.WriteFmLog("CreateBillJob==>上传中山账单[" + zsfilePath + "]结果:" + booldg);
                        if (booldg)
                        {
                            try
                            {
                                File.Move(zsfilePath, dir + "\\" + zsftpfilename);
                            }
                            catch (Exception ex)
                            {
                                logger.Error("CreateBillJob==>修改中山文件名[" + zsfilePath + "]to[" + zsftpfilename + "]失败:" + ex.Message);
                            }
                        }
                    }
                    else
                    {
                        logger.Error("CreateBillJob==>生成中山文件[" + zsfilePath + "]失败");
                    }
                }


                //潮洲账单
                if (czbillList != null)
                {
                    bool czb = MyFileOptions.WriteFileTXT(czbillList, czfilePath);
                    if (czb && isupload)
                    {
                        bool booldg = ftp.Upload(ftpdir, czftpfilename, czfilePath);
                        MyDelegateFunc.WriteFmLog("CreateBillJob==>上传潮洲账单[" + czfilePath + "]结果:" + booldg);
                        if (booldg)
                        {
                            try
                            {
                                File.Move(zsfilePath, dir + "\\" + czftpfilename);
                            }
                            catch (Exception ex)
                            {
                                logger.Error("CreateBillJob==>修改潮洲文件名[" + czfilePath + "]to[" + czftpfilename + "]失败:" + ex.Message);
                            }
                        }
                    }
                    else
                    {
                        logger.Error("CreateBillJob==>生成潮洲文件[" + czfilePath + "]失败");
                    }
                }
            }
            catch (Exception ex)
            {
                MyDelegateFunc.WriteFmLog("CreateBillJob==>Exception:" + ex.Message);
                logger.Error("CreateBillJob==>Exception:" + ex.Message);
            }
        }
示例#17
0
        public void Work(DateTime dtnow, bool isupload)
        {
            DateTime dt = DateTime.Now;
            int      yy = dtnow.Year;  // 得到年
            int      mm = dtnow.Month; // 得到月
            int      dd = dtnow.Day;   // 日
            int      hh = dtnow.Hour;  // 小时

            string strmm = mm > 9 ? mm + "" : "0" + mm;
            string strdd = dd > 9 ? dd + "" : "0" + dd;
            string strhh = hh > 9 ? hh + "" : "0" + hh;

            strhh = "01";
            string        ftpdir = yy + strmm + strdd;// ftp上的每天一个文件夹
            string        dir    = Application.StartupPath + "\\" + FactoryNo;
            DirectoryInfo dim    = new DirectoryInfo(dir);

            if (!dim.Exists)
            {
                dim.Create();
            }
            dir += "\\" + yy + strmm + strdd;// 文件夹(厂家编号/yyyyMMdd)
            DirectoryInfo di = new DirectoryInfo(dir);

            if (!di.Exists)
            {
                di.Create();
            }
            //深圳
            string fileName      = ProductId + "_" + yy + strmm + strdd + strhh + "0001.txt.sending"; // 文件名
            string filePath      = dir + "\\" + fileName;
            string szftpfilename = ProductId + "_" + yy + strmm + strdd + strhh + "0001.txt";         // ftp保存文件名


            EprInfoDAL          eprinfoDAL  = new EprInfoDAL();
            List <EprInfoModel> eprLst      = eprinfoDAL.GetTaoCanEprInfoAll();
            List <string>       szbillList  = new List <string>(); // 深圳帐单
            List <string>       daystatlist = new List <string>(); //帐号报表

            if (eprLst != null && eprLst.Count > 0)
            {
                TaoCanInfoDAL taocanDAL = new TaoCanInfoDAL();
                Dictionary <int, TaoCanInfoModel> taocandic = taocanDAL.GetAll();
                foreach (EprInfoModel e in eprLst)
                {
                    if (taocandic.ContainsKey(e.taocanId))
                    {
                        //他网和电信比率 8:2
                        TaoCanInfoModel tc       = taocandic[e.taocanId];
                        int             ctnumber = (int)(tc.Billnumber * 0.8); //移动账单数量
                        int             cmnumber = tc.Billnumber - ctnumber;   //电信账单数量

                        string bnetId = e.bnetId, bnetAccount = e.bnetAccount;
                        try
                        {
                            //生成sql
                            object[] obj = { e.id, bnetId, bnetAccount, ctnumber, 0, cmnumber, yy, mm, dd };
                            string   sql = string.Format("Insert into t_billdaystat(EprId,BnetId,BnetAccount,CTcount,CUcount,CMcount,YY,MM,DD) values({0},'{1}','{2}',{3},{4},{5},{6},{7},{8})", obj);
                            daystatlist.Add(sql);
                        }
                        catch (Exception ex)
                        {
                            MyDelegateFunc.WriteFmLog("CreateTaoCanBillJob==>生成sqlList失败:" + ex.Message);
                        }


                        for (int i = 0; i < ctnumber; i++)
                        {
                            StringBuilder sbstr = new StringBuilder();
                            sbstr.Append(e.bnetId);
                            sbstr.Append("|");
                            sbstr.Append(e.bnetAccount);
                            sbstr.Append("|");
                            sbstr.Append("0|1|0|0|");
                            sbstr.Append(dtnow.ToString("yyyy/MM/dd H:mm:ss", DateTimeFormatInfo.InvariantInfo));
                            szbillList.Add(sbstr.ToString());
                        }
                        for (int j = 0; j < cmnumber; j++)
                        {
                            StringBuilder sbstr = new StringBuilder();
                            sbstr.Append(e.bnetId);
                            sbstr.Append("|");
                            sbstr.Append(e.bnetAccount);
                            sbstr.Append("|");
                            sbstr.Append("0|0|1|0|");
                            sbstr.Append(dt.ToString("yyyy/MM/dd H:mm:ss", DateTimeFormatInfo.InvariantInfo));
                        }
                    }
                }
            }


            try
            {
                if (daystatlist != null && daystatlist.Count > 0)
                {
                    int result = SQLbll.BatchExec(daystatlist);
                    MyDelegateFunc.WriteFmLog("CreateTaoCanBillJob==>保存sql fail:" + result);
                }
            }
            catch (Exception ex)
            {
                MyDelegateFunc.WriteFmLog("CreateTaoCanBillJob==>保存sql失败:" + daystatlist[0]);
                MyDelegateFunc.WriteFmLog("CreateTaoCanBillJob==>保存sql失败:" + ex.Message);
            }

            if (isupload)
            {
                FtpClient ftp = new FtpClient();
                //深圳账单
                if (szbillList != null)
                {
                    bool bsz = MyFileOptions.WriteFileTXT(szbillList, filePath);
                    MyDelegateFunc.WriteFmLog("CreateTaoCanBillJob==>生成sz套餐文件[" + szftpfilename + "]结果:" + bsz);
                    if (bsz)
                    {
                        bool boolf = ftp.Upload(ftpdir, szftpfilename, filePath);
                        MyDelegateFunc.WriteFmLog("CreateTaoCanBillJob==>上传sz套餐账单[" + szftpfilename + "]结果:" + boolf);
                        if (boolf)
                        {
                            try
                            {
                                File.Move(filePath, dir + "\\" + szftpfilename);
                            }
                            catch (Exception ex)
                            {
                                MyDelegateFunc.WriteFmLog("CreateTaoCanBillJob==>修改sz套餐文件名[" + filePath + "]to[" + szftpfilename + "]失败:" + ex.Message);
                                logger.Error("CreateTaoCanBillJob==>修改sz套餐文件名[" + filePath + "]to[" + szftpfilename + "]失败:" + ex.Message);
                            }
                        }
                        else
                        {
                            MyDelegateFunc.WriteFmLog("CreateTaoCanBillJob=FTP=>上传sz套餐文件[" + filePath + "]失败");
                            logger.Error("CreateTaoCanBillJob=FTP=>上传sz套餐文件[" + filePath + "]失败");
                        }
                    }
                    else
                    {
                        MyDelegateFunc.WriteFmLog("CreateTaoCanBillJob==>生成sz文件[" + filePath + "]失败");
                        logger.Error("CreateTaoCanBillJob==>生成sz文件[" + filePath + "]失败");
                    }
                }
            }
        }
示例#18
0
        /// <summary>
        /// 手动生成,保存在补推文件夹中
        /// </summary>
        /// <param name="dtnow">账单时间</param>
        /// <param name="begintime">开始时间</param>
        /// <param name="endtime">结束时间</param>
        /// <param name="eprIdLst">企业ID</param>
        /// <param name="isupload">是否上传</param>
        public void Work(DateTime dtnow, string begintime, string endtime, List <int> eprIdLst, bool isupload)
        {
            DateTime dt = DateTime.Now;
            int      yy = dtnow.Year;  // 得到年
            int      mm = dtnow.Month; // 得到月
            int      dd = dtnow.Day;   // 日
            int      hh = dtnow.Hour;  // 小时

            try
            {
                string        strmm  = mm > 9 ? mm + "" : "0" + mm;
                string        strdd  = dd > 9 ? dd + "" : "0" + dd;
                string        strhh  = hh > 9 ? hh + "" : "0" + hh;
                string        ftpdir = yy + strmm + strdd;// ftp上的每天一个文件夹
                string        dir    = Application.StartupPath + "\\" + FactoryNo + "\\add";
                DirectoryInfo dim    = new DirectoryInfo(dir);
                if (!dim.Exists)
                {
                    dim.Create();
                }
                dir += "\\" + yy + strmm + strdd;// 文件夹(厂家编号/yyyyMMdd)
                DirectoryInfo di = new DirectoryInfo(dir);
                if (!di.Exists)
                {
                    di.Create();
                }
                //深圳23点
                string fileName      = ProductId + "_" + yy + strmm + strdd + strhh + "0001.txt.sending"; // 文件名
                string filePath      = dir + "\\" + fileName;
                string szftpfilename = ProductId + "_" + yy + strmm + strdd + strhh + "0001.txt";         // ftp保存文件名
                try
                {
                    if (File.Exists(szftpfilename))
                    {
                        File.Delete(szftpfilename);
                    }
                }
                catch { }

                //东莞22点
                string strdghh       = hh - 1 > 9 ? hh - 1 + "" : "0" + (hh - 1);                           //东莞
                string dgfileName    = ProductId + "_" + yy + strmm + strdd + strdghh + "0001.txt.sending"; // 文件名
                string dgfilePath    = dir + "\\" + dgfileName;
                string dgftpfilename = ProductId + "_" + yy + strmm + strdd + strdghh + "0001.txt";         // ftp保存的文件名

                try
                {
                    if (File.Exists(dgftpfilename))
                    {
                        File.Delete(dgftpfilename);
                    }
                }
                catch { }

                //中山21点
                string strzshh       = hh - 2 > 9 ? hh - 2 + "" : "0" + (hh - 2);                           //中山
                string zsfileName    = ProductId + "_" + yy + strmm + strdd + strzshh + "0001.txt.sending"; // 文件名
                string zsfilePath    = dir + "\\" + zsfileName;
                string zsftpfilename = ProductId + "_" + yy + strmm + strdd + strzshh + "0001.txt";         // ftp保存的文件名
                try
                {
                    if (File.Exists(zsftpfilename))
                    {
                        File.Delete(zsftpfilename);
                    }
                }
                catch { }

                //潮洲19点
                string strczhh       = hh - 4 > 9 ? hh - 4 + "" : "0" + (hh - 4);                           //潮洲
                string czfileName    = ProductId + "_" + yy + strmm + strdd + strczhh + "0001.txt.sending"; // 文件名
                string czfilePath    = dir + "\\" + zsfileName;
                string czftpfilename = ProductId + "_" + yy + strmm + strdd + strczhh + "0001.txt";         // ftp保存的文件名
                try
                {
                    if (File.Exists(czftpfilename))
                    {
                        File.Delete(czftpfilename);
                    }
                }
                catch { }


                EprInfoDAL   eprDAO    = new EprInfoDAL();
                SmsMobileDAL mobileDAO = new SmsMobileDAL();
                BnetInfoDAL  bnetDAO   = new BnetInfoDAL();

                //查出所有企业信息和bnet信息

                Dictionary <int, EprInfoModel>     dicEprInfo  = eprDAO.GetEprInfoAll();
                Dictionary <string, BnetInfoModel> dicBnetInfo = bnetDAO.GetAll();

                //帐单
                List <string> szbillList  = new List <string>(); // 深圳帐单
                List <string> dgbillList  = new List <string>(); //东莞帐单
                List <string> zsbillList  = new List <string>(); //中山帐单
                List <string> czbillList  = new List <string>(); //潮洲帐单
                List <string> daystatlist = new List <string>(); //帐号报表
                //if (eprIdLst == null || eprIdLst.Count==0)
                //{
                //    eprIdLst = dicEprInfo.Keys.ToList();
                //}
                Dictionary <int, MobileTypeCountModel> eprCount  = mobileDAO.GetSumSMScountByDay(eprIdLst, begintime, endtime); //查出企业发送量
                Dictionary <int, MobileTypeCountModel> billCount = new Dictionary <int, MobileTypeCountModel>();                //打折后企业的发送量
                foreach (int key in eprCount.Keys)
                {
                    try
                    {
                        MobileTypeCountModel mtcm    = null;
                        EprInfoModel         eprinfo = null;
                        try
                        {
                            mtcm    = eprCount[key];
                            eprinfo = dicEprInfo[key];
                            if (eprinfo != null && eprinfo.taocanId > 0)
                            {
                                continue;//套餐的不处理
                            }
                        }
                        catch (Exception ex)
                        {
                            MyDelegateFunc.WriteFmLog("打折异常[eprinfo]:" + ex.ToString());
                        }

                        if (eprinfo != null && (mtcm.CTcount > 0 || mtcm.CMcount > 0))
                        {
                            if (string.IsNullOrEmpty(eprinfo.bnetId) || eprinfo.bnetId.Equals("888"))
                            {
                                continue;
                            }

                            double        dprice = 10.00;
                            int           billct = mtcm.CTcount;
                            int           billcm = mtcm.CMcount;
                            BnetInfoModel bnetf  = null;
                            try
                            {
                                bnetf = dicBnetInfo[eprinfo.bnetId];
                            }
                            catch (Exception ex)
                            {
                                MyDelegateFunc.WriteFmLog("打折异常[bnetf]:" + ex.ToString());
                            }

                            if (bnetf != null)
                            {
                                //中山
                                if (bnetf.BnetAccount.StartsWith("760"))//eprinfo.areaId == 17
                                {
                                    billCount.Add(key, mtcm);
                                    continue;
                                }

                                string tprice = bnetf.Price;
                                if (!string.IsNullOrEmpty(tprice))
                                {
                                    bool b = double.TryParse(tprice, out dprice);
                                    if (dprice <= 0.00 || !b)
                                    {
                                        dprice = 10.00;
                                    }
                                }

                                MobileTypeCountModel mtcm_bill = new MobileTypeCountModel();
                                //double bcount_ct = billct * (dprice / 10);
                                mtcm_bill.CTcount = (int)(billct * (dprice / 10));// (int)Math.Ceiling(billct * (dprice / 10));

                                //  double bcount_cm = billcm * (dprice / 10);
                                mtcm_bill.CMcount    = (int)(billcm * (dprice / 10)); //(int)Math.Ceiling(billcm * (dprice / 10));
                                mtcm_bill.Pirce      = dprice + "";
                                mtcm_bill.InitialNum = billcm + billct;
                                string inf = string.Format("CreateBillJob==>企业id:{0},清单数量:{1},帐单数量:{2},单价:{3}", key, billcm + billct, mtcm_bill.CMcount + mtcm_bill.CTcount, tprice);
                                logger.Info(inf);
                                MyDelegateFunc.WriteFmLog(inf);
                                billCount.Add(key, mtcm_bill);
                            }//BnetInfo
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error("CreateBillJob==>计算账单条数异常:" + ex.Message);
                    }
                }//foreach eprCount


                //移动,联通
                foreach (int key in billCount.Keys)
                {
                    EprInfoModel         eprinfo     = eprDAO.GetEprInfo(key);
                    string               bnetId      = eprinfo.bnetId;
                    string               bnetAccount = eprinfo.bnetAccount;
                    MobileTypeCountModel mtcm        = billCount[key];//帐单数量

                    try
                    {
                        //生成sql

                        object[] obj = { eprinfo.id, bnetId, bnetAccount, mtcm.CTcount, mtcm.CUcount, mtcm.CMcount, yy, mm, dd, eprinfo.areaId, mtcm.Pirce, mtcm.InitialNum, mtcm.TotalCount };
                        string   sql = string.Format("Insert into JY15.gdkltx.dbo.t_billdaystat(EprId,BnetId,BnetAccount,CTcount,CUcount,CMcount,YY,MM,DD,AreaId,Price,InitialNum,TaoCanType) values({0},'{1}','{2}',{3},{4},{5},{6},{7},{8},{9},'{10}',{11},'{12}')", obj);
                        //object[] obj = { eprinfo.id, bnetId, bnetAccount, mtcm.CTcount, mtcm.CUcount, mtcm.CMcount, yy, mm, dd, mtcm.Pirce, mtcm.InitialNum, mtcm.TaoCanType };
                        //string sql = string.Format("Insert into  JY15.gdkltx.dbo.t_billdaystat(EprId,BnetId,BnetAccount,CTcount,CUcount,CMcount,YY,MM,DD,Price,InitialNum,TaoCanType) values({0},'{1}','{2}',{3},{4},{5},{6},{7},{8},'{9}','{10}','{11}')", obj);
                        MyDelegateFunc.WriteFmLog("CreateBillJob==>sql:" + sql);
                        logger.Info(sql);
                        daystatlist.Add(sql);
                    }
                    catch (Exception ex)
                    {
                        MyDelegateFunc.WriteFmLog("CreateBillJob==>保存sqlList失败:" + ex.ToString());
                    }
                    for (int i = 0; i < mtcm.CTcount; i++)
                    {
                        StringBuilder sbstr = new StringBuilder();
                        sbstr.Append(bnetId);
                        sbstr.Append("|");
                        sbstr.Append(bnetAccount);
                        sbstr.Append("|");
                        sbstr.Append("0|1|0|0|");
                        sbstr.Append(dtnow.ToString("yyyy/MM/dd H:mm:ss", DateTimeFormatInfo.InvariantInfo));
                        szbillList.Add(sbstr.ToString());

                        /*
                         * if (bnetAccount.StartsWith("755"))//深圳
                         * {
                         *  szbillList.Add(sbstr.ToString());
                         * }
                         * else if (bnetAccount.StartsWith("769"))//东莞
                         * {
                         *  dgbillList.Add(sbstr.ToString());
                         * }
                         * else if (bnetAccount.StartsWith("760"))//中山
                         * {
                         *  zsbillList.Add(sbstr.ToString());
                         * }
                         * else if (bnetAccount.StartsWith("0768"))//潮洲
                         * {
                         *  czbillList.Add(sbstr.ToString());
                         * }
                         * */
                    }

                    //电信
                    for (int j = 0; j < mtcm.CMcount; j++)
                    {
                        StringBuilder sbstr = new StringBuilder();
                        sbstr.Append(bnetId);
                        sbstr.Append("|");
                        sbstr.Append(bnetAccount);
                        sbstr.Append("|");
                        sbstr.Append("0|0|1|0|");
                        sbstr.Append(dtnow.ToString("yyyy/MM/dd H:mm:ss", DateTimeFormatInfo.InvariantInfo));
                        szbillList.Add(sbstr.ToString());

                        /*
                         * if (bnetAccount.StartsWith("755"))//深圳
                         * {
                         *  szbillList.Add(sbstr.ToString());
                         * }
                         * else if (bnetAccount.StartsWith("769"))//东莞
                         * {
                         *  dgbillList.Add(sbstr.ToString());
                         * }
                         * else if (bnetAccount.StartsWith("760"))//中山
                         * {
                         *  zsbillList.Add(sbstr.ToString());
                         * }
                         * else if (bnetAccount.StartsWith("0768"))//潮洲
                         * {
                         *  czbillList.Add(sbstr.ToString());
                         * }
                         * */
                    }


                    /*
                     * int billc = billCount[key];//帐单数量
                     * int totalcount = 0;//已累的数量
                     * List<SmsMobileModel> smslist = mobileDAO.GetListByYYMMDD(key, yy, mm, dd);
                     * foreach (SmsMobileModel sms in smslist)
                     * {
                     *    if (totalcount > billc)
                     *    {
                     *        break;
                     *    }
                     *    int t = Tools.GetMobileType(sms.mobile);
                     *    for (int i = 0; i < sms.smsCount; i++)
                     *    {
                     *        try
                     *        {
                     *            if (totalcount > billc)
                     *            {
                     *                break;
                     *            }
                     *            totalcount++;
                     *            // 账单格式:条数只能是1 多条,需要生成多条记录
                     *            // bnetid|bnetaccount|小灵通条数|移动条数|联通条数|电信条数|时间
                     *            StringBuilder sbstr = new StringBuilder();
                     *            sbstr.Append(bnetId);
                     *            sbstr.Append("|");
                     *            sbstr.Append(bnetAccount);
                     *            sbstr.Append("|");
                     *            switch (t)
                     *            {
                     *                case 1:
                     *                case 2:
                     *                    sbstr.Append("0|1|0|0|");
                     *                    break;
                     *                case 3:
                     *                    sbstr.Append("0|0|1|0|");
                     *                    break;
                     *                default:
                     *                    sbstr.Append("0|1|0|0|");
                     *                    break;
                     *                //	case 3:
                     *                //	sbstr.append("0|0|0|1|");
                     *                //	break;
                     *
                     *            }
                     *
                     *            sbstr.Append(sms.sendTime.ToString("yyyy/MM/dd H:mm:ss", DateTimeFormatInfo.InvariantInfo));
                     *
                     *            if (bnetAccount.StartsWith("755"))//深圳
                     *            {
                     *                szbillList.Add(sbstr.ToString());
                     *            }
                     *            else if (bnetAccount.StartsWith("769"))//东莞
                     *            {
                     *                dgbillList.Add(sbstr.ToString());
                     *            }
                     *            else if (bnetAccount.StartsWith("760"))//中山
                     *            {
                     *                zsbillList.Add(sbstr.ToString());
                     *            }
                     *        }
                     *        catch (Exception ex)
                     *        {
                     *            logger.Error("CreateBillJob==>生成账单字符串异常:" + ex.Message);
                     *        }
                     *
                     *    }//for smscount
                     *
                     * }//foreach smsList
                     */
                }//foreach billCount

                try
                {
                    if (daystatlist != null && daystatlist.Count > 0)
                    {
                        int result = SQLbll.BatchExec(daystatlist);
                        MyDelegateFunc.WriteFmLog("CreateBillJob==>保存sql fail:" + result);
                    }
                }
                catch (Exception ex)
                {
                    MyDelegateFunc.WriteFmLog("CreateBillJob==>保存sql失败:" + daystatlist[0]);
                    MyDelegateFunc.WriteFmLog("CreateBillJob==>保存sql失败:" + ex.Message);
                }


                FtpClient ftp = new FtpClient();

                //深圳账单
                if (szbillList != null)
                {
                    bool bsz = MyFileOptions.WriteFileTXT(szbillList, filePath);
                    MyDelegateFunc.WriteFmLog("CreateBillJob==>生成sz文件[" + filePath + "]结果:" + bsz);
                    if (bsz && isupload)
                    {
                        bool boolf = ftp.Upload(ftpdir, szftpfilename, filePath);
                        MyDelegateFunc.WriteFmLog("CreateBillJob==>上传sz账单[" + szftpfilename + "]结果:" + boolf);
                        if (boolf)
                        {
                            try
                            {
                                File.Move(filePath, dir + "\\" + szftpfilename);
                            }
                            catch (Exception ex)
                            {
                                MyDelegateFunc.WriteFmLog("CreateBillJob==>修改sz文件名[" + filePath + "]to[" + szftpfilename + "]失败:" + ex.Message);
                                logger.Error("CreateBillJob==>修改sz文件名[" + filePath + "]to[" + szftpfilename + "]失败:" + ex.Message);
                            }
                        }
                        else
                        {
                            MyDelegateFunc.WriteFmLog("CreateBillJob=FTP=>上传sz文件[" + filePath + "]失败");
                            logger.Error("CreateBillJob=FTP=>上传sz文件[" + filePath + "]失败");
                        }
                    }
                }

                //东莞账单
                if (dgbillList != null)
                {
                    bool bdg = MyFileOptions.WriteFileTXT(dgbillList, dgfilePath);
                    MyDelegateFunc.WriteFmLog("CreateBillJob==>生成dg文件[" + dgfilePath + "]结果:" + bdg);
                    if (bdg && isupload)
                    {
                        bool booldg = ftp.Upload(ftpdir, dgftpfilename, dgfilePath);
                        MyDelegateFunc.WriteFmLog("CreateBillJob==>上传dg账单[" + dgfilePath + "]结果:" + booldg);
                        if (booldg)
                        {
                            try
                            {
                                File.Move(dgfilePath, dir + "\\" + dgftpfilename);
                            }
                            catch (Exception ex)
                            {
                                logger.Error("CreateBillJob==>修改dg文件名[" + dgfilePath + "]to[" + dgftpfilename + "]失败:" + ex.Message);
                            }
                        }
                    }
                }



                //中山账单
                if (zsbillList != null)
                {
                    bool zsb = MyFileOptions.WriteFileTXT(zsbillList, zsfilePath);
                    MyDelegateFunc.WriteFmLog("CreateBillJob==>生成zs文件[" + zsfilePath + "]结果:" + zsb);
                    if (zsb && isupload)
                    {
                        bool booldg = ftp.Upload(ftpdir, zsftpfilename, zsfilePath);
                        MyDelegateFunc.WriteFmLog("CreateBillJob==>上传中山账单[" + zsfilePath + "]结果:" + booldg);
                        if (booldg)
                        {
                            try
                            {
                                File.Move(zsfilePath, dir + "\\" + zsftpfilename);
                            }
                            catch (Exception ex)
                            {
                                logger.Error("CreateBillJob==>修改中山文件名[" + zsfilePath + "]to[" + zsftpfilename + "]失败:" + ex.Message);
                            }
                        }
                    }
                }

                //潮洲账单
                if (czbillList != null)
                {
                    bool czb = MyFileOptions.WriteFileTXT(czbillList, czfilePath);
                    if (czb && isupload)
                    {
                        bool booldg = ftp.Upload(ftpdir, czftpfilename, czfilePath);
                        MyDelegateFunc.WriteFmLog("CreateBillJob==>上传潮洲账单[" + czfilePath + "]结果:" + booldg);
                        if (booldg)
                        {
                            try
                            {
                                File.Move(zsfilePath, dir + "\\" + czftpfilename);
                            }
                            catch (Exception ex)
                            {
                                logger.Error("CreateBillJob==>修改潮洲文件名[" + czfilePath + "]to[" + czftpfilename + "]失败:" + ex.Message);
                            }
                        }
                    }
                    else
                    {
                        logger.Error("CreateBillJob==>生成潮洲文件[" + czfilePath + "]失败");
                    }
                }
            }
            catch (Exception ex)
            {
                MyDelegateFunc.WriteFmLog("CreateBillJob==>Exception:" + ex.Message);
                logger.Error("CreateBillJob==>Exception:" + ex.Message);
            }
        }
        /// <summary>
        /// 计算套餐及超出部分
        /// </summary>
        /// <param name="dtnow">日期</param>
        /// <param name="isupload">是否上传</param>
        public void Work(DateTime dtnow, bool isupload)
        {
            string begintime = DateTools.FirstDayOfMonth(dtnow).ToShortDateString();
            string endtime   = DateTools.LastDayOfMonth(dtnow).ToShortDateString() + " 23:59:59";
            int    yy        = dtnow.Year;  // 得到年
            int    mm        = dtnow.Month; // 得到月
            int    dd        = dtnow.Day;   // 日
            int    hh        = dtnow.Hour;  // 小时

            string strmm = mm > 9 ? mm + "" : "0" + mm;
            string strdd = dd > 9 ? dd + "" : "0" + dd;
            string strhh = hh > 9 ? hh + "" : "0" + hh;

            strhh = "20";
            string        ftpdir = yy + strmm + strdd;// ftp上的每天一个文件夹
            string        dir    = Application.StartupPath + "\\" + FactoryNo;
            DirectoryInfo dim    = new DirectoryInfo(dir);

            if (!dim.Exists)
            {
                dim.Create();
            }
            dir += "\\" + yy + strmm + strdd;// 文件夹(厂家编号/yyyyMMdd)
            DirectoryInfo di = new DirectoryInfo(dir);

            if (!di.Exists)
            {
                di.Create();
            }
            //深圳
            string fileName      = ProductId + "_" + yy + strmm + strdd + strhh + "0001.txt.sending"; // 文件名
            string filePath      = dir + "\\" + fileName;
            string szftpfilename = ProductId + "_" + yy + strmm + strdd + strhh + "0001.txt";         // ftp保存文件名


            EprInfoDAL eprinfoDAL = new EprInfoDAL();
            Dictionary <int, EprInfoModel> eprDic = eprinfoDAL.GetTaoCanEprInfoAll2();


            SmsMobileDAL smsdal = new SmsMobileDAL();
            Dictionary <int, MobileTypeCountModel> eprCount  = smsdal.GetSumSMScountByMomth(eprDic.Keys.ToList(), begintime, endtime); //企业发送统计
            Dictionary <int, MobileTypeCountModel> billCount = new Dictionary <int, MobileTypeCountModel>();                           //套餐企业的发送量

            TaoCanInfoDAL taocanDAL = new TaoCanInfoDAL();
            Dictionary <int, TaoCanInfoModel> taocanDic = taocanDAL.GetAll(); //套餐企业信息
            List <string> daystatlist = new List <string>();                  //帐号报表
            List <string> szbillList  = new List <string>();                  // 深圳帐单

            //计算账单数量
            foreach (int key in eprCount.Keys)
            {
                MobileTypeCountModel mtcm    = eprCount[key]; //发送量
                EprInfoModel         eprinfo = eprDic[key];   //企业信息
                if (!taocanDic.ContainsKey(eprinfo.taocanId))
                {
                    continue;
                }
                TaoCanInfoModel taocaninfo = taocanDic[eprinfo.taocanId];                       //套餐信息
                int             billct     = mtcm.CMcount + mtcm.CTcount - taocaninfo.TCNumber; //超出套餐数量

                //套餐账单
                int taocanneiTotalCount = taocaninfo.Billnumber;


                if (billct > 0)//超出套餐量
                {
                    /*
                     * int taocanneiCTbillcount = (int)(taocaninfo.Billnumber / 2);//套餐内移动数量
                     * int taocanneiCMbillcount = taocaninfo.Billnumber - taocanneiCTbillcount;//套餐内电信动数量
                     *
                     *
                     * int taocanneiCTcount = (int)taocaninfo.TCNumber / 2;
                     * int taocanneiCMcount = taocaninfo.TCNumber = taocanneiCTcount;
                     * int ct = mtcm.CTcount - taocanneiCTcount > 0 ? mtcm.CTcount - taocanneiCTcount : 0;//套餐外移动多出数量
                     * int cm = mtcm.CMcount - taocanneiCMcount > 0 ? mtcm.CMcount - taocanneiCMcount : 0;//套餐外电信多出数量
                     * int ctwaibill = (int)Math.Ceiling(ct * (dprice / 10));//移动套餐外折算后数量
                     * int cmwaibill = (int)Math.Ceiling(cm * (dprice / 10));//电信动套餐外折算后数量
                     * */

                    double dprice = 10.00;
                    if (!string.IsNullOrEmpty(taocaninfo.TCOutsidePrice))
                    {
                        bool b = double.TryParse(taocaninfo.TCOutsidePrice, out dprice);
                        if (dprice <= 0.00 || !b)
                        {
                            dprice = 10.00;
                        }
                    }
                    int ctwaibill = (int)Math.Ceiling(billct * (dprice / 10));//移动套餐外折算后数量
                    int cmwaibill = 0;
                    //账单
                    MobileTypeCountModel mtcm_bill = new MobileTypeCountModel();
                    mtcm_bill.TotalCount = ctwaibill + cmwaibill + taocanneiTotalCount; //总量
                    mtcm_bill.CTcount    = mtcm_bill.TotalCount;                        //移动
                    mtcm_bill.CMcount    = 0;                                           //电信
                    MyDelegateFunc.WriteFmLog(string.Format("CreateTaoCanCloseBillJob==>【超出套餐】企业id:{0},清单数量:{1},帐单数量:{2},套餐外单价:{3},套餐量:{4}", key, (mtcm.CMcount + mtcm.CTcount), mtcm_bill.TotalCount, taocaninfo.TCOutsidePrice, taocaninfo.TCNumber));
                    billCount.Add(key, mtcm_bill);
                }
                else
                {
                    if (mtcm.TotalCount == 0)//未发送
                    {
                        MobileTypeCountModel mbill = new MobileTypeCountModel();
                        mbill.TotalCount = taocanneiTotalCount;
                        mbill.CTcount    = taocanneiTotalCount;
                        mbill.CMcount    = 0;
                        MyDelegateFunc.WriteFmLog(string.Format("CreateTaoCanCloseBillJob==>【未发】送企业id:{0},清单数量:{1}", key, mbill.TotalCount));
                        billCount.Add(key, mbill);
                    }
                    else//套餐内
                    {
                        double dprice = 10.00;
                        string tprice = taocaninfo.TCPrice;
                        if (!string.IsNullOrEmpty(tprice))
                        {
                            bool b = double.TryParse(tprice, out dprice);
                            if (dprice <= 0.00 || !b)
                            {
                                dprice = 10.00;
                            }
                        }

                        MobileTypeCountModel mbill = new MobileTypeCountModel();
                        mbill.TotalCount = taocanneiTotalCount;

                        //mbill.CTcount = (int)Math.Ceiling(mtcm.CTcount * (dprice / 10)); ;
                        // mbill.CMcount = taocanneiTotalCount - mbill.CTcount;
                        mbill.CTcount = taocanneiTotalCount;
                        mbill.CMcount = 0;
                        MyDelegateFunc.WriteFmLog(string.Format("CreateTaoCanCloseBillJob==>【套餐内】未发送企业id:{0},清单数量:{1},电信数量:{2},移动数量:{3}", key, mbill.TotalCount, mbill.CMcount, mbill.CMcount));
                        billCount.Add(key, mbill);
                    }
                }
            }


            //生成账单
            foreach (int key in billCount.Keys)
            {
                EprInfoModel         eprinfo = eprDic[key]; //企业信息
                MobileTypeCountModel mtcm = billCount[key]; //发送量
                string bnetId = eprinfo.bnetId, bnetAccount = eprinfo.bnetAccount;
                try
                {
                    //生成sql
                    object[] obj = { eprinfo.id, bnetId, bnetAccount, mtcm.CTcount, mtcm.CUcount, mtcm.CMcount, yy, mm, dd };
                    string   sql = string.Format("Insert into jy15.gdkltx.dbo.t_billdaystat(EprId,BnetId,BnetAccount,CTcount,CUcount,CMcount,YY,MM,DD) values({0},'{1}','{2}',{3},{4},{5},{6},{7},{8})", obj);
                    daystatlist.Add(sql);
                }
                catch (Exception ex)
                {
                    MyDelegateFunc.WriteFmLog("CreateTaoCanCloseBillJob==>生成sqlList失败:" + ex.Message);
                }
                for (int i = 0; i < mtcm.CTcount; i++)
                {
                    StringBuilder sbstr = new StringBuilder();
                    sbstr.Append(bnetId);
                    sbstr.Append("|");
                    sbstr.Append(bnetAccount);
                    sbstr.Append("|");
                    sbstr.Append("0|1|0|0|");
                    sbstr.Append(dtnow.ToString("yyyy/MM/dd H:mm:ss", DateTimeFormatInfo.InvariantInfo));
                    szbillList.Add(sbstr.ToString());
                }
            }

            try
            {
                if (daystatlist != null && daystatlist.Count > 0)
                {
                    int result = SQLbll.BatchExec(daystatlist);
                    MyDelegateFunc.WriteFmLog("CreateTaoCanCloseBillJob==>保存sql result:" + result);
                }
            }
            catch (Exception ex)
            {
                MyDelegateFunc.WriteFmLog("CreateTaoCanCloseBillJob==>保存sql失败:" + daystatlist[0]);
                MyDelegateFunc.WriteFmLog("CreateTaoCanCloseBillJob==>保存sql失败:" + ex.Message);
            }

            FtpClient ftp = new FtpClient();

            //深圳账单
            if (szbillList != null)
            {
                bool bsz = MyFileOptions.WriteFileTXT(szbillList, filePath);
                MyDelegateFunc.WriteFmLog("CreateTaoCanCloseBillJob==>生成sz套餐文件[" + filePath + "]结果:" + bsz);
                if (bsz)
                {
                    if (!isupload)
                    {
                        return;
                    }
                    bool boolf = ftp.Upload(ftpdir, szftpfilename, filePath);
                    MyDelegateFunc.WriteFmLog("CreateTaoCanCloseBillJob==>上传sz套餐账单[" + szftpfilename + "]结果:" + boolf);
                    if (boolf)
                    {
                        try
                        {
                            File.Move(filePath, dir + "\\" + szftpfilename);
                        }
                        catch (Exception ex)
                        {
                            MyDelegateFunc.WriteFmLog("CreateTaoCanCloseBillJob==>修改sz套餐文件名[" + filePath + "]to[" + szftpfilename + "]失败:" + ex.Message);
                            logger.Error("CreateTaoCanCloseBillJob==>修改sz套餐文件名[" + filePath + "]to[" + szftpfilename + "]失败:" + ex.Message);
                        }
                    }
                    else
                    {
                        MyDelegateFunc.WriteFmLog("CreateTaoCanCloseBillJob=FTP=>上传sz套餐文件[" + filePath + "]失败");
                        logger.Error("CreateTaoCanCloseBillJob=FTP=>上传sz套餐文件[" + filePath + "]失败");
                    }
                }
                else
                {
                    MyDelegateFunc.WriteFmLog("CreateTaoCanCloseBillJob==>生成sz文件[" + filePath + "]失败");
                    logger.Error("CreateTaoCanCloseBillJob==>生成sz文件[" + filePath + "]失败");
                }
            }
        }
示例#20
0
        public void Execute(IJobExecutionContext context)
        {
            DateTime dt     = DateTime.Now;
            int      yy     = dt.Year;  // 得到年
            int      mm     = dt.Month; // 得到月,因为从0开始的,所以要加1
            int      dd     = dt.Day;   // 日
            int      hh     = dt.Hour;  // 小时
            string   strmm  = mm > 9 ? mm + "" : "0" + mm;
            string   strdd  = dd > 9 ? dd + "" : "0" + dd;
            string   strhh  = hh > 9 ? hh + "" : "0" + hh;
            string   ftpdir = yy + strmm + strdd;// ftp上的每天一个文件夹

            FtpClient ftp = new FtpClient();

            try
            {
                if (!ftp.DirectoryIsExist(ftpdir))
                {
                    bool bmd = ftp.MakeDir(ftpdir);
                    MyDelegateFunc.WriteFmLog("CreateEmptyBillJob==>创建目录[" + ftpdir + "]结果:" + bmd);
                }
            }catch (Exception ex)
            {
                MyDelegateFunc.WriteFmLog("CreateEmptyBillJob==>创建目录[" + ftpdir + "]异常:" + ex.ToString());
            }


            //20 点的生成套餐账单,19点潮洲,21,22,23
            if (hh > 18)
            {
                return;
            }
            string        dir = Application.StartupPath + "\\" + FactoryNo;
            DirectoryInfo dim = new DirectoryInfo(dir);

            if (!dim.Exists)
            {
                dim.Create();
            }
            dir += "\\" + yy + strmm + strdd;// 文件夹(厂家编号/yyyyMMdd)
            DirectoryInfo di = new DirectoryInfo(dir);

            if (!di.Exists)
            {
                di.Create();
            }
            //深圳
            string        fileName      = ProductId + "_" + yy + strmm + strdd + strhh + "00" + "01.txt.sending"; // 文件名
            string        filePath      = dir + "\\" + fileName;
            string        szftpfilename = ProductId + "_" + yy + strmm + strdd + strhh + "00" + "01.txt";         // ftp保存文件名
            List <string> szbillList    = new List <string>();                                                    // 深圳帐单
            bool          bsz           = MyFileOptions.WriteFileTXT(szbillList, filePath);

            MyDelegateFunc.WriteFmLog("CreateEmptyBillJob==>生成空文件[" + filePath + "]结果:" + bsz);
            if (bsz)
            {
                bool boolf = ftp.Upload(ftpdir, szftpfilename, filePath);
                MyDelegateFunc.WriteFmLog("CreateEmptyBillJob==>上传空文件[" + filePath + "]结果:" + boolf);
                if (boolf)
                {
                    File.Move(filePath, dir + "\\" + szftpfilename);
                }
                else
                {
                }
            }
        }