|
|
using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; using ICSSoft.Common; using ICSSoft.Entity;
namespace ICSSoft.DataProject { public class ISComplete { private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static string connString = System.Configuration.ConfigurationManager.AppSettings["ERPConnStr"]; public string ConfirmRd08(List<Complete> Bills) { string sql = ""; string connS = ""; VouchKey key = new VouchKey(); SqlConnection conn = new SqlConnection(); SqlCommand cmd = new SqlCommand();
foreach (Complete head in Bills) { connS = string.Format(connString, head.WorkPoint); conn = new System.Data.SqlClient.SqlConnection(connS); conn.Open(); SqlTransaction sqlTran = conn.BeginTransaction(); cmd = new SqlCommand(); cmd.Transaction = sqlTran; cmd.Connection = conn; foreach (Completes body in head.details) { if (head.SourceType == "生产订单") { #region 齐套检验
sql = @" select cValue from AccInformation where cName=N'iMOProInCtrlBySet' "; DataTable qt = DBHelper.SQlReturnData(sql, cmd); if (qt != null && qt.Rows.Count > 0) { if (qt.Rows[0]["cValue"].ToString() == "1") {
sql = @"select MoCode,SortSeq,MIN(lotqty) min_lotqty from
( select a.MoCode,b.SortSeq, case when aa.AllocateId IS null then c.AllocateId else aa.AllocateId end as AllocateId,sum(c.Qty) as Qty,SUM(c.IssQty) IssQty,SUM(c.IssQty)/(SUM(c.Qty)/b.Qty) lotqty from DBO.mom_order a left join DBO.mom_orderdetail b on a.moid = b.moid left join DBO.mom_moallocate c on b.modid = c.modid left join (select d.AllocateId,e.InvCode,d.MoallocateSubId from DBO.mom_moallocatesub d left join DBO.bas_part e ON d.partid = e.PartId ) aa on c.MoallocateSubId=aa.MoallocateSubId left join DBO.Inventory_Sub f on c.InvCode=f.cInvSubCode where a.MoCode='{0}' and b.SortSeq='{1}' and c.WIPType<>1 and c.Qty<>0 and c.ByproductFlag<>1 group by a.MoCode,b.SortSeq,case when aa.AllocateId IS null then c.AllocateId else aa.AllocateId end ,b.Qty ) tt group by MoCode,SortSeq";
sql = string.Format(sql, head.SourceCode, body.Sequence); qt = DBHelper.SQlReturnData(sql, cmd);
if (qt == null || qt.Rows.Count == 0) { throw new Exception("该物料:" + body.InvCode + @"在订单内未领料!"); } else { if (Convert.ToDecimal(qt.Rows[0]["min_lotqty"]) <= 0) { throw new Exception("该物料:" + body.InvCode + @"在订单内未领料<=0!"); }
}
} else if (qt.Rows[0]["cValue"].ToString() == "2") { sql = @"select cValue from AccInformation where cName=N'bControlKeyMaterial'"; qt = DBHelper.SQlReturnData(sql, cmd); if (qt != null && qt.Rows.Count > 0) { if (qt.Rows[0]["cValue"].ToString() == "true") { sql = @"select MoCode,SortSeq,MIN(lotqty) min_lotqty from
( select a.MoCode,b.SortSeq, case when aa.AllocateId IS null then c.AllocateId else aa.AllocateId end as AllocateId,sum(c.Qty) as Qty,SUM(c.IssQty) IssQty,SUM(c.IssQty)/(SUM(c.Qty)/b.Qty) lotqty from DBO.mom_order a left join DBO.mom_orderdetail b on a.moid = b.moid left join DBO.mom_moallocate c on b.modid = c.modid left join (select d.AllocateId,e.InvCode,d.MoallocateSubId from DBO.mom_moallocatesub d left join DBO.bas_part e ON d.partid = e.PartId ) aa on c.MoallocateSubId=aa.MoallocateSubId left join DBO.Inventory_Sub f on c.InvCode=f.cInvSubCode where a.MoCode='{0}' and b.SortSeq='{1}' and c.WIPType<>1 and c.Qty<>0 and c.ByproductFlag<>1 and f.bInvKeyPart=1 group by a.MoCode,b.SortSeq,case when aa.AllocateId IS null then c.AllocateId else aa.AllocateId end ,b.Qty ) tt group by MoCode,SortSeq";
sql = string.Format(sql, head.SourceCode, body.Sequence); qt = DBHelper.SQlReturnData(sql, cmd);
if (qt == null || qt.Rows.Count == 0) { throw new Exception("该物料:" + body.InvCode + @"在订单内未有可用领料!"); } else { if (Convert.ToDecimal(qt.Rows[0]["min_lotqty"]) <= 0) { throw new Exception("该物料:" + body.InvCode + @"在订单内未领料!"); } else if (Convert.ToDecimal(qt.Rows[0]["min_lotqty"]) - body.Quantity <= 0) { throw new Exception("该物料:" + body.InvCode + @"入库数量大于关键物料领料套数!"); } }
} else {
sql = @"select MoCode,SortSeq,MIN(lotqty) min_lotqty from
( select a.MoCode,b.SortSeq, case when aa.AllocateId IS null then c.AllocateId else aa.AllocateId end as AllocateId,sum(c.Qty) as Qty,SUM(c.IssQty) IssQty,SUM(c.IssQty)/(SUM(c.Qty)/b.Qty) lotqty from DBO.mom_order a left join DBO.mom_orderdetail b on a.moid = b.moid left join DBO.mom_moallocate c on b.modid = c.modid left join (select d.AllocateId,e.InvCode,d.MoallocateSubId from DBO.mom_moallocatesub d left join DBO.bas_part e ON d.partid = e.PartId ) aa on c.MoallocateSubId=aa.MoallocateSubId left join DBO.Inventory_Sub f on c.InvCode=f.cInvSubCode where a.MoCode='{0}' and b.SortSeq='{1}' and c.WIPType<>1 and c.Qty<>0 and c.ByproductFlag<>1 group by a.MoCode,b.SortSeq,case when aa.AllocateId IS null then c.AllocateId else aa.AllocateId end ,b.Qty ) tt group by MoCode,SortSeq";
sql = string.Format(sql, head.SourceCode, body.Sequence); qt = DBHelper.SQlReturnData(sql, cmd);
if (qt == null || qt.Rows.Count == 0) { throw new Exception("该物料:" + body.InvCode + @"在订单内未有可用领料!"); } else { if (Convert.ToDecimal(qt.Rows[0]["min_lotqty"]) <= 0) { throw new Exception("该物料:" + body.InvCode + @"在订单内未领料!"); } else if (Convert.ToDecimal(qt.Rows[0]["min_lotqty"]) - body.Quantity <= 0) { throw new Exception("该物料:" + body.InvCode + @"入库数量大于领料套数!"); } }
} }
} }
#endregion
} else { #region 齐套检验
sql = @" select cValue from AccInformation where cName=N'iMOProInCtrlBySet' "; DataTable qt = DBHelper.SQlReturnData(sql, cmd); if (qt != null && qt.Rows.Count > 0) { if (qt.Rows[0]["cValue"].ToString() == "1") {
sql = @"select cCode,iVouchRowNo,MIN(lotqty) min_lotqty from
( select a.cCode,b.iVouchRowNo, c.MOMaterialsID as AllocateId,sum(c.iQuantity) as Qty,SUM(c.iSendQTY) IssQty,SUM(c.iSendQTY)/(SUM(c.iQuantity)/b.iQuantity) lotqty from DBO.OM_MOMain a left join DBO.OM_MODetails b on a.moid = b.moid left join DBO.OM_MOMaterials c on b.MODetailsID = c.MODetailsID left join DBO.Inventory_Sub f on c.cInvCode=f.cInvSubCode where a.cCode='{0}' and b.iVouchRowNo='{1}' and c.iQuantity<>0 group by a.cCode,b.iVouchRowNo,c.MOMaterialsID,b.iQuantity ) tt group by cCode,iVouchRowNo";
sql = string.Format(sql, head.SourceCode, body.Sequence); qt = DBHelper.SQlReturnData(sql, cmd);
if (qt == null || qt.Rows.Count == 0) { throw new Exception("该物料:" + body.InvCode + @"在订单内未领料!"); } else { if (Convert.ToDecimal(qt.Rows[0]["min_lotqty"]) <= 0) { throw new Exception("该物料:" + body.InvCode + @"在订单内未领料<=0!"); }
}
} else if (qt.Rows[0]["cValue"].ToString() == "2") { sql = @"select cValue from AccInformation where cName=N'bControlKeyMaterial'"; qt = DBHelper.SQlReturnData(sql, cmd); if (qt != null && qt.Rows.Count > 0) { if (qt.Rows[0]["cValue"].ToString() == "true") { sql = @"select cCode,iVouchRowNo,MIN(lotqty) min_lotqty from
( select a.cCode,b.iVouchRowNo, c.MOMaterialsID as AllocateId,sum(c.iQuantity) as Qty,SUM(c.iSendQTY) IssQty,SUM(c.iSendQTY)/(SUM(c.iQuantity)/b.iQuantity) lotqty from DBO.OM_MOMain a left join DBO.OM_MODetails b on a.moid = b.moid left join DBO.OM_MOMaterials c on b.MODetailsID = c.MODetailsID left join DBO.Inventory_Sub f on c.cInvCode=f.cInvSubCode where a.cCode='{0}' and b.iVouchRowNo='{1}' and c.iQuantity<>0 group by a.cCode,b.iVouchRowNo,c.MOMaterialsID,b.iQuantity ) tt group by cCode,iVouchRowNo";
sql = string.Format(sql, head.SourceCode, body.Sequence); qt = DBHelper.SQlReturnData(sql, cmd);
if (qt == null || qt.Rows.Count == 0) { throw new Exception("该物料:" + body.InvCode + @"在订单内未有可用领料!"); } else { if (Convert.ToDecimal(qt.Rows[0]["min_lotqty"]) <= 0) { throw new Exception("该物料:" + body.InvCode + @"在订单内未领料!"); } else if (Convert.ToDecimal(qt.Rows[0]["min_lotqty"]) - body.Quantity <= 0) { throw new Exception("该物料:" + body.InvCode + @"入库数量大于关键物料领料套数!"); } }
} else {
sql = @"select cCode,iVouchRowNo,MIN(lotqty) min_lotqty from
( select a.cCode,b.iVouchRowNo, c.MOMaterialsID as AllocateId,sum(c.iQuantity) as Qty,SUM(c.iSendQTY) IssQty,SUM(c.iSendQTY)/(SUM(c.iQuantity)/b.iQuantity) lotqty from DBO.OM_MOMain a left join DBO.OM_MODetails b on a.moid = b.moid left join DBO.OM_MOMaterials c on b.MODetailsID = c.MODetailsID left join DBO.Inventory_Sub f on c.cInvCode=f.cInvSubCode where a.cCode='{0}' and b.iVouchRowNo='{1}' and c.iQuantity<>0 group by a.cCode,b.iVouchRowNo,c.MOMaterialsID,b.iQuantity ) tt group by cCode,iVouchRowNo";
sql = string.Format(sql, head.SourceCode, body.Sequence); qt = DBHelper.SQlReturnData(sql, cmd);
if (qt == null || qt.Rows.Count == 0) { throw new Exception("该物料:" + body.InvCode + @"在订单内未有可用领料!"); } else { if (Convert.ToDecimal(qt.Rows[0]["min_lotqty"]) <= 0) { throw new Exception("该物料:" + body.InvCode + @"在订单内未领料!"); } else if (Convert.ToDecimal(qt.Rows[0]["min_lotqty"]) - body.Quantity <= 0) { throw new Exception("该物料:" + body.InvCode + @"入库数量大于领料套数!"); } }
} }
} }
#endregion
} }
} return "齐套检验完成"; } } }
|