using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Maticsoft.BLL; using System.Data; using System.Data.SqlClient; using Ajax; public partial class External_Form : CommonPage { //所有外协名称 public string waixiemingtishi = ""; //创建一个共用的编码bll层 Maticsoft.BLL.nr_sys_bianma bm = new Maticsoft.BLL.nr_sys_bianma(); //创建一个共用的类型BLL层 Maticsoft.BLL.nr_sys_leixing bmlx = new Maticsoft.BLL.nr_sys_leixing(); //创建一个共用的外协bll层 Maticsoft.BLL.nr_z_waixie waixiebll = new Maticsoft.BLL.nr_z_waixie(); //创建一个共用的外协联系人bll层 Maticsoft.BLL.nr_z_lianxiren_wx lxrbll = new Maticsoft.BLL.nr_z_lianxiren_wx(); //创建一个操作记录bll Maticsoft.BLL.nr_sys_rizhi rizhibll = new Maticsoft.BLL.nr_sys_rizhi(); //创建一个共用的外协模板 Maticsoft.Model.nr_z_waixie waixie = new Maticsoft.Model.nr_z_waixie(); //创建一个操作记录模板 Maticsoft.Model.nr_sys_rizhi rizhi = new Maticsoft.Model.nr_sys_rizhi(); protected void Page_Load(object sender, EventArgs e) { Utility.RegisterTypeForAjax(typeof(External_Form)); if (!IsPostBack) { if (Session["user"] == null) { Response.Redirect("../index.aspx"); } //获取角色权限 Maticsoft.Model.nr_z_yhzh user = (Maticsoft.Model.nr_z_yhzh)(Session["user"]); binddata(); if (Request.QueryString["uid"] != null && Request.QueryString["uid"].ToString().Length > 0) { pdquanxianbj(user.juese); string uid = Request.QueryString["uid"].ToString(); id.Value = uid; initdata(uid); jialxr(); } else { pdquanxian(user.juese); if (Request.QueryString["fid"] != null && Request.QueryString["fid"].ToString().Length > 0) { string fid = Request.QueryString["fid"].ToString(); initdata(fid); jialxr(); } else { nowlxr(); //ywy.Text = ((Maticsoft.Model.nr_z_yhzh)Session["user"]).zhanghao.ToString(); } //赋值默认值 bh.Text = "自动生成"; riqi.Value =DateTime.Now.ToString("yyyy-MM-dd"); } //给客户名称赋值 DataTable dtmingcheng = DBHlper.Execute("select mingcheng from nr_z_waixie where zt='1'").Tables[0]; foreach (DataRow drt in dtmingcheng.Rows) { waixiemingtishi += "'" + drt[0].ToString() + "'" + ','; } waixiemingtishi=waixiemingtishi.TrimEnd(','); } } #region 用来初始化绑定下拉框等值 private void binddata() { DataSet hylx = bmlx.GetAllList(); DataRow[] dr = hylx.Tables[0].Select("leixing='外协行业'"); if (dr != null&& dr.Length>0) { DataSet hy = bm.GetList("zhongleiid='" + dr[0]["id"] + "'"); if (hy != null) { hangye.DataSource = hy.Tables[0].DefaultView; hangye.DataValueField = "id"; hangye.DataTextField = "mingcheng"; hangye.DataBind(); } } } #endregion #region 修改时获取真正数据值 private void initdata(string wx_bh) { int idz = Convert.ToInt32(wx_bh); waixie = waixiebll.GetModel(idz); if (waixie != null) { bh.Text = waixie.wx_bh.ToString(); mingcheng.Text = waixie.mingcheng.ToString(); //youbian.Text = waixie.youbian.ToString(); //wangzhi.Text = waixie.wangzhi.ToString(); kaihuhang.Text = waixie.kaihuhang.ToString(); zhanghao.Text = waixie.zhanghao.ToString(); shuihao.Text = waixie.shuihao.ToString(); dianhua.Text = waixie.dianhua.ToString(); chuanzhen.Text = waixie.chuanzhen.ToString(); youjian.Text = waixie.youjian.ToString(); hangye.Text = waixie.hangye.ToString(); riqi.Value = DateTime.Parse(waixie.riqi.ToString()).ToString("yyyy-MM-dd"); //ywy.Text = waixie.yewuyuan.ToString(); dizhi.Text = waixie.dizhi.ToString(); beizhu.Text = waixie.beizhu.ToString(); } } #endregion #region 获取页面参数赋值model对象 private void getmd() { waixie.wx_bh = bh.Text; waixie.mingcheng = mingcheng.Text; //waixie.youbian = youbian.Text; //waixie.wangzhi = wangzhi.Text; waixie.kaihuhang = kaihuhang.Text; waixie.zhanghao = zhanghao.Text; waixie.shuihao = shuihao.Text; waixie.dianhua = dianhua.Text; waixie.chuanzhen = chuanzhen.Text; waixie.youjian = youjian.Text; waixie.hangye = hangye.Text; if (riqi.Value == "") { waixie.riqi = DateTime.Now; } else { waixie.riqi = Convert.ToDateTime(riqi.Value); } //waixie.yewuyuan = ywy.Text; waixie.dizhi = dizhi.Text; waixie.beizhu = beizhu.Text; //给日志模板赋值 rizhi.riqi = DateTime.Now; rizhi.leixing = "外协档案"; } #endregion #region 添加时加载时添加联系人 private void nowlxr() { DataSet lxrs = lxrbll.GetList("kz_bh='" + bh.Text + "'"); string pin = "

联系人信息

"; pin += "" + ""; lianxiren.InnerHtml = pin + "
联系人职务联系方式
"; } #endregion #region 编辑时加载联系人数据 private void jialxr() { string pin = "

联系人信息

" + ""; DataSet lxrs = lxrbll.GetList("kz_bh='" + bh.Text + "'"); if (lxrs != null && lxrs.Tables[0].Rows.Count > 0) { foreach (DataRow l in lxrs.Tables[0].Rows) { pin += "" + "" + "" + ""; } lianxiren.InnerHtml = pin + "
联系人职务联系方式
"; } else { //如果没有联系人的存在就调用添加时的新建方法 nowlxr(); } } #endregion #region 敏感权限查看 void pdquanxian(int juese) { Maticsoft.Model.nr_z_yhzh user = (Maticsoft.Model.nr_z_yhzh)(Session["user"]); if (DBHlper.getzt(user.id) != 1) { Response.Redirect("../index.aspx"); } if (DBHlper.GetPermission(juese, "外协档案", "nr_z_waixie", "添加") == false) { Response.Redirect("../Common/nopower.htm"); } } #endregion #region 编辑权限查看 void pdquanxianbj(int juese) { Maticsoft.Model.nr_z_yhzh user = (Maticsoft.Model.nr_z_yhzh)(Session["user"]); if (DBHlper.getzt(user.id) != 1) { Response.Redirect("../index.aspx"); } if (DBHlper.GetPermission(juese, "外协档案", "nr_z_waixie", "编辑个人") == false && DBHlper.GetPermission(juese, "外协档案", "nr_z_waixie", "编辑全部") == false) { Response.Redirect("../Common/nopower.htm"); } } #endregion protected void bt_tj_Click(object sender, EventArgs e) { try { string caozuo = "添加"; getmd(); //接收成功参数值 int rtx = 0; //判断uid是否存在值,有值为修改,无值为添加 if (id.Value != null && id.Value != "") { waixie.id = Convert.ToInt32(id.Value); if (waixiebll.Update(waixie)) { rtx = Convert.ToInt32(id.Value); caozuo = "修改"; } } else { waixie.wx_bh = DBHlper.getbh("WX-", "nr_z_waixie", "wx_bh", 4); bh.Text = waixie.wx_bh; rtx = waixiebll.Add(waixie); } if (rtx > 0) { //将session转换对象取值 Maticsoft.Model.nr_z_yhzh zh = (Maticsoft.Model.nr_z_yhzh)Session["user"]; //拼接字符串插入日志 rizhi.jilu = zh.zhanghao + caozuo + "了外协档案,档案编号为:" + bh.Text.Trim(); rizhi.yonghuming = zh.zhanghao; rizhibll.Add(rizhi); lxrbll.DeleteListwhere("kz_bh='" + bh.Text + "'"); List lxrmds = new List(); lxrmds = DBHlper.ConvertJsonToEntityListEntity(lxr.Value); foreach (Maticsoft.Model.nr_z_lianxiren_wx k in lxrmds) { k.kz_bh = bh.Text; lxrbll.Add(k); } Response.Redirect("External_browse.aspx?uid=" + rtx, false); } else { Response.Redirect("../Common/error.aspx"); } } catch (Exception) { Response.Redirect("../Common/error.aspx"); } } //查询名称是否重复 [Ajax.AjaxMethod()] public int serchmingcheng(string str) { string cmd = string.Format("select count(*) from nr_z_waixie where mingcheng='{0}' and zt='1'", str.Replace(" ", "")); int count = DBHlper.getcount(cmd); return count; } }