/// <summary> /// 更新一条数据 /// </summary> public int Update(SCZM.Model.Base.base_RepairItem model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update base_RepairItem set "); strSql.Append("ItemName=@ItemName,"); strSql.Append("FlagDel=@FlagDel,"); strSql.Append("OperaId=@OperaId,"); strSql.Append("OperaName=@OperaName,"); strSql.Append("OperaTime=@OperaTime,"); strSql.Append("ItemNat=@ItemNat"); strSql.Append(" where FlagDel=0 and ID=@ID "); SqlParameter[] parameters = { new SqlParameter("@ItemName", SqlDbType.NVarChar, 20), new SqlParameter("@FlagDel", SqlDbType.Int, 4), new SqlParameter("@OperaId", SqlDbType.Int, 4), new SqlParameter("@OperaName", SqlDbType.NVarChar, 10), new SqlParameter("@OperaTime", SqlDbType.DateTime), new SqlParameter("@ItemNat", SqlDbType.Decimal), new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = model.ItemName; parameters[1].Value = model.FlagDel; parameters[2].Value = model.OperaId; parameters[3].Value = model.OperaName; parameters[4].Value = model.OperaTime; parameters[5].Value = model.ItemNat; parameters[6].Value = model.ID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); return(rows); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(SCZM.Model.Base.base_RepairItem model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into base_RepairItem("); strSql.Append("ItemName,FlagDel,OperaId,OperaName,OperaTime,ItemNat)"); strSql.Append(" values ("); strSql.Append("@ItemName,@FlagDel,@OperaId,@OperaName,@OperaTime,@ItemNat)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@ItemName", SqlDbType.NVarChar, 20), new SqlParameter("@FlagDel", SqlDbType.Int, 4), new SqlParameter("@OperaId", SqlDbType.Int, 4), new SqlParameter("@OperaName", SqlDbType.NVarChar, 10), new SqlParameter("@OperaTime", SqlDbType.DateTime), new SqlParameter("@ItemNat", SqlDbType.Decimal) }; parameters[0].Value = model.ItemName; parameters[1].Value = model.FlagDel; parameters[2].Value = model.OperaId; parameters[3].Value = model.OperaName; parameters[4].Value = model.OperaTime; parameters[5].Value = model.ItemNat; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(1); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public SCZM.Model.Base.base_RepairItem GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,ItemName,ItemNat,FlagDel,OperaId,OperaName,OperaTime from base_RepairItem "); strSql.Append(" where FlagDel=0 and ID=@ID "); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = ID; SCZM.Model.Base.base_RepairItem model = new SCZM.Model.Base.base_RepairItem(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 得到一个对象实体 子方法 从DataRow中 /// </summary> public SCZM.Model.Base.base_RepairItem DataRowToModel(DataRow row) { SCZM.Model.Base.base_RepairItem model = new SCZM.Model.Base.base_RepairItem(); if (row != null) { if (row["ID"] != null && row["ID"].ToString() != "") { model.ID = int.Parse(row["ID"].ToString()); } if (row["ItemName"] != null) { model.ItemName = row["ItemName"].ToString(); } if (row["ItemNat"] != null && row["ItemNat"].ToString() != "") { model.ItemNat = decimal.Parse(row["ItemNat"].ToString()); } if (row["FlagDel"] != null && row["FlagDel"].ToString() != "") { model.FlagDel = int.Parse(row["FlagDel"].ToString()); } if (row["OperaId"] != null && row["OperaId"].ToString() != "") { model.OperaId = int.Parse(row["OperaId"].ToString()); } if (row["OperaName"] != null) { model.OperaName = row["OperaName"].ToString(); } if (row["OperaTime"] != null && row["OperaTime"].ToString() != "") { model.OperaTime = DateTime.Parse(row["OperaTime"].ToString()); } } return(model); }
private void SaveData(HttpContext context, string btn) { if (btn != "btnSave") { context.Response.Write("{\"status\":\"0.2\",\"msg\":\"对不起,您没有操作权限!\"}"); return; } string ID = RequestHelper.GetString("ID"); string ItemName = RequestHelper.GetString("ItemName"); string ItemNat = RequestHelper.GetString("ItemNat"); Model.System.sys_LoginUser loginUserModel = BaseWeb.GetLoginInfo(); SCZM.Model.Base.base_RepairItem model = new SCZM.Model.Base.base_RepairItem(); SCZM.BLL.Base.base_RepairItem bll = new SCZM.BLL.Base.base_RepairItem(); model.ID = Utils.StrToInt(ID, 0); model.ItemName = ItemName; model.ItemNat = Utils.StrToDecimal(ItemNat, 0); model.OperaId = loginUserModel.ID; model.OperaName = loginUserModel.PerName; model.OperaTime = DateTime.Now; string operaMessage = ""; string status = "0"; string operaAction = ""; string operaMemo = ""; try { if (ID == "") { model.ID = bll.Add(model, out operaMessage); if (model.ID > 0) { status = "1"; operaAction = Enums.ActionEnum.Add.ToString(); operaMemo = "新增维修项目:" + model.ID; } } else { if (bll.Update(model, out operaMessage)) { status = "1"; operaAction = Enums.ActionEnum.Edit.ToString(); operaMemo = "修改维修项目:" + model.ID; } } if (status == "1") { //写入操作日志 BaseWeb.AddOpera(loginUserModel, int.Parse(RequestHelper.GetQueryString("MenuId")), operaAction, operaMemo); } context.Response.Write("{\"status\":\"" + status + "\",\"msg\":\"" + operaMessage + "\"}"); return; } catch (Exception e) { context.Response.Write("{\"status\":\"0\",\"msg\":\"对不起,系统出错:" + Utils.HtmlEncode(e.Message) + "\"}"); return; } }