using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Dtsc.Cdtas.Run.Data;
using Dtsc.Cdtas.Common;
using System.Text;
using Dtsc.Common.ACL.Data;
namespace Dtsc.Cdtas.Run.Web.Run.AddressBook
{
public partial class AddressBookAdd : System.Web.UI.Page
{
RunAddressBook model = new RunAddressBook();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
hfid_sp.Value = Request.QueryString["lbid_sp"];
hftype_sp.Value=Request.QueryString["type"];//编辑
fd_SPOrgan_name.Value = Request.QueryString["SPOrgan_name"];//机构名称
if(!string.IsNullOrEmpty(hftype_sp.Value))
{
_loadUpde();
}
else
{
hfid_sp.Value = Guid.NewGuid().ToString();
hidFlag.Value = "0";//0添加,1修改
this.Title = "联系人新增";
Ltetitle.Text = "联系人新增";
}
}
}
/// <summary>
/// 页面加载(修改)
/// </summary>
private void _loadUpde()
{
model.Id = hfid_sp.Value;
RunAddressBook data = BizRunAddressBook.GetModel(model.Id);
FillPage(data);
}
protected void BtnSave_Click(object sender, EventArgs e)
{
model = this.GetAddressBook();
try
{
if (hidFlag.Value == "0")//新增
{
BizRunAddressBook.Insert(model);
Sxin(0);
}
else if (hidFlag.Value == "1") //更新
{
BizRunAddressBook.Update(model);
Sxin(1);
}
}
catch (Exception ex)
{
JavascriptHelper.Alert(this, string.Format("保存失败!原因{0}", ex.Message));
return;
}
}
/// <summary>
/// 刷新父页面(AddressBookList.aspx)
/// </summary>
public void Sxin(int flg_sp)
{
StringBuilder sbScript = new StringBuilder();
if (!string.IsNullOrEmpty(Request.QueryString["btnID"]))
{
sbScript.AppendFormat("window.dialogArguments.all[\"{0}\"].click();", Request.QueryString["btnID"]);
}
if (flg_sp == 1)
{
sbScript.Append("alert('更新成功!');window.close();");
}
else
{
sbScript.Append("alert('新增成功!');window.close();");
}
ClientScript.RegisterStartupScript(this.GetType(), "over", sbScript.ToString(), true);
}
private RunAddressBook GetAddressBook()
{
/*
* 封装页面上的通讯录信息
*/
return new RunAddressBook()
{
Id=hfid_sp.Value,
Name=txtName.Text.Trim(),
Sex=rbtn_sp.SelectedItem.Text,
OrganId = fd_SPOrgan_name.Value,//机构id
MobilePhone=txtPhone.Text.Trim(),
Phone=txtTelephone.Text.Trim(),
Address=txtAddress.Text.Trim(),
SPOrgan_name=fd_SPOrgan_name.Value,
Email=txtEmail.Text.Trim(),
};
}
private void FillPage(RunAddressBook model)
{
/*
* 填充页面控件内容
*/
hidFlag.Value = "1";//0添加,1修改
this.Title = "联系人修改";
Ltetitle.Text = "联系人修改";
txtName.Text = model.Name;
txtEmail.Text = model.Email;
txtTelephone.Text = model.Phone;
txtPhone.Text = model.MobilePhone;
txtAddress.Text = model.Address;
#region 默认选中
//for (int i = 0; i < rbtn_sp.Items.Count; i++)
//{
// if (rbtn_sp.Items[i].Value == data.Sex)
// {
// this.rbtn_sp.ClearSelection();
// this.rbtn_sp.Items[i].Selected = true;
// }
//}
#endregion
if (rbtn_sp.Items.FindByText(model.Sex) != null)
{
rbtn_sp.Items.FindByText(model.Sex).Selected = true;
}
}
}
}
通讯录 代码
最新推荐文章于 2023-01-14 18:13:32 发布