/// <summary> /// 获得数据列表 /// </summary> public List <System.Model.repairs_img> DataTableToList(DataTable dt) { List <System.Model.repairs_img> modelList = new List <System.Model.repairs_img>(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { System.Model.repairs_img model; for (int n = 0; n < rowsCount; n++) { model = new System.Model.repairs_img(); if (dt.Rows[n]["id"].ToString() != "") { model.id = int.Parse(dt.Rows[n]["id"].ToString()); } model.img = dt.Rows[n]["img"].ToString(); if (dt.Rows[n]["pudate"].ToString() != "") { model.pudate = DateTime.Parse(dt.Rows[n]["pudate"].ToString()); } model.guishu = dt.Rows[n]["guishu"].ToString(); model.uploader = dt.Rows[n]["uploader"].ToString(); modelList.Add(model); } } return(modelList); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(System.Model.repairs_img model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into repairs_img("); strSql.Append("img,pudate,guishu,uploader"); strSql.Append(") values ("); strSql.Append("@img,@pudate,@guishu,@uploader"); strSql.Append(") "); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@img", SqlDbType.NVarChar, 200), new SqlParameter("@pudate", SqlDbType.DateTime), new SqlParameter("@guishu", SqlDbType.NVarChar, 50), new SqlParameter("@uploader", SqlDbType.NVarChar, 50) }; parameters[0].Value = model.img; parameters[1].Value = model.pudate; parameters[2].Value = model.guishu; parameters[3].Value = model.uploader; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public System.Model.repairs_img GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select id, img, pudate, guishu, uploader "); strSql.Append(" from repairs_img "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; System.Model.repairs_img model = new System.Model.repairs_img(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["id"].ToString() != "") { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } model.img = ds.Tables[0].Rows[0]["img"].ToString(); if (ds.Tables[0].Rows[0]["pudate"].ToString() != "") { model.pudate = DateTime.Parse(ds.Tables[0].Rows[0]["pudate"].ToString()); } model.guishu = ds.Tables[0].Rows[0]["guishu"].ToString(); model.uploader = ds.Tables[0].Rows[0]["uploader"].ToString(); return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(System.Model.repairs_img model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update repairs_img set "); strSql.Append(" img = @img , "); strSql.Append(" pudate = @pudate , "); strSql.Append(" guishu = @guishu , "); strSql.Append(" uploader = @uploader "); strSql.Append(" where id=@id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4), new SqlParameter("@img", SqlDbType.NVarChar, 200), new SqlParameter("@pudate", SqlDbType.DateTime), new SqlParameter("@guishu", SqlDbType.NVarChar, 50), new SqlParameter("@uploader", SqlDbType.NVarChar, 50) }; parameters[0].Value = model.id; parameters[1].Value = model.img; parameters[2].Value = model.pudate; parameters[3].Value = model.guishu; parameters[4].Value = model.uploader; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string res = ""; JsonData jsonResult = new JsonData(); try { //设备编号 //string facility = Request["facility"] != null ? Utility.Helper.Checkstr(Request["facility"]) : ""; //用户编号 string customId = _bll.getUserToke(Utility.Helper.gerString(Request["memberid"])); //原因 string cause = Request["cause"] != null?Utility.Helper.Checkstr(Request["cause"]) : ""; //报修类型 string type = Request["type"] != null?Utility.Helper.Checkstr(Request["type"]) : ""; #region 报修设备 if (!string.IsNullOrEmpty(customId) && !string.IsNullOrEmpty(cause)) { string toid = System.Guid.NewGuid().ToString(); System.Model.repairs rp = new System.Model.repairs(); rp.cause = cause; rp.customId = customId; //rp.facility = facility; rp.pudate = System.DateTime.Now; rp.toid = toid; rp.types = Utility.Helper.gerInt(type); if (_bll.rebll.Add(rp) > 0) { #region 判断是否有图 List <FileInfos> fio = UploadFile(Request, "/Upload/", "repairs/"); if (fio.Count > 0) { for (int i = 0; i < fio.Count; i++) { FileInfos fs = fio[i]; System.Model.repairs_img ri = new System.Model.repairs_img(); ri.img = fs.datafilename; ri.pudate = System.DateTime.Now; ri.uploader = customId; ri.guishu = toid; _bll.reibll.Add(ri); } } #endregion } jsonResult["res"] = (int)MyEnum.ResultEnum.成功; jsonResult["msg"] = "报修成功"; jsonResult["code"] = ""; } else { jsonResult["res"] = (int)MyEnum.ResultEnum.失败; jsonResult["msg"] = "报修失败"; jsonResult["code"] = "参数有误"; } #endregion } catch (Exception ex) { jsonResult["res"] = (int)MyEnum.ResultEnum.系统错误; jsonResult["msg"] = "服务器繁忙,请稍后再试"; jsonResult["code"] = ex.Message; } res = JsonMapper.ToJson(jsonResult); res = MyString.UnicodeToString(res); Response.Write(res); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(System.Model.repairs_img model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(System.Model.repairs_img model) { return(dal.Add(model)); }