/// <summary> /// 加载通讯录数据 /// </summary> private void LoadAddressListData() { int id = int.Parse(Request.Params["id"]); EtNet_Models.AddressListInfo model = EtNet_BLL.AddressListInfoManager.GetModel(id); if (model != null) { this.iptcname.Value = model.cname; this.iptename.Value = model.ename; this.iptposition.Value = model.positiontxt; this.radsex.SelectedValue = model.sex; this.iptphone.Value = model.phone; this.iptcellphone.Value = model.cellphone; this.iptscellphone.Value = model.scellphone; this.ddldepart.SelectedValue = model.departid.ToString(); this.iptmailtxt.Value = model.mailbox.Split(',')[0]; this.trearemark.Value = model.remark; } else { string str = "<script>alert('加载出错');window.location='AddressListShow.aspx';</script>"; Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "load", str, false); } }
/// <summary> /// 增加一条数据 /// </summary> public static bool Add(EtNet_Models.AddressListInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into AddressListInfo("); strSql.Append("cname,ename,sex,phone,cellphone,mailbox,positiontxt,departid,linkstaff,staffid,founder,createtime,remark,scellphone)"); strSql.Append(" values ("); strSql.Append("@cname,@ename,@sex,@phone,@cellphone,@mailbox,@positiontxt,@departid,@linkstaff,@staffid,@founder,@createtime,@remark,@scellphone)"); SqlParameter[] parameters = { new SqlParameter("@cname", SqlDbType.VarChar, 40), new SqlParameter("@ename", SqlDbType.VarChar, 40), new SqlParameter("@sex", SqlDbType.VarChar, 10), new SqlParameter("@phone", SqlDbType.VarChar, 40), new SqlParameter("@cellphone", SqlDbType.VarChar, 40), new SqlParameter("@mailbox", SqlDbType.VarChar, 100), new SqlParameter("@positiontxt", SqlDbType.VarChar, 40), new SqlParameter("@departid", SqlDbType.Int, 4), new SqlParameter("@linkstaff", SqlDbType.Int, 4), new SqlParameter("@staffid", SqlDbType.Int, 4), new SqlParameter("@founder", SqlDbType.Int, 4), new SqlParameter("@createtime", SqlDbType.DateTime), new SqlParameter("@remark", SqlDbType.VarChar, 200), new SqlParameter("@scellphone", SqlDbType.VarChar, 40) }; parameters[0].Value = model.cname; parameters[1].Value = model.ename; parameters[2].Value = model.sex; parameters[3].Value = model.phone; parameters[4].Value = model.cellphone; parameters[5].Value = model.mailbox; parameters[6].Value = model.positiontxt; parameters[7].Value = model.departid; parameters[8].Value = model.linkstaff; parameters[9].Value = model.staffid; parameters[10].Value = model.founder; parameters[11].Value = model.createtime; parameters[12].Value = model.remark; parameters[13].Value = model.scellphone; int result = EtNet_DAL.DBHelper.ExecuteCommand(strSql.ToString(), parameters); if (result >= 1) { return(true); } else { return(false); } }
//保存 private void Save() { if (TestAdd()) { EtNet_Models.AddressListInfo model = new EtNet_Models.AddressListInfo(); model.cname = this.iptcname.Value; model.ename = this.iptename.Value; model.createtime = DateTime.Now; model.departid = int.Parse(this.ddldepart.SelectedValue); model.cellphone = this.iptcellphone.Value; model.scellphone = this.iptscellphone.Value; model.founder = ((EtNet_Models.LoginInfo)Session["login"]).Id; model.positiontxt = this.iptposition.Value; model.mailbox = this.iptmailtxt.Value; model.phone = this.iptphone.Value; model.sex = this.radsex.SelectedValue; model.remark = Server.UrlDecode(this.trearemark.Value); if (this.ddlstaff.SelectedIndex == 0) { model.linkstaff = 0; model.staffid = 0; } else { model.linkstaff = 1; model.staffid = int.Parse(this.ddlstaff.SelectedValue); } if (EtNet_BLL.AddressListInfoManager.Add(model)) { EtNet_Models.StaffInfo staff = EtNet_BLL.StaffInfoManager.GetModel(int.Parse(this.ddlstaff.SelectedValue)); if (staff != null) { staff.cname = this.iptcname.Value; staff.ename = this.iptename.Value; staff.positiontxt = this.iptposition.Value; staff.sex = this.radsex.SelectedValue; staff.phone = this.iptphone.Value; staff.cellphone = this.iptcellphone.Value; staff.departid = int.Parse(this.ddldepart.SelectedValue); staff.mailbox = this.iptmailtxt.Value; staff.remark = Server.UrlDecode(this.trearemark.Value); EtNet_BLL.StaffInfoManager.Update(staff); } Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "add", "<script>alert('添加成功');window.location='AddressListShow.aspx';</script>", false); } } }
//修改 private void Modify() { string str = ""; int id = int.Parse(Request.Params["id"]); EtNet_Models.AddressListInfo model = EtNet_BLL.AddressListInfoManager.GetModel(id); if (model != null) { model.cname = this.iptcname.Value; model.ename = this.iptename.Value; model.positiontxt = this.iptposition.Value; model.sex = this.radsex.SelectedValue; model.phone = this.iptphone.Value; model.cellphone = this.iptcellphone.Value; model.scellphone = this.iptscellphone.Value; model.departid = int.Parse(this.ddldepart.SelectedValue); model.mailbox = this.iptmailtxt.Value; model.remark = Server.UrlDecode(this.trearemark.Value); if (model.linkstaff == 1) { if (!ModifyStaff(model.staffid)) { model.linkstaff = 0; model.staffid = 0; } } if (EtNet_BLL.AddressListInfoManager.Update(model)) { str = "<script>alert('修改成功');window.location='AddressListShow.aspx';</script>"; } else { str = "<script>alert('修改失败');window.location='AddressListShow.aspx';</script>"; } } else { str = "<script>alert('修改失败,该通讯录已删除');window.location='AddressListShow.aspx';</script>"; } Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "modify", str, false); }
/// <summary> /// 得到一个对象实体 /// </summary> public static EtNet_Models.AddressListInfo GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 * from AddressListInfo "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; EtNet_Models.AddressListInfo model = new EtNet_Models.AddressListInfo(); DataTable tbl = EtNet_DAL.DBHelper.GetDataSet(strSql.ToString(), parameters); if (tbl.Rows.Count > 0) { model.id = int.Parse(tbl.Rows[0]["id"].ToString()); model.cname = tbl.Rows[0]["cname"].ToString(); model.ename = tbl.Rows[0]["ename"].ToString(); model.sex = tbl.Rows[0]["sex"].ToString(); model.phone = tbl.Rows[0]["phone"].ToString(); model.cellphone = tbl.Rows[0]["cellphone"].ToString(); model.mailbox = tbl.Rows[0]["mailbox"].ToString(); model.positiontxt = tbl.Rows[0]["positiontxt"].ToString(); model.departid = int.Parse(tbl.Rows[0]["departid"].ToString()); model.linkstaff = int.Parse(tbl.Rows[0]["linkstaff"].ToString()); model.staffid = int.Parse(tbl.Rows[0]["staffid"].ToString()); model.founder = int.Parse(tbl.Rows[0]["founder"].ToString()); model.createtime = DateTime.Parse(tbl.Rows[0]["createtime"].ToString()); model.remark = tbl.Rows[0]["remark"].ToString(); model.scellphone = tbl.Rows[0]["scellphone"].ToString(); return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public static bool Update(EtNet_Models.AddressListInfo model) { return(EtNet_DAL.AddressListInfoService.Update(model)); }
/// <summary> /// 更新一条数据 /// </summary> public static bool Update(EtNet_Models.AddressListInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update AddressListInfo set "); strSql.Append("cname=@cname,"); strSql.Append("ename=@ename,"); strSql.Append("sex=@sex,"); strSql.Append("phone=@phone,"); strSql.Append("cellphone=@cellphone,"); strSql.Append("mailbox=@mailbox,"); strSql.Append("positiontxt=@positiontxt,"); strSql.Append("departid=@departid,"); strSql.Append("linkstaff=@linkstaff,"); strSql.Append("staffid=@staffid,"); strSql.Append("founder=@founder,"); strSql.Append("createtime=@createtime,"); strSql.Append("remark=@remark,"); strSql.Append("scellphone=@scellphone"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@cname", SqlDbType.VarChar, 40), new SqlParameter("@ename", SqlDbType.VarChar, 40), new SqlParameter("@sex", SqlDbType.VarChar, 10), new SqlParameter("@phone", SqlDbType.VarChar, 40), new SqlParameter("@cellphone", SqlDbType.VarChar, 40), new SqlParameter("@mailbox", SqlDbType.VarChar, 100), new SqlParameter("@positiontxt", SqlDbType.VarChar, 40), new SqlParameter("@departid", SqlDbType.Int, 4), new SqlParameter("@linkstaff", SqlDbType.Int, 4), new SqlParameter("@staffid", SqlDbType.Int, 4), new SqlParameter("@founder", SqlDbType.Int, 4), new SqlParameter("@createtime", SqlDbType.DateTime), new SqlParameter("@remark", SqlDbType.VarChar, 200), new SqlParameter("@scellphone", SqlDbType.VarChar, 40), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.cname; parameters[1].Value = model.ename; parameters[2].Value = model.sex; parameters[3].Value = model.phone; parameters[4].Value = model.cellphone; parameters[5].Value = model.mailbox; parameters[6].Value = model.positiontxt; parameters[7].Value = model.departid; parameters[8].Value = model.linkstaff; parameters[9].Value = model.staffid; parameters[10].Value = model.founder; parameters[11].Value = model.createtime; parameters[12].Value = model.remark; parameters[13].Value = model.scellphone; parameters[14].Value = model.id; int result = EtNet_DAL.DBHelper.ExecuteCommand(strSql.ToString(), parameters); if (result >= 1) { return(true); } else { return(false); } }