using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; using Ajax; public partial class Purchase_Form : CommonPage { public string fanhuicode=""; //创建一个共用的编码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_caigoudan cgdbll = new Maticsoft.BLL.nr_z_caigoudan(); //创建一个操作记录bll Maticsoft.BLL.nr_sys_rizhi rizhibll = new Maticsoft.BLL.nr_sys_rizhi(); //创建一个共用的客户模板 Maticsoft.Model.nr_z_caigoudan cgdmodel = new Maticsoft.Model.nr_z_caigoudan(); //创建一个操作记录模板 Maticsoft.Model.nr_sys_rizhi rizhi = new Maticsoft.Model.nr_sys_rizhi(); //创建采购单管理详细模版 Maticsoft.Model.nr_z_caigoudan_xm cgddetail = new Maticsoft.Model.nr_z_caigoudan_xm(); Maticsoft.BLL.nr_z_caigoudan_xm cgddetailbll = new Maticsoft.BLL.nr_z_caigoudan_xm(); public string detailcode = ""; protected void Page_Load(object sender, EventArgs e) { Utility.RegisterTypeForAjax(typeof(Purchase_Form)); if (!IsPostBack) { if (Session["user"] == null) { Response.Redirect("../index.aspx"); } //获取角色权限 Maticsoft.Model.nr_z_yhzh user = (Maticsoft.Model.nr_z_yhzh)(Session["user"]); pdquanxian(user.juese); txt_caigouyuan.Text = user.zhanghao; txt_xdriqi.Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm"); if (Request.QueryString["uid"] != null && Request.QueryString["uid"].ToString().Length > 0) { string uid = Request.QueryString["uid"].ToString(); id.Value = uid; initdata(uid); pdquanxianbj(user.juese); binddatabycgd(uid); } else { if (Request.QueryString["fid"] != null && Request.QueryString["fid"].ToString().Length > 0) { string fid = Request.QueryString["fid"].ToString(); initdata(fid); binddatabycgd(fid); } pdquanxian(user.juese); if (Request["id"] != null) { binddatebysgd(); } } } } #region 编辑时提取信息 private void binddatabycgd(string uid) { DataTable dtcgddetail = DBHlper.Execute("select * from view_nr_z_caigoudan_xm where cgdid=" + uid).Tables[0]; int hcount = 0; for (int i = 0; i <= dtcgddetail.Rows.Count - 1; i++) { hcount++; detailcode += (" "); if (dtcgddetail.Rows[i]["sgdid"].ToString() != "0") { detailcode += (" " + " "); } else { detailcode += (" " + " "); } detailcode += ( " " + " " + " " + "" + " " + " " + "" + ""); } } #endregion #region 从申购单生成采购单管理时提取信息 private void binddatebysgd() { string scrq = DateTime.Now.ToString("yyyy-MM-dd"); string bzrq = DateTime.Now.AddYears(1).ToString("yyyy-MM-dd").ToString(); string[] idval = Request["id"].ToString().TrimEnd('/').Split('/'); string yhrq = DBHlper.getfirstcolmn("select yhriqi from view_nr_z_shengoudan where id="+idval[0]); txt_jhriqi.Value = Convert.ToDateTime(yhrq).ToString("yyyy-MM-dd"); DataTable dtsgd = null; int hcount = 0; for (int i = 0; i <= idval.Length - 1; i++) { dtsgd = DBHlper.Execute("select * from view_nr_z_shengoudan where id=" + idval[i]).Tables[0]; hcount = i + 1; detailcode += (" " + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + ""); } cgdtype.Value = "true"; } #endregion #region 修改时获取真正数据值 private void initdata(string did) { DataTable dt= DBHlper.Execute("select * from view_nr_z_caigoudan where id="+did).Tables[0]; DataTable tbl_lianxiren = DBHlper.Execute("select id,lxr_name,dianhua from nr_z_lianxiren_gys where gys_bh='" + dt.Rows[0]["gysbianhao"].ToString() + "'").Tables[0]; foreach (DataRow dr in tbl_lianxiren.Rows) { if (dt.Rows[0]["lixiren"].ToString() == dr["lxr_name"].ToString()) { fanhuicode += ""; } else { fanhuicode += ""; } } txt_cgdhao.Text =dt.Rows[0]["cgdbianhao"].ToString() ; drp_cgjindu.Text = dt.Rows[0]["cgjindu"].ToString(); txt_gyshao.Value = dt.Rows[0]["gysbianhao"].ToString(); txt_ghdanwei.Value = dt.Rows[0]["mingcheng"].ToString(); txt_lianxiren.Text = dt.Rows[0]["lixiren"].ToString(); lxrvalue.Value = dt.Rows[0]["lixiren"].ToString(); txt_lianxifangshi.Value = dt.Rows[0]["lianxifangshi"].ToString(); txt_fasongzhi.Text = dt.Rows[0]["songhuodidian"].ToString(); txt_yunshuleixing.Text = dt.Rows[0]["yunshuleixing"].ToString(); txt_caigouyuan.Text = dt.Rows[0]["caigouyuan"].ToString(); txt_xdriqi.Value = DateTime.Parse(dt.Rows[0]["riqi"].ToString()).ToString("yyyy-MM-dd HH:mm"); txt_jhriqi.Value = DateTime.Parse(dt.Rows[0]["jiaohuoriqi"].ToString()).ToString("yyyy-MM-dd"); txt_beizhu.Value = dt.Rows[0]["beizhu"].ToString(); gysid.Value = dt.Rows[0]["gyshangid"].ToString(); txt_shzt.Value = dt.Rows[0]["shzt"].ToString(); } #endregion #region 获取页面参数赋值model对象 private void getmd() { cgdmodel.cgjindu =drp_cgjindu.Text; cgdmodel.gyshangid =Convert.ToInt32(gysid.Value); cgdmodel.songhuodidian = txt_fasongzhi.Text.Trim(); cgdmodel.yunshuleixing = txt_yunshuleixing.Text.Trim(); cgdmodel.caigouyuan = txt_caigouyuan.Text.Trim(); cgdmodel.riqi = Convert.ToDateTime(txt_xdriqi.Value); cgdmodel.jiaohuoriqi = Convert.ToDateTime(txt_jhriqi.Value.Trim()); cgdmodel.beizhu = txt_beizhu.Value.Trim(); cgdmodel.lixiren = lxrvalue.Value; cgdmodel.lianxifangshi = txt_lianxifangshi.Value; } #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_caigoudan", "添加") == 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_caigoudan", "编辑个人") == false && DBHlper.GetPermission(juese, "采购单管理", "nr_z_caigoudan", "编辑全部") == false) { Response.Redirect("../Common/nopower.htm"); } } #endregion protected void bt_tj_Click(object sender, EventArgs e) { try { string str = detailcontent.Value; List cgddetail = new List(); cgddetail = DBHlper.ConvertJsonToEntityListEntity(detailcontent.Value); string caozuo = "添加"; //接收成功参数值 int cgdid = 0; int rtx = 0; //判断uid是否存在值,有值为修改,无值为添加 if (id.Value != "") { cgdid = Convert.ToInt32(id.Value); rtx = Convert.ToInt32(id.Value); cgdmodel = cgdbll.GetModel(rtx); getmd(); cgdbll.Update(cgdmodel); caozuo = "修改"; string exsitid = ""; foreach (Maticsoft.Model.nr_z_caigoudan_xm detail in cgddetail) { if (detail.id == 0) { detail.cgdid =Convert.ToInt16(id.Value); rtx=cgddetailbll.Add(detail); exsitid += rtx + ","; } else { detail.cgdid=Convert.ToInt32(id.Value); cgddetailbll.Update(detail); exsitid += detail.id + ","; } } exsitid = exsitid.TrimEnd(','); DBHlper.excutecmd("delete from nr_z_caigoudan_xm where id not in("+exsitid+") and cgdid="+id.Value); } else { getmd(); cgdmodel.cgdhao = DBHlper.getbh("CGD-", "nr_z_caigoudan", "cgdhao", 4); txt_cgdhao.Text = cgdmodel.cgdhao; cgdmodel.cgjindu = "已采购"; cgdmodel.shzt = "待审核"; cgdid=cgdbll.Add(cgdmodel); foreach (Maticsoft.Model.nr_z_caigoudan_xm xm in cgddetail) { xm.cgdid = cgdid; cgddetailbll.Add(xm); } } if (cgdid > 0) { //将session转换对象取值 Maticsoft.Model.nr_z_yhzh zh = (Maticsoft.Model.nr_z_yhzh)Session["user"]; rizhi.yonghuming = zh.zhanghao; //拼接字符串插入日志 rizhi.jilu = zh.zhanghao + caozuo + "了采购单管理,采购单管理号为:" + txt_cgdhao.Text.Trim(); rizhi.leixing = "采购单管理"; rizhi.riqi = DateTime.Now; rizhibll.Add(rizhi); Response.Redirect("Purchase_browse.aspx?uid="+cgdid, false); } else { Response.Redirect("../Common/error.aspx"); } } catch (Exception ex) { Response.Redirect("../Common/error.aspx"); } } //查询客户名称是否重复 [Ajax.AjaxMethod()] public int serchmingcheng(string str) { string cmd = string.Format("select count(*) from nr_z_kehu where mingcheng='{0}' and zt='1'", str.Replace(" ", "")); int count = DBHlper.getcount(cmd); return count; } //给最近单价列表赋值 [Ajax.AjaxMethod()] public string binddanjia(string tj) { DataTable dt = DBHlper.Execute("select top 5 * from view_nr_z_caigoudan_xm where 1=1 " + tj + " order by id desc").Tables[0]; string code = ""; foreach (DataRow dr in dt.Rows) { code += "" + dr["riqi"] + " " + dr["gysbh"] + "" + dr["gysmc"] + "" + dr["mingcheng"] + "" + dr["sl"] + "" + dr["dj"] + ""; } return code; } }