/// <summary> /// 删除 /// </summary> /// <param name="p_Entity">实体类</param> /// <returns>操作影响的记录行数</returns> public override int Delete(BaseEntity p_Entity) { try { ItemColorDts MasterEntity = (ItemColorDts)p_Entity; if (MasterEntity.ID == 0) { return(0); } //删除主表数据 string Sql = ""; Sql = "DELETE FROM Data_ItemColorDts 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> /// <param name="p_Entity"></param> /// <param name="p_BE"></param> /// <param name="sqlTrans"></param> public void RSave(Item p_Entity, BaseEntity[] p_BE, IDBTransAccess sqlTrans) { try { string sql = "DELETE FROM Data_ItemColorDts 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++) { ItemColorDts entitydts = (ItemColorDts)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); } }
private ItemColorDts getEntity() { int id = SysConvert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DtsID")); // 取到itemColor里的ID ItemColorDts entity = new ItemColorDts(); entity.ID = id; entity.SelectByID(); return(entity); }
/// <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++) { ItemColorDts entitydts = (ItemColorDts)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); ItemColorDts entity = (ItemColorDts)p_BE; ItemColorDtsCtl control = new ItemColorDtsCtl(sqlTrans); control.Delete(entity); } catch (BaseException) { throw; } catch (Exception E) { throw new BaseException(E.Message); } }
/// <summary> /// 获取颜色信息实体 /// </summary> /// <returns></returns> private ItemColorDts[] GetItemColorDts() { int Num = 0; for (int i = 0; i < gridView3.RowCount; i++) { if (SysConvert.ToString(gridView3.GetRowCellValue(i, "VendorID")) != string.Empty || SysConvert.ToString(gridView3.GetRowCellValue(i, "ColorNum")) != string.Empty || SysConvert.ToString(gridView3.GetRowCellValue(i, "ColorName")) != string.Empty) { Num++; } } ItemColorDts[] entitydts = new ItemColorDts[Num]; int index = 0; for (int i = 0; i < gridView3.RowCount; i++) { if (SysConvert.ToString(gridView3.GetRowCellValue(i, "VendorID")) != string.Empty || SysConvert.ToString(gridView3.GetRowCellValue(i, "ColorNum")) != string.Empty || SysConvert.ToString(gridView3.GetRowCellValue(i, "ColorName")) != string.Empty) { entitydts[index] = new ItemColorDts(); entitydts[index].ID = SysConvert.ToInt32(gridView3.GetRowCellValue(i, "ID")); entitydts[index].SelectByID(); entitydts[index].MainID = HTDataID; entitydts[index].Seq = i + 1; entitydts[index].ColorNum = SysConvert.ToString(gridView3.GetRowCellValue(i, "ColorNum")); entitydts[index].VendorID = SysConvert.ToString(gridView3.GetRowCellValue(i, "VendorID")); entitydts[index].DyePrice = SysConvert.ToDecimal(gridView3.GetRowCellValue(i, "DyePrice")); entitydts[index].ColorName = SysConvert.ToString(gridView3.GetRowCellValue(i, "ColorName")); entitydts[index].BuyPrice = SysConvert.ToDecimal(gridView3.GetRowCellValue(i, "BuyPrice")); entitydts[index].BuyPriceDate = SysConvert.ToDateTime(gridView3.GetRowCellValue(i, "BuyPriceDate")); entitydts[index].SalePrice = SysConvert.ToDecimal(gridView3.GetRowCellValue(i, "SalePrice")); entitydts[index].SalePriceDate = SysConvert.ToDateTime(gridView3.GetRowCellValue(i, "SalePriceDate")); entitydts[index].DHPrice = SysConvert.ToDecimal(gridView3.GetRowCellValue(i, "DHPrice")); entitydts[index].YBPrice = SysConvert.ToDecimal(gridView3.GetRowCellValue(i, "YBPrice")); entitydts[index].XHPrice = SysConvert.ToDecimal(gridView3.GetRowCellValue(i, "XHPrice")); entitydts[index].Remark = SysConvert.ToString(gridView3.GetRowCellValue(i, "Remark")); index++; } } return(entitydts); }
/// <summary> /// 新增(传入事务处理) /// </summary> /// <param name="p_BE">要新增的实体</param> /// <param name="sqlTrans">事务类</param> public void RAdd(BaseEntity p_BE, IDBTransAccess sqlTrans) { try { this.CheckCorrect(p_BE); ItemColorDts entity = (ItemColorDts)p_BE; ItemColorDtsCtl control = new ItemColorDtsCtl(sqlTrans); entity.ID = (int)EntityIDTable.GetID((long)SysEntity.Data_ItemColorDts, sqlTrans); control.AddNew(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 RUpdate(BaseEntity p_BE, IDBTransAccess sqlTrans) { try { this.CheckCorrect(p_BE); ItemColorDts entity = (ItemColorDts)p_BE; ItemColorDtsCtl control = new ItemColorDtsCtl(sqlTrans); control.Update(entity); ItemColorDtsHisRule hisrule = new ItemColorDtsHisRule(); hisrule.RSave(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 RSave(ItemColorDts p_Entity, IDBTransAccess sqlTrans) { try { if (p_Entity.BuyPrice == 0 && p_Entity.SalePrice == 0)//价格均为0,直接跳出 { return; } ParamSetRule psrule = new ParamSetRule(); int dayNum = psrule.RShowIntByCode((int)ParamSetEnum.产品价格管理历史价格检验天数); if (dayNum <= 0) { dayNum = 3; } string sql = ""; sql = "SELECT TOP 1 ID FROM Data_ItemColorDtsHis WHERE MainID=" + p_Entity.MainID + " AND ColorNum=" + SysString.ToDBString(p_Entity.ColorNum); sql += " ORDER BY Seq DESC"; //采购价、销售价 DataTable dt = sqlTrans.Fill(sql); ItemColorDtsHis entityLast = new ItemColorDtsHis(sqlTrans); //最近一次历史 bool addNewHisFlag = false; if (dt.Rows.Count != 0) { entityLast.ID = SysConvert.ToInt32(dt.Rows[0]["ID"]); entityLast.SelectByID(); if (entityLast.BuyPriceDate.AddDays(dayNum) < DateTime.Now)//说明是三天之前的了 { addNewHisFlag = true; } } else//没有找到历史记录 { addNewHisFlag = true; } if (addNewHisFlag) //需要新增加历史记录 { if (entityLast.ID != 0) //有历史 { if (entityLast.BuyPrice != p_Entity.BuyPrice || entityLast.SalePrice != p_Entity.SalePrice) //价格有不同则增加 { ItemColorDtsHis entity = new ItemColorDtsHis(sqlTrans); entity.MainID = p_Entity.MainID; entity.Seq = entityLast.Seq + 1; entity.ColorNum = p_Entity.ColorNum; entity.ColorName = p_Entity.ColorName; entity.BuyPrice = p_Entity.BuyPrice; entity.BuyPriceDate = p_Entity.BuyPriceDate; entity.SalePrice = p_Entity.SalePrice; entity.SalePriceDate = p_Entity.SalePriceDate; this.RAdd(entity, sqlTrans); } else//价格和历史完全一样,不保存 { } } else//没有历史,直接增加 { ItemColorDtsHis entity = new ItemColorDtsHis(sqlTrans); entity.MainID = p_Entity.MainID; entity.Seq = 1; entity.ColorNum = p_Entity.ColorNum; entity.ColorName = p_Entity.ColorName; entity.BuyPrice = p_Entity.BuyPrice; entity.BuyPriceDate = p_Entity.BuyPriceDate; entity.SalePrice = p_Entity.SalePrice; entity.SalePriceDate = p_Entity.SalePriceDate; this.RAdd(entity, sqlTrans); } } else//不增加历史,就更新为最新的价格即可 { entityLast.BuyPrice = p_Entity.BuyPrice; entityLast.SalePrice = p_Entity.SalePrice; this.RUpdate(entityLast, sqlTrans); } } catch (BaseException) { throw; } catch (Exception E) { throw new BaseException(E.Message); } }
/// <summary> /// 新增(传入事务处理) /// </summary> /// <param name="p_BE">要新增的实体</param> /// <param name="p_BE3">原料</param> /// <param name="p_BE4">颜色</param> /// <param name="p_BE5">类别</param> /// <param name="p_BE6">物理指标</param> /// <param name="p_BE7">替代白坯</param> /// <param name="p_BE8">工厂编码及报价</param> /// <param name="sqlTrans">事务类</param> public void RAdd(BaseEntity p_BE, BaseEntity[] p_BE3, BaseEntity[] p_BE4, BaseEntity[] p_BE5, BaseEntity[] p_BE6, BaseEntity[] p_BE7, BaseEntity[] p_BE8, IDBTransAccess sqlTrans) { try { this.CheckCorrect(p_BE); Item entity = (Item)p_BE; this.RAdd(p_BE, sqlTrans); for (int i = 0; i < p_BE3.Length; i++) { ItemDtsRule rule = new ItemDtsRule(); ItemDts entityItemDts = (ItemDts)p_BE3[i]; entityItemDts.MainID = entity.ID; entityItemDts.Seq = i + 1; rule.RAdd(entityItemDts, sqlTrans); } for (int i = 0; i < p_BE4.Length; i++) { ItemColorDtsRule rule = new ItemColorDtsRule(); ItemColorDts entityItemColorDts = (ItemColorDts)p_BE4[i]; entityItemColorDts.MainID = entity.ID; entityItemColorDts.Seq = i + 1; rule.RAdd(entityItemColorDts, sqlTrans); } for (int i = 0; i < p_BE5.Length; i++) { ItemLBDtsRule rule = new ItemLBDtsRule(); ItemLBDts entityItemLBDts = (ItemLBDts)p_BE5[i]; entityItemLBDts.MainID = entity.ID; entityItemLBDts.Seq = i + 1; rule.RAdd(entityItemLBDts, sqlTrans); } if (p_BE6 != null) { for (int i = 0; i < p_BE6.Length; i++) { ItemCheckStandardPhyRule rule = new ItemCheckStandardPhyRule(); ItemCheckStandardPhy entityItemcsp = (ItemCheckStandardPhy)p_BE6[i]; entityItemcsp.MainID = entity.ID; entityItemcsp.Seq = i + 1; rule.RAdd(entityItemcsp, sqlTrans); } } if (p_BE7 != null) { for (int i = 0; i < p_BE7.Length; i++) { ItemGreyFabReplaceRule rule = new ItemGreyFabReplaceRule(); ItemGreyFabReplace entityItemgfr = (ItemGreyFabReplace)p_BE7[i]; entityItemgfr.MainID = entity.ID; entityItemgfr.Seq = i + 1; rule.RAdd(entityItemgfr, sqlTrans); } } if (p_BE8 != null) { for (int i = 0; i < p_BE8.Length; i++) { ItemCodeFacDtsRule rule = new ItemCodeFacDtsRule(); ItemCodeFacDts entityItemfac = (ItemCodeFacDts)p_BE8[i]; entityItemfac.MainID = entity.ID; entityItemfac.Seq = i + 1; rule.RAdd(entityItemfac, sqlTrans); } } //FormNoControlRule rulefSt = new FormNoControlRule(); //rulefSt.RAddSort((int)FormNoControlEnum.产品编码, sqlTrans); } catch (BaseException) { throw; } catch (Exception E) { throw new BaseException(E.Message); } }
/// <summary> /// 检查将要操作的数据是否符合业务规则 /// </summary> /// <param name="p_BE"></param> private void CheckCorrect(BaseEntity p_BE) { ItemColorDts entity = (ItemColorDts)p_BE; }
/// <summary> /// 新增 /// </summary> /// <param name="p_Entity">实体类</param> /// <returns>操作影响的记录行数</returns> public override int AddNew(BaseEntity p_Entity) { try { ItemColorDts MasterEntity = (ItemColorDts)p_Entity; if (MasterEntity.ID == 0) { return(0); } //新增主表数据 StringBuilder MasterField = new StringBuilder(); StringBuilder MasterValue = new StringBuilder(); MasterField.Append("INSERT INTO Data_ItemColorDts("); 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("ColorNum" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.ColorNum) + ","); MasterField.Append("ColorName" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.ColorName) + ","); MasterField.Append("BuyPrice" + ","); if (MasterEntity.BuyPrice != 0) { MasterValue.Append(SysString.ToDBString(MasterEntity.BuyPrice) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("BuyPriceDate" + ","); if (MasterEntity.BuyPriceDate != SystemConfiguration.DateTimeDefaultValue) { MasterValue.Append(SysString.ToDBString(MasterEntity.BuyPriceDate.ToString("yyyy-MM-dd HH:mm:ss")) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("SalePrice" + ","); if (MasterEntity.SalePrice != 0) { MasterValue.Append(SysString.ToDBString(MasterEntity.SalePrice) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("SalePriceDate" + ","); if (MasterEntity.SalePriceDate != SystemConfiguration.DateTimeDefaultValue) { MasterValue.Append(SysString.ToDBString(MasterEntity.SalePriceDate.ToString("yyyy-MM-dd HH:mm:ss")) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("Remark" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.Remark) + ","); MasterField.Append("DHPrice" + ","); if (MasterEntity.DHPrice != 0) { MasterValue.Append(SysString.ToDBString(MasterEntity.DHPrice) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("XHPrice" + ","); if (MasterEntity.XHPrice != 0) { MasterValue.Append(SysString.ToDBString(MasterEntity.XHPrice) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("YBPrice" + ","); if (MasterEntity.YBPrice != 0) { MasterValue.Append(SysString.ToDBString(MasterEntity.YBPrice) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("VendorID" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.VendorID) + ","); MasterField.Append("DyePrice" + ","); if (MasterEntity.DyePrice != 0) { MasterValue.Append(SysString.ToDBString(MasterEntity.DyePrice) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("RS" + ")"); if (MasterEntity.RS != 0) { MasterValue.Append(SysString.ToDBString(MasterEntity.RS) + ")"); } 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 { ItemColorDts MasterEntity = (ItemColorDts)p_Entity; if (MasterEntity.ID == 0) { return(0); } //更新主表数据 StringBuilder UpdateBuilder = new StringBuilder(); UpdateBuilder.Append("UPDATE Data_ItemColorDts SET "); UpdateBuilder.Append(" ID=" + SysString.ToDBString(MasterEntity.ID) + ","); UpdateBuilder.Append(" MainID=" + SysString.ToDBString(MasterEntity.MainID) + ","); UpdateBuilder.Append(" Seq=" + SysString.ToDBString(MasterEntity.Seq) + ","); UpdateBuilder.Append(" ColorNum=" + SysString.ToDBString(MasterEntity.ColorNum) + ","); UpdateBuilder.Append(" ColorName=" + SysString.ToDBString(MasterEntity.ColorName) + ","); if (MasterEntity.BuyPrice != 0) { UpdateBuilder.Append(" BuyPrice=" + SysString.ToDBString(MasterEntity.BuyPrice) + ","); } else { UpdateBuilder.Append(" BuyPrice=null,"); } if (MasterEntity.BuyPriceDate != SystemConfiguration.DateTimeDefaultValue) { UpdateBuilder.Append(" BuyPriceDate=" + SysString.ToDBString(MasterEntity.BuyPriceDate.ToString("yyyy-MM-dd HH:mm:ss")) + ","); } else { UpdateBuilder.Append(" BuyPriceDate=null,"); } if (MasterEntity.SalePrice != 0) { UpdateBuilder.Append(" SalePrice=" + SysString.ToDBString(MasterEntity.SalePrice) + ","); } else { UpdateBuilder.Append(" SalePrice=null,"); } if (MasterEntity.SalePriceDate != SystemConfiguration.DateTimeDefaultValue) { UpdateBuilder.Append(" SalePriceDate=" + SysString.ToDBString(MasterEntity.SalePriceDate.ToString("yyyy-MM-dd HH:mm:ss")) + ","); } else { UpdateBuilder.Append(" SalePriceDate=null,"); } UpdateBuilder.Append(" Remark=" + SysString.ToDBString(MasterEntity.Remark) + ","); if (MasterEntity.DHPrice != 0) { UpdateBuilder.Append(" DHPrice=" + SysString.ToDBString(MasterEntity.DHPrice) + ","); } else { UpdateBuilder.Append(" DHPrice=null,"); } if (MasterEntity.XHPrice != 0) { UpdateBuilder.Append(" XHPrice=" + SysString.ToDBString(MasterEntity.XHPrice) + ","); } else { UpdateBuilder.Append(" XHPrice=null,"); } if (MasterEntity.YBPrice != 0) { UpdateBuilder.Append(" YBPrice=" + SysString.ToDBString(MasterEntity.YBPrice) + ","); } else { UpdateBuilder.Append(" YBPrice=null,"); } UpdateBuilder.Append(" VendorID=" + SysString.ToDBString(MasterEntity.VendorID) + ","); if (MasterEntity.DyePrice != 0) { UpdateBuilder.Append(" DyePrice=" + SysString.ToDBString(MasterEntity.DyePrice) + ","); } else { UpdateBuilder.Append(" DyePrice=null,"); } if (MasterEntity.RS != 0) { UpdateBuilder.Append(" RS=" + SysString.ToDBString(MasterEntity.RS)); } else { UpdateBuilder.Append(" RS=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); } }