示例#1
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                this.textBox1.Text = this.openFileDialog1.FileName;

                DataTable             dt   = FileSvr.GetExcelDatatable(this.textBox1.Text, this.openFileDialog1.SafeFileName);
                List <CategoryEntity> list = new List <CategoryEntity>();
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        CategoryEntity ca = new CategoryEntity();
                        ca.Category1 = dr[0].ToString().Trim();
                        ca.Category2 = dr[1].ToString().Trim();
                        ca.Category3 = dr[2].ToString().Trim();
                        list.Add(ca);
                    }
                }
                foreach (var item in list)
                {
                    if (!string.IsNullOrEmpty(item.Category1) && !string.IsNullOrEmpty(item.Category2) && !string.IsNullOrEmpty(item.Category3))
                    {
                        EC_Category ecca1 = ExcelToCategoryFormsDA.VCategory1(item.Category1);
                        if (ecca1 == null)
                        {
                            CategoryEntity entity1 = ExcelToCategoryFormsDA.AddCategory1(item);
                            CategoryEntity entity2 = ExcelToCategoryFormsDA.AddCategory2(entity1);
                            CategoryEntity entity3 = ExcelToCategoryFormsDA.AddCategory3(entity2);
                        }
                        else
                        {
                            EC_Category ecca2 = ExcelToCategoryFormsDA.VCategory2(item.Category2);
                            if (ecca2 == null)
                            {
                                EC_Category EC_CategoryRelationSysNo = ExcelToCategoryFormsDA.GetEC_CategoryRelationSysNo(item.Category1);
                                item.ParentCategorySysNo = ecca1.SysNo;
                                item.ParentSysNo         = EC_CategoryRelationSysNo.SysNo;
                                CategoryEntity entity2 = ExcelToCategoryFormsDA.AddCategory2(item);
                                CategoryEntity entity3 = ExcelToCategoryFormsDA.AddCategory3(entity2);
                            }
                            else
                            {
                                EC_Category ecca3 = ExcelToCategoryFormsDA.VCategory3(item.Category3);
                                if (ecca3 == null)
                                {
                                    EC_Category EC_CategoryRelationSysNo = ExcelToCategoryFormsDA.GetEC_CategoryRelationSysNo(item.Category2);
                                    item.ParentCategorySysNo = ecca2.SysNo;
                                    item.ParentSysNo         = EC_CategoryRelationSysNo.SysNo;
                                    CategoryEntity entity3 = ExcelToCategoryFormsDA.AddCategory3(item);
                                }
                            }
                        }
                    }
                }
                this.label2.Text = "上传完成,谢谢使用";
            }
        }
示例#2
0
        public ActionResult AjaxSaveExcel()
        {
            var data = SerializationUtility.JsonDeserialize2 <List <ExcelInfo> >(Request.Form["data"]);

            if (!string.IsNullOrEmpty(data[0].Url))
            {
                System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(".");
                System.Text.RegularExpressions.Match m = r.Match(data[0].Url);
                if (m.Success)
                {
                    string suffix = data[0].Url.Substring(data[0].Url.LastIndexOf(".") + 1);
                    if (suffix != "xls" && suffix != "xlsx" && suffix != "xlsm")
                    {
                        throw new BusinessException(LanguageHelper.GetText("只能导入Excel格式,请参考模板!!!"));
                    }
                }
            }
            string    Url = System.Web.HttpContext.Current.Server.MapPath(string.Format("~/UploadFiles/{0}", data[0].Url));
            DataTable dt  = FileSvr.GetExcelDatatable(Url, data[0].Name);

            if (dt.Rows.Count > 0)
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append("<SOTrackingInfos>");
                string    UserID          = UserAuthHelper.GetCurrentUser().UserID;
                int       SellerSysNo     = UserAuthHelper.GetCurrentUser().SellerSysNo;
                int[]     soSysNos        = new int[dt.Rows.Count];
                ArrayList TrackingNumbers = new ArrayList();
                int       i = 0;
                foreach (DataRow dr in dt.Rows)
                {
                    SOOutStockWaitReportRequest outStockWaitReportRequest = new Entity.SO.SOOutStockWaitReportRequest();
                    outStockWaitReportRequest.Logistics = new LogisticsInfo();
                    //如果订单号为空,SOSysNo=0
                    if (!string.IsNullOrEmpty(dr[0].ToString()))
                    {
                        try
                        {
                            outStockWaitReportRequest.SOSysNo = int.Parse(dr[0].ToString());
                        }
                        catch (Exception ex)
                        {
                            throw new BusinessException(LanguageHelper.GetText("订单号只能是正整数"));
                        }
                    }
                    else
                    {
                        outStockWaitReportRequest.SOSysNo = 0;
                    }
                    outStockWaitReportRequest.Logistics.TrackingNumber = string.IsNullOrEmpty(dr[1].ToString()) ? "" : dr[1].ToString();
                    soSysNos.SetValue(outStockWaitReportRequest.SOSysNo, i++);
                    TrackingNumbers.Add(outStockWaitReportRequest.Logistics.TrackingNumber);
                    stringBuilder.Append("<SOTrackingInfo><SONumber>" + outStockWaitReportRequest.SOSysNo + "</SONumber><TrackingNumber>" + outStockWaitReportRequest.Logistics.TrackingNumber + "</TrackingNumber></SOTrackingInfo>");
                }
                stringBuilder.Append("</SOTrackingInfos>");
                SOService.CreatMoreSOSysNoAndTrackingNumber(stringBuilder.ToString(), UserID, SellerSysNo, soSysNos, TrackingNumbers);
                return(Json(new { Success = true, Message = LanguageHelper.GetText("操作成功") }));
            }
            else
            {
                return(Json(new { Error = true, Message = LanguageHelper.GetText("Excel没有数据") }));
            }
        }