459 lines
19 KiB
C#
459 lines
19 KiB
C#
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 Product_Formt : System.Web.UI.Page
|
||
{
|
||
//创建一个操作记录bll
|
||
Maticsoft.BLL.nr_sys_rizhi rizhibll = new Maticsoft.BLL.nr_sys_rizhi();
|
||
//创建一个共用的申购单模板
|
||
Maticsoft.Model.nr_z_cpkc cpkcmodel = new Maticsoft.Model.nr_z_cpkc();
|
||
//创建一个共同的申购单bll
|
||
Maticsoft.BLL.nr_z_cpkc cpkcbll = new Maticsoft.BLL.nr_z_cpkc();
|
||
//创建一个操作记录模板
|
||
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();
|
||
//创建一个共同的产品物料bll
|
||
Maticsoft.BLL.nr_z_cpkc_wlxq cpwlbll = new Maticsoft.BLL.nr_z_cpkc_wlxq();
|
||
//创建一个共同的水彩用料bll
|
||
Maticsoft.BLL.nr_z_cpkc_scyl scylbll = new Maticsoft.BLL.nr_z_cpkc_scyl();
|
||
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"]);
|
||
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);
|
||
//getbjscyl();
|
||
setxmxq(id.Value);
|
||
}
|
||
else
|
||
{
|
||
|
||
pdquanxian(user.juese);
|
||
jsr.Value = user.zhanghao;
|
||
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
|
||
#region 修改时获取真正数据值
|
||
private void initdata(int did)
|
||
{
|
||
DataTable dt = DBHlper.Execute("select * from view_nr_z_cpkc where id=" + did).Tables[0];
|
||
|
||
if (dt.Rows.Count > 0)
|
||
{
|
||
cpbh.Text = dt.Rows[0]["cpbh"].ToString();
|
||
cpmc.Value = dt.Rows[0]["cpmc"].ToString();
|
||
riqi.Value = Convert.ToDateTime(dt.Rows[0]["riqi"]).ToString("yyyy-MM-dd");
|
||
gg.Value = dt.Rows[0]["gg"].ToString();
|
||
//zhongliang.Value = dt.Rows[0]["zhongliang"].ToString();
|
||
//tiji.Value = dt.Rows[0]["tiji"].ToString();
|
||
string danwei = dt.Rows[0]["dw"].ToString();
|
||
for (int i = 0; i < dw.Items.Count; i++)
|
||
{
|
||
if (dw.Items[i].Text == danwei)
|
||
{
|
||
dw.Items[i].Selected = true;
|
||
}
|
||
}
|
||
|
||
/*string zhonglei = dt.Rows[0]["zl"].ToString();
|
||
for (int i = 0; i < zl.Items.Count; i++)
|
||
{
|
||
if (zl.Items[i].Text == zhonglei)
|
||
{
|
||
zl.Items[i].Selected = true;
|
||
}
|
||
}*/
|
||
dj.Value = dt.Rows[0]["dj"].ToString();
|
||
jsr.Value = dt.Rows[0]["jsr"].ToString();
|
||
bz.Text = dt.Rows[0]["bz"].ToString();
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 用来初始化绑定下拉框等值
|
||
private void binddata()
|
||
{
|
||
riqi.Value = DateTime.Now.ToString("yyyy-MM-dd");
|
||
dj.Value = "0";
|
||
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)
|
||
{
|
||
|
||
dw.DataSource = ly.Tables[0].DefaultView;
|
||
dw.DataValueField = "id";
|
||
dw.DataTextField = "mingcheng";
|
||
dw.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)
|
||
{
|
||
|
||
zl.DataSource = ly.Tables[0].DefaultView;
|
||
zl.DataValueField = "id";
|
||
zl.DataTextField = "mingcheng";
|
||
zl.DataBind();
|
||
}
|
||
}*/
|
||
|
||
}
|
||
#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_cpkc", "添加") == 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_cpkc", "编辑全部") == false)
|
||
{
|
||
Response.Redirect("../Common/nopower.htm");
|
||
}
|
||
|
||
|
||
}
|
||
|
||
#endregion
|
||
#region 获取页面参数赋值model对象
|
||
private void getmd()
|
||
{
|
||
cpkcmodel.cpbh = cpbh.Text;
|
||
cpkcmodel.cpmc = cpmc.Value;
|
||
cpkcmodel.riqi = Convert.ToDateTime(riqi.Value);
|
||
cpkcmodel.gg = gg.Value;
|
||
//cpkcmodel.zhongliang = Convert.ToDecimal(zhongliang.Value);
|
||
//cpkcmodel.zl = zl.SelectedItem.Value;
|
||
//cpkcmodel.tiji = tiji.Value;
|
||
cpkcmodel.dw = dw.SelectedItem.Value;
|
||
cpkcmodel.dj = Convert.ToDecimal(dj.Value);
|
||
cpkcmodel.jsr = jsr.Value;
|
||
cpkcmodel.bz = bz.Text;
|
||
|
||
if (tp.FileContent.Length > 0)
|
||
{
|
||
FileUpLoadzm();
|
||
cpkcmodel.tp = tpName;
|
||
}
|
||
else
|
||
{
|
||
if (Request.QueryString["uid"] != null && Request.QueryString["uid"].ToString().Length > 0)
|
||
{
|
||
int idz = Convert.ToInt32(id.Value);
|
||
nr_z_cpkc cpmodel = cpkcbll.GetModel(idz);
|
||
cpkcmodel.tp = cpmodel.tp;
|
||
}
|
||
|
||
}
|
||
/*if (wj.FileContent.Length > 0)
|
||
{
|
||
FileUpLoadwj();
|
||
cpkcmodel.wj = wjName;
|
||
}
|
||
else
|
||
{
|
||
if (Request.QueryString["uid"] != null && Request.QueryString["uid"].ToString().Length > 0)
|
||
{
|
||
int idz = Convert.ToInt32(id.Value);
|
||
nr_z_cpkc cpmodel = cpkcbll.GetModel(idz);
|
||
cpkcmodel.wj = cpmodel.wj;
|
||
}
|
||
|
||
}*/
|
||
//给日志模板赋值
|
||
rizhi.riqi = DateTime.Now;
|
||
rizhi.leixing = "产品档案";
|
||
}
|
||
#endregion
|
||
#region 获取项目需求
|
||
private void setxmxq(string cpid)
|
||
{
|
||
//加载前段项目
|
||
string qdgjstring = "<table id='qdxmtb' class='bule'><tr class='tbtilt'><td><span>需求项目</span></td><td><span>物料编号</span></td><td><span>物料名称</span></td><td ><span>用量</span></td><td><span>需求项目</span></td><td><span>物料编号</span></td><td><span>物料名称</span></td><td><span>用量</span></td></tr> ";
|
||
string getgjsql = "select * from view_nr_z_cpkc_wlxq where cpid='" + id.Value + "'";
|
||
DataSet ds = DBHlper.Execute(getgjsql);
|
||
int ges = 0;
|
||
if (ds != null && ds.Tables[0].Rows.Count > 0)
|
||
{
|
||
int hang = 0;
|
||
foreach (DataRow r in ds.Tables[0].Rows)
|
||
{
|
||
ges = ges + 1;
|
||
|
||
if (ges == 1)
|
||
{
|
||
qdgjstring += "<tr id='" + hang + "'><td><span>" + r["xmmc"].ToString() + "</span></td><td> <input type=text tag='" + r["xmmc"].ToString() + "' ReadOnly onclick=\"selectwuliao('" + hang + "')\" id='wlbh" + hang + "' value='" + r["wlbh"].ToString() + "' class='inpittxt' /></td><td> <input type=text id='wlmc" + hang + "' ReadOnly value='" + r["wlmc"].ToString() + "' class='inpittxt' /></td><td> <input type=text id='xqyl" + hang + "' value='" + Convert.ToDouble(r["xqyl"]).ToString() + "' class='inpittxt' /></td>";
|
||
}
|
||
else
|
||
{
|
||
qdgjstring += "<td><span>" + r["xmmc"].ToString() + "</span></td><td> <input type=text tag='" + r["xmmc"].ToString() + "' ReadOnly onclick=\"selectwuliao('er" + hang + "')\" id='wlbher" + hang + "' value='" + r["wlbh"].ToString() + "' class='inpittxt' /></td><td> <input type=text id='wlmcer" + hang + "' ReadOnly value='" + r["wlmc"].ToString() + "' class='inpittxt' /></td><td > <input type=text id='xqyler" + hang + "' value='" + Convert.ToDouble(r["xqyl"]).ToString() + "' class='inpittxt' /></td></tr>";
|
||
ges = 0;
|
||
hang = hang + 1;
|
||
}
|
||
|
||
}
|
||
if (ges == 1)
|
||
{
|
||
qdgjstring += "<td></td><td></td><td></td><td ></td></tr>";
|
||
ges = 0;
|
||
}
|
||
}
|
||
xqwldiv.InnerHtml = qdgjstring + "</table>";
|
||
}
|
||
#endregion
|
||
|
||
#region 编辑加载水彩信息
|
||
/*private void getbjscyl()
|
||
{
|
||
//加载前段工价
|
||
string getgjsql = "select * from view_nr_z_cpkc_scyl where cpid='" + id.Value + "'";
|
||
string cltable = "<table id='scylxxtb' class='bule'>"
|
||
+ "<tr id='0' class='tbtilt'> <td width='25px' onclick='add_wl()'> <img src='../Images_Folder/Button/tjltj.png' width='25px' height='25px' /></td>" +
|
||
"<td><span>水彩用料</span></td><td><span>用量</span></td><td><span>备注</span></td><td><span>水彩用料</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(getgjsql);
|
||
if (ds != null && ds.Tables[0].Rows.Count > 0)
|
||
{
|
||
int sjint = 0;
|
||
int hcount = 1;
|
||
foreach (DataRow r in ds.Tables[0].Rows)
|
||
{
|
||
if (sjint == 0)
|
||
{
|
||
cltable += "<tr id='" + hcount + "'><td width='25px'> <img src='../Images_Folder/Button/tjljh.png' onclick='jianhang(this)' width='25px' height='25px' /></td>";
|
||
}
|
||
sjint = sjint + 1;
|
||
if (sjint == 1)
|
||
{
|
||
cltable += " <td><input type='text' id='wuliao" + hcount + "sc' name='" + r["scwlbh"].ToString() + "' ReadOnly value='" + r["wlmc"].ToString() + "' Class='inpittxt' onclick=\"selectwuliao('" + hcount + "sc')\" /></td><td><input type='text' onkeyup='doubleshuru(this)' id='yongl" + hcount + "' value='" + Convert.ToDouble(r["scyl"]).ToString() + "' Class='inpittxt' /></td><td ><input type='text' id='beizhu" + hcount + "' value='" + r["beizhu"].ToString() + "' Class='inpittxt' /> </td>";
|
||
}
|
||
else if (sjint == 2)
|
||
{
|
||
cltable += " <td><input type='text' id='wuliaoy" + hcount + "sc' name='" + r["scwlbh"].ToString() + "' ReadOnly value='" + r["wlmc"].ToString() + "' Class='inpittxt' onclick=\"selectwuliao('y" + hcount + "sc')\" /></td><td ><input type='text' onkeyup='doubleshuru(this)' id='yongly" + hcount + "' value='" + Convert.ToDouble(r["scyl"]).ToString() + "' Class='inpittxt' /></td><td ><input type='text' id='beizhuy" + hcount + "' value='" + r["beizhu"].ToString() + "' Class='inpittxt' /> </td>";
|
||
}
|
||
else
|
||
if (sjint == 3)
|
||
{
|
||
cltable += " <td ><input type='text' id='wuliaoe" + hcount + "sc' name='" + r["scwlbh"].ToString() + "' ReadOnly value='" + r["wlmc"].ToString() + "' Class='inpittxt' onclick=\"selectwuliao('e" + hcount + "sc')\" /></td><td><input type='text' onkeyup='doubleshuru(this)' id='yongle" + hcount + "' value='" + Convert.ToDouble(r["scyl"]).ToString() + "' Class='inpittxt' /></td><td><input type='text' id='beizhue" + hcount + "' value='" + r["beizhu"].ToString() + "' Class='inpittxt' /> </td>";
|
||
cltable += "</tr>";
|
||
sjint = 0;
|
||
hcount = hcount + 1;
|
||
}
|
||
|
||
}
|
||
if (3 - sjint > 0 && sjint > 0)
|
||
{
|
||
int dyz = 3 - sjint;
|
||
for (int hz = 0; hz < dyz; hz++)
|
||
{
|
||
sjint = sjint + 1;
|
||
if (sjint == 2)
|
||
{
|
||
cltable += " <td><input type='text' id='wuliaoy" + hcount + "' Class='inpittxt' onclick='selectscwuliao(this)' /></td><td ><input type='text' onkeyup='doubleshuru(this)' id='yongly" + hcount + "' Class='inpittxt' /></td><td><input type='text' id='beizhuy" + hcount + "' Class='inpittxt' /> </td>";
|
||
}
|
||
else
|
||
if (sjint == 3)
|
||
{
|
||
cltable += " <td ><input type='text' id='wuliaoe" + hcount + "' Class='inpittxt' onclick='selectscwuliao(this)' /></td><td><input type='text' onkeyup='doubleshuru(this)' id='yongle" + hcount + "' Class='inpittxt' /></td><td><input type='text' id='beizhue" + hcount + "' Class='inpittxt' /> </td>";
|
||
cltable += "</tr>";
|
||
sjint = 0;
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
cltable += "</table>";
|
||
scylxxdiv.InnerHtml = cltable;
|
||
|
||
}*/
|
||
#endregion
|
||
protected void bt_tj_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
|
||
string caozuo = "添加";
|
||
getmd();
|
||
//接收成功参数值
|
||
int rtx = 0;
|
||
//判断uid是否存在值,有值为修改,无值为添加
|
||
if (id.Value != null && id.Value != "")
|
||
{
|
||
cpkcmodel.id = Convert.ToInt32(id.Value);
|
||
if (cpkcbll.Update(cpkcmodel))
|
||
{
|
||
rtx = Convert.ToInt32(id.Value);
|
||
caozuo = "修改";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
cpkcmodel.cpbh = DBHlper.getbh("CP-", "nr_z_cpkc", "cpbh", 4);
|
||
cpbh.Text = cpkcmodel.cpbh;
|
||
rtx = cpkcbll.Add(cpkcmodel);
|
||
}
|
||
if (rtx > 0)
|
||
{
|
||
|
||
string gjscsl = "delete nr_z_cpkc_wlxq where cpid='" + rtx + "'";
|
||
DBHlper.excutecmd(gjscsl);
|
||
List<Maticsoft.Model.nr_z_cpkc_wlxq> cpwlds = new List<Maticsoft.Model.nr_z_cpkc_wlxq>();
|
||
cpwlds = DBHlper.ConvertJsonToEntityListEntity<Maticsoft.Model.nr_z_cpkc_wlxq>(wlxmhd.Value);
|
||
foreach (Maticsoft.Model.nr_z_cpkc_wlxq gjx in cpwlds)
|
||
{
|
||
gjx.cpid = rtx;
|
||
cpwlbll.Add(gjx);
|
||
|
||
}
|
||
|
||
|
||
|
||
gjscsl = "delete nr_z_cpkc_scyl where cpid='" + rtx + "'";
|
||
DBHlper.excutecmd(gjscsl);
|
||
List<Maticsoft.Model.nr_z_cpkc_scyl> scylds = new List<Maticsoft.Model.nr_z_cpkc_scyl>();
|
||
scylds = DBHlper.ConvertJsonToEntityListEntity<Maticsoft.Model.nr_z_cpkc_scyl>(scylhd.Value);
|
||
foreach (Maticsoft.Model.nr_z_cpkc_scyl scyl in scylds)
|
||
{
|
||
scyl.cpid = rtx;
|
||
scylbll.Add(scyl);
|
||
|
||
}
|
||
|
||
//将session转换对象取值
|
||
Maticsoft.Model.nr_z_yhzh zh = (Maticsoft.Model.nr_z_yhzh)Session["user"];
|
||
rizhi.yonghuming = zh.zhanghao;
|
||
//拼接字符串插入日志
|
||
rizhi.jilu = zh.zhanghao + caozuo + "了产品档案,编号为:" + cpbh.Text.Trim();
|
||
rizhibll.Add(rizhi);
|
||
Response.Redirect("Product_browse.aspx?uid=" + rtx, false);
|
||
}
|
||
else
|
||
{
|
||
Response.Redirect("../Common/error.aspx");
|
||
}
|
||
|
||
}
|
||
catch (Exception)
|
||
{
|
||
Response.Redirect("../Common/error.aspx");
|
||
}
|
||
}
|
||
|
||
|
||
string tpName = "";
|
||
public void FileUpLoadzm()
|
||
{
|
||
try
|
||
{
|
||
if (!tp.HasFile && !tp.HasFile)
|
||
{
|
||
Response.Write("<script>alert('请选择要上传的文件')</script>");
|
||
return;
|
||
}
|
||
if (!tp.HasFile) { }
|
||
else
|
||
{
|
||
string directoyPath = System.Web.HttpContext.Current.Server.MapPath("~/Client_Folder/");
|
||
if (!System.IO.Directory.Exists(directoyPath))
|
||
{
|
||
System.IO.Directory.CreateDirectory(directoyPath);
|
||
}
|
||
tpName = "CPTP" + DateTime.Now.ToString("yyyy-MM-dd") + "-" + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second + "-" + cpmc.Value + "." + tp.PostedFile.FileName.Substring(tp.PostedFile.FileName.LastIndexOf(".") + 1);
|
||
string path = "~/Client_Folder/" + tpName;
|
||
if (File.Exists(path))
|
||
{
|
||
Response.Write("<script language='javascript'>alert('服务器上已经有了你正在上传的文件:" + tpName + "!');</script>");
|
||
return;
|
||
}
|
||
tp.PostedFile.SaveAs(Server.MapPath(path));
|
||
|
||
}
|
||
}
|
||
catch
|
||
{ Response.Write("<script>alert('上传失败!')</script>"); }
|
||
}
|
||
|
||
|
||
string wjName = "";
|
||
/* public void FileUpLoadwj()
|
||
{
|
||
try
|
||
{
|
||
if (!wj.HasFile && !wj.HasFile)
|
||
{
|
||
Response.Write("<script>alert('请选择要上传的文件')</script>");
|
||
return;
|
||
}
|
||
if (!wj.HasFile) { }
|
||
else
|
||
{
|
||
string directoyPath = System.Web.HttpContext.Current.Server.MapPath("~/Client_Folder/");
|
||
if (!System.IO.Directory.Exists(directoyPath))
|
||
{
|
||
System.IO.Directory.CreateDirectory(directoyPath);
|
||
}
|
||
wjName ="CPWJ" + DateTime.Now.ToString("yyyy-MM-dd") + "-" + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second + "-" + cpmc.Value + "." + wj.PostedFile.FileName.Substring(wj.PostedFile.FileName.LastIndexOf(".") + 1);
|
||
string path = "~/Client_Folder/" + wjName;
|
||
if (File.Exists(path))
|
||
{
|
||
Response.Write("<script language='javascript'>alert('服务器上已经有了你正在上传的文件:" + wjName + "!');</script>");
|
||
return;
|
||
}
|
||
wj.PostedFile.SaveAs(Server.MapPath(path));
|
||
|
||
}
|
||
}
|
||
catch
|
||
{ Response.Write("<script>alert('上传失败!')</script>"); }
|
||
}
|
||
*/
|
||
} |