/// <summary> /// 新增(传入事务处理) /// </summary> /// <param name="p_BE">要新增的实体</param> /// <param name="sqlTrans">事务类</param> public void RAdd(BaseEntity p_BE, BaseEntity[] p_BE2, IDBTransAccess sqlTrans) { try { this.CheckCorrect(p_BE); FHForm entity = (FHForm)p_BE; string sql = "SELECT FormNo FROM Sale_FHForm WHERE FormNo=" + SysString.ToDBString(entity.FormNo); DataTable dt = sqlTrans.Fill(sql); if (dt.Rows.Count > 0) { throw new BaseException("单号已存在,请重新生成"); } //sql = "SELECT SendCode FROM Sale_FHForm WHERE SendCode=" + SysString.ToDBString(entity.SendCode); //dt = sqlTrans.Fill(sql); //if (dt.Rows.Count > 0) //{ // throw new BaseException("送货单号已存在,请重新生成"); //} FHFormCtl control = new FHFormCtl(sqlTrans); entity.ID = (int)EntityIDTable.GetID((long)SysEntity.Sale_FHForm, sqlTrans); control.AddNew(entity); FHFormDtsRule rule = new FHFormDtsRule(); for (int i = 0; i < p_BE2.Length; i++) { FHFormDts entityDts = (FHFormDts)p_BE2[i]; entityDts.MainID = entity.ID; entityDts.Seq = i + 1; rule.RAdd(entityDts, sqlTrans); } FormNoControlRule rulest = new FormNoControlRule(); //rulest.RAddSort((int)FormNoControlEnum.发货单号, sqlTrans); rulest.RAddSort("Sale_FHForm", "FormNo", 0, sqlTrans); //FormNCVendorRule rulencv = new FormNCVendorRule(); //rulencv.RAddSort((int)FormNoControlEnum.发货单送货单号, (int)EnumFNCV.发货单送货单号, entity.VendorID, sqlTrans); } catch (BaseException) { throw; } catch (Exception E) { throw new BaseException(E.Message); } }
/// <summary> /// 新增(传入事务处理) /// </summary> /// <param name="p_BE">要新增的实体</param> /// <param name="sqlTrans">事务类</param> public void RAdd(int p_ID, string p_IDStr, IDBTransAccess sqlTrans) { try { string sql = "SELECT SectionID,JarNum,Batch FROM WH_PackBox WHERE ID IN (" + p_IDStr + ")"; sql += " GROUP BY SectionID,JarNum,Batch"; DataTable dt = sqlTrans.Fill(sql); int MaxSeq = GetMaxSeq(p_ID); decimal Qty = 0; FHFormDtsRule rule = new FHFormDtsRule(); for (int i = 0; i < dt.Rows.Count; i++) { if (i == 0)//第一行更新 { sql = "SELECT * FROM WH_PackBox WHERE ID IN (" + p_IDStr + ")"; sql += " AND SectionID=" + SysString.ToDBString(SysConvert.ToString(dt.Rows[i]["SectionID"])); sql += " AND JarNum=" + SysString.ToDBString(SysConvert.ToString(dt.Rows[i]["JarNum"])); sql += " AND Batch=" + SysString.ToDBString(SysConvert.ToString(dt.Rows[i]["Batch"])); DataTable dtsql = sqlTrans.Fill(sql); FHFormDts entitydts = new FHFormDts(sqlTrans); entitydts.ID = p_ID; entitydts.SelectByID(); entitydts.SectionID = SysConvert.ToString(dt.Rows[i]["SectionID"]); entitydts.JarNum = SysConvert.ToString(dt.Rows[i]["JarNum"]); entitydts.Batch = SysConvert.ToString(dt.Rows[i]["Batch"]); entitydts.Qty = SysConvert.ToDecimal(dtsql.Compute("SUM(Qty)", "")); entitydts.PieceQty = dtsql.Rows.Count; entitydts.PackFlag = 1; entitydts.Amount = entitydts.Qty * entitydts.SingPrice; rule.RUpdate(entitydts, sqlTrans); FHFormDtsPackRule prule = new FHFormDtsPackRule(); sql = "DELETE Sale_FHFormDtsPack WHERE MainID=" + SysString.ToDBString(entitydts.MainID); sql += " AND Seq=" + SysString.ToDBString(entitydts.Seq); sqlTrans.ExecuteNonQuery(sql); for (int j = 0; j < dtsql.Rows.Count; j++) { FHFormDtsPack pentity = new FHFormDtsPack(sqlTrans); pentity.MainID = entitydts.MainID; pentity.Seq = entitydts.Seq; pentity.SubSeq = j + 1; pentity.BoxNo = SysConvert.ToString(dtsql.Rows[j]["BoxNo"]); pentity.Qty = SysConvert.ToDecimal(dtsql.Rows[j]["Qty"]); pentity.DID = entitydts.ID; prule.RAdd(pentity, sqlTrans); } } else { sql = "SELECT * FROM WH_PackBox WHERE ID IN (" + p_IDStr + ")"; sql += " AND SectionID=" + SysString.ToDBString(SysConvert.ToString(dt.Rows[i]["SectionID"])); sql += " AND JarNum=" + SysString.ToDBString(SysConvert.ToString(dt.Rows[i]["JarNum"])); sql += " AND Batch=" + SysString.ToDBString(SysConvert.ToString(dt.Rows[i]["Batch"])); DataTable dtsql = sqlTrans.Fill(sql); FHFormDts entitydts = new FHFormDts(sqlTrans); entitydts.ID = p_ID; entitydts.SelectByID(); entitydts.Seq = MaxSeq + i; entitydts.SectionID = SysConvert.ToString(dt.Rows[i]["SectionID"]); entitydts.JarNum = SysConvert.ToString(dt.Rows[i]["JarNum"]); entitydts.Batch = SysConvert.ToString(dt.Rows[i]["Batch"]); entitydts.Qty = SysConvert.ToDecimal(dtsql.Compute("SUM(Qty)", "")); entitydts.PieceQty = dtsql.Rows.Count; entitydts.PackFlag = 1; entitydts.Amount = entitydts.Qty * entitydts.SingPrice; sql = "SELECT ID FROM Sale_FHFormDts WHERE MainID=" + SysString.ToDBString(entitydts.MainID); sql += " AND Seq=" + SysString.ToDBString(entitydts.Seq); if (sqlTrans.Fill(sql).Rows.Count > 0) { throw new BaseException("不能增行,该行已存在"); } rule.RAdd(entitydts, sqlTrans); IOFormDtsPackRule prule = new IOFormDtsPackRule(); sql = "DELETE Sale_FHFormDtsPack WHERE MainID=" + SysString.ToDBString(entitydts.MainID); sql += " AND Seq=" + SysString.ToDBString(entitydts.Seq); sqlTrans.ExecuteNonQuery(sql); for (int j = 0; j < dtsql.Rows.Count; j++) { FHFormDtsPack pentity = new FHFormDtsPack(sqlTrans); pentity.MainID = entitydts.MainID; pentity.Seq = entitydts.Seq; pentity.SubSeq = j + 1; pentity.BoxNo = SysConvert.ToString(dtsql.Rows[j]["BoxNo"]); pentity.Qty = SysConvert.ToDecimal(dtsql.Rows[j]["Qty"]); pentity.DID = entitydts.ID; prule.RAdd(pentity, sqlTrans); } } } } catch (BaseException) { throw; } catch (Exception E) { throw new BaseException(E.Message); } }