/// <summary> /// 交期变更 /// </summary> /// <param name="dt"></param> /// <param name="TaskID">主表ID</param> protected void Update_JQ(DataTable dt, string TaskID) { POOrderEntryDal dal = new POOrderEntryDal(); POOrderEntry old_model = new POOrderEntry(); //原始的采购订单明细 //找出不重复的FEntryID 遍历 string sql = "select distinct FEntryID from dbo.JD_OrderListDeailBG_WL where TaskID='" + TaskID + "' order by FEntryID asc"; //string updatesql = ""; //string sqltemp = ""; var FEntryIDs = DBUtil.Query(sql).Tables[0].AsEnumerable().Select(r => r["FEntryID"]).Distinct(); foreach (var item in FEntryIDs) { DataRow[] dr = dt.Select("FEntryID='" + item.ToString() + "'", "FAuxQty desc"); int Count = 0; foreach (DataRow datarow in dr) { //更新 if (Count == 0) { common.WriteLogs("首行"); common.WriteLogs("Count:" + Count); common.WriteLogs("FEntryID:" + datarow["FInterID"].ToString() + ",FEntryID:" + item.ToString()); old_model = dal.Detail(Convert.ToInt32(datarow["FInterID"].ToString()), Convert.ToInt32(item.ToString())); if (!String.IsNullOrEmpty(datarow["FEntrySelfP0267"].ToString())) { old_model.FEntrySelfP0267 = Convert.ToDateTime(datarow["FEntrySelfP0267"].ToString()); } if (!String.IsNullOrEmpty(datarow["FEntrySelfP0268"].ToString())) { old_model.FEntrySelfP0268 = Convert.ToDateTime(datarow["FEntrySelfP0268"].ToString()); } if (!string.IsNullOrEmpty(datarow["FDate"].ToString())) { old_model.FDate = Convert.ToDateTime(datarow["FDate"].ToString()); } old_model.FAuxQty = Math.Round(Convert.ToDecimal(datarow["FAuxQty"].ToString()), 10); //数量更新 old_model = LastUpdateModel(old_model); dal.Update(old_model); //sqltemp = (!String.IsNullOrEmpty(datarow["FEntrySelfP0267"].ToString())) ? ",FEntrySelfP0267='" + Convert.ToDateTime(datarow["FEntrySelfP0267"].ToString()).ToString("yyyy-MM-dd") + "'" : ""; //sqltemp += (!String.IsNullOrEmpty(datarow["FEntrySelfP0268"].ToString())) ? ",FEntrySelfP0268='" + Convert.ToDateTime(datarow["FEntrySelfP0268"].ToString()).ToString("yyyy-MM-dd") + "'" : ""; //updatesql = string.Format(@"update POOrderEntry set FDate='{0}' {1} {4} // where FInterID='{2}' and FEntryID='{3}'", Convert.ToDateTime(datarow["FDate"].ToString()).ToString("yyyy-MM-dd"), sqltemp, datarow["FInterID"].ToString(), item.ToString(), // ",FAuxQty='"+ Math.Round(Convert.ToDecimal(datarow["FAuxQty"].ToString()), 10).ToString() + "'" ); //common.WriteLogs("首行"); //common.WriteLogs(updatesql); //DBUtil.ExecuteSql(updatesql, K3connectionString); } //插入 else { common.WriteLogs("非首行"); common.WriteLogs("Count:" + Count); //获取拆分订单中首个明细 POOrderEntry model = dal.Detail(Convert.ToInt32(datarow["FInterID"]), Convert.ToInt32(item.ToString())); //带出Max(FEntryID) int MaxFEntryID = common.GetMaxID("FEntryID", "POOrderEntry", " where FInterID='" + datarow["FInterID"] + "' "); model.FAuxQty = Math.Round(Convert.ToDecimal(datarow["FAuxQty"].ToString()), 10); if (!String.IsNullOrEmpty(datarow["FEntrySelfP0267"].ToString())) { model.FEntrySelfP0267 = Convert.ToDateTime(datarow["FEntrySelfP0267"].ToString()); } if (!String.IsNullOrEmpty(datarow["FEntrySelfP0268"].ToString())) { model.FEntrySelfP0268 = Convert.ToDateTime(datarow["FEntrySelfP0268"].ToString()); } if (!string.IsNullOrEmpty(datarow["FDate"].ToString())) { model.FDate = Convert.ToDateTime(datarow["FDate"].ToString()); } decimal zero = Convert.ToDecimal(0.00); model.FEntryID = MaxFEntryID; //行号更新 model.FCommitQty = model.FCheckAmount = model.FAuxCommitQty = model.FStockQty = model.FAuxStockQty = model.FQtyInvoice = model.FReceiveAmountFor_Commit = model.FReceiveAmount_Commit = model.FAuxQtyInvoice = model.FAuxReceiptQty = model.FReceiptQty = model.FAuxReturnQty = model.FReturnQty = model.FAmountExceptDisCount = model.FAllAmountExceptDisCount = zero; model = LastUpdateModel(model); dal.Add(model); } Count++; } } }