public string QueryCityZip()
 {
     zMgr = new ZipMgr(mySqlConnectionString);
     string json = string.Empty;
     try
     {
         if (!string.IsNullOrEmpty(Request.Params["zipcode"]))
         {
             json = "{success:true,data:" + JsonConvert.SerializeObject(zMgr.QueryCityAndZip(Request.Params["zipcode"])) + "}";//返回json數據
         }
     }
     catch (Exception ex)
     {
         Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
         logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
         logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
         log.Error(logMessage);
         json = "[]";
     }
     return json;
 }
Example #2
0
        public HttpResponseBase Import()
        {
            List<OrdersImport> all = (List<OrdersImport>)Session["import"] ?? null;
            int successCount = 0;
            int totalCount = 0;
            string json = string.Empty;
            try
            {
                if (all != null)
                {
                    if (!string.IsNullOrEmpty(Request.Form["Orders"]) && !string.IsNullOrEmpty(Request.Form["Files"]) && !string.IsNullOrEmpty(Request.Form["ImportType"]) && !string.IsNullOrEmpty(Request.Form["Channel"]))
                    {
                        string orders = Request.Form["Orders"];
                        int channel = Convert.ToInt32(Request.Form["Channel"]);
                        string improtType = Request.Form["ImportType"];
                        int site_id = int.Parse(Request.Form["site"]);//add xw
                        string files = Request.Form["Files"];

                        Resource.CoreMessage = new CoreResource("OrderImport");
                        orderImport = OrderImportFactory.InitOrderImport(channel);
                        if (orderImport != null)
                        {
                            string[] names = files.Split('|');
                            string execlFile = files.LastIndexOf("|") != -1 ? Server.MapPath(excelPath) + names[0] : Server.MapPath(excelPath) + files;
                            string pdfFile = files.LastIndexOf("|") != -1 && names.Length == 3 ? names[2] : "";

                            //修改 Excel 表裏面的地址  add by zhuoqin0830w  2015/04/17
                            for (int i = 0; i < all.Count; i++)
                            {
                                zMgr = new ZipMgr(connectionString);
                                if (!string.IsNullOrEmpty(all[i].agpesadrzip))
                                {
                                    string small = zMgr.QueryCityAndZip(all[i].agpesadrzip).small;
                                    int index = all[i].agpesadr.IndexOf(small);
                                    if (index != -1)
                                    {
                                        string newAddress = all[i].agpesadr.Substring(index + small.Length);
                                        all[i].agpesadr = newAddress;
                                    }
                                }
                            }

                            successCount = orderImport.Import2DB(all, pdfFile, improtType, orders, site_id, ref totalCount);
                            if (successCount > 0)
                            {
                                ImportOrdersLog log = new ImportOrdersLog { Channel_Id = channel, TCount = totalCount, Success_Count = successCount };
                                log.File_Name = names[1];
                                log.Import_Date = DateTime.Now;
                                log.Exec_Name = (Session["caller"] as Caller).user_username;

                                importOrdersLogMgr = new ImportOrdersLogMgr(connectionString);
                                importOrdersLogMgr.Save(log);
                            }
                        }
                    }
                    all.FindAll(m => m.IsSel).ForEach(m => m.IsSel = false);
                    Session["import"] = all;
                }
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
            }
            json = "{Total:" + totalCount + ",SucccessCount:" + successCount + ",Orders:" + JsonConvert.SerializeObject(all) + "}";
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }