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 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 = "<table id='scdcptab' class='bule'> <tr id='0' 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><td><span>生产数量</span></td><td><span>交货日期</span></td>"
+ "<td><span>备注</span></td></tr>" ;
DataSet jsds = DBHlper . Execute ( "select * from view_nr_z_scdjs_tccp where id in (" + Request . QueryString [ "jsxmid" ] . ToString ( ) + ")" ) ;
foreach ( DataRow r in jsds . Tables [ 0 ] . Rows )
{
if ( r [ "mxlx" ] . ToString ( ) = = "产品" )
{
//为保证唯一性, 获取id拼接, 保证稳定性
string hcount = "cp" + r [ "id" ] . ToString ( ) ;
biao + = "<tr id='" + hcount + "' name='0'>"
+ "<td><input type='text' id='djbh" + hcount + "' Value='" + r [ "bh" ] . ToString ( ) + "' Class='inpittxt_hx' readonly /></td>"
+ "<td><input type='text' id='khbh" + hcount + "' Value='" + r [ "kh_bh" ] . ToString ( ) + "' Class='inpittxt_hx' readonly /></td>"
+ "<td><input type='text' id='cphh" + hcount + "' Value='" + r [ "cphh" ] . ToString ( ) + "' Class='inpittxt_hx' readonly /></td>"
+ "<td><input type='text' id='cpmc" + hcount + "' Value='" + r [ "cpmc" ] . ToString ( ) + "' Class='inpittxt_hx' readonly /></td>"
+ "<td><input type='text' id='zl" + hcount + "' Value='" + r [ "zl" ] . ToString ( ) + "' Class='inpittxt_hx' readonly /></td>"
+ "<td><input type='text' id='scfs" + hcount + "' Value='" + r [ "scfs" ] . ToString ( ) + "' Class='inpittxt_hx' readonly /></td>"
+ "<td><input type='text' id='dhsl" + hcount + "' Value='" + r [ "dhsl" ] . ToString ( ) + "' onkeyup='doubleshuru(this)' Class='inpittxt_hx' readonly /></td>"
+ "<td><input type='text' id='tqsl" + hcount + "' name='' Value='0' onclick=\"tqkcsc('" + hcount + "')\" readonly Class='inpittxt' /></td>"
+ "<td><input type='text' id='scsl" + hcount + "' onkeyup='doubleshuru(this)' Value='" + r [ "dhsl" ] . ToString ( ) + "' Class='inpittxt' /></td>"
+ "<td><input type='text' id='jhrq" + hcount + "' Value='" + Convert . ToDateTime ( r [ "jhrq" ] ) . ToString ( "yyyy-MM-dd" ) + "' onclick='new Calendar().show(this);' readonly='readonly' Class='inpittxt' /> </td>"
+ "<td ><input type='text' id='beizhu" + hcount + "' Value='" + r [ "bz" ] . ToString ( ) + "' Class='inpittxt' /> </td></tr>" ;
}
else
{
cpmxstring = "" ;
biao + = getcpmx ( r [ "mxlx" ] . ToString ( ) , r [ "cpid" ] . ToString ( ) , Convert . ToDecimal ( r [ "dhsl" ] ) , r [ "bh" ] . ToString ( ) , r [ "kh_bh" ] . ToString ( ) , r [ "scfs" ] . ToString ( ) , Convert . ToDateTime ( r [ "jhrq" ] ) . ToString ( "yyyy-MM-dd" ) , r [ "bz" ] . ToString ( ) ) ;
}
}
cpxx . InnerHtml = biao + "</table>" ;
}
#endregion
private string getcpmx ( string zjlx , string zjid , decimal bhsl , string djbh , string khbh , string scfs , string jhrq , string bz )
{
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 + = "<tr id='" + hcount + "' name='0'>"
+ "<td><input type='text' id='djbh" + hcount + "' Value='" + djbh + "' Class='inpittxt_hx' readonly /></td>"
+ "<td><input type='text' id='khbh" + hcount + "' Value='" + khbh + "' Class='inpittxt_hx' readonly /></td>"
+ "<td><input type='text' id='cphh" + hcount + "' Value='" + ds . Tables [ 0 ] . Rows [ 0 ] [ "cpbh" ] . ToString ( ) + "' Class='inpittxt_hx' readonly /></td>"
+ "<td><input type='text' id='cpmc" + hcount + "' Value='" + ds . Tables [ 0 ] . Rows [ 0 ] [ "cpmc" ] . ToString ( ) + "' Class='inpittxt_hx' readonly /></td>"
+ "<td><input type='text' id='zl" + hcount + "' Value='" + ds . Tables [ 0 ] . Rows [ 0 ] [ "zl" ] . ToString ( ) + "' Class='inpittxt_hx' readonly /></td>"
+ "<td><input type='text' id='scfs" + hcount + "' Value='" + scfs + "' Class='inpittxt_hx' readonly /></td>"
+ "<td><input type='text' id='dhsl" + hcount + "' Value='" + bhsl + "' onkeyup='doubleshuru(this)' Class='inpittxt_hx' readonly /></td>"
+ "<td><input type='text' id='tqsl" + hcount + "' name='' Value='0' readonly onclick=\"tqkcsc('" + hcount + "')\" Class='inpittxt' /></td>"
+ "<td><input type='text' id='scsl" + hcount + "' onkeyup='doubleshuru(this)' Value='" + bhsl + "' Class='inpittxt' /></td>"
+ "<td><input type='text' id='jhrq" + hcount + "' Value='" + jhrq + "' onclick='new Calendar().show(this);' readonly='readonly' Class='inpittxt' /> </td>"
+ "<td><input type='text' id='beizhu" + hcount + "' Value='" + bz + "' Class='inpittxt' /> </td></tr>" ;
}
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 = "<table id='scdcptab' class='bule' > <tr id='0' 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><td><span>生产数量</span></td><td><span>交货日期</span></td>"
+ "<td><span>备注</span></td></tr>" ;
DataSet ds = DBHlper . Execute ( "select * from view_nr_z_allscdxm where scdid='" + scdid + "' order by id " ) ;
if ( ds ! = null & & ds . Tables [ 0 ] . Rows . Count > 0 )
{
//如果当前订单下存在明细就加载成tr行
foreach ( DataRow r in ds . Tables [ 0 ] . Rows )
{
DataSet tqds = DBHlper . Execute ( "select * from nr_z_scd_cp_tqkc where xmid='" + r [ "id" ] + "'" ) ;
string dqxmid = "" ;
string tqxxst = "" ;
if ( tqds ! = null & & tqds . Tables [ 0 ] . Rows . Count > 0 ) {
dqxmid = tqds . Tables [ 0 ] . Rows [ 0 ] [ "id" ] . ToString ( ) ;
tqxxst = tqds . Tables [ 0 ] . Rows [ 0 ] [ "tptqsl" ] . ToString ( ) + "," + tqds . Tables [ 0 ] . Rows [ 0 ] [ "sptqsl" ] . ToString ( ) + "," + tqds . Tables [ 0 ] . Rows [ 0 ] [ "bdtqsl" ] . ToString ( ) ;
}
//为保证唯一性, 获取id拼接, 保证稳定性
string hcount = r [ "id" ] . ToString ( ) ;
biao + = "<tr id='" + hcount + "' name='" + hcount + "'>"
+ "<td><input type='text' id='djbh" + hcount + "' Value='" + r [ "djbh" ] . ToString ( ) + "' Class='inpittxt_hx' readonly /></td>"
+ "<td><input type='text' id='khbh" + hcount + "' Value='" + r [ "khbh" ] . ToString ( ) + "' Class='inpittxt_hx' readonly /></td>"
+ "<td><input type='text' id='cphh" + hcount + "' Value='" + r [ "cphh" ] . ToString ( ) + "' Class='inpittxt_hx' readonly /></td>"
+ "<td><input type='text' id='cpmc" + hcount + "' Value='" + r [ "cpmc" ] . ToString ( ) + "' Class='inpittxt_hx' readonly /></td>"
+ "<td><input type='text' id='zl" + hcount + "' Value='" + r [ "zl" ] . ToString ( ) + "' Class='inpittxt_hx' readonly /></td>"
+ "<td><input type='text' id='scfs" + hcount + "' Value='" + r [ "scfs" ] . ToString ( ) + "' Class='inpittxt_hx' readonly /></td>"
+ "<td><input type='text' id='dhsl" + hcount + "' Value='" + r [ "ddsl" ] . ToString ( ) + "' onkeyup='doubleshuru(this)' Class='inpittxt_hx' readonly /></td>"
+ "<td><input type='text' id='tqsl" + hcount + "' name='" + dqxmid + "' Value='" + tqxxst + "' readonly onclick=tqkcsc(" + hcount + ") Class='inpittxt' /></td>"
+ "<td><input type='text' id='scsl" + hcount + "' onkeyup='doubleshuru(this)' Value='" + r [ "scsl" ] . ToString ( ) + "' Class='inpittxt' /></td>"
+ "<td><input type='text' id='jhrq" + hcount + "' Value='" + Convert . ToDateTime ( r [ "jhrq" ] ) . ToString ( "yyyy-MM-dd" ) + "' onclick='new Calendar().show(this);' readonly='readonly' Class='inpittxt' /> </td>"
+ "<td><input type='text' id='beizhu" + hcount + "' Value='" + r [ "bz" ] . ToString ( ) + "' Class='inpittxt' /> </td></tr>" ;
}
}
cpxx . InnerHtml = biao + "</table>" ;
}
#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" ) ;
}
2024-05-21 15:05:24 +08:00
if ( DBHlper . GetPermission ( juese , "生产施工单" , "nr_z_scd" , "编辑" ) = = false )
2024-05-18 15:28:29 +08:00
{
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 + = "<option value='" + r [ "mingcheng" ] + "' >" + r [ "mingcheng" ] + "</option>" ;
}
}
}
else
{
cpxmscfs + = "<option value='无' >无</option>" ;
}
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 + = "<option value='" + r [ "mingcheng" ] + "'selected='selected' >" + r [ "mingcheng" ] + "</option>" ;
}
else
{
tccpscfs + = "<option value='" + r [ "mingcheng" ] + "' >" + r [ "mingcheng" ] + "</option>" ;
}
}
}
}
else
{
tccpscfs + = "<option value='无' >无</option>" ;
}
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 < Maticsoft . Model . nr_z_scd_cp > sccpxmds = new List < Maticsoft . Model . nr_z_scd_cp > ( ) ;
sccpxmds = DBHlper . ConvertJsonToEntityListEntity < Maticsoft . Model . nr_z_scd_cp > ( 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 ( "<script>alert('生产单项目在第'" + 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 + "了生产施工单,档案编号为:" + 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 ;
}
}