public string Update(string json, string columns, string clientInf) { Dictionary <string, string> resultDic = new Dictionary <string, string>(); resultDic["result"] = ""; resultDic["message"] = ""; try { sara.dd.ldsw.model.tbl_ld_xgsbds model = Eva.Library.Format.FormatEntityTool.FormatJsonToModel <sara.dd.ldsw.model.tbl_ld_xgsbds>(json); columns = FormatColumns(columns).Replace("^", ","); resultDic["result"] = "true"; resultDic["message"] = _idal_tbl_ld_xgsbds.Update(model, columns, null); NewLog("数据更新成功,更新的数据为:json:" + json + ",columns:" + columns, "sql_update", clientInf); } catch (Exception ex) { resultDic["result"] = "false"; resultDic["message"] = Eva.Library.Format.FormatTextTool.ErrorMessageFormat(ex.Message + ex.StackTrace); NewLog("数据更新失败,更新的数据为:json:" + json + ",columns:" + columns + ",异常信息:" + Eva.Library.Format.FormatTextTool.ErrorMessageFormat(ex.Message + ex.StackTrace), "sql_update", clientInf); } return(Eva.Library.Format.FormatEntityTool.FormatDicToJson(resultDic)); }
public string Add(string json, string clientInf) { Dictionary <string, string> resultDic = new Dictionary <string, string>(); resultDic["result"] = ""; resultDic["message"] = ""; try { sara.dd.ldsw.model.tbl_ld_xgsbds model = Eva.Library.Format.FormatEntityTool.FormatJsonToModel <sara.dd.ldsw.model.tbl_ld_xgsbds>(json); resultDic["result"] = "true"; resultDic["message"] = _idal_tbl_ld_xgsbds.Add(model, null); NewLog("数据创建成功,创建的数据为:" + json, "sql_insert", clientInf); } catch (Exception ex) { resultDic["result"] = "false"; resultDic["message"] = Eva.Library.Format.FormatTextTool.ErrorMessageFormat(ex.Message + ex.StackTrace); NewLog("数据创建失败,创建的数据为:" + json + ",异常信息:" + Eva.Library.Format.FormatTextTool.ErrorMessageFormat(ex.Message + ex.StackTrace), "sql_insert", clientInf); } return(Eva.Library.Format.FormatEntityTool.FormatDicToJson(resultDic)); }
public string Analysis(string json, string columns, string clientInf, string czlx) { //首先保存数据 Dictionary <string, string> resultDic = new Dictionary <string, string>(); resultDic["result"] = ""; resultDic["message"] = ""; try { _t = sara.dd.ldsw.commonclass.commonclass.CreateIAccessDataTrans(); _t.getTrans().begin(); sara.dd.ldsw.model.tbl_ld_xgsbds model = Eva.Library.Format.FormatEntityTool.FormatJsonToModel <sara.dd.ldsw.model.tbl_ld_xgsbds>(json); //获取附件根路径 string FileUpLoadRootPath = Eva.Library.Configuration.ConfigurationManager.AppSettings["FileUpLoadRootPath"].ToString() + "fileuploadpath/"; FileUpLoadRootPath = Eva.Library.Format.FormatTextTool.GetMapPath(FileUpLoadRootPath, HttpContext.Current.Server); //获取附件名称 //_iAccessData = sara.dd.ldsw.commonclass.commonclass.CreateIAccessData(); string sqlString = ""; string sql = ""; sqlString = "SELECT fileuploadname FROM tbl_file_content WHERE menuid='" + model.f_drwj + "'"; DataTable dt = _t.Query(sqlString).Tables[0]; //判断是否上传附件 if (dt.Rows.Count > 0 && dt.Rows[0]["fileuploadname"] != null && dt.Rows[0]["fileuploadname"].ToString().Length > 0) { DataTable importfile = commonclass.commonclass.ReadExcel(FileUpLoadRootPath + dt.Rows[0]["fileuploadname"].ToString()).Tables[0]; //判断是否为正确的导入模板 if (importfile.Columns[0].ColumnName == "客户编号" && importfile.Columns[1].ColumnName == "新水表底数") { sqlString = "DELETE FROM tbl_ld_xgsbdszb WHERE fk_tbl_ld_xgsbds_sys_id='" + model.sys_id + "'"; string aa = _t.ExecuteSql(sqlString).ToString(); //创建子表对象list DateTimeFormatInfo dtFormat = new DateTimeFormatInfo(); dtFormat.ShortDatePattern = "yyyy/MM/dd"; IDictionary <String, String> userInfDic = Eva.Library.Format.FormatEntityTool.FormatJsonToDic(clientInf); System.DateTime currentTime = new System.DateTime(); currentTime = System.DateTime.Now; DateTime blankTime = Convert.ToDateTime("1900/01/01", dtFormat); #region 循环Excel实例化子表对象 for (int i = 0; i < importfile.Rows.Count; i++) { DataRow dr = importfile.Rows[i]; if (dr[0].ToString() == "" || dr[1].ToString() == "") { resultDic["result"] = "false"; resultDic["message"] = "客户编号或新水表底数未填写,请重新确认!"; } else { sara.dd.ldsw.model.tbl_ld_khb model_tbl_ld_khb = new sara.dd.ldsw.model.tbl_ld_khb(); string khbh = dr[0].ToString().PadLeft(10, '0'); IList <sara.dd.ldsw.model.tbl_ld_khb> ml = _idal_tbl_ld_khb.GetList(" f_khbh = '" + khbh + "'and f_value1 is null and f_value2 is null and f_ztid='0' ", "", "*", "", "", _t); if (ml.Count > 0) { sara.dd.ldsw.model.tbl_ld_khb khmodel = ml[0]; //创建子表实例化对象 sara.dd.ldsw.model.tbl_ld_xgsbdszb tempmodel = new sara.dd.ldsw.model.tbl_ld_xgsbdszb(); tempmodel.sys_id = 0; tempmodel.fk_tbl_ld_xgsbds_sys_id = model.sys_id.ToString(); tempmodel.sys_creatuserid = userInfDic["userid"].ToString(); tempmodel.sys_creatusername = userInfDic["username"].ToString(); tempmodel.sys_lastedituserid = userInfDic["userid"].ToString(); tempmodel.sys_lasteditusername = userInfDic["username"].ToString(); tempmodel.sys_creatdate = currentTime; tempmodel.sys_lasteditdate = currentTime; tempmodel.sys_deldate = blankTime; tempmodel.sys_delflag = "0"; #region 对象赋值 tempmodel.f_khbh = khbh; tempmodel.f_xsbds = dr[1].ToString(); tempmodel.f_dh = khmodel.f_dh; tempmodel.f_dz = khmodel.f_dz; tempmodel.f_yhm = khmodel.f_yhm; tempmodel.f_sbbh = khmodel.f_sbbh; tempmodel.f_ysbds = khmodel.f_bqzm; string sys_id = _idal_tbl_ld_xgsbdszb.Add(tempmodel, _t); #endregion sql = "update tbl_ld_khb set f_value1='" + czlx + "',f_value2 = '" + model.sys_id + "' where sys_id = '" + model_tbl_ld_khb.sys_id + "'"; _t.ExecuteSql(sql); } #endregion } } _t.getTrans().commit(); string result1 = this.Update(json, columns, clientInf); resultDic["result"] = "true"; resultDic["message"] = result1; } else { resultDic["result"] = "false"; resultDic["message"] = "导入模板错误,请下载正确的导入模板进行导入!"; } } else { resultDic["result"] = "false"; resultDic["message"] = "请先上传导入文件再进行分析!"; } NewLog("数据更新成功,更新的数据为:json:" + json + ",columns:" + columns, "sql_update", clientInf); } catch (Exception ex) { if (_t != null) { _t.getTrans().rollback(); } resultDic["result"] = "false"; resultDic["message"] = Eva.Library.Format.FormatTextTool.ErrorMessageFormat(ex.Message + ex.StackTrace); NewLog("数据更新失败,更新的数据为:json:" + json + ",columns:" + columns + ",异常信息:" + Eva.Library.Format.FormatTextTool.ErrorMessageFormat(ex.Message + ex.StackTrace), "sql_update", clientInf); } return(Eva.Library.Format.FormatEntityTool.FormatDicToJson(resultDic)); }