/// <summary> /// 得到一个对象实体 /// </summary> public Model.payPic GetModel(int id) { StringBuilder strSql = new StringBuilder(); StringBuilder str1 = new StringBuilder(); Model.payPic model = new Model.payPic(); //利用反射获得属性的所有公共属性 PropertyInfo[] pros = model.GetType().GetProperties(); foreach (PropertyInfo p in pros) { str1.Append(p.Name + ",");//拼接字段 } strSql.Append("select top 1 " + str1.ToString().Trim(',')); strSql.Append(" from MS_payPic"); strSql.Append(" where pp_id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; DataTable dt = DbHelperSQL.Query(strSql.ToString(), parameters).Tables[0]; if (dt.Rows.Count > 0) { return(DataRowToFileModel(dt.Rows[0])); } else { return(null); } }
private void UpLoadPayFile(HttpContext context) { Model.sysconfig sysConfig = new BLL.sysconfig().loadConfig(); //检查是否允许匿名上传 if (!new ManagePage().IsAdminLogin()) { context.Response.Write("{\"status\": 0, \"msg\": \"禁止匿名非法上传!\"}"); return; } string fileName = DTRequest.GetString("name"); //文件名 int pid = DTRequest.GetQueryInt("pid"); string ftype = DTRequest.GetQueryString("ftype");; //文件类别 bool _isthumbnail = false; //默认不生成缩略图 byte[] byteData = FileHelper.ConvertStreamToByteBuffer(context.Request.InputStream); //获取文件流 if (byteData.Length == 0) { context.Response.Write("{\"status\": 0, \"msg\": \"请选择要上传文件!\"}"); return; } if (DTRequest.GetQueryString("IsThumbnail") == "1") { _isthumbnail = true; } UpLoad upLoad = new UpLoad(); fileName = fileName.Replace(" ", "");//去掉空格 string msg = upLoad.PayFileSaveAs(byteData, fileName, _isthumbnail, pid, ftype); msg = Regex.Replace(msg, @"(\\[^bfrnt\\/'\""])", "\\$1");//利用正则表达式先把待解析的字符串中的带“\”特殊字符处理,再进行解析操作 JObject jo = JObject.Parse(msg); if (jo["status"].ToString() == "1") { Model.manager manager = new ManagePage().GetAdminInfo();//获得当前登录管理员信息 Model.payPic file = new Model.payPic(); file.pp_rid = pid; file.pp_type = Utils.ObjToByte(ftype); file.pp_fileName = fileName; file.pp_filePath = jo["path"].ToString(); file.pp_thumbFilePath = jo["thumb"].ToString(); file.pp_size = Utils.ObjToDecimal(jo["size"].ToString(), 0); file.pp_addDate = DateTime.Now; file.pp_addName = manager.real_name; file.pp_addPerson = manager.user_name; new BLL.payPic().insertPayFile(file, manager); } //返回成功信息 context.Response.Write(msg); context.Response.End(); }
/// <summary> /// 添加活动文件 /// </summary> /// <param name="file"></param> /// <returns></returns> public int insertPayFile(Model.payPic model, Model.manager manager) { int ret = dal.insertPayFile(model); if (ret > 0) { Model.business_log logmodel = new Model.business_log(); logmodel.ol_relateID = model.pp_rid.Value; logmodel.ol_title = model.pp_type == 1?"添加付款明细附件":"添加费业务付款申请附件"; logmodel.ol_content = "文件名:" + model.pp_fileName + ",文件路径:" + model.pp_filePath; logmodel.ol_operateDate = DateTime.Now; new business_log().Add(DTEnums.ActionEnum.Add.ToString(), logmodel, manager.user_name, manager.real_name); } return(ret); }
/// <summary> /// 将对象转换实体 /// </summary> public Model.payPic DataRowToFileModel(DataRow row) { Model.payPic model = new Model.payPic(); if (row != null) { //利用反射获得属性的所有公共属性 Type modelType = model.GetType(); for (int i = 0; i < row.Table.Columns.Count; i++) { //查找实体是否存在列表相同的公共属性 PropertyInfo proInfo = modelType.GetProperty(row.Table.Columns[i].ColumnName); if (proInfo != null && row[i] != DBNull.Value) { proInfo.SetValue(model, row[i], null);//用索引值设置属性值 } } } return(model); }
/// <summary> /// 删除活动文件 /// </summary> /// <param name="file"></param> /// <param name="manager"></param> /// <returns></returns> public bool deletePayFile(Model.payPic file, Model.manager manager) { if (dal.deleteOrderFile(file.pp_id.Value)) { string path = System.AppDomain.CurrentDomain.BaseDirectory.ToString() + "\\" + file.pp_filePath; if (File.Exists(path)) { File.Delete(path); } Model.business_log logmodel = new Model.business_log(); logmodel.ol_relateID = file.pp_id.Value; logmodel.ol_title = file.pp_type == 1 ? "删除付款明细附件" : "删除费业务付款申请附件"; logmodel.ol_content = "文件名:" + file.pp_fileName + ",文件路径:" + file.pp_filePath; logmodel.ol_operateDate = DateTime.Now; new business_log().Add(DTEnums.ActionEnum.Add.ToString(), logmodel, manager.user_name, manager.real_name); return(true); } return(false); }
/// <summary> /// 添加活动文件 /// </summary> /// <param name="file"></param> /// <returns></returns> public int insertPayFile(Model.payPic model) { StringBuilder strSql = new StringBuilder(); StringBuilder str1 = new StringBuilder(); //数据字段 StringBuilder str2 = new StringBuilder(); //数据参数 //利用反射获得属性的所有公共属性 PropertyInfo[] pros = model.GetType().GetProperties(); List <SqlParameter> paras = new List <SqlParameter>(); strSql.Append("insert into MS_payPic("); foreach (PropertyInfo pi in pros) { //如果不是主键则追加sql字符串 if (!pi.Name.Equals("pp_id")) { //判断属性值是否为空 if (pi.GetValue(model, null) != null) { str1.Append(pi.Name + ","); //拼接字段 str2.Append("@" + pi.Name + ","); //声明参数 paras.Add(new SqlParameter("@" + pi.Name, pi.GetValue(model, null))); //对参数赋值 } } } strSql.Append(str1.ToString().Trim(',')); strSql.Append(") values ("); strSql.Append(str2.ToString().Trim(',')); strSql.Append(") "); strSql.Append(";select @@IDENTITY;"); object obj = DbHelperSQL.GetSingle(strSql.ToString(), paras.ToArray()); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
private void deletePayFile(HttpContext context) { //检查是否允许匿名上传 if (!new ManagePage().IsAdminLogin()) { context.Response.Write("{\"status\": 0, \"msg\": \"禁止匿名非法删除!\"}"); return; } BLL.payPic bll = new BLL.payPic(); Model.manager manager = new ManagePage().GetAdminInfo();//获得当前登录管理员信息 int id = DTRequest.GetQueryInt("id"); Model.payPic file = bll.GetModel(id); if (bll.deletePayFile(file, manager)) { context.Response.Write("{\"status\": 1, \"msg\": \"删除成功!\"}"); context.Response.End(); } context.Response.Write("{\"status\": 0, \"msg\": \"删除失败!\"}"); context.Response.End(); }
//保存 protected void btnSubmit_Click(object sender, EventArgs e) { string result = ""; if (action == DTEnums.ActionEnum.Edit.ToString()) //修改 { ChkAdminLevel("sys_unBusiness_list", DTEnums.ActionEnum.Edit.ToString()); //检查权限 result = DoEdit(this.id); if (result != "") { PrintJscriptMsg(result, ""); return; } if (fromOrder == "true") { PrintMsg("修改非业务支付申请成功!"); } else { JscriptMsg("修改非业务支付申请成功!", "unBusinessPay_list.aspx"); } } else if (action == DTEnums.ActionEnum.Add.ToString()) //添加 { ChkAdminLevel("sys_unBusiness_list", DTEnums.ActionEnum.Add.ToString()); //检查权限 int id = 0; result = DoAdd(out id); if (result != "") { PrintJscriptMsg(result, ""); return; } if (fromOrder == "true") { PrintMsg("添加非业务支付申请成功!"); } else { JscriptMsg("添加非业务支付申请成功!", "unBusinessPay_list.aspx"); } if (fileUp.HasFile) { for (int i = 0; i < fileUp.PostedFiles.Count; i++) { string savePath = Server.MapPath("~/uploadPay/"); if (!Directory.Exists(savePath)) { //需要注意的是,需要对这个物理路径有足够的权限,否则会报错 //另外,这个路径应该是在网站之下,而将网站部署在C盘却把文件保存在D盘 Directory.CreateDirectory(savePath); } if (!Directory.Exists(savePath + "2/" + id + "/")) { Directory.CreateDirectory(savePath + "2/" + id + "/"); } Model.payPic file = new Model.payPic(); file.pp_rid = id; file.pp_type = 2; file.pp_fileName = fileUp.PostedFiles[i].FileName; file.pp_filePath = "uploadPay/2/" + id + "/" + fileUp.PostedFiles[i].FileName; //file.pp_thumbFilePath = jo["thumb"].ToString(); file.pp_size = Math.Round((decimal)fileUp.PostedFiles[i].ContentLength / 1024, 2, MidpointRounding.AwayFromZero); file.pp_addDate = DateTime.Now; file.pp_addName = manager.real_name; file.pp_addPerson = manager.user_name; fileUp.PostedFiles[i].SaveAs(savePath + "2/" + id + "/" + fileUp.PostedFiles[i].FileName);//保存文件 new BLL.payPic().insertPayFile(file, manager); } } } }