/// <summary> /// 更新一条数据 /// </summary> public int Update(SCZM.Model.Base.base_MachineModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update base_MachineModel set "); strSql.Append("MachineModel=@MachineModel,"); strSql.Append("FlagDel=@FlagDel,"); strSql.Append("OperaId=@OperaId,"); strSql.Append("OperaName=@OperaName,"); strSql.Append("OperaTime=@OperaTime,"); strSql.Append("MachineLevel=@MachineLevel"); strSql.Append(" where FlagDel=0 and ID=@ID "); SqlParameter[] parameters = { new SqlParameter("@MachineModel", SqlDbType.VarChar, 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("@MachineLevel", SqlDbType.Int, 4), new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = model.MachineModel; parameters[1].Value = model.FlagDel; parameters[2].Value = model.OperaId; parameters[3].Value = model.OperaName; parameters[4].Value = model.OperaTime; parameters[5].Value = model.MachineLevel; parameters[6].Value = model.ID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); return(rows); }
private void SaveData(HttpContext context, string btn) { if (btn != "btnSave") { context.Response.Write("{\"status\":\"0.2\",\"msg\":\"对不起,您没有操作权限!\"}"); return; } string ID = RequestHelper.GetString("ID"); string MachineModel = RequestHelper.GetString("MachineModel"); string MachineLevel = RequestHelper.GetString("MachineLevel"); Model.System.sys_LoginUser loginUserModel = BaseWeb.GetLoginInfo(); SCZM.Model.Base.base_MachineModel model = new SCZM.Model.Base.base_MachineModel(); SCZM.BLL.Base.base_MachineModel bll = new SCZM.BLL.Base.base_MachineModel(); model.ID = Utils.StrToInt(ID, 0); model.MachineModel = MachineModel; model.MachineLevel = Utils.StrToInt(MachineLevel, 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; } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(SCZM.Model.Base.base_MachineModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into base_MachineModel("); strSql.Append("MachineModel,FlagDel,OperaId,OperaName,OperaTime,MachineLevel)"); strSql.Append(" values ("); strSql.Append("@MachineModel,@FlagDel,@OperaId,@OperaName,@OperaTime,@MachineLevel)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@MachineModel", SqlDbType.VarChar, 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("@MachineLevel", SqlDbType.Int, 4) }; parameters[0].Value = model.MachineModel; parameters[1].Value = model.FlagDel; parameters[2].Value = model.OperaId; parameters[3].Value = model.OperaName; parameters[4].Value = model.OperaTime; parameters[5].Value = model.MachineLevel; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(1); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 子方法 从DataRow中 /// </summary> public SCZM.Model.Base.base_MachineModel DataRowToModel(DataRow row) { SCZM.Model.Base.base_MachineModel model = new SCZM.Model.Base.base_MachineModel(); if (row != null) { if (row["ID"] != null && row["ID"].ToString() != "") { model.ID = int.Parse(row["ID"].ToString()); } if (row["MachineModel"] != null) { model.MachineModel = row["MachineModel"].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()); } if (row["MachineLevel"] != null && row["MachineLevel"].ToString() != "") { model.MachineLevel = int.Parse(row["MachineLevel"].ToString()); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public SCZM.Model.Base.base_MachineModel GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,MachineModel,MachineLevel,FlagDel,OperaId,OperaName,OperaTime from base_MachineModel "); strSql.Append(" where FlagDel=0 and ID=@ID "); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = ID; SCZM.Model.Base.base_MachineModel model = new SCZM.Model.Base.base_MachineModel(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }