public Dictionary <int, List <int> > upload_base_company(string newfile, string fileName, string action, JObject json_formdata, string table) { 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.Base_blend_web bc = new Sql.Base_blend_web(); //插入成功的个数(返回放入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()); } ////代码 //名字 //string code = stringList[0]; string name = stringList[1]; ////是否启用 //备注 //string enabled = stringList[2] == "是" ? "1" : "0"; string remark = stringList[3]; ////启用日期 //string startdate = json_formdata.Value<string>("STARTDATE"); ////停用日期 //string enddate = json_formdata.Value<string>("ENDDATE"); //string formdata = "{\"CODE\":\"" + code + "\",\"NAME\":\"" + name + "\",\"ENABLED\":\"" + enabled + "\",\"REMARK\":\"" + remark + "\",\"STARTDATE\":\"" + startdate + "\",\"ENDDATE\":\"" + enddate + "\"}"; string formdata = sw.importValue(json_formdata, table, stringList); JObject json = (JObject)JsonConvert.DeserializeObject(formdata); if (bc.check_repeat(table, json) > 0 || string.IsNullOrEmpty(json.Value <string>("CODE"))) { errorlines.Add(i + 2); } else { bc.insertTable(table, json); count = count + 1; } stringList.Clear(); } successinsert.Add(count); returndic.Add(1, successinsert); returndic.Add(2, errorlines); return(returndic); }
public Dictionary <int, List <int> > upload_base_company(string newfile, string fileName, string action, JObject json_formdata, string table) { 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.Base_blend_web bc = new Sql.Base_blend_web(); //插入成功的个数(返回放入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()); } string formdata = sw.importValue(json_formdata, table, stringList); JObject json = (JObject)JsonConvert.DeserializeObject(formdata); if (bc.check_repeat(table, json) > 0 || string.IsNullOrEmpty(json.Value <string>("CODE"))) { errorlines.Add(i + 2); } else { bc.insertTable(table, json); count = count + 1; } stringList.Clear(); } successinsert.Add(count); returndic.Add(1, successinsert); returndic.Add(2, errorlines); return(returndic); }
private void save_category(string formdata, string action) { JObject json = (JObject)JsonConvert.DeserializeObject(formdata); Sql.Base_blend_web bc = new Sql.Base_blend_web(); string response = ""; string table = ""; switch (action) { case "save_category": table = "category"; break; case "save_chapter": table = "base_declhschapter"; break; case "save_smallclass": table = "base_declhsclass"; break; } if (bc.check_repeat(table, json) > 0) { response = "{\"success\":\"4\"}"; } else { int i = bc.insertTable(table, json); if (i > 0) { response = "{\"success\":\"5\"}"; } } Response.Write(response); Response.End(); }
private void save(string table, string formdata) { JObject json = (JObject)JsonConvert.DeserializeObject(formdata); Sql.Base_blend_web bc = new Sql.Base_blend_web(); //返回界面值 string response = ""; if (string.IsNullOrEmpty(json.Value <string>("ID"))) { if (json.Value <string>("ENABLED") == "1") { if (bc.check_repeat(table, json) > 0) { response = "{\"success\":\"4\"}"; } else { int i = bc.insertTable(table, json); if (i > 0) { response = "{\"success\":\"5\"}"; } } } else { int i = bc.insertTable(table, json); if (i > 0) { response = "{\"success\":\"5\"}"; } } } else { if (json.Value <string>("ENABLED") == "1") { if (bc.update_check_repeat(table, json) > 0) { response = "{\"success\":\"4\"}"; } else { //获取修改之前的datatable DataTable dt = bc.getBeforeChangeData(table, json); int i = bc.updataTable(table, json); if (i > 0) { //插入修改信息到表内 int j = bc.insertAlterRecordTable(dt, table, json); if (j > 0) { response = "{\"success\":\"5\"}"; } } } } else { //获取修改之前的datatable DataTable dt = bc.getBeforeChangeData(table, json); int i = bc.updataTable(table, json); if (i > 0) { //插入修改信息到表内 int j = bc.insertAlterRecordTable(dt, table, json); if (j > 0) { response = "{\"success\":\"5\"}"; } } } } Response.Write(response); Response.End(); }