@ -114,14 +114,14 @@ namespace ICSSoft.DataProject
{
string msg = "" ;
DataTable dt = null ;
string iFatherIdTwo = string . Empty ;
string iFatherIdTwo = string . Empty ;
DataSet ds = null ;
string connS = "" ;
VouchKey key = new VouchKey ( ) ;
int num = 0 ;
int iFatherId = 0 ;
int iChildId = 0 ;
string sql = string . Empty ;
SqlConnection conn = new SqlConnection ( ) ;
@ -132,110 +132,107 @@ namespace ICSSoft.DataProject
}
LogInfo ( Bills ) ;
//MergeObject(Bills, cmd);
List < string > result = Bills . Select ( t = > t . WorkPoint ) . Distinct ( ) . ToList ( ) ;
foreach ( string WorkPoint in result )
{
try
{
connS = string . Format ( connString , WorkPoint ) ;
conn = new System . Data . SqlClient . SqlConnection ( connS ) ;
conn . Open ( ) ;
SqlTransaction sqlTran = conn . BeginTransaction ( ) ;
cmd = new SqlCommand ( ) ;
cmd . Transaction = sqlTran ;
cmd . Connection = conn ;
foreach ( ICSRdrecord11 head in Bills )
{
iFatherIdTwo = "" ;
if ( WorkPoint ! = head . WorkPoint )
continue ;
ICSUserInfo userInfo = new ICSUserInfo ( ) ;
userInfo = DBHelper . GetPersonInfo ( head . User , cmd ) ;
num = head . details . Count ( ) ;
string [ ] ss = head . WorkPoint . Split ( '_' ) ;
ERPDB = ss [ 1 ] ;
if ( ! DBHelper . IsInventoryConsolidation ( cmd , head . WorkPoint ) )
throw new Exception ( "U8正在整理现存量,请稍后再试" ) ;
string [ ] dd = CRNALL . Split ( '~' ) ;
string crdname = dd [ 0 ] ;
string carname = dd [ 1 ] ;
string surface = dd [ 2 ] ;
string cardnewcode = DBHelper . GetCardNumber ( carname , cmd ) ;
string cRDcode = DBHelper . GetRDCode ( crdname , cmd ) ;
Dictionary < string , int > dic = DBHelper . GetAllCode ( "" + ERPDB + "" , surface , "" + num + "" , head . WorkPoint ) ;
iFatherId = Convert . ToInt32 ( dic [ "iFatherId" ] . ToString ( ) ) ;
iChildId = Convert . ToInt32 ( dic [ "iChildId" ] . ToString ( ) ) ;
DateTime date = DateTime . Now ;
string iBaseCodeLen = DBHelper . GetAllRDCode ( cardnewcode , "" + date + "" , "admin" , cRDcode , head . WorkPoint ) ;
string DEF_ID = DBHelper . GetDefaultTemplate ( cardnewcode , cmd ) ;
#region 判断工单是否已关闭
sql = @ "SELECT isnull(CloseUser,'') as CloseUser from mom_orderdetail a
List < string > result = Bills . Select ( t = > t . WorkPoint ) . Distinct ( ) . ToList ( ) ;
foreach ( string WorkPoint in result )
{
try
{
connS = string . Format ( connString , WorkPoint ) ;
conn = new System . Data . SqlClient . SqlConnection ( connS ) ;
conn . Open ( ) ;
SqlTransaction sqlTran = conn . BeginTransaction ( ) ;
cmd = new SqlCommand ( ) ;
cmd . Transaction = sqlTran ;
cmd . Connection = conn ;
foreach ( ICSRdrecord11 head in Bills )
{
iFatherIdTwo = "" ;
if ( WorkPoint ! = head . WorkPoint )
continue ;
ICSUserInfo userInfo = new ICSUserInfo ( ) ;
userInfo = DBHelper . GetPersonInfo ( head . User , cmd ) ;
num = head . details . Count ( ) ;
string [ ] ss = head . WorkPoint . Split ( '_' ) ;
ERPDB = ss [ 1 ] ;
if ( ! DBHelper . IsInventoryConsolidation ( cmd , head . WorkPoint ) )
throw new Exception ( "U8正在整理现存量,请稍后再试" ) ;
string [ ] dd = CRNALL . Split ( '~' ) ;
string crdname = dd [ 0 ] ;
string carname = dd [ 1 ] ;
string surface = dd [ 2 ] ;
string cardnewcode = DBHelper . GetCardNumber ( carname , cmd ) ;
string cRDcode = DBHelper . GetRDCode ( crdname , cmd ) ;
Dictionary < string , int > dic = DBHelper . GetAllCode ( "" + ERPDB + "" , surface , "" + num + "" , head . WorkPoint ) ;
iFatherId = Convert . ToInt32 ( dic [ "iFatherId" ] . ToString ( ) ) ;
iChildId = Convert . ToInt32 ( dic [ "iChildId" ] . ToString ( ) ) ;
DateTime date = DateTime . Now ;
string iBaseCodeLen = DBHelper . GetAllRDCode ( cardnewcode , "" + date + "" , "admin" , cRDcode , head . WorkPoint ) ;
string DEF_ID = DBHelper . GetDefaultTemplate ( cardnewcode , cmd ) ;
#region 判断工单是否已关闭
sql = @ "SELECT isnull(CloseUser,'') as CloseUser from mom_orderdetail a
inner join mom_order b on a . MoId = b . MoId where b . MoCode = ' " + head.SourceCode + " ' ";
DataTable dtClose = DBHelper . SQlReturnData ( sql , cmd ) ;
if ( dtClose ! = null & & dtClose . Rows . Count > 0 )
{
if ( ! string . IsNullOrEmpty ( dtClose . Rows [ 0 ] [ 0 ] . ToString ( ) ) )
{
throw new Exception ( "该工单行已关闭,无法领料!" ) ;
}
}
#endregion
#region 判断物料是否超额领取
// foreach (rdrecords11 body in head.details)
// {
// sql = @"SELECT isnull(b.fOutExcess,0) as fOutExcess,isnull(a.IssQty,0) as IssQty,a.Qty,a.ReplenishQty FROM dbo.mom_moallocate a
// LEFT JOIN dbo.Inventory b ON a.InvCode=b.cInvCode
// WHERE a.AllocateId='" + body.SourceDetailID + "'";
// DataTable dtQty = DBHelper.SQlReturnData(sql, cmd);
// if (dtQty != null && dtQty.Rows.Count > 0)
// {
// //可超领比率
// decimal fOutExcess = Convert.ToDecimal(dtQty.Rows[0]["fOutExcess"]);
// //已领数量
// decimal IssQty = Convert.ToDecimal(dtQty.Rows[0]["IssQty"]);
// //应领数量
// decimal Qty = Convert.ToDecimal(dtQty.Rows[0]["Qty"]);
// //当前可总领数量
// decimal TotalQty = Qty;// + fOutExcess * Qty;
// //补料数量
// decimal ReplenishQty = Convert.ToDecimal(dtQty.Rows[0]["ReplenishQty"]);
// string cql = @"SELECT * from Inventory where cInvCode='" + body.InvCode + "'AND bKCCutMantissa =1 AND bCutMantissa=1";
// DataTable dtInv = DBHelper.SQlReturnData(cql, cmd);
// if (dtInv != null && dtInv.Rows.Count > 0)
// {
// }
// else
// {
// if (IssQty - ReplenishQty + body.Quantity > TotalQty)
// {
// throw new Exception("物料领取超过当前可领用最大数,AllocateId:" + body.SourceDetailID);
// }
// }
// //if (IssQty + body.iQuantity > TotalQty)
// //{
// // throw new Exception("物料领取超过当前可领用最大数,AllocateId:" + body.AllocateId);
// //}
// }
// else
// {
// throw new Exception("工单行子件不存在!AllocateId:" + body.SourceDetailID);
// }
// }
#endregion
#region 材料出库单表头
sql = @ "INSERT INTO dbo.rdrecord11
DataTable dtClose = DBHelper . SQlReturnData ( sql , cmd ) ;
if ( dtClose ! = null & & dtClose . Rows . Count > 0 )
{
if ( ! string . IsNullOrEmpty ( dtClose . Rows [ 0 ] [ 0 ] . ToString ( ) ) )
{
throw new Exception ( "该工单行已关闭,无法领料!" ) ;
}
}
#endregion
#region 判断物料是否超额领取
// foreach (rdrecords11 body in head.details)
// {
// sql = @"SELECT isnull(b.fOutExcess,0) as fOutExcess,isnull(a.IssQty,0) as IssQty,a.Qty,a.ReplenishQty FROM dbo.mom_moallocate a
// LEFT JOIN dbo.Inventory b ON a.InvCode=b.cInvCode
// WHERE a.AllocateId='" + body.SourceDetailID + "'";
// DataTable dtQty = DBHelper.SQlReturnData(sql, cmd);
// if (dtQty != null && dtQty.Rows.Count > 0)
// {
// //可超领比率
// decimal fOutExcess = Convert.ToDecimal(dtQty.Rows[0]["fOutExcess"]);
// //已领数量
// decimal IssQty = Convert.ToDecimal(dtQty.Rows[0]["IssQty"]);
// //应领数量
// decimal Qty = Convert.ToDecimal(dtQty.Rows[0]["Qty"]);
// //当前可总领数量
// decimal TotalQty = Qty;// + fOutExcess * Qty;
// //补料数量
// decimal ReplenishQty = Convert.ToDecimal(dtQty.Rows[0]["ReplenishQty"]);
// string cql = @"SELECT * from Inventory where cInvCode='" + body.InvCode + "'AND bKCCutMantissa =1 AND bCutMantissa=1";
// DataTable dtInv = DBHelper.SQlReturnData(cql, cmd);
// if (dtInv != null && dtInv.Rows.Count > 0)
// {
// }
// else
// {
// if (IssQty - ReplenishQty + body.Quantity > TotalQty)
// {
// throw new Exception("物料领取超过当前可领用最大数,AllocateId:" + body.SourceDetailID);
// }
// }
// //if (IssQty + body.iQuantity > TotalQty)
// //{
// // throw new Exception("物料领取超过当前可领用最大数,AllocateId:" + body.AllocateId);
// //}
// }
// else
// {
// throw new Exception("工单行子件不存在!AllocateId:" + body.SourceDetailID);
// }
// }
#endregion
#region 材料出库单表头
sql = @ "INSERT INTO dbo.rdrecord11
( ID , bRdFlag , cVouchType , cBusType , cSource , cWhCode , dDate ,
cCode , cRdCode , cDepCode , cHandler , bTransFlag , cMaker ,
dVeriDate , bpufirst , biafirst , VT_ID , bIsSTQc
@ -255,74 +252,73 @@ namespace ICSSoft.DataProject
left JOIN dbo . mom_order b ON a . MoId = b . MoId
left join mom_morder c on a . modid = c . modid
WHERE b . MoCode = ' " + head.SourceCode + " ' ";
cmd . Parameters . Clear ( ) ;
cmd . Parameters . Add ( new SqlParameter ( "@ID" , iFatherId ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cWhCode" , head . WHCode ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cCode" , iBaseCodeLen ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cHandler" , userInfo . UserName ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cMaker" , userInfo . UserName ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@VT_ID" , DEF_ID ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cRDcode" , cRDcode ) ) ;
cmd . CommandText = sql ;
try
{
int count = cmd . ExecuteNonQuery ( ) ;
if ( count < = 0 )
{
log . Error ( "生成材料出库单表头失败,受影响行数<=0;" ) ;
throw new Exception ( "生成材料出库单表头失败,受影响行数<=0;" ) ;
}
}
catch ( Exception ex )
{
log . Error ( "生成材料出库单表头失败" + sql , ex ) ;
throw new Exception ( "生成材料出库单表头失败" + sql , ex ) ;
}
#endregion
#region 材料出库单表体
int irowno = 0 ;
foreach ( rdrecords11 body in head . details )
{
irowno + + ;
//if (irowno == 0)
//{
// iChildId = iChildId;
//}
//else
//{
// iChildId -= 1;
//}
//irowno += 1;
//if (head.IsReturn == "1")
//{
// body.iQuantity = -body.iQuantity;
//}
//if (head.IsReturn == "0")
//{
// //判断物料批号与现存量表批号是否一致、数量不能超过现存量物料数量
// sql = @"SELECT cBatch,iQuantity from CurrentStock WHERE cInvCode='" + body.cInvCode + "'AND cBatch='" + body.cBatch + "'and cWhCode='" + head.cWhCode + "'";
// DataTable dtItem = U8Helper.SQlReturnData(sql, cmd);
// if (dtItem != null && dtItem.Rows.Count > 0)
// {
// if (!dtItem.Rows[0]["cBatch"].ToString().Equals(body.cBatch))
// {
// throw new Exception("物料条码的批号与U8现存量物料批号不一致,物料:" + body.cInvCode);
// }
// if (Convert.ToDecimal(dtItem.Rows[0]["iQuantity"].ToString()) < body.iQuantity)
// {
// throw new Exception("物料条码的数量大于U8现存量物料数量,物料:" + body.cInvCode);
// }
// }
// else
// {
// throw new Exception("物料:" + body.cInvCode + "在现存量表中不存在!");
// }
//}
sql = @ "INSERT INTO dbo.rdrecords11
cmd . Parameters . Clear ( ) ;
cmd . Parameters . Add ( new SqlParameter ( "@ID" , iFatherId ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cWhCode" , head . WHCode ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cCode" , iBaseCodeLen ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cHandler" , userInfo . UserName ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cMaker" , userInfo . UserName ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@VT_ID" , DEF_ID ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cRDcode" , cRDcode ) ) ;
cmd . CommandText = sql ;
try
{
int count = cmd . ExecuteNonQuery ( ) ;
if ( count < = 0 )
{
log . Error ( "生成材料出库单表头失败,受影响行数<=0;" ) ;
throw new Exception ( "生成材料出库单表头失败,受影响行数<=0;" ) ;
}
}
catch ( Exception ex )
{
log . Error ( "生成材料出库单表头失败" + sql , ex ) ;
throw new Exception ( "生成材料出库单表头失败" + sql , ex ) ;
}
#endregion
#region 材料出库单表体
int irowno = 0 ;
foreach ( rdrecords11 body in head . details )
{
irowno + + ;
//if (irowno == 0)
//{
// iChildId = iChildId;
//}
//else
//{
// iChildId -= 1;
//}
//irowno += 1;
//if (head.IsReturn == "1")
//{
// body.iQuantity = -body.iQuantity;
//}
//if (head.IsReturn == "0")
//{
// //判断物料批号与现存量表批号是否一致、数量不能超过现存量物料数量
// sql = @"SELECT cBatch,iQuantity from CurrentStock WHERE cInvCode='" + body.cInvCode + "'AND cBatch='" + body.cBatch + "'and cWhCode='" + head.cWhCode + "'";
// DataTable dtItem = U8Helper.SQlReturnData(sql, cmd);
// if (dtItem != null && dtItem.Rows.Count > 0)
// {
// if (!dtItem.Rows[0]["cBatch"].ToString().Equals(body.cBatch))
// {
// throw new Exception("物料条码的批号与U8现存量物料批号不一致,物料:" + body.cInvCode);
// }
// if (Convert.ToDecimal(dtItem.Rows[0]["iQuantity"].ToString()) < body.iQuantity)
// {
// throw new Exception("物料条码的数量大于U8现存量物料数量,物料:" + body.cInvCode);
// }
// }
// else
// {
// throw new Exception("物料:" + body.cInvCode + "在现存量表中不存在!");
// }
//}
sql = @ "INSERT INTO dbo.rdrecords11
( AutoID , ID , cInvCode , iQuantity , cBatch , iFlag , iNum ,
cItemCode , cName , iNQuantity , iMPoIds , bLPUseFree ,
iOriTrackID , bCosting , bVMIUsed , cmocode , invcode , imoseq ,
@ -339,93 +335,89 @@ namespace ICSSoft.DataProject
INNER JOIN dbo . mom_orderdetail b ON a . MoDId = b . MoDId
INNER JOIN dbo . mom_order c ON b . MoId = c . MoId
WHERE a . AllocateId = ' " + body.SourceDetailID + " ' ";
cmd . Parameters . Clear ( ) ;
cmd . Parameters . Add ( new SqlParameter ( "@AutoID" , iChildId ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@iQuantity" , body . Quantity ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@iNum" , body . Amount . ToString ( "0.00" ) ) ) ;
//cmd.Parameters.Add(new SqlParameter("@cBatch", "''"));
cmd . Parameters . Add ( new SqlParameter ( "@ID" , iFatherId ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cCode" , iBaseCodeLen ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cBatch" , body . BatchCode ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cItemCode" , body . ProjectCode ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@irowno" , irowno ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cFree1" , body . cFree1 ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cFree2" , body . cFree2 ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cFree3" , body . cFree3 ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cFree4" , body . cFree4 ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cFree5" , body . cFree5 ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cFree6" , body . cFree6 ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cFree7" , body . cFree7 ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cFree8" , body . cFree8 ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cFree9" , body . cFree9 ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cFree10" , body . cFree10 ) ) ;
cmd . CommandText = sql ;
try
{
int count = cmd . ExecuteNonQuery ( ) ;
if ( count < = 0 )
{
log . Error ( "生成材料出库单表体失败,受影响行数<=0;" ) ;
throw new Exception ( "生成材料出库单表体失败,受影响行数<=0;" ) ;
}
}
catch ( Exception ex )
{
log . Error ( "生成材料出库单表体失败" + sql , ex ) ;
throw new Exception ( "生成材料出库单表体失败 " + sql , ex ) ;
}
#region 回写工单子件已领数量
sql = "update mom_moallocate set IssQty=isnull(IssQty,0)+" + body . Quantity + ",RequisitionIssQty=isnull(RequisitionIssQty,0)+(" + body . Quantity + ") where AllocateId='" + body . SourceDetailID + "' " ;
DBHelper . CmdExecuteNonQuery ( sql , cmd , "回写工单子件已领数量失败!" ) ;
#endregion
sql = @ "select isnull(Issqty,0)fOutQuantity,isnull(qty,0)iQuantity,ISNULL(AuxQty, 0)iNum,ISNULL(NiNum, 0)NiNum,ISNULL(AuxQty, 0)-ISNULL(NiNum, 0) SiNum from mom_moallocate a
cmd . Parameters . Clear ( ) ;
cmd . Parameters . Add ( new SqlParameter ( "@AutoID" , iChildId ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@iQuantity" , body . Quantity ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@iNum" , body . Amount . ToString ( "0.00" ) ) ) ;
//cmd.Parameters.Add(new SqlParameter("@cBatch", "''"));
cmd . Parameters . Add ( new SqlParameter ( "@ID" , iFatherId ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cCode" , iBaseCodeLen ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cBatch" , body . BatchCode ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cItemCode" , body . ProjectCode ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@irowno" , irowno ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cFree1" , body . cFree1 ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cFree2" , body . cFree2 ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cFree3" , body . cFree3 ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cFree4" , body . cFree4 ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cFree5" , body . cFree5 ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cFree6" , body . cFree6 ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cFree7" , body . cFree7 ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cFree8" , body . cFree8 ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cFree9" , body . cFree9 ) ) ;
cmd . Parameters . Add ( new SqlParameter ( "@cFree10" , body . cFree10 ) ) ;
cmd . CommandText = sql ;
try
{
int count = cmd . ExecuteNonQuery ( ) ;
if ( count < = 0 )
{
log . Error ( "生成材料出库单表体失败,受影响行数<=0;" ) ;
throw new Exception ( "生成材料出库单表体失败,受影响行数<=0;" ) ;
}
}
catch ( Exception ex )
{
log . Error ( "生成材料出库单表体失败" + sql , ex ) ;
throw new Exception ( "生成材料出库单表体失败 " + sql , ex ) ;
}
#region 回写工单子件已领数量
sql = "update mom_moallocate set IssQty=isnull(IssQty,0)+" + body . Quantity + ",RequisitionIssQty=isnull(RequisitionIssQty,0)+(" + body . Quantity + ") where AllocateId='" + body . SourceDetailID + "' " ;
DBHelper . CmdExecuteNonQuery ( sql , cmd , "回写工单子件已领数量失败!" ) ;
#endregion
sql = @ "select isnull(Issqty,0)fOutQuantity,isnull(qty,0)iQuantity,ISNULL(AuxQty, 0)iNum,ISNULL(NiNum, 0)NiNum,ISNULL(AuxQty, 0)-ISNULL(NiNum, 0) SiNum from mom_moallocate a
LEFT JOIN ( select sum ( iNum ) NiNum , ipesodid from rdrecords11 GROUP BY ipesodid ) b on a . AllocateId = b . ipesodid
where a . AllocateId = ' " + body.SourceDetailID + " ' ";
DataTable dtDisCheck = DBHelper . SQlReturnData ( sql , cmd ) ;
if ( dtDisCheck ! = null & & dtDisCheck . Rows . Count > 0 )
{
foreach ( DataRow item1 in dtDisCheck . Rows )
{
if ( Convert . ToDecimal ( item1 [ "fOutQuantity" ] . ToString ( ) ) = = Convert . ToDecimal ( item1 [ "iQuantity" ] . ToString ( ) ) )
{
if ( Convert . ToDecimal ( item1 [ "iNum" ] . ToString ( ) ) ! = 0 )
{
if ( Convert . ToDecimal ( item1 [ "SiNum" ] . ToString ( ) ) ! = 0 )
{
sql = @"Update rdrecords11 set iNum=isnull(iNum,0)+(" + item1 [ "SiNum" ] . ToString ( ) + ") where autoid='" + iChildId + "' " ;
body . Amount = ( Convert . ToDecimal ( body . Amount . ToString ( "0.00" ) ) ) + ( Convert . ToDecimal ( item1 [ "SiNum" ] . ToString ( ) ) ) ;
DBHelper . CmdExecuteNonQuery ( sql , cmd , "辅计量余数处理失败!" ) ;
}
}
}
}
}
//更新现存量
key . cBustypeUN = "领料" ;
key . cVouchTypeUN = "11" ;
key . TableName = "IA_ST_UnAccountVouch11" ;
//DBHelper.UpdateCurrentStock(cmd, body.InvCode, head.WHCode, "", body.Quantity, key);
//DBHelper.UpdateCurrentStockNEW(cmd, body.InvCode, head.WHCode, body.BatchCode, body.Quantity, body.cFree1, body.cFree2, body.cFree3, body.cFree4, body.cFree5, body.cFree6, body.cFree7, body.cFree8, body.cFree9, body.cFree10, key);
DBHelper . UpdateCurrentStockCCGC ( cmd , body . InvCode , head . WHCode , body . BatchCode , body . Quantity , body . Amount , body . cFree1 ,
body . cFree2 , body . cFree3 , body . cFree4 , body . cFree5 , body . cFree6 , body . cFree7 , body . cFree8 , body . cFree9 , body . cFree10 ,
"" , key , "" , "" , "" , "" , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , iFatherId , iChildId ) ;
DataTable dtDisCheck = DBHelper . SQlReturnData ( sql , cmd ) ;
if ( dtDisCheck ! = null & & dtDisCheck . Rows . Count > 0 )
{
foreach ( DataRow item1 in dtDisCheck . Rows )
{
if ( Convert . ToDecimal ( item1 [ "fOutQuantity" ] . ToString ( ) ) = = Convert . ToDecimal ( item1 [ "iQuantity" ] . ToString ( ) ) )
{
if ( Convert . ToDecimal ( item1 [ "iNum" ] . ToString ( ) ) ! = 0 )
{
if ( Convert . ToDecimal ( item1 [ "SiNum" ] . ToString ( ) ) ! = 0 )
{
sql = @"Update rdrecords11 set iNum=isnull(iNum,0)+(" + item1 [ "SiNum" ] . ToString ( ) + ") where autoid='" + iChildId + "' " ;
body . Amount = ( Convert . ToDecimal ( body . Amount . ToString ( "0.00" ) ) ) + ( Convert . ToDecimal ( item1 [ "SiNum" ] . ToString ( ) ) ) ;
DBHelper . CmdExecuteNonQuery ( sql , cmd , "辅计量余数处理失败!" ) ;
}
}
}
}
}
//更新现存量
key . cBustypeUN = "领料" ;
key . cVouchTypeUN = "11" ;
key . TableName = "IA_ST_UnAccountVouch11" ;
//DBHelper.UpdateCurrentStock(cmd, body.InvCode, head.WHCode, "", body.Quantity, key);
//DBHelper.UpdateCurrentStockNEW(cmd, body.InvCode, head.WHCode, body.BatchCode, body.Quantity, body.cFree1, body.cFree2, body.cFree3, body.cFree4, body.cFree5, body.cFree6, body.cFree7, body.cFree8, body.cFree9, body.cFree10, key);
DBHelper . UpdateCurrentStockCCGC ( cmd , body . InvCode , head . WHCode , body . BatchCode , body . Quantity , body . Amount , body . cFree1 ,
body . cFree2 , body . cFree3 , body . cFree4 , body . cFree5 , body . cFree6 , body . cFree7 , body . cFree8 , body . cFree9 , body . cFree10 ,
"" , key , "" , "" , "" , "" , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , iFatherId , iChildId ) ;
iFatherIdTwo = "'" + iFatherId + "'," ;
iChildId - - ;
iFatherIdTwo = "'" + iFatherId + "'," ;
iChildId - - ;
}
#endregion
#region 查询
sql = @ "
}
#endregion
#region 查询
sql = @ "
select DISTINCT a . ID as ID , a . ID as IDs , cMPoCode as SourceCode ,
cCode as IssueCode , a . cDepCode , c . cDepName , a . cWhCode , d . cWhName ,
cSource as SourceType , cMaker as CreateUser , dnmaketime as CreateDateTime ,
@ -457,32 +449,34 @@ isnull(b.cFree10,'') as cFree10
INNER JOIN dbo . mom_orderdetail f ON e . MoDId = f . MoDId
INNER JOIN dbo . mom_order g ON f . MoId = g . MoId WHERE a . ID in ( { 0 } ) ";
sql = string . Format ( sql , iFatherIdTwo . TrimEnd ( ',' ) ) ;
if ( ds ! = null )
ds . Merge ( DBHelper . SQlReturnDataSet ( sql , cmd ) ) ;
else
ds = DBHelper . SQlReturnDataSet ( sql , cmd ) ;
#endregion
}
cmd . Transaction . Commit ( ) ;
}
catch ( Exception ex )
{
cmd . Transaction . Rollback ( ) ;
log . Error ( ex . Message ) ;
throw new Exception ( ex . Message ) ;
}
finally
{
if ( conn . State = = ConnectionState . Open )
{
conn . Close ( ) ;
}
conn . Dispose ( ) ;
}
}
sql = string . Format ( sql , iFatherIdTwo . TrimEnd ( ',' ) ) ;
if ( ds ! = null )
ds . Merge ( DBHelper . SQlReturnDataSet ( sql , cmd ) ) ;
else
ds = DBHelper . SQlReturnDataSet ( sql , cmd ) ;
#endregion
}
cmd . Transaction . Commit ( ) ;
}
catch ( Exception ex )
{
if ( cmd . Transaction ! = null )
cmd . Transaction . Rollback ( ) ;
log . Error ( ex . Message ) ;
throw new Exception ( ex . Message ) ;
}
finally
{
if ( conn . State = = ConnectionState . Open )
{
conn . Close ( ) ;
}
conn . Dispose ( ) ;
}
}
msg = JSON . DataSetToJson ( ds , "details" , "IDs" ) ;
return msg ;
}
@ -493,8 +487,8 @@ isnull(b.cFree10,'') as cFree10
public string MaterialAppVouchs ( List < ICSRdrecord11 > Bills )
{
string mag = "" ;
string sql = "" ;
string sql = "" ;
DataSet ds = null ;
string connS = "" ;
@ -802,7 +796,7 @@ update mom_moallocate set IssQty=isnull(IssQty,0)+(" + body.Quantity + "),Requis
body . cFree2 , body . cFree3 , body . cFree4 , body . cFree5 , body . cFree6 , body . cFree7 , body . cFree8 , body . cFree9 , body . cFree10 ,
"" , key , "" , "" , "" , "" , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , iFatherId , iChildId ) ;
}
else
@ -902,56 +896,56 @@ isnull(b.cFree10,'') as cFree10
string sql = string . Empty ;
List < string > result = infos . Select ( t = > t . WorkPoint ) . Distinct ( ) . ToList ( ) ;
foreach ( string WorkPoint in result )
{
try
{
connS = string . Format ( connString , WorkPoint ) ;
conn = new System . Data . SqlClient . SqlConnection ( connS ) ;
conn . Open ( ) ;
SqlTransaction sqlTran = conn . BeginTransaction ( ) ;
cmd = new SqlCommand ( ) ;
cmd . Transaction = sqlTran ;
cmd . Connection = conn ;
foreach ( ICSRdrecord11 info in infos )
{
if ( WorkPoint ! = info . WorkPoint )
continue ;
if ( ! DBHelper . IsInventoryConsolidation ( cmd , info . WorkPoint ) )
throw new Exception ( "U8正在整理现存量,请稍后再试" ) ;
ICSUserInfo userInfo = new ICSUserInfo ( ) ;
userInfo = DBHelper . GetPersonInfo ( info . User , cmd ) ;
if ( info . MTime < new DateTime ( 2 0 0 0 , 0 1 , 0 1 ) )
throw new Exception ( "请输入正确的操作时间:" + info . MTime ) ;
sql = @"UPDATE dbo.rdrecord11 SET cHandler='" + userInfo . UserName + @ "' ,
List < string > result = infos . Select ( t = > t . WorkPoint ) . Distinct ( ) . ToList ( ) ;
foreach ( string WorkPoint in result )
{
try
{
connS = string . Format ( connString , WorkPoint ) ;
conn = new System . Data . SqlClient . SqlConnection ( connS ) ;
conn . Open ( ) ;
SqlTransaction sqlTran = conn . BeginTransaction ( ) ;
cmd = new SqlCommand ( ) ;
cmd . Transaction = sqlTran ;
cmd . Connection = conn ;
foreach ( ICSRdrecord11 info in infos )
{
if ( WorkPoint ! = info . WorkPoint )
continue ;
if ( ! DBHelper . IsInventoryConsolidation ( cmd , info . WorkPoint ) )
throw new Exception ( "U8正在整理现存量,请稍后再试" ) ;
ICSUserInfo userInfo = new ICSUserInfo ( ) ;
userInfo = DBHelper . GetPersonInfo ( info . User , cmd ) ;
if ( info . MTime < new DateTime ( 2 0 0 0 , 0 1 , 0 1 ) )
throw new Exception ( "请输入正确的操作时间:" + info . MTime ) ;
sql = @"UPDATE dbo.rdrecord11 SET cHandler='" + userInfo . UserName + @ "' ,
dVeriDate = CONVERT ( VARCHAR ( 5 0 ) , GETDATE ( ) , 1 1 2 ) , dnverifytime = GETDATE ( )
WHERE ID = ' " + info.ID + " ' ";
DBHelper . CmdExecuteNonQuery ( sql , cmd , "审核材料出库单失败!" ) ;
}
cmd . Transaction . Commit ( ) ;
}
catch ( Exception ex )
{
cmd . Transaction . Rollback ( ) ;
log . Error ( ex . Message ) ;
throw new Exception ( ex . Message ) ;
}
finally
{
if ( conn . State = = ConnectionState . Open )
{
conn . Close ( ) ;
}
conn . Dispose ( ) ;
}
}
DBHelper . CmdExecuteNonQuery ( sql , cmd , "审核材料出库单失败!" ) ;
}
cmd . Transaction . Commit ( ) ;
}
catch ( Exception ex )
{
cmd . Transaction . Rollback ( ) ;
log . Error ( ex . Message ) ;
throw new Exception ( ex . Message ) ;
}
finally
{
if ( conn . State = = ConnectionState . Open )
{
conn . Close ( ) ;
}
conn . Dispose ( ) ;
}
}
return json ;
}
@ -979,53 +973,53 @@ isnull(b.cFree10,'') as cFree10
string sql = string . Empty ;
List < string > result = infos . Select ( t = > t . WorkPoint ) . Distinct ( ) . ToList ( ) ;
foreach ( string WorkPoint in result )
{
try
{
connS = string . Format ( connString , WorkPoint ) ;
conn = new System . Data . SqlClient . SqlConnection ( connS ) ;
conn . Open ( ) ;
SqlTransaction sqlTran = conn . BeginTransaction ( ) ;
cmd = new SqlCommand ( ) ;
cmd . Transaction = sqlTran ;
cmd . Connection = conn ;
foreach ( ICSRdrecord11 info in infos )
{
if ( WorkPoint ! = info . WorkPoint )
continue ;
if ( info . MTime < new DateTime ( 2 0 0 0 , 0 1 , 0 1 ) )
throw new Exception ( "请输入正确的操作时间:" + info . MTime ) ;
sql = @"delete rdrecord11 where rdrecord11.ID='" + info . ID + "'" ;
sql + = @"delete rdrecords11 where rdrecords11.ID='" + info . ID + "'" ;
//UPDATE dbo.rdrecord11 a SET cHandler='" + info.User + @"' ,
// dVeriDate=CONVERT(VARCHAR(50),GETDATE(),112),dnverifytime=GETDATE()
// WHERE a.ID='" + info.ID + "'";
DBHelper . CmdExecuteNonQuery ( sql , cmd , "删除材料出库单失败!" ) ;
}
cmd . Transaction . Commit ( ) ;
}
catch ( Exception ex )
{
cmd . Transaction . Rollback ( ) ;
log . Error ( ex . Message ) ;
throw new Exception ( ex . Message ) ;
}
finally
{
if ( conn . State = = ConnectionState . Open )
{
conn . Close ( ) ;
}
conn . Dispose ( ) ;
}
}
List < string > result = infos . Select ( t = > t . WorkPoint ) . Distinct ( ) . ToList ( ) ;
foreach ( string WorkPoint in result )
{
try
{
connS = string . Format ( connString , WorkPoint ) ;
conn = new System . Data . SqlClient . SqlConnection ( connS ) ;
conn . Open ( ) ;
SqlTransaction sqlTran = conn . BeginTransaction ( ) ;
cmd = new SqlCommand ( ) ;
cmd . Transaction = sqlTran ;
cmd . Connection = conn ;
foreach ( ICSRdrecord11 info in infos )
{
if ( WorkPoint ! = info . WorkPoint )
continue ;
if ( info . MTime < new DateTime ( 2 0 0 0 , 0 1 , 0 1 ) )
throw new Exception ( "请输入正确的操作时间:" + info . MTime ) ;
sql = @"delete rdrecord11 where rdrecord11.ID='" + info . ID + "'" ;
sql + = @"delete rdrecords11 where rdrecords11.ID='" + info . ID + "'" ;
//UPDATE dbo.rdrecord11 a SET cHandler='" + info.User + @"' ,
// dVeriDate=CONVERT(VARCHAR(50),GETDATE(),112),dnverifytime=GETDATE()
// WHERE a.ID='" + info.ID + "'";
DBHelper . CmdExecuteNonQuery ( sql , cmd , "删除材料出库单失败!" ) ;
}
cmd . Transaction . Commit ( ) ;
}
catch ( Exception ex )
{
cmd . Transaction . Rollback ( ) ;
log . Error ( ex . Message ) ;
throw new Exception ( ex . Message ) ;
}
finally
{
if ( conn . State = = ConnectionState . Open )
{
conn . Close ( ) ;
}
conn . Dispose ( ) ;
}
}
return json ;
}