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 Materiel_Form : CommonPage { //所有客户名称 public string wuliaomingtishi = ""; //创建一个共用的编码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_wuliao wuliaobll = new Maticsoft.BLL.nr_z_wuliao(); //创建一个共用的物料模板 Maticsoft.Model.nr_z_wuliao wuliao = new Maticsoft.Model.nr_z_wuliao(); //创建一个操作记录模板 Maticsoft.Model.nr_sys_rizhi rizhi = new Maticsoft.Model.nr_sys_rizhi(); //创建一个操作记录bll Maticsoft.BLL.nr_sys_rizhi rizhibll = new Maticsoft.BLL.nr_sys_rizhi(); public string wulmingtishi = ""; protected void Page_Load(object sender, EventArgs e) { Utility.RegisterTypeForAjax(typeof(Materiel_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); } else { pdquanxian(user.juese); if (Request.QueryString["fid"] != null && Request.QueryString["fid"].ToString().Length > 0) { string fid = Request.QueryString["fid"].ToString(); initdata(fid); } //赋值默认值 bh.Text = "自动生成"; riqi.Value = DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day; } DataTable dtmingcheng = DBHlper.Execute("select mingcheng from nr_z_wuliao where zt='1'").Tables[0]; foreach (DataRow drt in dtmingcheng.Rows) { wulmingtishi += "'" + drt[0].ToString() + "'" + ','; } wulmingtishi = wulmingtishi.TrimEnd(','); } } #region 用来初始化绑定下拉框等值 private void binddata() { zdkc.Value = "0"; zgkc.Value = "0"; 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) { zhonglei.DataSource = hy.Tables[0].DefaultView; zhonglei.DataValueField = "id"; zhonglei.DataTextField = "mingcheng"; zhonglei.DataBind(); } } dr = hylx.Tables[0].Select("leixing='单位'"); if (dr != null && dr.Length > 0) { DataSet xz = bm.GetList("zhongleiid='" + dr[0]["id"] + "'"); if (xz != null) { danwei.DataSource = xz.Tables[0].DefaultView; danwei.DataValueField = "id"; danwei.DataTextField = "mingcheng"; danwei.DataBind(); } } } #endregion #region 修改时获取真正数据值 private void initdata(string did) { int idz = Convert.ToInt32(did); wuliao = wuliaobll.GetModel(idz); if (wuliao != null) { bh.Text = wuliao.wlbh.ToString(); mingcheng.Text = wuliao.mingcheng.ToString(); pinpai.Text = wuliao.pinpai.ToString(); zhonglei.Text = wuliao.zhonglei.ToString(); danwei.Text = wuliao.danwei.ToString(); cangku.Text = wuliao.kufang.ToString(); zdkc.Value = Convert.ToDouble(wuliao.zuidkucun).ToString(); zgkc.Value = Convert.ToDouble(wuliao.zuigkucun).ToString(); riqi.Value = DateTime.Parse(wuliao.riqi.ToString()).ToString("yyyy-MM-dd"); changdu.Value = Convert.ToDouble(wuliao.changdu).ToString(); kuandu.Value = Convert.ToDouble(wuliao.kuandu).ToString(); guige.Value = wuliao.guige; // baojia.Value = Convert.ToDouble(wuliao.baojia).ToString(); beizhu.Text = wuliao.beizhu.ToString(); } } #endregion #region 获取页面参数赋值model对象 private void getmd() { wuliao.wlbh = bh.Text; wuliao.mingcheng = mingcheng.Text; wuliao.pinpai = pinpai.Text; wuliao.zhonglei = Convert.ToInt32( zhonglei.Text); wuliao.danwei = Convert.ToInt32( danwei.Text); wuliao.kufang = cangku.Text; if (zdkc.Value.Length > 0) { wuliao.zuidkucun = Convert.ToDecimal(zdkc.Value); } if (zgkc.Value.Length > 0) { wuliao.zuigkucun = Convert.ToDecimal(zgkc.Value); } //wuliao.baojia = Convert.ToDecimal(baojia.Value); wuliao.guige = guige.Value; wuliao.beizhu = beizhu.Text; wuliao.riqi =Convert.ToDateTime(riqi.Value); try { wuliao.changdu = Convert.ToDecimal(changdu.Value); } catch { wuliao.changdu = 0; } try { wuliao.kuandu = Convert.ToDecimal(kuandu.Value); } catch { wuliao.kuandu = 0; } //给日志模板赋值 rizhi.riqi = DateTime.Now; rizhi.leixing = "物料档案"; } #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_wuliao", "添加") == 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_wuliao", "编辑") == false) { Response.Redirect("../Common/nopower.htm"); } } #endregion #region 查询物料名称是否重复 [Ajax.AjaxMethod()] public int serchmingcheng(string str,string ckname,string guige,string pinpai) { string cmd = string.Format("select count(*) from nr_z_wuliao where mingcheng='{0}' and kufang='{1}' and guige='{2}' and pinpai='{3}' ", str.Replace(" ", ""), ckname.Replace(" ", ""), guige.Replace(" ", ""), pinpai.Replace(" ", "")); int count = DBHlper.getcount(cmd); return count; } #endregion //保存操作 protected void bt_tj_Click(object sender, EventArgs e) { try { if (mingcheng.Text == "" || mingcheng.Text == null) { z_error.Text = "物料名称不能为空!"; return; } string caozuo = "添加"; //接收成功参数值 int rtx = 0; //判断uid是否存在值,有值为修改,无值为添加 if (id.Value != null && id.Value != "") { wuliao = wuliaobll.GetModel(Convert.ToInt32(id.Value)); getmd(); if (wuliaobll.Update(wuliao)) { rtx = Convert.ToInt32(id.Value); caozuo = "修改"; } } else { getmd(); wuliao.wlbh = DBHlper.getbh("WL-", "nr_z_wuliao", "wlbh", 4); bh.Text = wuliao.wlbh; rtx = wuliaobll.Add(wuliao); } if (rtx > 0) { //将session转换对象取值 Maticsoft.Model.nr_z_yhzh zh = (Maticsoft.Model.nr_z_yhzh)Session["user"]; rizhi.yonghuming = zh.zhanghao; //拼接字符串插入日志 rizhi.jilu = zh.zhanghao + caozuo + "了物料档案,档案编号为:" + bh.Text.Trim(); rizhibll.Add(rizhi); Response.Redirect("Materiel_browse.aspx?uid=" + rtx, false); } else { Response.Redirect("../Common/error.aspx"); } } catch (Exception) { Response.Redirect("../Common/error.aspx"); } } }