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;
using Ajax;
public partial class Sample_browse : System.Web.UI.Page
{
//创建一个操作记录bll
Maticsoft.BLL.nr_sys_rizhi rizhibll = new Maticsoft.BLL.nr_sys_rizhi();
//创建一个共同的申购单bll
Maticsoft.BLL.nr_z_ypdj ypdjbll = new Maticsoft.BLL.nr_z_ypdj();
//创建一个操作记录模板
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)
{
Utility.RegisterTypeForAjax(typeof(Sample_browse));
if (!IsPostBack)
{
if (Session["user"] == null)
{
Response.Redirect("../index.aspx");
}
//获取角色权限
Maticsoft.Model.nr_z_yhzh user = (Maticsoft.Model.nr_z_yhzh)(Session["user"]);
if (Request.QueryString["uid"] != null && Request.QueryString["uid"].ToString().Length > 0)
{
string uid = Request.QueryString["uid"].ToString();
id.Value = uid;
initdata(Convert.ToInt32(uid));
pdquanxian(user.juese);
}
getqdgj();
getxmxx();
getxgfyxx();
getscyl();
getcpxmxx();
}
}
#region 修改时获取真正数据值
private void initdata(int did)
{
DataTable dt = DBHlper.Execute("select * from nr_z_ypdj where id=" + did).Tables[0];
if (dt.Rows.Count > 0)
{
kfh.Text = dt.Rows[0]["kfh"].ToString();
huohao.Text = dt.Rows[0]["huohao"].ToString();
xlh.Text = dt.Rows[0]["xiliehao"].ToString();
cpmc.Text = dt.Rows[0]["cpmc"].ToString();
zdysj.Text = Convert.ToDateTime(dt.Rows[0]["zdysj"]).ToString("yyyy-MM-dd");
xgsj.Text = Convert.ToDateTime(dt.Rows[0]["xgsj"]).ToString("yyyy-MM-dd");
ypcc.Text = dt.Rows[0]["ypcc"].ToString();
zhongliang.Text = Convert.ToDouble(dt.Rows[0]["zhongl"]).ToString();
rongliang.Text = Convert.ToDouble(dt.Rows[0]["rongl"]).ToString();
banci.Text = dt.Rows[0]["banci"].ToString();
zhuangtai.Text = dt.Rows[0]["zt"].ToString();
qdqz.Text = dt.Rows[0]["qdqz"].ToString();
zdqz.Text = dt.Rows[0]["zdqz"].ToString();
hdqz.Text = dt.Rows[0]["hdqz"].ToString();
shr.Text = dt.Rows[0]["shr"].ToString();
tp.Src = "../Client_Folder/" + dt.Rows[0]["tupian"].ToString() + "";
}
}
#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_ypdj", "查看全部") == false)
{
Response.Redirect("../Common/nopower.htm");
}
if (DBHlper.GetPermission(juese, "样品登记", "nr_z_ypdj", "编辑全部"))
{
bt_bj.Visible = true;
}
if (DBHlper.GetPermission(juese, "样品登记", "nr_z_ypdj", "删除全部"))
{
shanchu.Visible = true;
}
if (DBHlper.GetPermission(juese, "样品登记", "nr_z_ypdj", "前段签字"))
{
bt_qdsh.Visible = true;
}
if (DBHlper.GetPermission(juese, "样品登记", "nr_z_ypdj", "添加"))
{
bt_add.Visible = true;
}
if (DBHlper.GetPermission(juese, "样品登记", "nr_z_ypdj", "中段签字"))
{
bt_zdsh.Visible = true;
}
if (DBHlper.GetPermission(juese, "样品登记", "nr_z_ypdj", "后段签字"))
{
bt_hdsh.Visible = true;
}
if (DBHlper.GetPermission(juese, "样品登记", "nr_z_ypdj", "生成产品"))
{
bt_sccpda.Visible = true;
}
if (DBHlper.GetPermission(juese, "样品登记", "nr_z_ypdj", "打印"))
{
dayin.Visible = true;
}
if (DBHlper.GetPermission(juese, "样品登记", "nr_z_ypdj", "审核"))
{
bt_shtg.Visible = true;
bt_shbg.Visible = true;
}
if (zhuangtai.Text == "通过")
{
bt_shtg.Enabled = false;
bt_shtg.BackColor = System.Drawing.Color.Gray;
bt_bj.Enabled = false;
bt_bj.BackColor = System.Drawing.Color.Gray;
shanchu.Enabled = false;
shanchu.BackColor = System.Drawing.Color.Gray;
}
if (zhuangtai.Text == "不过")
{
bt_shbg.Enabled = false;
bt_shbg.BackColor = System.Drawing.Color.Gray;
}
if (zhuangtai.Text != "通过")
{
bt_sccpda.Enabled = false;
bt_sccpda.BackColor = System.Drawing.Color.Gray;
}
}
#endregion
#region 加载工价信息
private void getqdgj()
{
//加载前段工价
string qdgjstring = "
";
string getgjsql = "select * from nr_z_ypdj_gj where ypdid='" + id.Value + "' and jieduan='前段工价'";
DataSet ds = DBHlper.Execute(getgjsql);
//判断拼接列值,根据值更改前台样式
int lies = 0;
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow r in ds.Tables[0].Rows)
{
if (lies == 0)
{
qdgjstring += "";
}
qdgjstring += "" + r["gjmc"].ToString() + ": " + Convert.ToDouble(r["gjjg"]).ToString() + " | ";
lies = lies + 1;
if (lies == 7)
{
lies = 0;
qdgjstring += "
";
}
}
if (7 - lies > 0 && lies > 0)
{
for (int x = 0; x < 7 - lies; x++)
{
qdgjstring += " | ";
}
qdgjstring += "";
}
}
qdgjxx.InnerHtml = qdgjstring + "
";
//中段工价
qdgjstring = "";
getgjsql = "select * from nr_z_ypdj_gj where ypdid='" + id.Value + "' and jieduan='中段工价'";
ds = DBHlper.Execute(getgjsql);
//判断拼接列值,根据值更改前台样式
lies = 0;
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow r in ds.Tables[0].Rows)
{
if (lies == 0)
{
qdgjstring += "";
}
qdgjstring += "" + r["gjmc"].ToString() + ": " + Convert.ToDouble(r["gjjg"]).ToString() + " | ";
lies = lies + 1;
if (lies == 7)
{
lies = 0;
qdgjstring += "
";
}
}
if (7 - lies > 0 && lies > 0)
{
for (int x = 0; x < 7 - lies; x++)
{
qdgjstring += " | ";
}
qdgjstring += "";
}
}
zdgjxx.InnerHtml = qdgjstring + "
";
//后段工价
qdgjstring = "";
getgjsql = "select * from nr_z_ypdj_gj where ypdid='" + id.Value + "' and jieduan='后段工价'";
ds = DBHlper.Execute(getgjsql);
//判断拼接列值,根据值更改前台样式
lies = 0;
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow r in ds.Tables[0].Rows)
{
if (lies == 0)
{
qdgjstring += "";
}
qdgjstring += "" + r["gjmc"].ToString() + ": " + Convert.ToDouble(r["gjjg"]).ToString() + " | ";
lies = lies + 1;
if (lies == 7)
{
lies = 0;
qdgjstring += "
";
}
}
if (7 - lies > 0 && lies > 0)
{
for (int x = 0; x < 7 - lies; x++)
{
qdgjstring += " | ";
}
qdgjstring += "";
}
}
hdgjxx.InnerHtml = qdgjstring + "
";
}
#endregion
#region 加载项目信息
private void getxmxx()
{
//加载前段项目
string qdgjstring = " 项目名称 | 物料名称 | 用量 | 项目名称 | 物料名称 | 用量 | 项目名称 | 物料名称 | 用量 |
";
string getgjsql = "select * from view_nr_z_ypdj_xmxx where ypdid='" + id.Value + "' and jieduan='前段项目'";
DataSet ds = DBHlper.Execute(getgjsql);
//判断拼接列值,根据值更改前台样式
int lies = 0;
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow r in ds.Tables[0].Rows)
{
if (lies == 0)
{
qdgjstring += "";
}
qdgjstring += "" + r["xmmc"].ToString() + " | " + r["wlmc"].ToString() + " | " + Convert.ToDouble(r["wlyl"]).ToString() + " | ";
lies = lies + 1;
if (lies == 3)
{
lies = 0;
qdgjstring += "
";
}
}
if (3 - lies > 0 && lies > 0)
{
for (int x = 0; x < 3 - lies; x++)
{
qdgjstring += " | | | ";
}
qdgjstring += "";
}
}
qdxmxx.InnerHtml = qdgjstring + "
";
//加载中段项目
qdgjstring = " 项目名称 | 物料名称 | 用量 | 项目名称 | 物料名称 | 用量 | 项目名称 | 物料名称 | 用量 |
";
getgjsql = "select * from view_nr_z_ypdj_xmxx where ypdid='" + id.Value + "' and jieduan='中段项目'";
ds = DBHlper.Execute(getgjsql);
//判断拼接列值,根据值更改前台样式
lies = 0;
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow r in ds.Tables[0].Rows)
{
if (lies == 0)
{
qdgjstring += "";
}
qdgjstring += "" + r["xmmc"].ToString() + " | " + r["wlmc"].ToString() + " | " + Convert.ToDouble(r["wlyl"]).ToString() + " | ";
lies = lies + 1;
if (lies == 3)
{
lies = 0;
qdgjstring += "
";
}
}
if (3 - lies > 0 && lies > 0)
{
for (int x = 0; x < 3 - lies; x++)
{
qdgjstring += " | | | ";
}
qdgjstring += "";
}
}
zdxmxx.InnerHtml = qdgjstring + "
";
//加载后段项目
qdgjstring = " 项目名称 | 物料名称 | 用量 | 项目名称 | 物料名称 | 用量 | 项目名称 | 物料名称 | 用量 |
";
getgjsql = "select * from view_nr_z_ypdj_xmxx where ypdid='" + id.Value + "' and jieduan='后段项目'";
ds = DBHlper.Execute(getgjsql);
//判断拼接列值,根据值更改前台样式
lies = 0;
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow r in ds.Tables[0].Rows)
{
if (lies == 0)
{
qdgjstring += "";
}
qdgjstring += "" + r["xmmc"].ToString() + " | " + r["wlmc"].ToString() + " | " + Convert.ToDouble(r["wlyl"]).ToString() + " | ";
lies = lies + 1;
if (lies == 3)
{
lies = 0;
qdgjstring += "
";
}
}
if (3 - lies > 0 && lies > 0)
{
for (int x = 0; x < 3 - lies; x++)
{
qdgjstring += " | | | ";
}
qdgjstring += "";
}
}
hdxmxx.InnerHtml = qdgjstring + "
";
}
#endregion
#region 加载相关费用信息
private void getxgfyxx()
{
//加载前段工价
string qdgjstring = "";
string getgjsql = "select * from nr_z_ypdj_xgfy where ypdid='" + id.Value + "'";
DataSet ds = DBHlper.Execute(getgjsql);
//判断拼接列值,根据值更改前台样式
int lies = 0;
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow r in ds.Tables[0].Rows)
{
if (lies == 0)
{
qdgjstring += "";
}
qdgjstring += "" + r["fymc"].ToString() + ": " + Convert.ToDouble(r["fyje"]).ToString() + " | ";
lies = lies + 1;
if (lies == 7)
{
lies = 0;
qdgjstring += "
";
}
}
if (7 - lies > 0 && lies > 0)
{
for (int x = 0; x < 7 - lies; x++)
{
qdgjstring += " | ";
}
qdgjstring += "";
}
}
xgfydiv.InnerHtml = qdgjstring + "
";
}
#endregion
#region 加载水彩信息
private void getscyl()
{
//加载前段工价
string getgjsql = "select * from view_nr_z_ypdj_scyl where ypdid='" + id.Value + "'";
string cltable = "" +
" 水彩用料 | 用量 | 备注 | 水彩用料 | 用量 | 备注 | 水彩用料 | 用量 | 备注 |
";
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 += "";
}
sjint = sjint + 1;
cltable += " " + r["wlmc"].ToString() + " | " + Convert.ToDouble(r["scyl"]).ToString() + " | " + r["beizhu"].ToString() + " | ";
if (sjint == 3)
{
cltable += "
";
}
hcount = hcount + 1;
}
if (3 - sjint > 0)
{
for (int hz = 0; hz < 3 - sjint; hz++)
{
cltable += " | | | ";
}
cltable += "";
}
}
cltable += "
";
scylxxdiv.InnerHtml = cltable;
}
#endregion
#region 获取页面参数赋值model对象
private void getmd()
{
//给日志模板赋值
rizhi.riqi = DateTime.Now;
rizhi.leixing = "样品登记";
}
#endregion
#region 加载设置跟随项目
public void getcpxmxx()
{
string code = "";
DataTable dt = DBHlper.Execute("select * from view_bianma where zhonglei='前段项目'").Tables[0];
DataTable xmdjds = DBHlper.Execute("select * from nr_z_ypdj_cpxgxm").Tables[0]; ;
foreach (DataRow dr in dt.Rows)
{
DataRow[] xmtr = xmdjds.Select("xmmc='" + dr["mingcheng"] + "'");
if (xmtr != null && xmtr.Length > 0)
{
code += "" + dr["mingcheng"] + "";
}
else
{
code += "" + dr["mingcheng"] + "";
}
}
ul_gx.InnerHtml = code;
code = "";
dt = DBHlper.Execute("select * from view_bianma where zhonglei='中段项目'").Tables[0];
foreach (DataRow dr in dt.Rows)
{
DataRow[] xmtr = xmdjds.Select("xmmc='" + dr["mingcheng"] + "'");
if (xmtr != null && xmtr.Length > 0)
{
code += "" + dr["mingcheng"] + "";
}
else
{
code += "" + dr["mingcheng"] + "";
}
}
ul_gxzd.InnerHtml = code;
code = "";
dt = DBHlper.Execute("select * from view_bianma where zhonglei='后段项目'").Tables[0];
foreach (DataRow dr in dt.Rows)
{
DataRow[] xmtr = xmdjds.Select("xmmc='" + dr["mingcheng"] + "'");
if (xmtr != null && xmtr.Length > 0)
{
code += "" + dr["mingcheng"] + "";
}
else
{
code += "" + dr["mingcheng"] + "";
}
}
ul_gxhd.InnerHtml = code;
}
#endregion
//保存项目
[Ajax.AjaxMethod]
public int savegx(string[] gx, string djid, string xmjd)
{
int fhz = 0;
DBHlper.excutecmd("delete from nr_z_ypdj_cpxgxm where xmjd='" + xmjd + "'");
foreach (string i in gx)
{
fhz = DBHlper.excutecmd("insert into nr_z_ypdj_cpxgxm(kfid,xmmc,xmjd) values(" + djid + ",'" + i + "','" + xmjd + "')");
}
return fhz;
}
protected void wj_Click(object sender, EventArgs e)
{
DataSet ds = DBHlper.Execute("select wenjian from nr_z_ypdj where id='" + id.Value + "'");
string filenams = ds.Tables[0].Rows[0]["wenjian"].ToString();
if (filenams != "" && filenams != null)
{
string f5 = filenams;
string fileName = f5;//客户端保存的文件名
string filePath = Server.MapPath("~/Client_Folder/" + f5);//路径
FileStream fs = new FileStream(filePath, FileMode.Open);
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
Response.ContentType = "application/octet-stream";
//通知浏览器下载文件而不是打开
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
}
else
{
Response.Write("");
return;
}
}
protected void bt_bj_Click(object sender, EventArgs e)
{
Response.Redirect("Sample_Form.aspx?uid=" + id.Value);
}
protected void Shanchu_Click(object sender, EventArgs e)
{
getmd();
if (ypdjbll.Delete(Convert.ToInt32(id.Value)))
{
DBHlper.excutecmd(" delete nr_z_ypdj_gj where ypdid='" + id.Value + "'");
DBHlper.excutecmd(" delete nr_z_ypdj_scyl where ypdid='" + id.Value + "'");
DBHlper.excutecmd(" delete nr_z_ypdj_xgfy where ypdid='" + id.Value + "'");
DBHlper.excutecmd(" delete nr_z_ypdj_xmxx where ypdid='" + id.Value + "'");
//将session转换对象取值
Maticsoft.Model.nr_z_yhzh zh = (Maticsoft.Model.nr_z_yhzh)Session["user"];
//拼接字符串插入日志
rizhi.jilu = zh.zhanghao + "删除了样品登记,开发号为:" + kfh.Text.Trim();
rizhi.yonghuming = zh.zhanghao;
rizhibll.Add(rizhi);
Response.Redirect("Sample_list.aspx", false);
}
}
protected void bt_qdsh_Click(object sender, EventArgs e)
{
getmd();
Maticsoft.Model.nr_z_yhzh zh = (Maticsoft.Model.nr_z_yhzh)Session["user"];
string sqldj = "update nr_z_ypdj set qdqz='" + zh.zhanghao + "' where id='" + id.Value + "'";
int fzhi = DBHlper.excutecmd(sqldj);
if (fzhi > 0)
{
rizhi.jilu = zh.zhanghao + "进行了前段签字,开发号为:" + kfh.Text.Trim();
rizhi.yonghuming = zh.zhanghao;
rizhibll.Add(rizhi);
Response.Redirect("Sample_browse.aspx?uid=" + id.Value);
}
}
protected void bt_zdsh_Click(object sender, EventArgs e)
{
getmd();
Maticsoft.Model.nr_z_yhzh zh = (Maticsoft.Model.nr_z_yhzh)Session["user"];
string sqldj = "update nr_z_ypdj set zdqz='" + zh.zhanghao + "' where id='" + id.Value + "'";
int fzhi = DBHlper.excutecmd(sqldj);
if (fzhi > 0)
{
rizhi.jilu = zh.zhanghao + "进行了中段签字,开发号为:" + kfh.Text.Trim();
rizhi.yonghuming = zh.zhanghao;
rizhibll.Add(rizhi);
Response.Redirect("Sample_browse.aspx?uid=" + id.Value);
}
}
protected void bt_hdsh_Click(object sender, EventArgs e)
{
getmd();
Maticsoft.Model.nr_z_yhzh zh = (Maticsoft.Model.nr_z_yhzh)Session["user"];
string sqldj = "update nr_z_ypdj set hdqz='" + zh.zhanghao + "' where id='" + id.Value + "'";
int fzhi = DBHlper.excutecmd(sqldj);
if (fzhi > 0)
{
rizhi.jilu = zh.zhanghao + "进行了后段签字,开发号为:" + kfh.Text.Trim();
rizhi.yonghuming = zh.zhanghao;
rizhibll.Add(rizhi);
Response.Redirect("Sample_browse.aspx?uid=" + id.Value);
}
}
protected void bt_shtg_Click(object sender, EventArgs e)
{
getmd();
Maticsoft.Model.nr_z_yhzh zh = (Maticsoft.Model.nr_z_yhzh)Session["user"];
string sqldj = "update nr_z_ypdj set shr='" + zh.zhanghao + "',zt='通过' where id='" + id.Value + "'";
int fzhi = DBHlper.excutecmd(sqldj);
if (fzhi > 0)
{
rizhi.jilu = zh.zhanghao + "进行了审核通过,开发号为:" + kfh.Text.Trim();
rizhi.yonghuming = zh.zhanghao;
rizhibll.Add(rizhi);
Response.Redirect("Sample_browse.aspx?uid=" + id.Value);
}
}
protected void bt_shbg_Click(object sender, EventArgs e)
{
getmd();
Maticsoft.Model.nr_z_yhzh zh = (Maticsoft.Model.nr_z_yhzh)Session["user"];
string sqldj = "update nr_z_ypdj set shr='" + zh.zhanghao + "',zt='不过' where id='" + id.Value + "'";
int fzhi = DBHlper.excutecmd(sqldj);
if (fzhi > 0)
{
rizhi.jilu = zh.zhanghao + "进行了审核不过,开发号为:" + kfh.Text.Trim();
rizhi.yonghuming = zh.zhanghao;
rizhibll.Add(rizhi);
Response.Redirect("Sample_browse.aspx?uid=" + id.Value);
}
}
protected void bt_sccpda_Click(object sender, EventArgs e)
{
Maticsoft.Model.nr_z_yhzh user = (Maticsoft.Model.nr_z_yhzh)(Session["user"]);
string cpbh = DBHlper.getbh("CP-", "nr_z_cpkc", "cpbh", 4);
string ypdcpjsql = "insert into nr_z_cpkc(cpbh,cpmc,riqi,gg,zhongliang,tiji,dj,jsr,tp)select '" + cpbh + "',cpmc,'" + DateTime.Now.ToString("yyyy-MM-dd") + "',ypcc,zhongl,rongl,'0','" + user.zhanghao + "',tupian from nr_z_ypdj where id='" + id.Value + "';SELECT id from nr_z_cpkc WHERE (id = @@IDENTITY)";
int getcpz = DBHlper.ExecuteReid(ypdcpjsql);
if (getcpz > 0)
{
string getxmsql = "select * from nr_z_ypdj_cpxgxm ";
DataSet ds = DBHlper.Execute(getxmsql);
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow r in ds.Tables[0].Rows)
{
int xmz = DBHlper.excutecmd("insert into nr_z_cpkc_wlxq(cpid,xmmc,wlbh,xqyl) select '" + getcpz + "',xmmc,wlbh,wlyl from nr_z_ypdj_xmxx where xmmc='" + r["xmmc"] + "' and ypdid='" + id.Value + "'");
}
}
int scfhz = DBHlper.excutecmd("insert into nr_z_cpkc_scyl(cpid,scwlbh,scyl,beizhu) select '" + getcpz + "',scwlbh,scyl,beizhu from nr_z_ypdj_scyl where ypdid='" + id.Value + "'");
int scmjz = DBHlper.excutecmd("insert into nr_z_mjda (mjdm,mjmc,riqi,beizhu) select '" + DBHlper.getbh("MJ-", "nr_z_mjda", "mjdm", 4) + "',cpmc,'" + DateTime.Now.ToString("yyyy-MM-dd") + "','' from nr_z_ypdj where id='" + id.Value + "'");
int ypgjz = DBHlper.excutecmd("insert into dbo.nr_z_cpkc_gj(cpid,gjmc,gjjg) select '" + getcpz + "',gjmc,gjjg from nr_z_ypdj_gj where ypdid='" + id.Value + "'");
Response.Redirect("Product_browse.aspx?uid=" + getcpz);
}
}
}