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 Dispatch_Form : CommonPage
{
//创建一个共用的生产单bll层
Maticsoft.BLL.nr_z_scd scdbll = new Maticsoft.BLL.nr_z_scd();
//创建一个共用的生产单模板
Maticsoft.Model.nr_z_scd scd = new Maticsoft.Model.nr_z_scd();
//创建一个操作项目bll
Maticsoft.BLL.nr_z_scd_cp scdcpbll = new Maticsoft.BLL.nr_z_scd_cp();
//创建一个操作记录模板
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();
//创建一个共用的编码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(Dispatch_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)
{
string uid = Request.QueryString["uid"].ToString();
id.Value = uid;
initdata(uid);
updatewlxx(Convert.ToInt32(uid));
}
else if (Request.QueryString["jsxmid"] != null && Request.QueryString["jsxmid"].ToString().Length > 0)
{
jssccpxx();
}
}
}
#region 获取页面参数赋值model对象
private void getmd()
{
scd.sclx = sclx.Text;
scd.xdrq = Convert.ToDateTime(xdrq.Value);
scd.wgrq = Convert.ToDateTime(wgrq.Value);
scd.kdr = ywy.Value;
scd.bz = ddbz.Value;
scd.zt = "草稿";
//给日志模板赋值
rizhi.riqi = DateTime.Now;
rizhi.leixing = "生产施工单";
}
#endregion
#region 获取真正数据值
private void initdata(string did)
{
DataSet scdds = DBHlper.Execute("select * from view_nr_z_scd where id='" + did + "'");
if (scdds != null && scdds.Tables[0].Rows.Count > 0)
{
bh.Value = scdds.Tables[0].Rows[0]["bh"].ToString();
sclx.Text = scdds.Tables[0].Rows[0]["sclx"].ToString();
xdrq.Value = Convert.ToDateTime(scdds.Tables[0].Rows[0]["xdrq"]).ToString("yyyy-MM-dd");
wgrq.Value = Convert.ToDateTime(scdds.Tables[0].Rows[0]["wgrq"]).ToString("yyyy-MM-dd");
ywy.Value = scdds.Tables[0].Rows[0]["kdr"].ToString();
ddbz.Value = scdds.Tables[0].Rows[0]["bz"].ToString();
}
}
#endregion
string cpmxstring = "";
#region 接收生产单项目
private void jssccpxx()
{
//修改页面时,首先吧项目明细的表头加载出来
string biao = "
";
}
#endregion
private string getcpmx(string zjlx, string zjid, decimal bhsl, string djbh, string khbh, string scfs, string jhrq, string bz)
{
/*
tptq
sptq
bdtq
*/
if (zjlx == "产品")
{
DataSet ds = DBHlper.Execute("select * from dbo.view_nr_z_cpkc where id='" + zjid + "'");
//为保证唯一性,获取id拼接,保证稳定性
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
string hcount = "bm" + ds.Tables[0].Rows[0]["id"].ToString();
cpmxstring += ""
+ " | "
+ " | "
+ " | "
+ " | "
+ " | "
+ " | "
+ " | "
+ " | "
+ " | "
+ " | "
+ " |
";
}
return cpmxstring;
}
else
{
DataSet ds = DBHlper.Execute("select * from view_nr_z_cpbom_xm where bomid='" + zjid + "'");
foreach (DataRow r in ds.Tables[0].Rows)
{
decimal cpmxbhsl = bhsl * Convert.ToDecimal(r["mtsl"]);
getcpmx(r["cplx"].ToString(), r["zjid"].ToString(), cpmxbhsl, djbh, khbh, scfs, jhrq, bz);
}
return cpmxstring;
}
}
#region 修改时用来加载项目
private void updatewlxx(int scdid)
{
//修改页面时,首先吧项目明细的表头加载出来
string biao = "";
}
#endregion
#region 用来初始化绑定下拉框等值
private void binddata()
{
Maticsoft.Model.nr_z_yhzh zh = (Maticsoft.Model.nr_z_yhzh)Session["user"];
ywy.Value = zh.zhanghao;
xdrq.Value = DateTime.Now.ToString("yyyy-MM-dd");
wgrq.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 hy = bm.GetList("zhongleiid='" + dr[0]["id"] + "'");
if (hy != null)
{
sclx.DataSource = hy.Tables[0].DefaultView;
sclx.DataValueField = "mingcheng";
sclx.DataTextField = "mingcheng";
sclx.DataBind();
}
}
DBHlper.excutecmd("delete nr_z_scd_cp_tqkc where xmid='0'");
}
#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_scd", "编辑") == false)
{
Response.Redirect("../Common/nopower.htm");
}
}
#endregion
#region 获取烧成方式
public string hqyscpscfs()
{
string cpxmscfs = "";
//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)
// {
// foreach (DataRow r in hy.Tables[0].Rows)
// {
// cpxmscfs += "";
// }
// }
//}
//else
//{
// cpxmscfs += "";
//}
return cpxmscfs;
}
#endregion
#region 编辑时获取烧成方式
public string hqyscpscfs(string xz)
{
string tccpscfs = "";
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)
{
foreach (DataRow r in hy.Tables[0].Rows)
{
if (xz == r["mingcheng"].ToString())
{
tccpscfs += "";
}
else
{
tccpscfs += "";
}
}
}
}
else
{
tccpscfs += "";
}
return tccpscfs;
}
#endregion
protected void bt_tj_Click(object sender, EventArgs e)
{
try
{
string caozuo = "添加";
//接收成功参数值
int rtx = 0;
//判断uid是否存在值,有值为修改,无值为添加
if (id.Value != null && id.Value != "")
{
scd = scdbll.GetModel(Convert.ToInt32(id.Value));
getmd();
caozuo = "修改";
scd.id = Convert.ToInt32(id.Value);
if (scdbll.Update(scd))
{
rtx = Convert.ToInt32(id.Value);
}
}
else
{
getmd();
scd.bh = DBHlper.getbh("SC-", "nr_z_dd", "bh", 4);
rtx = scdbll.Add(scd);
}
if (rtx > 0)
{
List sccpxmds = new List();
sccpxmds = DBHlper.ConvertJsonToEntityListEntity(sccphd.Value);
string deletecmd = "delete from nr_z_scd_cp where scdid='" + rtx + "'";
int ci = 0;
try
{
foreach (Maticsoft.Model.nr_z_scd_cp x in sccpxmds)
{
ci = ci + 1;
int cpxmid = 0;
x.scdid = Convert.ToInt32(rtx);
//判断如果存在id的时候且是修改操作时
if (x.id > 0 && Request.QueryString["uid"] != null)
{
scdcpbll.Update(x);
deletecmd += " and id !=" + x.id;
cpxmid = x.id;
}
else
{
int mxid = scdcpbll.Add(x);
deletecmd += " and id !=" + mxid;
cpxmid = mxid;
}
if (x.tqkc != 0)
{
int tqrt = DBHlper.excutecmd("update nr_z_scd_cp_tqkc set xmid='" + cpxmid + "' where id='" + x.tqkc + "'");
}
}
DBHlper.excutecmd(deletecmd);
}
catch
{
Response.Write("");
}
//将session转换对象取值
Maticsoft.Model.nr_z_yhzh zh = (Maticsoft.Model.nr_z_yhzh)Session["user"];
rizhi.yonghuming = zh.zhanghao;
//拼接字符串插入日志
rizhi.jilu = zh.zhanghao + caozuo + "了生产施工单,档案编号为:" + bh.Value.Trim();
rizhibll.Add(rizhi);
Response.Redirect("Dispatch_browse.aspx?uid=" + rtx, false);
}
else
{
Response.Redirect("../Common/error.aspx");
}
}
catch (Exception)
{
Response.Redirect("../Common/error.aspx");
}
}
[Ajax.AjaxMethod]
public string getcpkc(string cphh)
{
string code = "";
DataSet ds = DBHlper.Execute("select tpkysl,spkysl,bdkysl from view_nr_z_cpkc where cpbh='" + cphh + "' and zt='1'");
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
code = ds.Tables[0].Rows[0]["tpkysl"].ToString() + "&" + ds.Tables[0].Rows[0]["spkysl"].ToString() + "&" + ds.Tables[0].Rows[0]["bdkysl"].ToString();
}
else
{
code = "0&0&0";
}
return code;
}
[Ajax.AjaxMethod]
public string getxmyt(string ytxmid)
{
string code = "";
DataSet ds = DBHlper.Execute("select tptqsl,sptqsl,bdtqsl from nr_z_scd_cp_tqkc where id='" + ytxmid + "'");
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
code = ds.Tables[0].Rows[0]["tptqsl"].ToString() + "&" + ds.Tables[0].Rows[0]["sptqsl"].ToString() + "&" + ds.Tables[0].Rows[0]["bdtqsl"].ToString();
}
else
{
code = "0&0&0";
}
return code;
}
[Ajax.AjaxMethod]
public int settqsl(string tpsl, string spsl, string bdsl, string cphh)
{
int code = DBHlper.ExecuteReid("insert into nr_z_scd_cp_tqkc(xmid,tptqsl,sptqsl,bdtqsl,cphh) values ('0','" + tpsl + "','" + spsl + "','" + bdsl + "','" + cphh + "');SELECT id from nr_z_scd_cp_tqkc WHERE (id = @@IDENTITY)");
return code;
}
[Ajax.AjaxMethod]
public int deletetqlc(string tqid)
{
int gshrt = DBHlper.excutecmd("delete nr_z_scd_cp_tqkc where id='" + tqid + "'");
return gshrt;
}
}