/// <summary> /// 新增(传入事务处理) /// </summary> /// <param name="p_BE">要新增的实体</param> /// <param name="sqlTrans">事务类</param> public void RAdd(BaseEntity p_BE, BaseEntity[] p_BE2, BaseEntity[] p_BE3, BaseEntity[] p_BE4, BaseEntity[] p_BE5, int Flag, IDBTransAccess sqlTrans) { try { this.CheckCorrect(p_BE); Item entity = (Item)p_BE; string sql = "SELECT ItemCode FROM Data_Item WHERE ItemCode=" + SysString.ToDBString(entity.ItemCode); DataTable dt = sqlTrans.Fill(sql); if (dt.Rows.Count > 0) { throw new BaseException("编码已存在,请重新生成"); } ItemCtl control = new ItemCtl(sqlTrans); entity.ID = (int)EntityIDTable.GetID((long)SysEntity.Data_Item, sqlTrans); control.AddNew(entity); ItemColorDtsRule rule2 = new ItemColorDtsRule(); rule2.RSave(entity, p_BE2, sqlTrans); ItemAddRule ruleItemAdd = new ItemAddRule(); for (int i = 0; i < p_BE3.Length; i++) { ItemAdd entityDts = (ItemAdd)p_BE3[i]; entityDts.MainID = entity.ID; entityDts.Seq = i + 1; ruleItemAdd.RAdd(entityDts, sqlTrans); ruleItemAdd.UpdateFiledSet(entity.ID, entityDts.FiledSetID, entityDts.Value, sqlTrans); } ItemPicRule ruleItemPic = new ItemPicRule(); for (int i = 0; i < p_BE4.Length; i++) { ItemPic entityDts = (ItemPic)p_BE4[i]; entityDts.MainID = entity.ID; entityDts.Seq = i + 1; ruleItemPic.RAdd(entityDts, sqlTrans); } ItemCodeFacDtsRule ruleItemCodeFac = new ItemCodeFacDtsRule(); for (int i = 0; i < p_BE5.Length; i++) { ItemCodeFacDts entityDts = (ItemCodeFacDts)p_BE5[i]; entityDts.MainID = entity.ID; entityDts.Seq = i + 1; ruleItemCodeFac.RAdd(entityDts, 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 RUpdate(BaseEntity p_BE, BaseEntity[] p_BE2, BaseEntity[] p_BE3, BaseEntity[] p_BE4, BaseEntity[] p_BE5, int Flag, IDBTransAccess sqlTrans) { try { this.CheckCorrect(p_BE); Item entity = (Item)p_BE; string sql = "SELECT ItemCode FROM Data_Item WHERE ItemCode=" + SysString.ToDBString(entity.ItemCode) + " AND ID<>" + entity.ID; DataTable dt = sqlTrans.Fill(sql); if (dt.Rows.Count > 0) { throw new BaseException("编码已存在,请重新生成"); } ItemCtl control = new ItemCtl(sqlTrans); control.Update(entity); ItemColorDtsRule rule2 = new ItemColorDtsRule(); rule2.RSave(entity, p_BE2, sqlTrans); if (p_BE3.Length > 0) { sql = "DELETE Data_ItemAdd WHERE MainID=" + SysString.ToDBString(entity.ID); sql += " AND ISNULL(FormID,0)=" + SysString.ToDBString(((ItemAdd)p_BE3[0]).FormID); sql += " AND ISNULL(FormAID,0)=" + SysString.ToDBString(((ItemAdd)p_BE3[0]).FormAID); sql += " AND ISNULL(FormBID,0)=" + SysString.ToDBString(((ItemAdd)p_BE3[0]).FormBID); sqlTrans.ExecuteNonQuery(sql); } ItemAddRule ruleItemAdd = new ItemAddRule(); for (int i = 0; i < p_BE3.Length; i++) { ItemAdd entityDts = (ItemAdd)p_BE3[i]; entityDts.MainID = entity.ID; entityDts.Seq = i + 1; ruleItemAdd.RAdd(entityDts, sqlTrans); ruleItemAdd.UpdateFiledSet(entity.ID, entityDts.FiledSetID, entityDts.Value, sqlTrans); } sql = "DELETE Data_ItemPic WHERE MainID=" + SysString.ToDBString(entity.ID); sqlTrans.ExecuteNonQuery(sql); ItemPicRule ruleItemPic = new ItemPicRule(); for (int i = 0; i < p_BE4.Length; i++) { ItemPic entityDts = (ItemPic)p_BE4[i]; entityDts.MainID = entity.ID; entityDts.Seq = i + 1; ruleItemPic.RAdd(entityDts, sqlTrans); } sql = "DELETE Data_ItemCodeFacDts WHERE MainID=" + SysString.ToDBString(entity.ID); sqlTrans.ExecuteNonQuery(sql); ItemCodeFacDtsRule ruleItemCodeFac = new ItemCodeFacDtsRule(); for (int i = 0; i < p_BE5.Length; i++) { ItemCodeFacDts entityDts = (ItemCodeFacDts)p_BE5[i]; entityDts.MainID = entity.ID; entityDts.Seq = i + 1; ruleItemCodeFac.RAdd(entityDts, 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 RUpdate(BaseEntity p_BE, BaseEntity[] p_BE2, BaseEntity[] p_BE3, BaseEntity[] p_BE4, int p_Flag, IDBTransAccess sqlTrans) { try { this.CheckCorrect(p_BE); Item entity = (Item)p_BE; string sql = "SELECT ItemCode FROM Data_Item WHERE ItemCode=" + SysString.ToDBString(entity.ItemCode) + " AND ID<>" + entity.ID; DataTable dt = sqlTrans.Fill(sql); if (dt.Rows.Count > 0) { throw new BaseException("编码已存在,请重新生成"); } ItemCtl control = new ItemCtl(sqlTrans); control.Update(entity); ItemColorDtsRule rule2 = new ItemColorDtsRule(); rule2.RSave(entity, p_BE2, sqlTrans); if (p_BE3.Length > 0) { sql = "DELETE Data_ItemAdd WHERE MainID=" + SysString.ToDBString(entity.ID); sql += " AND ISNULL(FormID,0)=" + SysString.ToDBString(((ItemAdd)p_BE3[0]).FormID); sql += " AND ISNULL(FormAID,0)=" + SysString.ToDBString(((ItemAdd)p_BE3[0]).FormAID); sql += " AND ISNULL(FormBID,0)=" + SysString.ToDBString(((ItemAdd)p_BE3[0]).FormBID); sqlTrans.ExecuteNonQuery(sql); } ItemAddRule ruleItemAdd = new ItemAddRule(); for (int i = 0; i < p_BE3.Length; i++) { ItemAdd entityDts = (ItemAdd)p_BE3[i]; entityDts.MainID = entity.ID; entityDts.Seq = i + 1; ruleItemAdd.RAdd(entityDts, sqlTrans); ruleItemAdd.UpdateFiledSet(entity.ID, entityDts.FiledSetID, entityDts.Value, sqlTrans); } sql = "DELETE Data_ItemPic WHERE MainID=" + SysString.ToDBString(entity.ID); sqlTrans.ExecuteNonQuery(sql); ItemPicRule ruleItemPic = new ItemPicRule(); for (int i = 0; i < p_BE4.Length; i++) { ItemPic entityDts = (ItemPic)p_BE4[i]; entityDts.MainID = entity.ID; entityDts.Seq = i + 1; ruleItemPic.RAdd(entityDts, sqlTrans); } #region cost自动计算 entity = new Item(sqlTrans); entity.ID = ((Item)p_BE).ID; entity.SelectByID(); decimal Cost = 0; decimal PBPrice = entity.PBPrice;//坯价格 decimal RShrinkage = GetDecimalByString(entity.RShrinkage, '%'); decimal RSAmount = entity.RSAmount; decimal RSSH = GetDecimalByString(entity.RSSH, '%'); decimal JGAmount = entity.JGAmount; decimal JGSH = GetDecimalByString(entity.JGSH, '%'); decimal HZAmount = entity.HZAmount; decimal ProfitMargin = GetDecimalByString(entity.ProfitMargin, '%'); decimal Quot = GetDecimalByString(entity.COST, '/') * (1m + (ProfitMargin / 100m)); Cost = (((PBPrice * (1m + (RShrinkage / 100m)) + RSAmount) * (1m + (RSSH / 100m)) + JGAmount) * (1m + (JGSH / 100m)) + HZAmount) * 1.06m + 0.2m; Cost = SysConvert.ToDecimal(Cost, 2); //Quot = SysConvert.ToDecimal(Quot, 2); sql = "UPDATE Data_Item SET COSTA=" + SysString.ToDBString(Cost.ToString() + "/M"); //sql += ",QUOT="+SysString.ToDBString(Quot.ToString()+"/M"); sql += " WHERE ID=" + SysString.ToDBString(entity.ID); sqlTrans.ExecuteNonQuery(sql); sql = "UPDATE Data_ItemAdd SET Value=" + SysString.ToDBString(Cost.ToString() + "/M"); sql += " WHERE FiledName='COSTA'";// +SysString.ToDBString(entity.ID); sql += " AND MainID=" + SysString.ToDBString(entity.ID); sqlTrans.ExecuteNonQuery(sql); //sql = "UPDATE Data_ItemAdd SET Value=" + SysString.ToDBString(Quot.ToString() + "/M"); //sql += " WHERE FiledName='QUOT'";// +SysString.ToDBString(entity.ID); //sql += " AND MainID=" + SysString.ToDBString(entity.ID); //sqlTrans.ExecuteNonQuery(sql); #endregion } catch (BaseException) { throw; } catch (Exception E) { throw new BaseException(E.Message); } }