public Dictionary <int, List <int> > upload_base_company(string newfile, string fileName, string action, JObject json_formdata) { Base_Company_Method bcm = new Base_Company_Method(); Switch_helper_Base_blend_web sw = new Switch_helper_Base_blend_web(); DataTable dtExcel = bcm.GetExcelData_Table(Server.MapPath(newfile), 0); List <string> stringList = new List <string>(); //记住发生错误的行数 List <int> errorlines = new List <int>(); //记住插入成功的个数 int count = 0; //Sql.busi_RecordInfor bc = new Sql.busi_RecordInfor(); Sql.busi_SpecialHsConvernet bsh = new Sql.busi_SpecialHsConvernet(); //插入成功的个数(返回放入dictionary) List <int> successinsert = new List <int>(); //返回值 Dictionary <int, List <int> > returndic = new Dictionary <int, List <int> >(); for (int i = 0; i < dtExcel.Rows.Count; i++) { for (int j = 0; j < dtExcel.Columns.Count; j++) { stringList.Add(dtExcel.Rows[i][j].ToString()); } //商品HS编码 //附加码 string CODE = stringList[0]; string EXTRACODE = stringList[1]; //是否启用 string ENABLED = stringList[5] == "是" ? "1" : "0"; //商品名称 string NAME = stringList[2]; //类型 string TYPE = stringList[3]; //国家 string COUNTRY = stringList[4]; //备注 string REMARK = stringList[6]; //启用日期 string startdate = json_formdata.Value <string>("STARTDATE"); //停用日期 string enddate = json_formdata.Value <string>("ENDDATE"); string formdata = "{\"CODE\":\"" + CODE + "\",\"EXTRACODE\":\"" + EXTRACODE + "\",\"ENABLED\":\"" + ENABLED + "\",\"STARTDATE\":\"" + startdate + "\",\"ENDDATE\":\"" + enddate + "\"," + "\"NAME\":\"" + NAME + "\",\"TYPE\":\"" + TYPE + "\",\"COUNTRY\":\"" + COUNTRY + "\",\"REMARK\":\"" + REMARK + "\"}"; JObject json = (JObject)JsonConvert.DeserializeObject(formdata); if (bsh.check_repeat(json).Rows.Count > 0 || string.IsNullOrEmpty(json.Value <string>("CODE"))) { errorlines.Add(i + 2); } else { bsh.inser_specialhsconvert(json, COUNTRY); count = count + 1; } stringList.Clear(); } successinsert.Add(count); returndic.Add(1, successinsert); returndic.Add(2, errorlines); return(returndic); }
private void save() { string formdata = Request["formdata"]; string country = Request["country"]; JObject json = (JObject)JsonConvert.DeserializeObject(formdata); Sql.busi_SpecialHsConvernet bsh = new Sql.busi_SpecialHsConvernet(); string response = String.Empty; Base_Codename_Method bm = new Base_Codename_Method(); if (string.IsNullOrEmpty(json.Value <string>("ID"))) { //查询是否有重复值 if (json.Value <string>("ENABLED") == "1") { if (bsh.check_repeat(json).Rows.Count > 0) { response = "{\"success\":\"4\"}"; } else { int i = bsh.inser_specialhsconvert(json, country); response = "{\"success\":" + (i > 0 ? "true" : "false") + "}"; } } else { int i = bsh.inser_specialhsconvert(json, country); response = "{\"success\":" + (i > 0 ? "true" : "false") + "}"; } } else { if (json.Value <string>("ENABLED") == "1") { if (bsh.check_update_repeat(json).Rows.Count > 0) { response = "{\"success\":\"4\"}"; } else { DataTable dt = bsh.before_data(json); int i = bsh.update_base_specialhsconvert(json, country); if (i > 0) { string content = bm.getbasespecialhsconvert(dt, json, country); bsh.insert_alert_record(json, content); response = "{\"success\":" + (i > 0 ? "true" : "false") + "}"; } } } else { DataTable dt = bsh.before_data(json); int i = bsh.update_base_specialhsconvert(json, country); if (i > 0) { string content = bm.getbasespecialhsconvert(dt, json, country); bsh.insert_alert_record(json, content); response = "{\"success\":" + (i > 0 ? "true" : "false") + "}"; } } } Response.Write(response); Response.End(); }