/// <summary> /// 保存(传入事务处理) /// </summary> /// <param name="p_Entity"></param> /// <param name="p_BE"></param> /// <param name="sqlTrans"></param> public void RSave(SaleOrderInstruct p_Entity, BaseEntity[] p_BE, IDBTransAccess sqlTrans) { try { string sql = "DELETE FROM Sale_SaleOrderInstructDts WHERE MainID=" + p_Entity.ID.ToString(); sql += " AND ID NOT IN" + string.Format("({0})", GetIDExist(p_BE)); sqlTrans.ExecuteNonQuery(sql); //删除原单据里应该删除的明细数据,即数据库里有但是UI里已经删除的数据 sql = "SELECT ISNULL(MAX(Seq),0)+1 As MSEQ FROM Sale_SaleOrderInstructDts WHERE MainID=" + p_Entity.ID.ToString(); ////找到最大的Seq 将获得最大Seq的语句放到循环外更高效(多人操作时会有问题吗?) int MSEQ = SysConvert.ToInt32(sqlTrans.Fill(sql).Rows[0][0].ToString()); for (int i = 0; i < p_BE.Length; i++) { SaleOrderInstructDts entitydts = (SaleOrderInstructDts)p_BE[i]; if (entitydts.ID != 0)//ID不为0说明数据库中已经存在 { this.RUpdate(entitydts, sqlTrans); } else { entitydts.Seq = MSEQ; entitydts.MainID = p_Entity.ID; this.RAdd(entitydts, sqlTrans); MSEQ++;//最大值加1 } } } 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 { SaleOrderInstructDts MasterEntity = (SaleOrderInstructDts)p_Entity; if (MasterEntity.ID == 0) { return(0); } //删除主表数据 string Sql = ""; Sql = "DELETE FROM Sale_SaleOrderInstructDts 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> /// 获得数据库里没有被删除的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++) { SaleOrderInstructDts entitydts = (SaleOrderInstructDts)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); SaleOrderInstructDts entity = (SaleOrderInstructDts)p_BE; SaleOrderInstructDtsCtl control = new SaleOrderInstructDtsCtl(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); SaleOrderInstructDts entity = (SaleOrderInstructDts)p_BE; SaleOrderInstructDtsCtl control = new SaleOrderInstructDtsCtl(sqlTrans); entity.ID = (int)EntityIDTable.GetID((long)SysEntity.Sale_SaleOrderInstructDts, sqlTrans); control.AddNew(entity); } catch (BaseException) { throw; } catch (Exception E) { throw new BaseException(E.Message); } }
/// <summary> /// 获得实体 /// </summary> /// <returns></returns> private SaleOrderInstructDts[] EntityDtsGet() { int index = GetDataCompleteNum(); SaleOrderInstructDts[] entitydts = new SaleOrderInstructDts[index]; index = 0; for (int i = 0; i < gridView1.RowCount; i++) { if (CheckDataCompleteDts(i)) { entitydts[index] = new SaleOrderInstructDts(); 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].ColorNum = SysConvert.ToString(gridView1.GetRowCellValue(i, "ColorNum")); entitydts[index].ColorName = SysConvert.ToString(gridView1.GetRowCellValue(i, "ColorName")); entitydts[index].Qty = SysConvert.ToDecimal(gridView1.GetRowCellValue(i, "Qty")); entitydts[index].TPQty = SysConvert.ToDecimal(gridView1.GetRowCellValue(i, "TPQty")); entitydts[index].Shrinkage = SysConvert.ToDecimal(gridView1.GetRowCellValue(i, "Shrinkage")); entitydts[index].SinglePrice = SysConvert.ToDecimal(gridView1.GetRowCellValue(i, "SinglePrice")); entitydts[index].Amount = SysConvert.ToDecimal(gridView1.GetRowCellValue(i, "Amount")); entitydts[index].Remark = SysConvert.ToString(gridView1.GetRowCellValue(i, "Remark")); index++; } } return(entitydts); }
/// <summary> /// 检查将要操作的数据是否符合业务规则 /// </summary> /// <param name="p_BE"></param> private void CheckCorrect(BaseEntity p_BE) { SaleOrderInstructDts entity = (SaleOrderInstructDts)p_BE; }
/// <summary> /// 新增 /// </summary> /// <param name="p_Entity">实体类</param> /// <returns>操作影响的记录行数</returns> public override int AddNew(BaseEntity p_Entity) { try { SaleOrderInstructDts MasterEntity = (SaleOrderInstructDts)p_Entity; if (MasterEntity.ID == 0) { return(0); } //新增主表数据 StringBuilder MasterField = new StringBuilder(); StringBuilder MasterValue = new StringBuilder(); MasterField.Append("INSERT INTO Sale_SaleOrderInstructDts("); 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("Qty" + ","); if (MasterEntity.Qty != 0) { MasterValue.Append(SysString.ToDBString(MasterEntity.Qty) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("TPQty" + ","); if (MasterEntity.TPQty != 0) { MasterValue.Append(SysString.ToDBString(MasterEntity.TPQty) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("Shrinkage" + ","); if (MasterEntity.Shrinkage != 0) { MasterValue.Append(SysString.ToDBString(MasterEntity.Shrinkage) + ","); } 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) + ")"); //执行 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 { SaleOrderInstructDts MasterEntity = (SaleOrderInstructDts)p_Entity; if (MasterEntity.ID == 0) { return(0); } //更新主表数据 StringBuilder UpdateBuilder = new StringBuilder(); UpdateBuilder.Append("UPDATE Sale_SaleOrderInstructDts 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.Qty != 0) { UpdateBuilder.Append(" Qty=" + SysString.ToDBString(MasterEntity.Qty) + ","); } else { UpdateBuilder.Append(" Qty=null,"); } if (MasterEntity.TPQty != 0) { UpdateBuilder.Append(" TPQty=" + SysString.ToDBString(MasterEntity.TPQty) + ","); } else { UpdateBuilder.Append(" TPQty=null,"); } if (MasterEntity.Shrinkage != 0) { UpdateBuilder.Append(" Shrinkage=" + SysString.ToDBString(MasterEntity.Shrinkage) + ","); } else { UpdateBuilder.Append(" Shrinkage=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)); 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); } }