/// <summary> /// 删除 /// </summary> /// <param name="p_Entity">实体类</param> /// <returns>操作影响的记录行数</returns> public override int Delete(BaseEntity p_Entity) { try { ItemDts MasterEntity = (ItemDts)p_Entity; if (MasterEntity.ID == 0) { return(0); } //删除主表数据 string Sql = ""; Sql = "DELETE FROM Data_ItemDts 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_BE">要新增的实体</param> /// <param name="sqlTrans">事务类</param> public void RAddYarn(BaseEntity p_BE, BaseEntity[] p_BE2, IDBTransAccess sqlTrans) { try { this.CheckCorrect(p_BE); Item entity = (Item)p_BE; this.RAdd(p_BE, sqlTrans); for (int i = 0; i < p_BE2.Length; i++) { ItemDtsRule rule = new ItemDtsRule(); ItemDts entityItemDts = (ItemDts)p_BE2[i]; entityItemDts.MainID = entity.ID; entityItemDts.Seq = i + 1; rule.RAdd(entityItemDts, sqlTrans); } ; } catch (BaseException) { throw; } catch (Exception E) { throw new BaseException(E.Message); } }
/// <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_ItemDts 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++) { ItemDts entitydts = (ItemDts)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> /// <returns></returns> private ItemDts[] GetItemDts() { int Num = 0; for (int i = 0; i < gridView1.RowCount; i++) { if (SysConvert.ToString(gridView1.GetRowCellValue(i, "DtsItemCode")) != string.Empty) { Num++; } } ItemDts[] entitydts = new ItemDts[Num]; int index = 0; for (int i = 0; i < gridView1.RowCount; i++) { if (SysConvert.ToString(gridView1.GetRowCellValue(i, "DtsItemCode")) != string.Empty) { entitydts[index] = new ItemDts(); entitydts[index].ID = SysConvert.ToInt32(gridView1.GetRowCellValue(i, "ID")); entitydts[index].SelectByID(); entitydts[index].MainID = HTDataID; entitydts[index].Seq = i + 1; entitydts[index].DtsItemCode = SysConvert.ToString(gridView1.GetRowCellValue(i, "DtsItemCode")); entitydts[index].DtsItemName = SysConvert.ToString(gridView1.GetRowCellValue(i, "DtsItemName")); entitydts[index].DtsItemStd = SysConvert.ToString(gridView1.GetRowCellValue(i, "DtsItemStd")); entitydts[index].DtsItemModel = SysConvert.ToString(gridView1.GetRowCellValue(i, "DtsItemModel")); entitydts[index].Percentage = SysConvert.ToDecimal(gridView1.GetRowCellValue(i, "Percentage")); entitydts[index].Loss = SysConvert.ToDecimal(gridView1.GetRowCellValue(i, "Loss")); entitydts[index].PerMiWeight = SysConvert.ToDecimal(txtPerMiWeight.Text.Trim()) * (entitydts[index].Percentage / 100m) * (1 + entitydts[index].Loss);//SysConvert.ToDecimal(gridView2.GetRowCellValue(i, "PerMiWeight")); entitydts[index].GoodsCode = SysConvert.ToString(gridView1.GetRowCellValue(i, "GoodsCode")); entitydts[index].MWidth = SysConvert.ToString(gridView1.GetRowCellValue(i, "MWidth")); entitydts[index].MWeight = SysConvert.ToString(gridView1.GetRowCellValue(i, "MWeight")); entitydts[index].MWeight2 = SysConvert.ToString(gridView1.GetRowCellValue(i, "MWeight2")); entitydts[index].FactoryID = SysConvert.ToString(gridView1.GetRowCellValue(i, "FactoryID")); entitydts[index].VendorID = SysConvert.ToString(gridView1.GetRowCellValue(i, "VendorID")); entitydts[index].Price = SysConvert.ToDecimal(gridView1.GetRowCellValue(i, "Price")); entitydts[index].FormDate = SysConvert.ToDateTime(gridView1.GetRowCellValue(i, "FormDate")); entitydts[index].ReqDate = SysConvert.ToString(gridView1.GetRowCellValue(i, "ReqDate")); entitydts[index].MinQty = SysConvert.ToString(gridView1.GetRowCellValue(i, "MinQty")); entitydts[index].Remark = SysConvert.ToString(gridView1.GetRowCellValue(i, "Remark")); 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++) { ItemDts entitydts = (ItemDts)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); ItemDts entity = (ItemDts)p_BE; ItemDtsCtl control = new ItemDtsCtl(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, IDBTransAccess sqlTrans) { try { this.CheckCorrect(p_BE); ItemDts entity = (ItemDts)p_BE; ItemDtsCtl control = new ItemDtsCtl(sqlTrans); entity.ID = (int)EntityIDTable.GetID((long)SysEntity.Data_ItemDts, sqlTrans); control.AddNew(entity); } catch (BaseException) { throw; } catch (Exception E) { throw new BaseException(E.Message); } }
/// <summary> /// 获取颜色信息实体 /// </summary> /// <returns></returns> private ItemDts[] GetItemDts() { int Num = 0; for (int i = 0; i < gridView1.RowCount; i++) { if (SysConvert.ToString(gridView1.GetRowCellValue(i, "DtsItemCode")) != string.Empty) { Num++; } } ItemDts[] entitydts = new ItemDts[Num]; int index = 0; for (int i = 0; i < gridView1.RowCount; i++) { if (SysConvert.ToString(gridView1.GetRowCellValue(i, "DtsItemCode")) != string.Empty) { entitydts[index] = new ItemDts(); entitydts[index].ID = SysConvert.ToInt32(gridView1.GetRowCellValue(i, "ID")); entitydts[index].SelectByID(); entitydts[index].MainID = HTDataID; entitydts[index].Seq = i + 1; entitydts[index].DtsItemCode = SysConvert.ToString(gridView1.GetRowCellValue(i, "DtsItemCode")); entitydts[index].DtsItemName = SysConvert.ToString(gridView1.GetRowCellValue(i, "DtsItemName")); entitydts[index].DtsItemStd = SysConvert.ToString(gridView1.GetRowCellValue(i, "DtsItemStd")); entitydts[index].DtsItemModel = SysConvert.ToString(gridView1.GetRowCellValue(i, "DtsItemModel")); entitydts[index].Percentage = SysConvert.ToDecimal(gridView1.GetRowCellValue(i, "Percentage")); entitydts[index].Loss = SysConvert.ToDecimal(gridView1.GetRowCellValue(i, "Loss")); entitydts[index].PerMiWeight = SysConvert.ToDecimal(txtPerMiWeight.Text.Trim()) * (entitydts[index].Percentage / 100m) * (1 + entitydts[index].Loss);//SysConvert.ToDecimal(gridView2.GetRowCellValue(i, "PerMiWeight")); index++; } } return(entitydts); }
/// <summary> /// 新增 /// </summary> /// <param name="p_Entity">实体类</param> /// <returns>操作影响的记录行数</returns> public override int AddNew(BaseEntity p_Entity) { try { ItemDts MasterEntity = (ItemDts)p_Entity; if (MasterEntity.ID == 0) { return(0); } //新增主表数据 StringBuilder MasterField = new StringBuilder(); StringBuilder MasterValue = new StringBuilder(); MasterField.Append("INSERT INTO Data_ItemDts("); 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("DtsItemCode" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.DtsItemCode) + ","); MasterField.Append("DtsItemName" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.DtsItemName) + ","); MasterField.Append("DtsItemStd" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.DtsItemStd) + ","); MasterField.Append("DtsItemModel" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.DtsItemModel) + ","); MasterField.Append("Percentage" + ","); if (MasterEntity.Percentage != 0) { MasterValue.Append(SysString.ToDBString(MasterEntity.Percentage) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("Loss" + ","); if (MasterEntity.Loss != 0) { MasterValue.Append(SysString.ToDBString(MasterEntity.Loss) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("SinglePrice" + ","); if (MasterEntity.SinglePrice != 0) { MasterValue.Append(SysString.ToDBString(MasterEntity.SinglePrice) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("Amount" + ","); if (MasterEntity.Amount != 0) { MasterValue.Append(SysString.ToDBString(MasterEntity.Amount) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("Remark" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.Remark) + ","); MasterField.Append("PerMiWeight" + ","); if (MasterEntity.PerMiWeight != 0) { MasterValue.Append(SysString.ToDBString(MasterEntity.PerMiWeight) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("GoodsCode" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.GoodsCode) + ","); MasterField.Append("MWidth" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.MWidth) + ","); MasterField.Append("MWeight" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.MWeight) + ","); MasterField.Append("MWeight2" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.MWeight2) + ","); MasterField.Append("FactoryID" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.FactoryID) + ","); MasterField.Append("VendorID" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.VendorID) + ","); MasterField.Append("Price" + ","); if (MasterEntity.Price != 0) { MasterValue.Append(SysString.ToDBString(MasterEntity.Price) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("FormDate" + ","); if (MasterEntity.FormDate != SystemConfiguration.DateTimeDefaultValue) { MasterValue.Append(SysString.ToDBString(MasterEntity.FormDate.ToString("yyyy-MM-dd HH:mm:ss")) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("ReqDate" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.ReqDate) + ","); MasterField.Append("MinQty" + ")"); MasterValue.Append(SysString.ToDBString(MasterEntity.MinQty) + ")"); //执行 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 { ItemDts MasterEntity = (ItemDts)p_Entity; if (MasterEntity.ID == 0) { return(0); } //更新主表数据 StringBuilder UpdateBuilder = new StringBuilder(); UpdateBuilder.Append("UPDATE Data_ItemDts SET "); UpdateBuilder.Append(" ID=" + SysString.ToDBString(MasterEntity.ID) + ","); UpdateBuilder.Append(" MainID=" + SysString.ToDBString(MasterEntity.MainID) + ","); UpdateBuilder.Append(" Seq=" + SysString.ToDBString(MasterEntity.Seq) + ","); UpdateBuilder.Append(" DtsItemCode=" + SysString.ToDBString(MasterEntity.DtsItemCode) + ","); UpdateBuilder.Append(" DtsItemName=" + SysString.ToDBString(MasterEntity.DtsItemName) + ","); UpdateBuilder.Append(" DtsItemStd=" + SysString.ToDBString(MasterEntity.DtsItemStd) + ","); UpdateBuilder.Append(" DtsItemModel=" + SysString.ToDBString(MasterEntity.DtsItemModel) + ","); if (MasterEntity.Percentage != 0) { UpdateBuilder.Append(" Percentage=" + SysString.ToDBString(MasterEntity.Percentage) + ","); } else { UpdateBuilder.Append(" Percentage=null,"); } if (MasterEntity.Loss != 0) { UpdateBuilder.Append(" Loss=" + SysString.ToDBString(MasterEntity.Loss) + ","); } else { UpdateBuilder.Append(" Loss=null,"); } if (MasterEntity.SinglePrice != 0) { UpdateBuilder.Append(" SinglePrice=" + SysString.ToDBString(MasterEntity.SinglePrice) + ","); } else { UpdateBuilder.Append(" SinglePrice=null,"); } if (MasterEntity.Amount != 0) { UpdateBuilder.Append(" Amount=" + SysString.ToDBString(MasterEntity.Amount) + ","); } else { UpdateBuilder.Append(" Amount=null,"); } UpdateBuilder.Append(" Remark=" + SysString.ToDBString(MasterEntity.Remark) + ","); if (MasterEntity.PerMiWeight != 0) { UpdateBuilder.Append(" PerMiWeight=" + SysString.ToDBString(MasterEntity.PerMiWeight) + ","); } else { UpdateBuilder.Append(" PerMiWeight=null,"); } UpdateBuilder.Append(" GoodsCode=" + SysString.ToDBString(MasterEntity.GoodsCode) + ","); UpdateBuilder.Append(" MWidth=" + SysString.ToDBString(MasterEntity.MWidth) + ","); UpdateBuilder.Append(" MWeight=" + SysString.ToDBString(MasterEntity.MWeight) + ","); UpdateBuilder.Append(" MWeight2=" + SysString.ToDBString(MasterEntity.MWeight2) + ","); UpdateBuilder.Append(" FactoryID=" + SysString.ToDBString(MasterEntity.FactoryID) + ","); UpdateBuilder.Append(" VendorID=" + SysString.ToDBString(MasterEntity.VendorID) + ","); if (MasterEntity.Price != 0) { UpdateBuilder.Append(" Price=" + SysString.ToDBString(MasterEntity.Price) + ","); } else { UpdateBuilder.Append(" Price=null,"); } if (MasterEntity.FormDate != SystemConfiguration.DateTimeDefaultValue) { UpdateBuilder.Append(" FormDate=" + SysString.ToDBString(MasterEntity.FormDate.ToString("yyyy-MM-dd HH:mm:ss")) + ","); } else { UpdateBuilder.Append(" FormDate=null,"); } UpdateBuilder.Append(" ReqDate=" + SysString.ToDBString(MasterEntity.ReqDate) + ","); UpdateBuilder.Append(" MinQty=" + SysString.ToDBString(MasterEntity.MinQty)); 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> /// <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) { ItemDts entity = (ItemDts)p_BE; }