/// <summary>
 /// 保存(传入事务处理)
 /// </summary>
 /// <param name="p_Entity"></param>
 /// <param name="p_BE"></param>
 /// <param name="sqlTrans"></param>
 public void RSave(ItemBuyForm p_Entity, BaseEntity[] p_BE, IDBTransAccess sqlTrans)
 {
     try
     {
         string sql = "DELETE FROM Buy_ItemBuyFormDts WHERE MainID=" + p_Entity.ID.ToString();
         sql += " AND ID NOT IN" + string.Format("({0})", GetIDExist(p_BE));
         sqlTrans.ExecuteNonQuery(sql);//删除原单据里应该删除的明细数据,即数据库里有但是UI里已经删除的数据
         for (int i = 0; i < p_BE.Length; i++)
         {
             ItemBuyFormDts entitydts = (ItemBuyFormDts)p_BE[i];
             if (entitydts.ID != 0)//ID不为0说明数据库中已经存在
             {
                 this.RUpdate(entitydts, sqlTrans);
             }
             else
             {
                 entitydts.MainID = p_Entity.ID;
                 this.RAdd(entitydts, sqlTrans);
             }
         }
     }
     catch (BaseException)
     {
         throw;
     }
     catch (Exception E)
     {
         throw new BaseException(E.Message);
     }
 }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="p_Entity">实体类</param>
        /// <returns>操作影响的记录行数</returns>
        public override int Delete(BaseEntity p_Entity)
        {
            try
            {
                ItemBuyFormDts MasterEntity = (ItemBuyFormDts)p_Entity;
                if (MasterEntity.ID == 0)
                {
                    return(0);
                }

                //删除主表数据
                string Sql = "";
                Sql = "DELETE FROM Buy_ItemBuyFormDts WHERE " + "ID=" + SysString.ToDBString(MasterEntity.ID);
                //执行
                int AffectedRows = 0;
                if (!this.sqlTransFlag)
                {
                    AffectedRows = this.ExecuteNonQuery(Sql);
                }
                else
                {
                    AffectedRows = sqlTrans.ExecuteNonQuery(Sql);
                }

                return(AffectedRows);
            }
            catch (BaseException E)
            {
                throw new BaseException(E.Message, E);
            }
            catch (Exception E)
            {
                throw new BaseException(FrameWorkMessage.GetAlertMessage((int)Message.CommonDBDelete), E);
            }
        }
        /// <summary>
        /// 获得实体
        /// </summary>
        /// <returns></returns>
        private ItemBuyFormDts[] EntityDtsGet()
        {
            int index = GetDataCompleteNum();

            ItemBuyFormDts[] entitydts = new ItemBuyFormDts[index];
            index = 0;
            for (int i = 0; i < gridView1.RowCount; i++)
            {
                if (CheckDataCompleteDts(i))
                {
                    entitydts[index]    = new ItemBuyFormDts();
                    entitydts[index].ID = SysConvert.ToInt32(gridView1.GetRowCellValue(i, "ID"));
                    entitydts[index].SelectByID();
                    entitydts[index].MainID = HTDataID;
                    entitydts[index].Seq    = i + 1;

                    entitydts[index].ItemCode   = SysConvert.ToString(gridView1.GetRowCellValue(i, "ItemCode"));
                    entitydts[index].ItemName   = SysConvert.ToString(gridView1.GetRowCellValue(i, "ItemName"));
                    entitydts[index].ItemStd    = SysConvert.ToString(gridView1.GetRowCellValue(i, "ItemStd"));
                    entitydts[index].ItemModel  = SysConvert.ToString(gridView1.GetRowCellValue(i, "ItemModel"));
                    entitydts[index].Batch      = SysConvert.ToString(gridView1.GetRowCellValue(i, "Batch"));
                    entitydts[index].GoodsCode  = SysConvert.ToString(gridView1.GetRowCellValue(i, "GoodsCode"));
                    entitydts[index].ColorNum   = SysConvert.ToString(gridView1.GetRowCellValue(i, "ColorNum"));
                    entitydts[index].ColorName  = SysConvert.ToString(gridView1.GetRowCellValue(i, "ColorName"));
                    entitydts[index].MWidth     = SysConvert.ToString(gridView1.GetRowCellValue(i, "MWidth"));
                    entitydts[index].MWeight    = SysConvert.ToString(gridView1.GetRowCellValue(i, "MWeight"));
                    entitydts[index].WeightUnit = SysConvert.ToString(gridView1.GetRowCellValue(i, "WeightUnit"));

                    entitydts[index].VColorNum  = SysConvert.ToString(gridView1.GetRowCellValue(i, "VColorNum"));
                    entitydts[index].VColorName = SysConvert.ToString(gridView1.GetRowCellValue(i, "VColorName"));
                    entitydts[index].VItemCode  = SysConvert.ToString(gridView1.GetRowCellValue(i, "VItemCode"));
                    entitydts[index].Qty        = SysConvert.ToDecimal(gridView1.GetRowCellValue(i, "Qty"));
                    entitydts[index].Unit       = SysConvert.ToString(gridView1.GetRowCellValue(i, "Unit"));
                    entitydts[index].SingPrice  = SysConvert.ToDecimal(gridView1.GetRowCellValue(i, "SingPrice"));
                    entitydts[index].Amount     = entitydts[index].Qty * entitydts[index].SingPrice;
                    //entitydts[index].RemainQty = entitydts[index].Qty - entitydts[index].TotalRecQty;
                    //if (entitydts[index].Qty > 0)
                    //{
                    //    entitydts[index].RemainRate = entitydts[index].RemainQty / entitydts[index].Qty;
                    //}

                    //entitydts[index].OrderPreStatusID = SysConvert.ToInt32(gridView1.GetRowCellValue(i, "OrderPreStatusID"));
                    //entitydts[index].OrderStatusID = SysConvert.ToInt32(gridView1.GetRowCellValue(i, "OrderStatusID"));
                    entitydts[index].DVendorID = SysConvert.ToString(gridView1.GetRowCellValue(i, "DVendorID"));
                    entitydts[index].DtsSO     = SysConvert.ToString(gridView1.GetRowCellValue(i, "DtsSO"));
                    entitydts[index].DLoadID   = SysConvert.ToInt32(gridView1.GetRowCellValue(i, "DLoadID"));


                    entitydts[index].DtsRemark = SysConvert.ToString(gridView1.GetRowCellValue(i, "DtsRemark"));
                    entitydts[index].FreeStr1  = SysConvert.ToString(gridView1.GetRowCellValue(i, "FreeStr1"));
                    entitydts[index].FreeStr2  = SysConvert.ToString(gridView1.GetRowCellValue(i, "FreeStr2"));
                    entitydts[index].FreeStr3  = SysConvert.ToString(gridView1.GetRowCellValue(i, "FreeStr3"));
                    entitydts[index].FreeStr4  = SysConvert.ToString(gridView1.GetRowCellValue(i, "FreeStr4"));
                    entitydts[index].FreeStr5  = SysConvert.ToString(gridView1.GetRowCellValue(i, "FreeStr5"));

                    index++;
                }
            }
            return(entitydts);
        }
        /// <summary>
        /// 获得数据库里没有被删除的ID(即数据库里有而且UI里也没有删除的数据)
        /// </summary>
        /// <param name="p_BE"></param>
        /// <returns></returns>
        private string GetIDExist(BaseEntity[] p_BE)
        {
            string outstr = "0";

            for (int i = 0; i < p_BE.Length; i++)
            {
                ItemBuyFormDts entitydts = (ItemBuyFormDts)p_BE[i];
                if (entitydts.ID != 0)
                {
                    outstr += "," + entitydts.ID;
                }
            }
            return(outstr);
        }
 /// <summary>
 /// 删除
 /// </summary>
 /// <param name="p_BE">要删除的实体</param>
 /// <param name="sqlTrans">事务类</param>
 public void RDelete(BaseEntity p_BE, IDBTransAccess sqlTrans)
 {
     try
     {
         this.CheckCorrect(p_BE);
         ItemBuyFormDts    entity  = (ItemBuyFormDts)p_BE;
         ItemBuyFormDtsCtl control = new ItemBuyFormDtsCtl(sqlTrans);
         control.Delete(entity);
     }
     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(BaseEntity p_BE, BaseEntity[] p_BE2, IDBTransAccess sqlTrans)
        {
            try
            {
                this.CheckCorrect(p_BE);
                ItemBuyForm entity = (ItemBuyForm)p_BE;
                this.RAdd(entity, sqlTrans);
                for (int i = 0; i < p_BE2.Length; i++)
                {
                    ItemBuyFormDtsRule rule      = new ItemBuyFormDtsRule();
                    ItemBuyFormDts     entityDts = (ItemBuyFormDts)p_BE2[i];
                    entityDts.MainID = entity.ID;
                    entityDts.Seq    = i + 1;
                    rule.RAdd(entityDts, sqlTrans);
                }
                //FormNoControlRule rulest = new FormNoControlRule();
                //switch (entity.FormAID)     //注意各采购窗体的配置
                //{
                //    case 0:
                //        rulest.RAddSort((int)FormNoControlEnum.销售合同采购单号, sqlTrans); //采购成品面料
                //        break;
                //    case 1:
                //        rulest.RAddSort((int)FormNoControlEnum.坯布采购单号, sqlTrans);
                //        break;
                //    case 2:
                //        rulest.RAddSort((int)FormNoControlEnum.纱线采购单号, sqlTrans);
                //        break;
                //    default:
                //        rulest.RAddSort((int)FormNoControlEnum.销售合同采购单号, sqlTrans);
                //        break;
                //}

                ItemBuyCapDtsRule capRule = new ItemBuyCapDtsRule();
                capRule.RSaveBuyCap(entity, 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(BaseEntity p_BE, IDBTransAccess sqlTrans)
 {
     try
     {
         this.CheckCorrect(p_BE);
         ItemBuyFormDts    entity  = (ItemBuyFormDts)p_BE;
         ItemBuyFormDtsCtl control = new ItemBuyFormDtsCtl(sqlTrans);
         entity.ID = (int)EntityIDTable.GetID((long)SysEntity.Buy_ItemBuyFormDts, sqlTrans);
         control.AddNew(entity);
     }
     catch (BaseException)
     {
         throw;
     }
     catch (Exception E)
     {
         throw new BaseException(E.Message);
     }
 }
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="p_Entity">实体类</param>
        /// <returns>操作影响的记录行数</returns>
        public override int AddNew(BaseEntity p_Entity)
        {
            try
            {
                ItemBuyFormDts MasterEntity = (ItemBuyFormDts)p_Entity;
                if (MasterEntity.ID == 0)
                {
                    return(0);
                }

                //新增主表数据
                StringBuilder MasterField = new StringBuilder();
                StringBuilder MasterValue = new StringBuilder();
                MasterField.Append("INSERT INTO Buy_ItemBuyFormDts(");
                MasterValue.Append(" VALUES(");
                MasterField.Append("ID" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.ID) + ",");
                MasterField.Append("MainID" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.MainID) + ",");
                MasterField.Append("Seq" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.Seq) + ",");
                MasterField.Append("ItemCode" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.ItemCode) + ",");
                MasterField.Append("GoodsCode" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.GoodsCode) + ",");
                MasterField.Append("ColorNum" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.ColorNum) + ",");
                MasterField.Append("ColorName" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.ColorName) + ",");
                MasterField.Append("MWidth" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.MWidth) + ",");
                MasterField.Append("MWeight" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.MWeight) + ",");
                MasterField.Append("WeightUnit" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.WeightUnit) + ",");
                MasterField.Append("ItemName" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.ItemName) + ",");
                MasterField.Append("VColorNum" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.VColorNum) + ",");
                MasterField.Append("VColorName" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.VColorName) + ",");
                MasterField.Append("VItemCode" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.VItemCode) + ",");
                MasterField.Append("Qty" + ",");
                if (MasterEntity.Qty != 0)
                {
                    MasterValue.Append(SysString.ToDBString(MasterEntity.Qty) + ",");
                }
                else
                {
                    MasterValue.Append("null,");
                }

                MasterField.Append("Unit" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.Unit) + ",");
                MasterField.Append("SingPrice" + ",");
                if (MasterEntity.SingPrice != 0)
                {
                    MasterValue.Append(SysString.ToDBString(MasterEntity.SingPrice) + ",");
                }
                else
                {
                    MasterValue.Append("null,");
                }

                MasterField.Append("Amount" + ",");
                if (MasterEntity.Amount != 0)
                {
                    MasterValue.Append(SysString.ToDBString(MasterEntity.Amount) + ",");
                }
                else
                {
                    MasterValue.Append("null,");
                }

                MasterField.Append("ReceivedDate" + ",");
                if (MasterEntity.ReceivedDate != SystemConfiguration.DateTimeDefaultValue)
                {
                    MasterValue.Append(SysString.ToDBString(MasterEntity.ReceivedDate.ToString("yyyy-MM-dd HH:mm:ss")) + ",");
                }
                else
                {
                    MasterValue.Append("null,");
                }

                MasterField.Append("ReceivedQty" + ",");
                if (MasterEntity.ReceivedQty != 0)
                {
                    MasterValue.Append(SysString.ToDBString(MasterEntity.ReceivedQty) + ",");
                }
                else
                {
                    MasterValue.Append("null,");
                }

                MasterField.Append("TotalRecQty" + ",");
                if (MasterEntity.TotalRecQty != 0)
                {
                    MasterValue.Append(SysString.ToDBString(MasterEntity.TotalRecQty) + ",");
                }
                else
                {
                    MasterValue.Append("null,");
                }

                MasterField.Append("RemainQty" + ",");
                if (MasterEntity.RemainQty != 0)
                {
                    MasterValue.Append(SysString.ToDBString(MasterEntity.RemainQty) + ",");
                }
                else
                {
                    MasterValue.Append("null,");
                }

                MasterField.Append("RemainRate" + ",");
                if (MasterEntity.RemainRate != 0)
                {
                    MasterValue.Append(SysString.ToDBString(MasterEntity.RemainRate) + ",");
                }
                else
                {
                    MasterValue.Append("null,");
                }

                MasterField.Append("OrderPreStatusID" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.OrderPreStatusID) + ",");
                MasterField.Append("OrderStatusID" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.OrderStatusID) + ",");
                MasterField.Append("DtsSO" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.DtsSO) + ",");
                MasterField.Append("DVendorID" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.DVendorID) + ",");
                MasterField.Append("ItemStd" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.ItemStd) + ",");
                MasterField.Append("ItemModel" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.ItemModel) + ",");
                MasterField.Append("Batch" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.Batch) + ",");
                MasterField.Append("VendorBatch" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.VendorBatch) + ",");
                MasterField.Append("YarnType" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.YarnType) + ",");
                MasterField.Append("DLoadID" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.DLoadID) + ",");
                MasterField.Append("BGNo" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.BGNo) + ",");
                MasterField.Append("PieceQty" + ",");
                if (MasterEntity.PieceQty != 0)
                {
                    MasterValue.Append(SysString.ToDBString(MasterEntity.PieceQty) + ",");
                }
                else
                {
                    MasterValue.Append("null,");
                }

                MasterField.Append("Weight" + ",");
                if (MasterEntity.Weight != 0)
                {
                    MasterValue.Append(SysString.ToDBString(MasterEntity.Weight) + ",");
                }
                else
                {
                    MasterValue.Append("null,");
                }

                MasterField.Append("CPItemCode" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.CPItemCode) + ",");
                MasterField.Append("CPItemName" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.CPItemName) + ",");
                MasterField.Append("CPItemStd" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.CPItemStd) + ",");
                MasterField.Append("CPItemModel" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.CPItemModel) + ",");
                MasterField.Append("DtsRemark" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.DtsRemark) + ",");
                MasterField.Append("FreeStr1" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.FreeStr1) + ",");
                MasterField.Append("FreeStr2" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.FreeStr2) + ",");
                MasterField.Append("FreeStr3" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.FreeStr3) + ",");
                MasterField.Append("FreeStr4" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.FreeStr4) + ",");
                MasterField.Append("FreeStr5" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.FreeStr5) + ",");
                MasterField.Append("Needle" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.Needle) + ",");
                MasterField.Append("AddFee" + ",");
                if (MasterEntity.AddFee != 0)
                {
                    MasterValue.Append(SysString.ToDBString(MasterEntity.AddFee) + ",");
                }
                else
                {
                    MasterValue.Append("null,");
                }

                MasterField.Append("AddFee2" + ",");
                if (MasterEntity.AddFee2 != 0)
                {
                    MasterValue.Append(SysString.ToDBString(MasterEntity.AddFee2) + ",");
                }
                else
                {
                    MasterValue.Append("null,");
                }

                MasterField.Append("AddFee3" + ",");
                if (MasterEntity.AddFee3 != 0)
                {
                    MasterValue.Append(SysString.ToDBString(MasterEntity.AddFee3) + ",");
                }
                else
                {
                    MasterValue.Append("null,");
                }

                MasterField.Append("AddFee4" + ",");
                if (MasterEntity.AddFee4 != 0)
                {
                    MasterValue.Append(SysString.ToDBString(MasterEntity.AddFee4) + ",");
                }
                else
                {
                    MasterValue.Append("null,");
                }

                MasterField.Append("AddFee5" + ",");
                if (MasterEntity.AddFee5 != 0)
                {
                    MasterValue.Append(SysString.ToDBString(MasterEntity.AddFee5) + ",");
                }
                else
                {
                    MasterValue.Append("null,");
                }

                MasterField.Append("AddFee6" + ",");
                if (MasterEntity.AddFee6 != 0)
                {
                    MasterValue.Append(SysString.ToDBString(MasterEntity.AddFee6) + ",");
                }
                else
                {
                    MasterValue.Append("null,");
                }

                MasterField.Append("Currency" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.Currency) + ",");
                MasterField.Append("StyleNo" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.StyleNo) + ",");
                MasterField.Append("OrderUnit" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.OrderUnit) + ",");
                MasterField.Append("OrderQty" + ",");
                if (MasterEntity.OrderQty != 0)
                {
                    MasterValue.Append(SysString.ToDBString(MasterEntity.OrderQty) + ",");
                }
                else
                {
                    MasterValue.Append("null,");
                }

                MasterField.Append("BCPItemCode" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.BCPItemCode) + ",");
                MasterField.Append("BCPItemStd" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.BCPItemStd) + ",");
                MasterField.Append("BCPItemName" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.BCPItemName) + ",");
                MasterField.Append("BCPItemModel" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.BCPItemModel) + ",");
                MasterField.Append("OrderSinglePrice" + ",");
                if (MasterEntity.OrderSinglePrice != 0)
                {
                    MasterValue.Append(SysString.ToDBString(MasterEntity.OrderSinglePrice) + ",");
                }
                else
                {
                    MasterValue.Append("null,");
                }

                MasterField.Append("BCPColorNum" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.BCPColorNum) + ",");
                MasterField.Append("BCPColorName" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.BCPColorName) + ",");
                MasterField.Append("BCPMWidth" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.BCPMWidth) + ",");
                MasterField.Append("BCPMWeight" + ",");
                MasterValue.Append(SysString.ToDBString(MasterEntity.BCPMWeight) + ",");
                MasterField.Append("BoxQty" + ",");
                if (MasterEntity.BoxQty != 0)
                {
                    MasterValue.Append(SysString.ToDBString(MasterEntity.BoxQty) + ",");
                }
                else
                {
                    MasterValue.Append("null,");
                }

                MasterField.Append("SetQty" + ",");
                if (MasterEntity.SetQty != 0)
                {
                    MasterValue.Append(SysString.ToDBString(MasterEntity.SetQty) + ",");
                }
                else
                {
                    MasterValue.Append("null,");
                }

                MasterField.Append("DozensQty" + ")");
                if (MasterEntity.DozensQty != 0)
                {
                    MasterValue.Append(SysString.ToDBString(MasterEntity.DozensQty) + ")");
                }
                else
                {
                    MasterValue.Append("null)");
                }



                //执行
                int AffectedRows = 0;
                if (!this.sqlTransFlag)
                {
                    AffectedRows = this.ExecuteNonQuery(MasterField.Append(MasterValue.ToString()).ToString());
                }
                else
                {
                    AffectedRows = sqlTrans.ExecuteNonQuery(MasterField.Append(MasterValue.ToString()).ToString());
                }
                return(AffectedRows);
            }
            catch (BaseException E)
            {
                throw new BaseException(E.Message, E);
            }
            catch (Exception E)
            {
                throw new BaseException(FrameWorkMessage.GetAlertMessage((int)Message.CommonDBInsert), E);
            }
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="p_Entity">实体类</param>
        /// <returns>操作影响的记录行数</returns>
        public override int Update(BaseEntity p_Entity)
        {
            try
            {
                ItemBuyFormDts MasterEntity = (ItemBuyFormDts)p_Entity;
                if (MasterEntity.ID == 0)
                {
                    return(0);
                }

                //更新主表数据
                StringBuilder UpdateBuilder = new StringBuilder();
                UpdateBuilder.Append("UPDATE Buy_ItemBuyFormDts SET ");
                UpdateBuilder.Append(" ID=" + SysString.ToDBString(MasterEntity.ID) + ",");
                UpdateBuilder.Append(" MainID=" + SysString.ToDBString(MasterEntity.MainID) + ",");
                UpdateBuilder.Append(" Seq=" + SysString.ToDBString(MasterEntity.Seq) + ",");
                UpdateBuilder.Append(" ItemCode=" + SysString.ToDBString(MasterEntity.ItemCode) + ",");
                UpdateBuilder.Append(" GoodsCode=" + SysString.ToDBString(MasterEntity.GoodsCode) + ",");
                UpdateBuilder.Append(" ColorNum=" + SysString.ToDBString(MasterEntity.ColorNum) + ",");
                UpdateBuilder.Append(" ColorName=" + SysString.ToDBString(MasterEntity.ColorName) + ",");
                UpdateBuilder.Append(" MWidth=" + SysString.ToDBString(MasterEntity.MWidth) + ",");
                UpdateBuilder.Append(" MWeight=" + SysString.ToDBString(MasterEntity.MWeight) + ",");
                UpdateBuilder.Append(" WeightUnit=" + SysString.ToDBString(MasterEntity.WeightUnit) + ",");
                UpdateBuilder.Append(" ItemName=" + SysString.ToDBString(MasterEntity.ItemName) + ",");
                UpdateBuilder.Append(" VColorNum=" + SysString.ToDBString(MasterEntity.VColorNum) + ",");
                UpdateBuilder.Append(" VColorName=" + SysString.ToDBString(MasterEntity.VColorName) + ",");
                UpdateBuilder.Append(" VItemCode=" + SysString.ToDBString(MasterEntity.VItemCode) + ",");

                if (MasterEntity.Qty != 0)
                {
                    UpdateBuilder.Append(" Qty=" + SysString.ToDBString(MasterEntity.Qty) + ",");
                }
                else
                {
                    UpdateBuilder.Append(" Qty=null,");
                }

                UpdateBuilder.Append(" Unit=" + SysString.ToDBString(MasterEntity.Unit) + ",");

                if (MasterEntity.SingPrice != 0)
                {
                    UpdateBuilder.Append(" SingPrice=" + SysString.ToDBString(MasterEntity.SingPrice) + ",");
                }
                else
                {
                    UpdateBuilder.Append(" SingPrice=null,");
                }


                if (MasterEntity.Amount != 0)
                {
                    UpdateBuilder.Append(" Amount=" + SysString.ToDBString(MasterEntity.Amount) + ",");
                }
                else
                {
                    UpdateBuilder.Append(" Amount=null,");
                }


                if (MasterEntity.ReceivedDate != SystemConfiguration.DateTimeDefaultValue)
                {
                    UpdateBuilder.Append(" ReceivedDate=" + SysString.ToDBString(MasterEntity.ReceivedDate.ToString("yyyy-MM-dd HH:mm:ss")) + ",");
                }
                else
                {
                    UpdateBuilder.Append(" ReceivedDate=null,");
                }


                if (MasterEntity.ReceivedQty != 0)
                {
                    UpdateBuilder.Append(" ReceivedQty=" + SysString.ToDBString(MasterEntity.ReceivedQty) + ",");
                }
                else
                {
                    UpdateBuilder.Append(" ReceivedQty=null,");
                }


                if (MasterEntity.TotalRecQty != 0)
                {
                    UpdateBuilder.Append(" TotalRecQty=" + SysString.ToDBString(MasterEntity.TotalRecQty) + ",");
                }
                else
                {
                    UpdateBuilder.Append(" TotalRecQty=null,");
                }


                if (MasterEntity.RemainQty != 0)
                {
                    UpdateBuilder.Append(" RemainQty=" + SysString.ToDBString(MasterEntity.RemainQty) + ",");
                }
                else
                {
                    UpdateBuilder.Append(" RemainQty=null,");
                }


                if (MasterEntity.RemainRate != 0)
                {
                    UpdateBuilder.Append(" RemainRate=" + SysString.ToDBString(MasterEntity.RemainRate) + ",");
                }
                else
                {
                    UpdateBuilder.Append(" RemainRate=null,");
                }

                UpdateBuilder.Append(" OrderPreStatusID=" + SysString.ToDBString(MasterEntity.OrderPreStatusID) + ",");
                UpdateBuilder.Append(" OrderStatusID=" + SysString.ToDBString(MasterEntity.OrderStatusID) + ",");
                UpdateBuilder.Append(" DtsSO=" + SysString.ToDBString(MasterEntity.DtsSO) + ",");
                UpdateBuilder.Append(" DVendorID=" + SysString.ToDBString(MasterEntity.DVendorID) + ",");
                UpdateBuilder.Append(" ItemStd=" + SysString.ToDBString(MasterEntity.ItemStd) + ",");
                UpdateBuilder.Append(" ItemModel=" + SysString.ToDBString(MasterEntity.ItemModel) + ",");
                UpdateBuilder.Append(" Batch=" + SysString.ToDBString(MasterEntity.Batch) + ",");
                UpdateBuilder.Append(" VendorBatch=" + SysString.ToDBString(MasterEntity.VendorBatch) + ",");
                UpdateBuilder.Append(" YarnType=" + SysString.ToDBString(MasterEntity.YarnType) + ",");
                UpdateBuilder.Append(" DLoadID=" + SysString.ToDBString(MasterEntity.DLoadID) + ",");
                UpdateBuilder.Append(" BGNo=" + SysString.ToDBString(MasterEntity.BGNo) + ",");

                if (MasterEntity.PieceQty != 0)
                {
                    UpdateBuilder.Append(" PieceQty=" + SysString.ToDBString(MasterEntity.PieceQty) + ",");
                }
                else
                {
                    UpdateBuilder.Append(" PieceQty=null,");
                }


                if (MasterEntity.Weight != 0)
                {
                    UpdateBuilder.Append(" Weight=" + SysString.ToDBString(MasterEntity.Weight) + ",");
                }
                else
                {
                    UpdateBuilder.Append(" Weight=null,");
                }

                UpdateBuilder.Append(" CPItemCode=" + SysString.ToDBString(MasterEntity.CPItemCode) + ",");
                UpdateBuilder.Append(" CPItemName=" + SysString.ToDBString(MasterEntity.CPItemName) + ",");
                UpdateBuilder.Append(" CPItemStd=" + SysString.ToDBString(MasterEntity.CPItemStd) + ",");
                UpdateBuilder.Append(" CPItemModel=" + SysString.ToDBString(MasterEntity.CPItemModel) + ",");
                UpdateBuilder.Append(" DtsRemark=" + SysString.ToDBString(MasterEntity.DtsRemark) + ",");
                UpdateBuilder.Append(" FreeStr1=" + SysString.ToDBString(MasterEntity.FreeStr1) + ",");
                UpdateBuilder.Append(" FreeStr2=" + SysString.ToDBString(MasterEntity.FreeStr2) + ",");
                UpdateBuilder.Append(" FreeStr3=" + SysString.ToDBString(MasterEntity.FreeStr3) + ",");
                UpdateBuilder.Append(" FreeStr4=" + SysString.ToDBString(MasterEntity.FreeStr4) + ",");
                UpdateBuilder.Append(" FreeStr5=" + SysString.ToDBString(MasterEntity.FreeStr5) + ",");
                UpdateBuilder.Append(" Needle=" + SysString.ToDBString(MasterEntity.Needle) + ",");

                if (MasterEntity.AddFee != 0)
                {
                    UpdateBuilder.Append(" AddFee=" + SysString.ToDBString(MasterEntity.AddFee) + ",");
                }
                else
                {
                    UpdateBuilder.Append(" AddFee=null,");
                }


                if (MasterEntity.AddFee2 != 0)
                {
                    UpdateBuilder.Append(" AddFee2=" + SysString.ToDBString(MasterEntity.AddFee2) + ",");
                }
                else
                {
                    UpdateBuilder.Append(" AddFee2=null,");
                }


                if (MasterEntity.AddFee3 != 0)
                {
                    UpdateBuilder.Append(" AddFee3=" + SysString.ToDBString(MasterEntity.AddFee3) + ",");
                }
                else
                {
                    UpdateBuilder.Append(" AddFee3=null,");
                }


                if (MasterEntity.AddFee4 != 0)
                {
                    UpdateBuilder.Append(" AddFee4=" + SysString.ToDBString(MasterEntity.AddFee4) + ",");
                }
                else
                {
                    UpdateBuilder.Append(" AddFee4=null,");
                }


                if (MasterEntity.AddFee5 != 0)
                {
                    UpdateBuilder.Append(" AddFee5=" + SysString.ToDBString(MasterEntity.AddFee5) + ",");
                }
                else
                {
                    UpdateBuilder.Append(" AddFee5=null,");
                }


                if (MasterEntity.AddFee6 != 0)
                {
                    UpdateBuilder.Append(" AddFee6=" + SysString.ToDBString(MasterEntity.AddFee6) + ",");
                }
                else
                {
                    UpdateBuilder.Append(" AddFee6=null,");
                }

                UpdateBuilder.Append(" Currency=" + SysString.ToDBString(MasterEntity.Currency) + ",");
                UpdateBuilder.Append(" StyleNo=" + SysString.ToDBString(MasterEntity.StyleNo) + ",");
                UpdateBuilder.Append(" OrderUnit=" + SysString.ToDBString(MasterEntity.OrderUnit) + ",");

                if (MasterEntity.OrderQty != 0)
                {
                    UpdateBuilder.Append(" OrderQty=" + SysString.ToDBString(MasterEntity.OrderQty) + ",");
                }
                else
                {
                    UpdateBuilder.Append(" OrderQty=null,");
                }

                UpdateBuilder.Append(" BCPItemCode=" + SysString.ToDBString(MasterEntity.BCPItemCode) + ",");
                UpdateBuilder.Append(" BCPItemStd=" + SysString.ToDBString(MasterEntity.BCPItemStd) + ",");
                UpdateBuilder.Append(" BCPItemName=" + SysString.ToDBString(MasterEntity.BCPItemName) + ",");
                UpdateBuilder.Append(" BCPItemModel=" + SysString.ToDBString(MasterEntity.BCPItemModel) + ",");

                if (MasterEntity.OrderSinglePrice != 0)
                {
                    UpdateBuilder.Append(" OrderSinglePrice=" + SysString.ToDBString(MasterEntity.OrderSinglePrice) + ",");
                }
                else
                {
                    UpdateBuilder.Append(" OrderSinglePrice=null,");
                }

                UpdateBuilder.Append(" BCPColorNum=" + SysString.ToDBString(MasterEntity.BCPColorNum) + ",");
                UpdateBuilder.Append(" BCPColorName=" + SysString.ToDBString(MasterEntity.BCPColorName) + ",");
                UpdateBuilder.Append(" BCPMWidth=" + SysString.ToDBString(MasterEntity.BCPMWidth) + ",");
                UpdateBuilder.Append(" BCPMWeight=" + SysString.ToDBString(MasterEntity.BCPMWeight) + ",");

                if (MasterEntity.BoxQty != 0)
                {
                    UpdateBuilder.Append(" BoxQty=" + SysString.ToDBString(MasterEntity.BoxQty) + ",");
                }
                else
                {
                    UpdateBuilder.Append(" BoxQty=null,");
                }


                if (MasterEntity.SetQty != 0)
                {
                    UpdateBuilder.Append(" SetQty=" + SysString.ToDBString(MasterEntity.SetQty) + ",");
                }
                else
                {
                    UpdateBuilder.Append(" SetQty=null,");
                }


                if (MasterEntity.DozensQty != 0)
                {
                    UpdateBuilder.Append(" DozensQty=" + SysString.ToDBString(MasterEntity.DozensQty));
                }
                else
                {
                    UpdateBuilder.Append(" DozensQty=null");
                }


                UpdateBuilder.Append(" WHERE " + "ID=" + SysString.ToDBString(MasterEntity.ID));



                //执行
                int AffectedRows = 0;
                if (!this.sqlTransFlag)
                {
                    AffectedRows = this.ExecuteNonQuery(UpdateBuilder.ToString());
                }
                else
                {
                    AffectedRows = sqlTrans.ExecuteNonQuery(UpdateBuilder.ToString());
                }
                return(AffectedRows);
            }
            catch (BaseException E)
            {
                throw new BaseException(E.Message, E);
            }
            catch (Exception E)
            {
                throw new BaseException(FrameWorkMessage.GetAlertMessage((int)Message.CommonDBUpdate), E);
            }
        }
 /// <summary>
 /// 检查将要操作的数据是否符合业务规则
 /// </summary>
 /// <param name="p_BE"></param>
 private void CheckCorrect(BaseEntity p_BE)
 {
     ItemBuyFormDts entity = (ItemBuyFormDts)p_BE;
 }
        /// <summary>
        /// 获得实体
        /// </summary>
        /// <returns></returns>
        private ItemBuyFormDts[] EntityDtsGet()
        {
            int index = GetDataCompleteNum();

            ItemBuyFormDts[] entitydts = new ItemBuyFormDts[index];
            index = 0;
            for (int i = 0; i < gridView1.RowCount; i++)
            {
                if (CheckDataCompleteDts(i))
                {
                    entitydts[index]    = new ItemBuyFormDts();
                    entitydts[index].ID = SysConvert.ToInt32(gridView1.GetRowCellValue(i, "ID"));
                    entitydts[index].SelectByID();
                    entitydts[index].MainID = HTDataID;
                    entitydts[index].Seq    = i + 1;

                    entitydts[index].ItemCode  = SysConvert.ToString(gridView1.GetRowCellValue(i, "ItemCode"));
                    entitydts[index].ItemName  = SysConvert.ToString(gridView1.GetRowCellValue(i, "ItemName"));
                    entitydts[index].ItemStd   = SysConvert.ToString(gridView1.GetRowCellValue(i, "ItemStd"));
                    entitydts[index].ItemModel = SysConvert.ToString(gridView1.GetRowCellValue(i, "ItemModel"));


                    entitydts[index].CPItemCode  = SysConvert.ToString(gridView1.GetRowCellValue(i, "CPItemCode"));
                    entitydts[index].CPItemName  = SysConvert.ToString(gridView1.GetRowCellValue(i, "CPItemName"));
                    entitydts[index].CPItemStd   = SysConvert.ToString(gridView1.GetRowCellValue(i, "CPItemStd"));
                    entitydts[index].CPItemModel = SysConvert.ToString(gridView1.GetRowCellValue(i, "CPItemModel"));

                    entitydts[index].Batch      = SysConvert.ToString(gridView1.GetRowCellValue(i, "Batch"));
                    entitydts[index].GoodsCode  = SysConvert.ToString(gridView1.GetRowCellValue(i, "GoodsCode"));
                    entitydts[index].ColorNum   = SysConvert.ToString(gridView1.GetRowCellValue(i, "ColorNum"));
                    entitydts[index].ColorName  = SysConvert.ToString(gridView1.GetRowCellValue(i, "ColorName"));
                    entitydts[index].MWidth     = SysConvert.ToString(gridView1.GetRowCellValue(i, "MWidth"));
                    entitydts[index].MWeight    = SysConvert.ToString(gridView1.GetRowCellValue(i, "MWeight"));
                    entitydts[index].WeightUnit = SysConvert.ToString(gridView1.GetRowCellValue(i, "WeightUnit"));

                    entitydts[index].StyleNo = SysConvert.ToString(gridView1.GetRowCellValue(i, "StyleNo")); //款号


                    entitydts[index].BoxQty    = SysConvert.ToInt32(gridView1.GetRowCellValue(i, "BoxQty"));
                    entitydts[index].SetQty    = SysConvert.ToInt32(gridView1.GetRowCellValue(i, "SetQty"));
                    entitydts[index].DozensQty = SysConvert.ToInt32(gridView1.GetRowCellValue(i, "DozensQty"));

                    entitydts[index].VColorNum  = SysConvert.ToString(gridView1.GetRowCellValue(i, "VColorNum"));
                    entitydts[index].VColorName = SysConvert.ToString(gridView1.GetRowCellValue(i, "VColorName"));
                    entitydts[index].VItemCode  = SysConvert.ToString(gridView1.GetRowCellValue(i, "VItemCode"));

                    entitydts[index].PieceQty = SysConvert.ToInt32(gridView1.GetRowCellValue(i, "PieceQty"));
                    entitydts[index].Weight   = SysConvert.ToDecimal(gridView1.GetRowCellValue(i, "Weight"));

                    entitydts[index].Qty = SysConvert.ToDecimal(gridView1.GetRowCellValue(i, "Qty"));
                    //entitydts[index].Qty = entitydts[index].PieceQty * entitydts[index].Weight;

                    entitydts[index].Unit      = SysConvert.ToString(gridView1.GetRowCellValue(i, "Unit"));
                    entitydts[index].SingPrice = SysConvert.ToDecimal(gridView1.GetRowCellValue(i, "SingPrice"));
                    entitydts[index].AddFee    = SysConvert.ToDecimal(gridView1.GetRowCellValue(i, "AddFee"));
                    entitydts[index].AddFee2   = SysConvert.ToDecimal(gridView1.GetRowCellValue(i, "AddFee2"));
                    entitydts[index].AddFee3   = SysConvert.ToDecimal(gridView1.GetRowCellValue(i, "AddFee3"));
                    entitydts[index].AddFee4   = SysConvert.ToDecimal(gridView1.GetRowCellValue(i, "AddFee4"));
                    entitydts[index].AddFee5   = SysConvert.ToDecimal(gridView1.GetRowCellValue(i, "AddFee5"));
                    entitydts[index].AddFee6   = SysConvert.ToDecimal(gridView1.GetRowCellValue(i, "AddFee6"));
                    entitydts[index].Currency  = SysConvert.ToString(gridView1.GetRowCellValue(i, "Currency"));

                    entitydts[index].Amount    = (entitydts[index].Qty * entitydts[index].SingPrice) + entitydts[index].AddFee + entitydts[index].AddFee2 + entitydts[index].AddFee3 + entitydts[index].AddFee4 + entitydts[index].AddFee5;
                    entitydts[index].RemainQty = entitydts[index].Qty - entitydts[index].TotalRecQty;
                    if (entitydts[index].Qty > 0)
                    {
                        entitydts[index].RemainRate = entitydts[index].RemainQty / entitydts[index].Qty;
                    }

                    entitydts[index].OrderPreStatusID = SysConvert.ToInt32(gridView1.GetRowCellValue(i, "OrderPreStatusID"));
                    entitydts[index].OrderStatusID    = SysConvert.ToInt32(gridView1.GetRowCellValue(i, "OrderStatusID"));
                    entitydts[index].DVendorID        = SysConvert.ToString(gridView1.GetRowCellValue(i, "DVendorID"));
                    entitydts[index].DtsSO            = SysConvert.ToString(gridView1.GetRowCellValue(i, "DtsSO"));
                    entitydts[index].DLoadID          = SysConvert.ToInt32(gridView1.GetRowCellValue(i, "DLoadID"));



                    entitydts[index].DtsRemark = SysConvert.ToString(gridView1.GetRowCellValue(i, "DtsRemark"));
                    entitydts[index].FreeStr1  = SysConvert.ToString(gridView1.GetRowCellValue(i, "FreeStr1"));// 高雅利花本号
                    entitydts[index].FreeStr2  = SysConvert.ToString(gridView1.GetRowCellValue(i, "FreeStr2"));
                    entitydts[index].FreeStr3  = SysConvert.ToString(gridView1.GetRowCellValue(i, "FreeStr3"));
                    entitydts[index].FreeStr4  = SysConvert.ToString(gridView1.GetRowCellValue(i, "FreeStr4"));
                    entitydts[index].FreeStr5  = SysConvert.ToString(gridView1.GetRowCellValue(i, "FreeStr5"));
                    entitydts[index].Needle    = SysConvert.ToString(gridView1.GetRowCellValue(i, "Needle"));

                    entitydts[index].OrderUnit = SysConvert.ToString(gridView1.GetRowCellValue(i, "OrderUnit"));
                    entitydts[index].OrderQty  = SysConvert.ToDecimal(gridView1.GetRowCellValue(i, "OrderQty"));

                    index++;
                }
            }
            return(entitydts);
        }