public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtStuName.Text.Trim().Length == 0) { strErr += "姓名不能为空!\\n"; } if (this.txtStuTel.Text.Trim().Length == 0) { strErr += "电话不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int ID = int.Parse(this.lblID.Text); string StuName = this.txtStuName.Text; string StuEmail = this.txtStuEmail.Text; string StuTel = this.txtStuTel.Text; string StuAddress = this.txtStuAddress.Text; int RoleId = int.Parse(this.DropDownList1.SelectedValue); DateTime CreateTime = model1.CreateTime.Value; DateTime UpdteTime = DateTime.Now; JiaJiao.Model.Student model = new JiaJiao.Model.Student(); model.ID = ID; model.StuName = StuName; model.StuEmail = StuEmail; model.StuTel = StuTel; model.StuAddress = StuAddress; model.RoleId = RoleId; model.CreateTime = CreateTime; model.UpdteTime = UpdteTime; JiaJiao.BLL.Student bll = new JiaJiao.BLL.Student(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }
/// <summary> /// 得到一个对象实体 /// </summary> public JiaJiao.Model.Student DataRowToModel(DataRow row) { JiaJiao.Model.Student model=new JiaJiao.Model.Student(); if (row != null) { if(row["ID"]!=null && row["ID"].ToString()!="") { model.ID=int.Parse(row["ID"].ToString()); } if(row["StuName"]!=null) { model.StuName=row["StuName"].ToString(); } if(row["StuEmail"]!=null) { model.StuEmail=row["StuEmail"].ToString(); } if(row["StuTel"]!=null) { model.StuTel=row["StuTel"].ToString(); } if(row["StuAddress"]!=null) { model.StuAddress=row["StuAddress"].ToString(); } if(row["RoleId"]!=null && row["RoleId"].ToString()!="") { model.RoleId=int.Parse(row["RoleId"].ToString()); } if(row["CreateTime"]!=null && row["CreateTime"].ToString()!="") { model.CreateTime=DateTime.Parse(row["CreateTime"].ToString()); } if(row["UpdteTime"]!=null && row["UpdteTime"].ToString()!="") { model.UpdteTime=DateTime.Parse(row["UpdteTime"].ToString()); } } return model; }
private void ShowInfo(int ID) { JiaJiao.BLL.Student bll = new JiaJiao.BLL.Student(); model1 = bll.GetModel(ID); this.lblID.Text = model1.ID.ToString(); this.txtStuName.Text = model1.StuName; this.txtStuEmail.Text = model1.StuEmail; this.txtStuTel.Text = model1.StuTel; this.txtStuAddress.Text = model1.StuAddress; }
/// <summary> /// 得到一个对象实体 /// </summary> public JiaJiao.Model.Student GetModel(int ID) { StringBuilder strSql=new StringBuilder(); strSql.Append("select top 1 ID,StuName,StuEmail,StuTel,StuAddress,RoleId,CreateTime,UpdteTime from Student "); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int,4) }; parameters[0].Value = ID; JiaJiao.Model.Student model=new JiaJiao.Model.Student(); DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters); if(ds.Tables[0].Rows.Count>0) { return DataRowToModel(ds.Tables[0].Rows[0]); } else { return null; } }