void UCDictionaryAddOrEdit_ExportEvent(object sender, EventArgs e)
 {
     try
     {
         string dir = Application.StartupPath + @"\ExportFile";
         if (!Directory.Exists(dir))
         {
             Directory.CreateDirectory(dir);
         }
         SaveFileDialog sfd = new SaveFileDialog();
         sfd.InitialDirectory = dir;
         sfd.Title = "导出文件";
         sfd.DefaultExt = "xls";
         sfd.Filter = "Microsoft Office Excel 文件(*.xls;*.xlsx)|*.xls;*.xlsx|Microsoft Office Excel 文件(*.xls)|*.xls|Microsoft Office Excel 文件(*.xlsx)|*.xlsx";
         sfd.FileName = dir + @"\字典码表" + DateTime.Now.ToString("yyyy-MM-dd") + ".xls";
         DialogResult result = sfd.ShowDialog();
         if (result == DialogResult.OK)
         {
             int totalCount = 0;
             PercentProcessOperator process = new PercentProcessOperator();
             #region 匿名方法,后台线程执行完调用
             process.BackgroundWork =
                 delegate(Action<int> percent)
                 {
                     DataTable dt = DBHelper.GetTable("查询码表", "v_dictionaries", "*", where, "", "order by dic_code");
                     totalCount = dt.Rows.Count;
                     dt = ExcelHandler.HandleDataTableForExcel(dt, dgvDicList);
                     ExcelHandler.ExportDTtoExcel(dt, "", sfd.FileName, percent);
                 };
             #endregion
             process.MessageInfo = "正在执行中";
             process.Maximum = totalCount;
             #region 匿名方法,后台线程执行完调用
             process.BackgroundWorkerCompleted += new EventHandler<BackgroundWorkerEventArgs>(
                     delegate(object osender, BackgroundWorkerEventArgs be)
                     {
                         if (be.BackGroundException == null)
                         {
                             MessageBoxEx.ShowInformation("导出成功!");
                         }
                         else
                         {
                             Utility.Log.Log.writeLineToLog("【字典码表】" + be.BackGroundException.Message, "client");
                             MessageBoxEx.ShowWarning("导出出现异常");
                         }
                     }
                 );
             #endregion
             process.Start();
         }
     }
     catch (Exception ex)
     {
         Utility.Log.Log.writeLineToLog("【字典码表】" + ex.Message, "client");
         MessageBoxEx.ShowWarning("导出失败!");
     }
 }
