/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { Model.T_Area_MDL model = new DigiPower.Onlinecol.Standard.Model.T_Area_MDL(); if (ViewState["model"] != null) { model = (Model.T_Area_MDL)ViewState["model"]; } object obj = Comm.GetValueToObject(model, this.tbl); if (obj != null) { Model.T_Area_MDL Newmodel = (Model.T_Area_MDL)obj; switch ((CommonEnum.PageState)ViewState["ps"]) { case CommonEnum.PageState.ADD: { int areaID = areaBLL.Add(Newmodel); PublicModel.writeLog(SystemSet.EumLogType.AddData.ToString(), string.Concat("T_Area;key=", areaID, ";area_code=", Newmodel.area_code, ";area_name=", Newmodel.area_name)); break; } case CommonEnum.PageState.EDIT: { Newmodel.AreaID = Convert.ToInt32(ID); areaBLL.Update(Newmodel); PublicModel.writeLog(SystemSet.EumLogType.UpdData.ToString(), string.Concat("T_Area;key=", Newmodel.AreaID, ";area_code=", Newmodel.area_code, ";area_name=", Newmodel.area_name)); } break; } } Common.MessageBox.CloseLayerOpenWeb(this.Page); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(DigiPower.Onlinecol.Standard.Model.T_Area_MDL model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into T_Area("); strSql.Append("area_code,area_name,PID,OrderIndex)"); strSql.Append(" values ("); strSql.Append("@area_code,@area_name,@PID,@OrderIndex)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@area_code", SqlDbType.NVarChar, 20), new SqlParameter("@area_name", SqlDbType.VarChar, 30), new SqlParameter("@PID", SqlDbType.Int, 8), new SqlParameter("@OrderIndex", SqlDbType.Int, 8) }; parameters[0].Value = model.area_code; parameters[1].Value = model.area_name; parameters[2].Value = model.PID; parameters[3].Value = model.OrderIndex; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(1); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public void Update(DigiPower.Onlinecol.Standard.Model.T_Area_MDL model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update T_Area set "); strSql.Append("area_code=@area_code,"); strSql.Append("area_name=@area_name,"); strSql.Append("PID=@PID,"); strSql.Append("OrderIndex=@OrderIndex"); strSql.Append(" where AreaID=@AreaID "); SqlParameter[] parameters = { new SqlParameter("@AreaID", SqlDbType.Int, 8), new SqlParameter("@area_code", SqlDbType.NVarChar, 20), new SqlParameter("@area_name", SqlDbType.VarChar, 30), new SqlParameter("@PID", SqlDbType.Int, 8), new SqlParameter("@OrderIndex", SqlDbType.Int, 8) }; parameters[0].Value = model.AreaID; parameters[1].Value = model.area_code; parameters[2].Value = model.area_name; parameters[3].Value = model.PID; parameters[4].Value = model.OrderIndex; DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); }
/// <summary> /// 绑定页面 /// </summary> /// <param name="ID"></param> private void BindPage(string ID) { Model.T_Area_MDL model = new DigiPower.Onlinecol.Standard.Model.T_Area_MDL(); model = areaBLL.GetModel(Convert.ToInt32(ID)); if (model != null) { ViewState["model"] = model; DigiPower.Onlinecol.Standard.Web.Comm.SetValueToPage(model, this.tbl); PID.SelectValue = model.PID.ToString(); } }
/// <summary> /// 得到一个对象实体 /// </summary> public DigiPower.Onlinecol.Standard.Model.T_Area_MDL GetModel(int AreaID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 AreaID,area_code,area_name,PID,OrderIndex from T_Area "); strSql.Append(" where AreaID=@AreaID "); SqlParameter[] parameters = { new SqlParameter("@AreaID", SqlDbType.Int, 8) }; parameters[0].Value = AreaID; DigiPower.Onlinecol.Standard.Model.T_Area_MDL model = new DigiPower.Onlinecol.Standard.Model.T_Area_MDL(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["AreaID"].ToString() != "") { model.AreaID = int.Parse(ds.Tables[0].Rows[0]["AreaID"].ToString()); } model.area_code = ds.Tables[0].Rows[0]["area_code"].ToString(); model.area_name = ds.Tables[0].Rows[0]["area_name"].ToString(); if (ds.Tables[0].Rows[0]["PID"].ToString() != "") { model.PID = int.Parse(ds.Tables[0].Rows[0]["PID"].ToString()); } if (ds.Tables[0].Rows[0]["OrderIndex"].ToString() != "") { model.OrderIndex = int.Parse(ds.Tables[0].Rows[0]["OrderIndex"].ToString()); } return(model); } else { return(null); } }