CeramicProject/newyt/Module_data/Suite_browse.aspx.cs

323 lines
13 KiB
C#
Raw Normal View History

2024-05-18 15:28:29 +08:00
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.IO;
using Maticsoft.Model;
public partial class Suite_browse: System.Web.UI.Page
{
//创建一个操作记录bll
Maticsoft.BLL.nr_sys_rizhi rizhibll = new Maticsoft.BLL.nr_sys_rizhi();
//创建一个共用的产品BOM模板
Maticsoft.Model.nr_z_cpbom cpbommodel = new Maticsoft.Model.nr_z_cpbom();
//创建一个共同的产品BOMbll
Maticsoft.BLL.nr_z_cpbom cpbombll = new Maticsoft.BLL.nr_z_cpbom();
//创建一个共同的产品bom明细bll
Maticsoft.BLL.nr_z_cpbom_xm cpbommxbll = new Maticsoft.BLL.nr_z_cpbom_xm();
//创建一个操作记录模板
Maticsoft.Model.nr_sys_rizhi rizhi = new Maticsoft.Model.nr_sys_rizhi();
//创建一个共用的编码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();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["user"] == null)
{
Response.Redirect("../index.aspx");
}
//获取角色权限
Maticsoft.Model.nr_z_yhzh user = (Maticsoft.Model.nr_z_yhzh)(Session["user"]);
ywy.Value = user.zhanghao;
binddata();
if (Request.QueryString["uid"] != null && Request.QueryString["uid"].ToString().Length > 0)
{
string uid = Request.QueryString["uid"].ToString();
id.Value = uid;
initdata(Convert.ToInt32(uid));
pdquanxianbj(user.juese);
}
else
{
setbommx();
pdquanxian(user.juese);
}
}
}
#region
private void initdata(int did)
{
int idz = Convert.ToInt32(did);
cpbommodel = cpbombll.GetModel(idz);
cpbh.Value = cpbommodel.huohao;
cpmc.Value = cpbommodel.pinming;
riqi.Value = cpbommodel.riqi.ToString();
gg.Value = cpbommodel.guige;
danwei.Text = cpbommodel.danwei;
//zhongliang.Value = Convert.ToDouble(cpbommodel.zhongliang).ToString();
zl.Text = cpbommodel.zhonglei;
ywy.Value = cpbommodel.ywy;
beizhu.Value = cpbommodel.bz;
bmdj.Value = Convert.ToDouble(cpbommodel.bmdj).ToString();
TreeNode NewNode = new TreeNode(cpbommodel.pinming, "无", "", "", "");
string bomhtml = "<table id='bomxmtb' class='bule'> <tr id='0' class='tbtilt'>"
+ "<td width='25' onclick='add_cpmx()'> <img width='25' height='25' src='../Images_Folder/Button/tjltj.png'></td>"
+ "<td><span><font>*明细类型</font></span></td><td><span><font>*产品编号</font></span></td><td ><span>产品名称</span></td><td ><span>产品单价</span></td>"
+ "<td ><span>产品单位</span></td><td ><span>小计<span></td><td ><span>备注</span></td> </tr>";
DataSet ds = DBHlper.Execute("select * from view_nr_z_cpbom_xm where bomid='" + idz + "'");
foreach( DataRow r in ds.Tables[0].Rows)
{
//查询所有bom子项目循环输出列表
string hcount = r["id"].ToString();
if (r["cplx"].ToString() == "产品")
{
bomhtml += "<tr id='" + hcount + "' name='" + hcount + "'><td width='25px'> <img src='../Images_Folder/Button/tjljh.png' onclick='jianhang(this)' width='25px' height='25px' /></td>"
+ "<td> <select Class='inpittxt_xl' id='mxlx" + hcount + "' >" + "<option value='产品' selected='true' >产品</option><option value='母件' >母件</option>" + "</select></td>"
+ "<td><input type='text' id='cpbh" + hcount + "' onclick='selectcp(" + hcount + ")' value='" + r["cpbh"] + "' Class='inpittxt' /></td><td Class='tbtxt_hx'><input type='text' id='cpmc" + hcount + "' readonly value='" + r["cpmc"] + "' Class='inpittxt_hx' /></td>"
+ "<td Class='tbtxt_hx'><input type='text' id='cpdj" + hcount + "' readonly value='" + r["dj"] + "' Class='inpittxt_hx' /></td>"
+ "<td Class='tbtxt_hx'><input type='text' id='cpdw" + hcount + "' value='" + r["dw"] + "' readonly Class='inpittxt_hx' /></td>"
+ "<td ><input type='text' id='xiaoji" + hcount + "' value='" + r["xiaoji"] + "' Class='inpittxt' /></td><td><input type='text' id='beizhu" + hcount + "' value='" + r["beizhu"] + "' Class='inpittxt' /></td></tr>";
}
else if(r["cplx"].ToString() == "母件")
{
bomhtml += "<tr id='" + hcount + "' name='" + hcount + "'><td width='25px'> <img src='../Images_Folder/Button/tjljh.png' onclick='jianhang(this)' width='25px' height='25px' /></td>"
+ "<td> <select Class='inpittxt_xl' id='mxlx" + hcount + "' >" + "<option value='产品' >产品</option><option value='母件' selected='true' >母件</option>" + "</select></td>"
+ "<td><input type='text' id='cpbh" + hcount + "' onclick='selectcp(" + hcount + ")' value='" + r["cpbh"] + "' Class='inpittxt' /></td><td class='tbtxt_hx'><input type='text' id='cpmc" + hcount + "' readonly value='" + r["cpmc"] + "' Class='inpittxt_hx' /></td>"
+ "<td Class='tbtxt_hx'><input type='text' id='cpdj" + hcount + "' readonly value='" + r["dj"] + "' Class='inpittxt_hx' /></td>"
+ "<td Class='tbtxt_hx'><input type='text' id='cpdw" + hcount + "' value='" + r["dw"] + "' readonly Class='inpittxt_hx' /></td>"
+ "<td ><input type='text' id='xiaoji" + hcount + "' value='" + r["xiaoji"] + "' Class='inpittxt' /></td><td ><input type='text' id='beizhu" + hcount + "' value='" + r["beizhu"] + "' Class='inpittxt' /></td></tr>";
}
TreeNode NewNode2 =diguisxjg(r["cplx"].ToString(), r["zjid"].ToString(), r["cpmc"].ToString());
NewNode.ChildNodes.Add(NewNode2);
}
TreeView1.Nodes.Add(NewNode);
bommx.InnerHtml = bomhtml + "</table>";
}
private TreeNode diguisxjg(string zjlx,string zjid,string zjmc)
{
if (zjlx == "产品")
{
TreeNode NewNodezjnd = new TreeNode(zjmc, "无", "", "", "");
return NewNodezjnd;
}
else
{
TreeNode NewNodezjnd = new TreeNode(zjmc, "无", "", "", "");
DataSet ds = DBHlper.Execute("select * from view_nr_z_cpbom_xm where bomid='" + zjid + "'");
foreach (DataRow r in ds.Tables[0].Rows)
{
TreeNode NewNodezjnd2 = diguisxjg(r["cplx"].ToString(), r["zjid"].ToString(), r["cpmc"].ToString());
NewNodezjnd.ChildNodes.Add(NewNodezjnd2);
}
return NewNodezjnd;
}
}
#endregion
#region
private void binddata()
{
riqi.Value = DateTime.Now.ToString("yyyy-MM-dd");
DataSet hylx = bmlx.GetAllList();
DataRow[] dr = hylx.Tables[0].Select("leixing='产品种类'");
if (dr != null && dr.Length > 0)
{
DataSet ly = bm.GetList("zhongleiid='" + dr[0]["id"] + "' and zt='1'");
if (ly != null)
{
zl.DataSource = ly.Tables[0].DefaultView;
zl.DataValueField = "mingcheng";
zl.DataTextField = "mingcheng";
zl.DataBind();
}
}
dr = hylx.Tables[0].Select("leixing='单位'");
if (dr != null && dr.Length > 0)
{
DataSet ly = bm.GetList("zhongleiid='" + dr[0]["id"] + "' and zt='1'");
if (ly != null)
{
danwei.DataSource = ly.Tables[0].DefaultView;
danwei.DataValueField = "mingcheng";
danwei.DataTextField = "mingcheng";
danwei.DataBind();
}
}
}
#endregion
#region
private void setbommx()
{
string bomhtml = "<table id='bomxmtb' class='bule'> <tr id='0' class='tbtilt'>"
+ "<td width='25' onclick='add_cpmx()'> <img width='25' height='25' src='../Images_Folder/Button/tjltj.png'></td>"
+ "<td><span><font>*明细类型</font></span></td><td><span><font>*产品编号</font></span></td><td ><span>产品名称</span></td><td ><span>产品单价</span></td>"
+ "<td ><span>产品单位</span></td><td ><span>小计<span></td><td ><span>备注</span></td> </tr>";
bommx.InnerHtml = bomhtml;
TreeNode NewNode = new TreeNode("BOM信息添加完成后显示", "无", "", "", "");
TreeView1.Nodes.Add(NewNode);
}
#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");
}
2024-05-21 15:05:24 +08:00
if (DBHlper.GetPermission(juese, "产品BOM", "nr_z_cpbom", "添加") == false)
2024-05-18 15:28:29 +08:00
{
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");
}
2024-05-21 15:05:24 +08:00
if (DBHlper.GetPermission(juese, "产品BOM", "nr_z_cpbom", "编辑全部") == false)
2024-05-18 15:28:29 +08:00
{
Response.Redirect("../Common/nopower.htm");
}
}
#endregion
#region model对象
private void getmd()
{
cpbommodel.huohao = cpbh.Value;
cpbommodel.pinming = cpmc.Value;
cpbommodel.riqi = Convert.ToDateTime(riqi.Value);
cpbommodel.guige = gg.Value;
cpbommodel.danwei = danwei.Text;
//cpbommodel.zhongliang = Convert.ToDecimal(zhongliang.Value);
cpbommodel.zhonglei = zl.Text;
cpbommodel.ywy = ywy.Value;
cpbommodel.bz = beizhu.Value;
cpbommodel.bmdj = Convert.ToDecimal(bmdj.Value);
//给日志模板赋值
rizhi.riqi = DateTime.Now;
rizhi.leixing = "产品BOM";
}
#endregion
protected void bt_tj_Click(object sender, EventArgs e)
{
try
{
string caozuo = "添加";
getmd();
//接收成功参数值
int rtx = 0;
//判断uid是否存在值有值为修改无值为添加
if (id.Value != null && id.Value != "")
{
cpbommodel.id = Convert.ToInt32(id.Value);
if (cpbombll.Update(cpbommodel))
{
rtx = Convert.ToInt32(id.Value);
caozuo = "修改";
}
}
else
{
cpbommodel.huohao = DBHlper.getbh("BOM-", "nr_z_cpbom", "huohao", 4);
rtx = cpbombll.Add(cpbommodel);
}
if (rtx > 0)
{
List<Maticsoft.Model.nr_z_cpbom_xm> xmmds = new List<Maticsoft.Model.nr_z_cpbom_xm>();
xmmds = DBHlper.ConvertJsonToEntityListEntity<Maticsoft.Model.nr_z_cpbom_xm>(bommxhd.Value);
string deletecmd = "delete from nr_z_cpbom_xm where bomid='" + rtx + "'";
int ci = 0;
try
{
foreach (Maticsoft.Model.nr_z_cpbom_xm x in xmmds)
{
ci = ci + 1;
x.bomid = Convert.ToInt32(rtx);
//判断如果存在id的时候且是修改操作时
if (x.id > 0 && Request.QueryString["uid"] != null)
{
cpbommxbll.Update(x);
deletecmd += " and id !=" + x.id;
}
else
{
int mxid = cpbommxbll.Add(x);
deletecmd += " and id !=" + mxid;
}
}
DBHlper.excutecmd(deletecmd);
} catch
{
Response.Write("<script>alert('BOM明细在第'" + ci + "行时保存失败!);</script>");
}
//将session转换对象取值
Maticsoft.Model.nr_z_yhzh zh = (Maticsoft.Model.nr_z_yhzh)Session["user"];
rizhi.yonghuming = zh.zhanghao;
//拼接字符串插入日志
rizhi.jilu = zh.zhanghao + caozuo + "了产品BOM编号为" + cpbh.Value;
rizhibll.Add(rizhi);
Response.Redirect("Suite_browse.aspx?uid=" + rtx, false);
}
else
{
Response.Redirect("../Common/error.aspx");
}
}
catch (Exception)
{
Response.Redirect("../Common/error.aspx");
}
}
}