Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
0
        public JsonResult ReadExcelFile()
        {
            List<OrdersImport> orders = new List<OrdersImport>();
            Session["import"] = null;
            try
            {
                if (!string.IsNullOrEmpty(Request.Form["Files"]) && !string.IsNullOrEmpty(Request.Form["ImportType"]) && !string.IsNullOrEmpty(Request.Form["Channel"]))
                {
                    string improtType = Request.Form["ImportType"];
                    int channel = Convert.ToInt32(Request.Form["Channel"]);
                    string excelFile = Server.MapPath(excelPath) + Request.Form["Files"].Split('|')[0];

                    Resource.CoreMessage = new CoreResource("OrderImport");
                    orderImport = OrderImportFactory.InitOrderImport(channel);

                    siteConfigMgr = new SiteConfigMgr(Server.MapPath(xmlPath));
                    SiteConfig config = siteConfigMgr.GetConfigByName("Template_OrderImport_Path");
                    if (orderImport != null && config != null)
                    {
                        string template = Server.MapPath(string.IsNullOrEmpty(config.Value) ? config.DefaultValue : config.Value);
                        if (System.IO.File.Exists(template))
                        {
                            orders = orderImport.ReadExcel2Page(excelFile, template, orderImport.CurChannel.model_in);
                            Session["import"] = orders;
                        }
                    }
                }
            }
            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);
            }
            return Json(orders);
        }