Пример #2
0
 //导出
 void UCReceivableManage_ExportEvent(object sender, EventArgs e)
 {
     try
     {
         string dir = Application.StartupPath + @"\ExportFile";
         if (!Directory.Exists(dir))
         {
             Directory.CreateDirectory(dir);
         }
         SaveFileDialog sfd = new SaveFileDialog();
         sfd.InitialDirectory = dir;
         sfd.Title = "导出文件";
         sfd.DefaultExt = "xls";
         sfd.Filter = "Microsoft Office Excel 文件(*.xls;*.xlsx)|*.xls;*.xlsx|Microsoft Office Excel 文件(*.xls)|*.xls|Microsoft Office Excel 文件(*.xlsx)|*.xlsx";
         sfd.FileName = dir + @"\" + Title + DateTime.Now.ToString("yyyy-MM-dd") + ".xls";
         DialogResult result = sfd.ShowDialog();
         if (result == DialogResult.OK)
         {
             string strWhere = GetWhere();
             DataTable dt = DBHelper.GetTable("查询" + Title, "tb_bill_receivable", "*", strWhere, "", "order by create_time desc");
             if (dt == null || dt.Rows.Count == 0)
             {
                 MessageBoxEx.ShowInformation("没有可导出的数据!");
                 return;
             }
             dt.DataTableToDate("order_date");
             if (orderType == DataSources.EnumOrderType.RECEIVABLE)
             {
                 dt.DateTableToEnum("payment_type", typeof(DataSources.EnumReceivableType));
             }
             else
             {
                 dt.DateTableToEnum("payment_type", typeof(DataSources.EnumPaymentType));
             }
             dt.DateTableToEnum("order_status", typeof(DataSources.EnumAuditStatus));
             PercentProcessOperator process = new PercentProcessOperator();
             #region 匿名方法,后台线程执行完调用
             process.BackgroundWork =
                 delegate(Action<int> percent)
                 {
                     dt = ExcelHandler.HandleDataTableForExcel(dt, dgvBillReceivable);
                     ExcelHandler.ExportDTtoExcel(dt, "", sfd.FileName, percent);
                 };
             #endregion
             process.MessageInfo = "正在执行中";
             process.Maximum = dt.Rows.Count;
             #region 匿名方法,后台线程执行完调用
             process.BackgroundWorkerCompleted += new EventHandler<BackgroundWorkerEventArgs>(
                     delegate(object osender, BackgroundWorkerEventArgs be)
                     {
                         if (be.BackGroundException == null)
                         {
                             MessageBoxEx.ShowInformation("导出成功!");
                         }
                         else
                         {
                             Utility.Log.Log.writeLineToLog("【" + Title + "】" + be.BackGroundException.Message, "client");
                             MessageBoxEx.ShowWarning("导出出现异常");
                         }
                     }
                 );
             #endregion
             process.Start();
         }
     }
     catch (Exception ex)
     {
         Utility.Log.Log.writeLineToLog("【" + Title + "】" + ex.Message, "client");
         MessageBoxEx.ShowWarning("导出失败!");
     }
 }
        /// <summary> 全量同步车辆客户信息
        /// </summary>
        /// <returns>返回错误信息</returns>
        public static string InitData_Customer()
        {
            //如果没有接入码或者sap代码,则不调用接口
            if (string.IsNullOrEmpty(GlobalStaticObj_YT.ClientID) ||
                string.IsNullOrEmpty(GlobalStaticObj_YT.SAPCode))
            {
                return "";
            }
            PercentProcessOperator process = new PercentProcessOperator();
            process.BackgroundWork = delegate(Action<int> percent)
            {
                int percentCount = 0;
                string errMsg = "";
                string serviceType = "CustomerQuery";
                //GlobalStaticObj_Server.Instance.ServiceStationProvince = "330000";
                string url = "https://isgqas.yutong.com:2222/ISG/downloadFile/downloadFile.do";
                Hashtable ht = new Hashtable();
                ht.Add("method", "downLoadFile");
                ht.Add("provinceCode", GlobalStaticObj_Server.Instance.ServiceStationProvince);
                ht.Add("serviceType", serviceType);
                string tempDir = "tmp";
                string fileName = serviceType + GlobalStaticObj_Server.Instance.ServiceStationProvince;
                string zipFilePath = tempDir + "\\" + fileName + ".zip";
                DateTime dtStart = GlobalStaticObj_Server.Instance.CurrentDateTime;//开始时间
                percent(10);
                bool flagDownLoad = HttpRequest.DoGet(url, ht, zipFilePath);
                if (!flagDownLoad)
                {
                    GlobalStaticObj_Server.YTInterfaceLogService.WriteLog("全量同步车辆客户信息", "下载文件失败");
                    //return "下载文件失败";
                }
                string fileDir = ZipCompress.UnZipFile(zipFilePath, tempDir, GlobalStaticObj_YT.KeySecurity_YT, ref errMsg);
                if (!string.IsNullOrEmpty(errMsg))
                {
                    GlobalStaticObj_Server.YTInterfaceLogService.WriteLog("全量同步车辆客户信息", errMsg);
                    //return errMsg;
                }
                percent(15);
                string jsonFilePath = fileDir + "\\" + fileName + ".json";
                if (!File.Exists(jsonFilePath))
                {
                    GlobalStaticObj_Server.YTInterfaceLogService.WriteLog("全量同步车辆客户信息", "文件不存在");
                    //return "文件不存在";
                }
                string jsonStr = File.ReadAllText(jsonFilePath, Encoding.UTF8);
                string customerJson = HandleJson(jsonStr, out errMsg);
                percent(18);
                if (!string.IsNullOrEmpty(errMsg))
                {
                    GlobalStaticObj_Server.YTInterfaceLogService.WriteLog("全量同步车辆客户信息", errMsg);
                    //return errMsg;
                }

                QueryCustomer.customer[] customerArr = Newtonsoft.Json.JsonConvert.DeserializeObject<QueryCustomer.customer[]>(customerJson);
                jsonStr = null;//释放
                customerJson = null;
                int updateCount = 0;
                bool flagContact = SaveCustomerNotBatch(customerArr, ref updateCount);
                percent(80);
                customerArr = null;//释放
                if (!flagContact)
                {
                    GlobalStaticObj_Server.YTInterfaceLogService.WriteLog("全量同步车辆客户信息", "车辆客户更新到数据库失败");
                    //return "车辆客户更新到数据库失败";
                }
                DateTime dtEnd = GlobalStaticObj_Server.Instance.CurrentDateTime;//结束时间
                int totalCount = int.Parse(DBHelper.GetSingleValue("", GlobalStaticObj_Server.DbPrefix + GlobalStaticObj_Server.Instance.MainAccCode, "select count(1) from tb_customer where data_source='2'"));
                WebServUtil.WriteInterficeSync(DataSources.EnumInterfaceType.BusCustomer, DataSources.EnumExternalSys.YTCRM, totalCount, updateCount, GlobalStaticObj_Server.Instance.CurrentDateTime);
                WebServUtil.WriteInterficeSyncLog(DataSources.EnumInterfaceType.BusCustomer, DataSources.EnumExternalSys.YTCRM, DataSources.EnumSyncDirection.DownLoad, "tb_customer", dtStart, dtEnd, updateCount, "");
                percent(100);
            };
            process.MessageInfo = "正在初始化车辆客户信息";
            process.Maximum = 100;
            process.BackgroundWorkerCompleted += new EventHandler<BackgroundWorkerEventArgs>(process_BackgroundWorkerCompleted);
            process.Start();
            return "";
        }
 /// <summary> 全量同步配件信息
 /// </summary>
 /// <returns>返回错误信息</returns>
 public static string InitData_Part()
 {
     //如果没有接入码或者sap代码,则不调用接口
     if (string.IsNullOrEmpty(GlobalStaticObj_YT.ClientID) ||
         string.IsNullOrEmpty(GlobalStaticObj_YT.SAPCode))
     {
         return "";
     }
     PercentProcessOperator process = new PercentProcessOperator();
     process.BackgroundWork = delegate(Action<int> percent)
     {
         int percentCount = 0;
         string errMsg = "";
         string serviceType = "Part";
         string url = "https://isgqas.yutong.com:2222/ISG/downloadFile/downloadFile.do";
         Hashtable ht = new Hashtable();
         ht.Add("method", "downLoadFile");
         //ht.Add("provinceCode", GlobalStaticObj_Server.Instance.ServiceStationProvince);
         ht.Add("serviceType", serviceType);
         string tempDir = "tmp";
         string zipFilePath = tempDir + "\\" + serviceType + ".zip";
         DateTime dtStart = GlobalStaticObj_Server.Instance.CurrentDateTime;//开始时间
         percent(5);
         bool flagDownLoad = HttpRequest.DoGet(url, ht, zipFilePath);
         if (!flagDownLoad)
         {
             GlobalStaticObj_Server.YTInterfaceLogService.WriteLog("全量同步配件信息", "下载文件失败");
             //return "下载文件失败";
         }
         string fileDir = ZipCompress.UnZipFile(zipFilePath, tempDir, serviceType, GlobalStaticObj_YT.KeySecurity_YT, ref errMsg);
         if (!string.IsNullOrEmpty(errMsg))
         {
             GlobalStaticObj_Server.YTInterfaceLogService.WriteLog("全量同步配件信息", errMsg);
             //return errMsg;
         }
         int updateCount = 0;
         string[] files = Directory.GetFiles(fileDir);
         if (files.Count() == 0)
         {
             GlobalStaticObj_Server.YTInterfaceLogService.WriteLog("全量同步配件信息", "找不到解压后的json文件!");
             throw new Exception("找不到解压后的json文件!");
         }
         percentCount = 8;
         percent(percentCount);
         int pre = 92 / files.Count();//分割量
         foreach (string fileName in files)
         {
             percentCount += pre;
             percent(percentCount);
             if (!File.Exists(fileName))
             {
                 GlobalStaticObj_Server.YTInterfaceLogService.WriteLog("全量同步配件信息", "文件不存在");
                 //return "文件不存在";
             }
             string jsonStr = File.ReadAllText(fileName, Encoding.UTF8);
             QueryPartsModels parts = Newtonsoft.Json.JsonConvert.DeserializeObject<QueryPartsModels>(jsonStr);
             jsonStr = null;//释放
             if (parts.ReturnStatus != "S")
             {
                 parts = null;//释放
                 //return bus.ReturnValue;
             }
             updateCount = 0;
             bool flagContact = SavePartNotBatch(parts.details, ref updateCount);
             parts = null;//释放
             if (!flagContact)
             {
                 GlobalStaticObj_Server.YTInterfaceLogService.WriteLog("全量同步配件信息", "配件更新到数据库失败");
                 //return "配件更新到数据库失败";
             }
         }
         DateTime dtEnd = GlobalStaticObj_Server.Instance.CurrentDateTime;//结束时间
         int totalCount = int.Parse(DBHelper.GetSingleValue("", GlobalStaticObj_Server.DbPrefix + GlobalStaticObj_Server.Instance.MainAccCode, "select count(1) from tb_parts where data_source='2'"));
         WebServUtil.WriteInterficeSync(DataSources.EnumInterfaceType.Part, DataSources.EnumExternalSys.YTCRM, totalCount, updateCount, GlobalStaticObj_Server.Instance.CurrentDateTime);
         WebServUtil.WriteInterficeSyncLog(DataSources.EnumInterfaceType.Part, DataSources.EnumExternalSys.YTCRM, DataSources.EnumSyncDirection.DownLoad, "tb_parts", dtStart, dtEnd, updateCount, "");
     };
     process.MessageInfo = "正在初始化配件信息";
     process.Maximum = 100;
     process.BackgroundWorkerCompleted += new EventHandler<BackgroundWorkerEventArgs>(process_BackgroundWorkerCompleted);
     process.Start();
     return "";
 }
Пример #5
0
 /// <summary> 导出excel
 /// </summary>
 /// <param name="fileName">文件名</param>
 /// <param name="dt">数据表</param>
 /// <returns>错误信息</returns>
 public static string ExportExcel(string fileName, DataTable dt)
 {
     string errMsg = string.Empty;
     string dir = Application.StartupPath + @"\ExportFile";
     if (!Directory.Exists(dir))
     {
         Directory.CreateDirectory(dir);
     }
     SaveFileDialog sfd = new SaveFileDialog();
     sfd.InitialDirectory = dir;
     sfd.Title = "导出文件";
     sfd.DefaultExt = "xls";
     sfd.Filter = "Microsoft Office Excel 文件(*.xls;*.xlsx)|*.xls;*.xlsx|Microsoft Office Excel 文件(*.xls)|*.xls|Microsoft Office Excel 文件(*.xlsx)|*.xlsx";
     sfd.FileName = dir + @"\" + fileName;
     DialogResult result = sfd.ShowDialog();
     if (result == DialogResult.OK)
     {
         PercentProcessOperator process = new PercentProcessOperator();
         #region 匿名方法,后台线程执行调用
         process.BackgroundWork =
             delegate(Action<int> percent)
             {
                 ExcelHandler.ExportDTtoExcel(dt, "", sfd.FileName, percent);
             };
         #endregion
         process.MessageInfo = "正在执行中";
         process.Maximum = dt.Rows.Count;
         #region 匿名方法,后台线程执行完调用
         process.BackgroundWorkerCompleted += new EventHandler<BackgroundWorkerEventArgs>(
                 delegate(object osender, BackgroundWorkerEventArgs be)
                 {
                     if (be.BackGroundException == null)
                     {
                         MessageBoxEx.ShowInformation("导出成功!");
                     }
                     else
                     {
                         throw be.BackGroundException;
                     }
                 }
             );
         #endregion
         process.Start();
     }
     return errMsg;
 }