private void ShowInfo(int AssnID) { Maticsoft.BLL.Assn bll = new Maticsoft.BLL.Assn(); Maticsoft.Model.Assn model = bll.GetModel(AssnID); this.lblAssnID.Text = model.AssnID.ToString(); this.lblSocialName.Text = model.SocialName; this.lblSocialTeacher.Text = model.SocialTeacher; this.lblSocialLogo.Text = model.SocialLogo; this.lblAddTime.Text = model.AddTime.ToString(); this.lblSocialState.Text = model.SocialState; this.lblSocialPurpose.Text = model.SocialPurpose; this.lblSocialType.Text = model.SocialType; }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.Assn GetModel(int AssnID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 "); strSql.Append(" AssnID,SocialName,SocialTeacher,SocialLogo,AddTime,SocialState,SocialPurpose,SocialType "); strSql.Append(" from Assn "); strSql.Append(" where AssnID=" + AssnID + " "); Maticsoft.Model.Assn model = new Maticsoft.Model.Assn(); DataSet ds = DbHelperSQL.Query(strSql.ToString()); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.Assn DataRowToModel(DataRow row) { Maticsoft.Model.Assn model = new Maticsoft.Model.Assn(); if (row != null) { if (row["AssnID"] != null && row["AssnID"].ToString() != "") { model.AssnID = int.Parse(row["AssnID"].ToString()); } if (row["SocialName"] != null) { model.SocialName = row["SocialName"].ToString(); } if (row["SocialTeacher"] != null) { model.SocialTeacher = row["SocialTeacher"].ToString(); } if (row["SocialLogo"] != null) { model.SocialLogo = row["SocialLogo"].ToString(); } if (row["AddTime"] != null && row["AddTime"].ToString() != "") { model.AddTime = DateTime.Parse(row["AddTime"].ToString()); } if (row["SocialState"] != null) { model.SocialState = row["SocialState"].ToString(); } if (row["SocialPurpose"] != null) { model.SocialPurpose = row["SocialPurpose"].ToString(); } if (row["SocialType"] != null) { model.SocialType = row["SocialType"].ToString(); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(Maticsoft.Model.Assn model) { StringBuilder strSql = new StringBuilder(); StringBuilder strSql1 = new StringBuilder(); StringBuilder strSql2 = new StringBuilder(); if (model.AssnID != null) { strSql1.Append("AssnID,"); strSql2.Append("" + model.AssnID + ","); } if (model.SocialName != null) { strSql1.Append("SocialName,"); strSql2.Append("'" + model.SocialName + "',"); } if (model.SocialTeacher != null) { strSql1.Append("SocialTeacher,"); strSql2.Append("'" + model.SocialTeacher + "',"); } if (model.SocialLogo != null) { strSql1.Append("SocialLogo,"); strSql2.Append("'" + model.SocialLogo + "',"); } if (model.AddTime != null) { strSql1.Append("AddTime,"); strSql2.Append("'" + model.AddTime + "',"); } if (model.SocialState != null) { strSql1.Append("SocialState,"); strSql2.Append("'" + model.SocialState + "',"); } if (model.SocialPurpose != null) { strSql1.Append("SocialPurpose,"); strSql2.Append("'" + model.SocialPurpose + "',"); } if (model.SocialType != null) { strSql1.Append("SocialType,"); strSql2.Append("'" + model.SocialType + "',"); } strSql.Append("insert into Assn("); strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1)); strSql.Append(")"); strSql.Append(" values ("); strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1)); strSql.Append(")"); int rows = DbHelperSQL.ExecuteSql(strSql.ToString()); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.Assn model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Assn set "); if (model.SocialName != null) { strSql.Append("SocialName='" + model.SocialName + "',"); } else { strSql.Append("SocialName= null ,"); } if (model.SocialTeacher != null) { strSql.Append("SocialTeacher='" + model.SocialTeacher + "',"); } else { strSql.Append("SocialTeacher= null ,"); } if (model.SocialLogo != null) { strSql.Append("SocialLogo='" + model.SocialLogo + "',"); } else { strSql.Append("SocialLogo= null ,"); } if (model.AddTime != null) { strSql.Append("AddTime='" + model.AddTime + "',"); } else { strSql.Append("AddTime= null ,"); } if (model.SocialState != null) { strSql.Append("SocialState='" + model.SocialState + "',"); } else { strSql.Append("SocialState= null ,"); } if (model.SocialPurpose != null) { strSql.Append("SocialPurpose='" + model.SocialPurpose + "',"); } else { strSql.Append("SocialPurpose= null ,"); } if (model.SocialType != null) { strSql.Append("SocialType='" + model.SocialType + "',"); } else { strSql.Append("SocialType= null ,"); } int n = strSql.ToString().LastIndexOf(","); strSql.Remove(n, 1); strSql.Append(" where AssnID=" + model.AssnID + " "); int rowsAffected = DbHelperSQL.ExecuteSql(strSql.ToString()); if (rowsAffected > 0) { return(true); } else { return(false); } }
protected void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (!PageValidate.IsNumber(txtAssnID.Text)) { strErr += "AssnID格式错误!\\n"; } if (this.txtSocialName.Text.Trim().Length == 0) { strErr += "SocialName不能为空!\\n"; } if (this.txtSocialTeacher.Text.Trim().Length == 0) { strErr += "SocialTeacher不能为空!\\n"; } if (this.txtSocialLogo.Text.Trim().Length == 0) { strErr += "SocialLogo不能为空!\\n"; } if (!PageValidate.IsDateTime(txtAddTime.Text)) { strErr += "AddTime格式错误!\\n"; } if (this.txtSocialState.Text.Trim().Length == 0) { strErr += "SocialState不能为空!\\n"; } if (this.txtSocialPurpose.Text.Trim().Length == 0) { strErr += "SocialPurpose不能为空!\\n"; } if (this.txtSocialType.Text.Trim().Length == 0) { strErr += "SocialType不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int AssnID = int.Parse(this.txtAssnID.Text); string SocialName = this.txtSocialName.Text; string SocialTeacher = this.txtSocialTeacher.Text; string SocialLogo = this.txtSocialLogo.Text; DateTime AddTime = DateTime.Parse(this.txtAddTime.Text); string SocialState = this.txtSocialState.Text; string SocialPurpose = this.txtSocialPurpose.Text; string SocialType = this.txtSocialType.Text; Maticsoft.Model.Assn model = new Maticsoft.Model.Assn(); model.AssnID = AssnID; model.SocialName = SocialName; model.SocialTeacher = SocialTeacher; model.SocialLogo = SocialLogo; model.AddTime = AddTime; model.SocialState = SocialState; model.SocialPurpose = SocialPurpose; model.SocialType = SocialType; Maticsoft.BLL.Assn bll = new Maticsoft.BLL.Assn(); bll.Add(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx"); }