/// <summary> /// 保存(传入事务处理) /// </summary> /// <param name="p_Entity"></param> /// <param name="p_BE"></param> /// <param name="sqlTrans"></param> public void RSave(ProductionNotice p_Entity, BaseEntity[] p_BE, IDBTransAccess sqlTrans) { try { string sql = "DELETE FROM Sale_ProductionNoticeDts 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++) { ProductionNoticeDts entitydts = (ProductionNoticeDts)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 { ProductionNoticeDts MasterEntity = (ProductionNoticeDts)p_Entity; if (MasterEntity.ID == 0) { return(0); } //删除主表数据 string Sql = ""; Sql = "DELETE FROM Sale_ProductionNoticeDts 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_TableName">表名</param> /// <param name="p_FieldName">字段名</param> /// <param name="p_FieldValue">字段值</param> /// <param name="p_KeyField">主键(只考虑主键为ID的情况)</param> /// <param name="p_KeyValue">主键值</param> /// <param name="p_sqlTrans"></param> /// <returns></returns> private bool CheckFieldValueIsExist(BaseEntity p_BE, string p_FieldName, string p_FieldValue, IDBTransAccess p_sqlTrans) { ProductionNoticeDts entity = (ProductionNoticeDts)p_BE; bool ret = false; string sql = string.Format(" SELECT {0} FROM {1} WHERE 1=1 AND {0}={2} AND {3}<>{4}", p_FieldName, ProductionNoticeDts.TableName, SysString.ToDBString(p_FieldValue), "ID", entity.ID); DataTable dt = p_sqlTrans.Fill(sql); if (dt.Rows.Count != 0) { ret = true; } return(ret); }
/// <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++) { ProductionNoticeDts entitydts = (ProductionNoticeDts)p_BE[i]; if (entitydts.ID != 0) { outstr += "," + entitydts.ID; } } return(outstr); }
/// <summary> /// 获得实体 /// </summary> /// <returns></returns> private ProductionNoticeDts[] EntityDtsGet() { int index = GetDataCompleteNum(); ProductionNoticeDts[] entitydts = new ProductionNoticeDts[index]; index = 0; for (int i = 0; i < gridView1.RowCount; i++) { if (CheckDataCompleteDts(i)) { entitydts[index] = new ProductionNoticeDts(); entitydts[index].MainID = SysConvert.ToInt32(gridView1.GetRowCellValue(i, "MainID")); if (entitydts[index].MainID == HTDataID && HTDataID != 0)//已存在表示修改 { entitydts[index].ID = SysConvert.ToInt32(gridView1.GetRowCellValue(i, "ID")); entitydts[index].SelectByID(); } else//新增 { entitydts[index].MainID = HTDataID; entitydts[index].Seq = i + 1; } entitydts[index].SO = SysConvert.ToString(gridView1.GetRowCellValue(i, "SO")); 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].ConfirmSample = SysConvert.ToString(gridView1.GetRowCellValue(i, "ConfirmSample")); entitydts[index].SOQty = SysConvert.ToDecimal(gridView1.GetRowCellValue(i, "SOQty")); entitydts[index].CPQty = SysConvert.ToDecimal(gridView1.GetRowCellValue(i, "CPQty")); entitydts[index].TPQty = SysConvert.ToDecimal(gridView1.GetRowCellValue(i, "TPQty")); entitydts[index].MWidth = SysConvert.ToString(gridView1.GetRowCellValue(i, "MWidth")); entitydts[index].MWeight = SysConvert.ToString(gridView1.GetRowCellValue(i, "MWeight")); entitydts[index].Needle = SysConvert.ToString(gridView1.GetRowCellValue(i, "Needle")); entitydts[index].DRemark = SysConvert.ToString(gridView1.GetRowCellValue(i, "DRemark")); entitydts[index].ColorName = SysConvert.ToString(gridView1.GetRowCellValue(i, "ColorName")); entitydts[index].Flower = SysConvert.ToString(gridView1.GetRowCellValue(i, "Flower")); entitydts[index].Shrinkage = SysConvert.ToDecimal(gridView1.GetRowCellValue(i, "Shrinkage")); entitydts[index].LoadID = SysConvert.ToInt32(gridView1.GetRowCellValue(i, "LoadID")); index++; } } return(entitydts); }
/// <summary> /// 删除 /// </summary> /// <param name="p_BE">要删除的实体</param> /// <param name="sqlTrans">事务类</param> public void RDelete(BaseEntity p_BE, IDBTransAccess sqlTrans) { try { this.CheckCorrect(p_BE); ProductionNoticeDts entity = (ProductionNoticeDts)p_BE; ProductionNoticeDtsCtl control = new ProductionNoticeDtsCtl(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); ProductionNoticeDts entity = (ProductionNoticeDts)p_BE; ProductionNoticeDtsCtl control = new ProductionNoticeDtsCtl(sqlTrans); entity.ID = (int)EntityIDTable.GetID((long)SysEntity.Sale_ProductionNoticeDts, 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 { ProductionNoticeDts MasterEntity = (ProductionNoticeDts)p_Entity; if (MasterEntity.ID == 0) { return(0); } //新增主表数据 StringBuilder MasterField = new StringBuilder(); StringBuilder MasterValue = new StringBuilder(); MasterField.Append("INSERT INTO Sale_ProductionNoticeDts("); 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("SO" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.SO) + ","); MasterField.Append("ItemCode" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.ItemCode) + ","); MasterField.Append("ItemName" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.ItemName) + ","); MasterField.Append("ItemStd" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.ItemStd) + ","); MasterField.Append("ItemModel" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.ItemModel) + ","); MasterField.Append("ConfirmSample" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.ConfirmSample) + ","); MasterField.Append("SOQty" + ","); if (MasterEntity.SOQty != 0) { MasterValue.Append(SysString.ToDBString(MasterEntity.SOQty) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("CPQty" + ","); if (MasterEntity.CPQty != 0) { MasterValue.Append(SysString.ToDBString(MasterEntity.CPQty) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("TPQty" + ","); if (MasterEntity.TPQty != 0) { MasterValue.Append(SysString.ToDBString(MasterEntity.TPQty) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("MWidth" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.MWidth) + ","); MasterField.Append("MWeight" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.MWeight) + ","); MasterField.Append("DRemark" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.DRemark) + ","); MasterField.Append("Shrinkage" + ","); if (MasterEntity.Shrinkage != 0) { MasterValue.Append(SysString.ToDBString(MasterEntity.Shrinkage) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("ColorNum" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.ColorNum) + ","); MasterField.Append("ColorName" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.ColorName) + ","); MasterField.Append("Flower" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.Flower) + ","); MasterField.Append("LoadID" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.LoadID) + ","); MasterField.Append("TBCPQty" + ","); if (MasterEntity.TBCPQty != 0) { MasterValue.Append(SysString.ToDBString(MasterEntity.TBCPQty) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("FactoryID" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.FactoryID) + ","); MasterField.Append("ReqDate" + ","); if (MasterEntity.ReqDate != SystemConfiguration.DateTimeDefaultValue) { MasterValue.Append(SysString.ToDBString(MasterEntity.ReqDate.ToString("yyyy-MM-dd HH:mm:ss")) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("MaxQty" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.MaxQty) + ","); MasterField.Append("MainQty" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.MainQty) + ","); MasterField.Append("Unit" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.Unit) + ","); MasterField.Append("VendorID" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.VendorID) + ","); MasterField.Append("OutRange" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.OutRange) + ","); MasterField.Append("Needle" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.Needle) + ","); MasterField.Append("VItemCode" + ")"); MasterValue.Append(SysString.ToDBString(MasterEntity.VItemCode) + ")"); //执行 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 { ProductionNoticeDts MasterEntity = (ProductionNoticeDts)p_Entity; if (MasterEntity.ID == 0) { return(0); } //更新主表数据 StringBuilder UpdateBuilder = new StringBuilder(); UpdateBuilder.Append("UPDATE Sale_ProductionNoticeDts SET "); UpdateBuilder.Append(" ID=" + SysString.ToDBString(MasterEntity.ID) + ","); UpdateBuilder.Append(" MainID=" + SysString.ToDBString(MasterEntity.MainID) + ","); UpdateBuilder.Append(" Seq=" + SysString.ToDBString(MasterEntity.Seq) + ","); UpdateBuilder.Append(" SO=" + SysString.ToDBString(MasterEntity.SO) + ","); UpdateBuilder.Append(" ItemCode=" + SysString.ToDBString(MasterEntity.ItemCode) + ","); UpdateBuilder.Append(" ItemName=" + SysString.ToDBString(MasterEntity.ItemName) + ","); UpdateBuilder.Append(" ItemStd=" + SysString.ToDBString(MasterEntity.ItemStd) + ","); UpdateBuilder.Append(" ItemModel=" + SysString.ToDBString(MasterEntity.ItemModel) + ","); UpdateBuilder.Append(" ConfirmSample=" + SysString.ToDBString(MasterEntity.ConfirmSample) + ","); if (MasterEntity.SOQty != 0) { UpdateBuilder.Append(" SOQty=" + SysString.ToDBString(MasterEntity.SOQty) + ","); } else { UpdateBuilder.Append(" SOQty=null,"); } if (MasterEntity.CPQty != 0) { UpdateBuilder.Append(" CPQty=" + SysString.ToDBString(MasterEntity.CPQty) + ","); } else { UpdateBuilder.Append(" CPQty=null,"); } if (MasterEntity.TPQty != 0) { UpdateBuilder.Append(" TPQty=" + SysString.ToDBString(MasterEntity.TPQty) + ","); } else { UpdateBuilder.Append(" TPQty=null,"); } UpdateBuilder.Append(" MWidth=" + SysString.ToDBString(MasterEntity.MWidth) + ","); UpdateBuilder.Append(" MWeight=" + SysString.ToDBString(MasterEntity.MWeight) + ","); UpdateBuilder.Append(" Needle=" + SysString.ToDBString(MasterEntity.Needle) + ","); UpdateBuilder.Append(" DRemark=" + SysString.ToDBString(MasterEntity.DRemark) + ","); if (MasterEntity.Shrinkage != 0) { UpdateBuilder.Append(" Shrinkage=" + SysString.ToDBString(MasterEntity.Shrinkage) + ","); } else { UpdateBuilder.Append(" Shrinkage=null,"); } UpdateBuilder.Append(" ColorNum=" + SysString.ToDBString(MasterEntity.ColorNum) + ","); UpdateBuilder.Append(" ColorName=" + SysString.ToDBString(MasterEntity.ColorName) + ","); UpdateBuilder.Append(" Flower=" + SysString.ToDBString(MasterEntity.Flower) + ","); UpdateBuilder.Append(" LoadID=" + SysString.ToDBString(MasterEntity.LoadID) + ","); if (MasterEntity.TBCPQty != 0) { UpdateBuilder.Append(" TBCPQty=" + SysString.ToDBString(MasterEntity.TBCPQty) + ","); } else { UpdateBuilder.Append(" TBCPQty=null,"); } UpdateBuilder.Append(" FactoryID=" + SysString.ToDBString(MasterEntity.FactoryID) + ","); if (MasterEntity.ReqDate != SystemConfiguration.DateTimeDefaultValue) { UpdateBuilder.Append(" ReqDate=" + SysString.ToDBString(MasterEntity.ReqDate.ToString("yyyy-MM-dd HH:mm:ss")) + ","); } else { UpdateBuilder.Append(" ReqDate=null,"); } UpdateBuilder.Append(" MaxQty=" + SysString.ToDBString(MasterEntity.MaxQty) + ","); UpdateBuilder.Append(" MainQty=" + SysString.ToDBString(MasterEntity.MainQty) + ","); UpdateBuilder.Append(" Unit=" + SysString.ToDBString(MasterEntity.Unit) + ","); UpdateBuilder.Append(" VendorID=" + SysString.ToDBString(MasterEntity.VendorID) + ","); UpdateBuilder.Append(" OutRange=" + SysString.ToDBString(MasterEntity.OutRange) + ","); UpdateBuilder.Append(" VItemCode=" + SysString.ToDBString(MasterEntity.VItemCode)); 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) { ProductionNoticeDts entity = (ProductionNoticeDts)p_BE; }