/// <summary> /// 保存数据 /// </summary> private void DataSave() { #region 得到 post 提交的数据 int dataLength = Request.Form.Count + 3; string[] filedName = new string[dataLength]; object[] filedValue = new object[dataLength]; for (int i = 0; i < Request.Form.Count; i++) { string controlName = Request.Form.Keys[i]; filedName[i] = controlName; filedValue[i] = Request.Form[controlName].Trim();//添加去除空格 } if (Request.Files.Count > 0 && Request.Files[0].FileName != "") { //保存二进制数据 filedName[dataLength - 3] = Request.Files.Keys[0]; HttpPostedFile postedFile = Request.Files[0]; byte[] buffer = new byte[postedFile.ContentLength]; postedFile.InputStream.Read(buffer, 0, postedFile.ContentLength); postedFile.InputStream.Close(); filedValue[dataLength - 3] = buffer; //保存文件格式 filedName[dataLength - 2] = "imgFormat"; filedValue[dataLength - 2] = postedFile.FileName.Remove(0, postedFile.FileName.LastIndexOf('.')); } #endregion string config_id = "1005"; GetFormInfo getfrom = new GetFormInfo(); string message = ""; //得到操作类型 Detail、Update、Add string operate_Type = "Update"; string desc = ""; string pk_Field = "ID"; string pk_Value = GetID(); string sqlWhere = " where " + pk_Field + " = '" + pk_Value + "'"; message = getfrom.DataSave(config_id, filedName, filedValue, sqlWhere); desc = " ID 为 " + pk_Value; #region 操作记录 string IP = GetSystemProperties.GetIP(); string Mac = GetSystemProperties.GetMacBySendARP(IP); string userID = getSession("userID"); string userName = getSession("userName"); LogInformation.OperationLog(userID, userName, operate_Type, config_id, desc, IP, Mac); #endregion Response.Write(message); Response.End(); }
/// <summary> /// 导入数据 /// </summary> /// <param name="dt">需要导入数据表</param> /// <returns>提示信息</returns> private string ImportData(DataTable dt) { GetFormInfo getF = new GetFormInfo(); int executeRowNum = getF.ImportExcelData(Request.Form["config_Id"].ToString(), dt); string message = " 成功导入数据 " + executeRowNum.ToString() + " 行! "; #region 操作记录 string IP = GetSystemProperties.GetIP(); string Mac = GetSystemProperties.GetMacBySendARP(IP); string userID = getSession("userID"); string userName = getSession("userName"); LogInformation.OperationLog(userID, userName, "Import", Request.QueryString["Config_ID"], message, IP, Mac); #endregion return(message); }
/// <summary> /// 保存数据 /// </summary> private void DataSave() { string config_id = Request.Form["config_Id"].ToString(); GetFormInfo getfrom = new GetFormInfo(); #region 得到 post 提交的数据 int dataLength = Request.Form.Count + 3; string[] filedName = new string[dataLength]; object[] filedValue = new object[dataLength]; for (int i = 0; i < Request.Form.Count; i++) { string controlName = Request.Form.Keys[i]; filedName[i] = controlName; filedValue[i] = Request.Form[controlName].Trim();//添加去除空格 } if (Request.Files.Count > 0 && Request.Files[0].FileName != "") { //保存二进制数据 filedName[dataLength - 3] = Request.Files.Keys[0]; HttpPostedFile postedFile = Request.Files[0]; string type = getfrom.CheckSaveFileAddress(config_id, Request.Files.Keys[0]); if (type == "文件上传控件_Disk") { string uploadPath = HttpContext.Current.Server.MapPath("upfiles") + "\\" + config_id + "\\"; if (postedFile != null) { if (!Directory.Exists(uploadPath)) { Directory.CreateDirectory(uploadPath); } string fileName = DateTime.Now.ToString("yyyy-MM-dd_HHmmss") + "-" + postedFile.FileName; postedFile.SaveAs(uploadPath + fileName); filedValue[dataLength - 3] = fileName; //保存文件格式 filedName[dataLength - 2] = "imgFormat"; filedValue[dataLength - 2] = postedFile.FileName.Remove(0, postedFile.FileName.LastIndexOf('.')); } } else { byte[] buffer = new byte[postedFile.ContentLength]; postedFile.InputStream.Read(buffer, 0, postedFile.ContentLength); postedFile.InputStream.Close(); filedValue[dataLength - 3] = buffer; //保存文件格式 filedName[dataLength - 2] = "imgFormat"; filedValue[dataLength - 2] = postedFile.FileName.Remove(0, postedFile.FileName.LastIndexOf('.')); } } #endregion //联合主键 if (Request.Form["Composite_FieldName"] != null && Request.Form["Composite_FieldName"] != "undefined") { filedName[dataLength - 1] = "." + Request.Form["Composite_FieldName"].ToString(); filedValue[dataLength - 1] = Request.Form["Composite_FieldValue"].ToString(); } string message = ""; //得到操作类型 Detail、Update、Add string operate_Type = Request.Form["operate_Type"].ToString(); string desc = ""; if (operate_Type == "Update") { string pk_Field = Request.Form["pk_Field"].ToString(); string pk_Value = Request.Form["pk_Value"].ToString(); string sqlWhere = " where " + pk_Field + " = '" + pk_Value + "'"; message = getfrom.DataSave(config_id, filedName, filedValue, sqlWhere); desc = Request.Form["pk_Field"].ToString() + " 为 " + Request.Form["pk_Value"].ToString(); } else { message = getfrom.DataSave(config_id, filedName, filedValue); desc = message; } #region 操作记录 string IP = GetSystemProperties.GetIP(); string Mac = GetSystemProperties.GetMacBySendARP(IP); string userID = getSession("userID"); string userName = getSession("userName"); LogInformation.OperationLog(userID, userName, operate_Type, config_id, desc, IP, Mac); #endregion Response.Write(message); Response.End(); }