/// <summary> /// 新增(传入事务处理) /// </summary> /// <param name="p_BE">要新增的实体</param> /// <param name="sqlTrans">事务类</param> public void RAdd(BaseEntity p_BE, IDBTransAccess sqlTrans) { try { this.CheckCorrect(p_BE); CWDuiZhang entity = (CWDuiZhang)p_BE; CWDuiZhangCtl control = new CWDuiZhangCtl(sqlTrans); string sql = "SELECT Code FROM CaiWu_CWDuiZhang WHERE Code=" + SysString.ToDBString(entity.Code) + " AND DZTypeID=" + SysString.ToDBString(entity.DZTypeID); if (sqlTrans.Fill(sql).Rows.Count != 0) { throw new Exception("该单号已经存在,请双击重新生成"); } //entity.ID = (int)EntityIDTable.GetID((long)SysEntity.CaiWu_CWDuiZhang, sqlTrans); control.AddNew(entity); if (entity.DZTypeID == 1) { //sql = " UPDATE Enum_FormNoControl SET CurSort=CurSort+1 WHERE ID=" + (int)FormNoControlEnum.进项对账单号;//更新CurSort } else if (entity.DZTypeID == 2) { //sql = " UPDATE Enum_FormNoControl SET CurSort=CurSort+1 WHERE ID=" + (int)FormNoControlEnum.销项对账单号;//更新CurSort } SysUtils.ExecuteNonQuery(sql); } 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 { CWDuiZhang MasterEntity = (CWDuiZhang)p_Entity; if (MasterEntity.ID == 0) { return(0); } //删除主表数据 string Sql = ""; Sql = "DELETE FROM CaiWu_CWDuiZhang 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(CWDuiZhang p_Entity, BaseEntity[] p_BE, IDBTransAccess sqlTrans) { try { ///初始化对账标志 string sql = "Select * From CaiWu_CWDuiZhangDts WHERE 1=1"; sql += " AND MainID=" + SysString.ToDBString(p_Entity.ID); DataTable dt = sqlTrans.Fill(sql); if (dt.Rows.Count != 0) { for (int i = 0; i < dt.Rows.Count; i++) { sql = "Update WH_IOFormDts Set DZFlag=0,DZTime=null,DZOPID='',DZNo='',DZQty=0"; sql += " WHERE 1=1 AND MainID=" + SysConvert.ToInt32(dt.Rows[i]["IOFormID"]); sql += " AND Seq=" + SysConvert.ToInt32(dt.Rows[i]["IOFormSeq"]); sqlTrans.ExecuteNonQuery(sql); } } sql = "DELETE FROM CaiWu_CWDuiZhangDts WHERE MainID=" + p_Entity.ID.ToString(); sqlTrans.ExecuteNonQuery(sql);//删除原单据明细数据 for (int i = 0; i < p_BE.Length; i++) { CWDuiZhangDts entitydts = (CWDuiZhangDts)p_BE[i]; sql = "SELECT ISNULL(MAX(Seq),0)+1 As MSEQ FROM CaiWu_CWDuiZhangDts WHERE MainID=" + p_Entity.ID.ToString(); entitydts.Seq = SysConvert.ToInt32(sqlTrans.Fill(sql).Rows[0][0].ToString());//找到最大的Seq entitydts.MainID = p_Entity.ID; this.RAdd(entitydts, sqlTrans); ///处理对账标志 sql = "Update WH_IOFormDts Set DZFlag=1"; if (p_Entity.DZDate != SystemConfiguration.DateTimeDefaultValue) { sql += " ,DZTime=" + SysString.ToDBString(p_Entity.DZDate.Date); } else { sql += " ,DZTime=null"; } sql += ",DZQty=" + SysString.ToDBString(p_Entity.DZQty); sql += ",DZOPID=" + SysString.ToDBString(p_Entity.DZOPID); sql += ",DZNo=" + SysString.ToDBString(p_Entity.Code); sql += ",SinglePrice=" + SysString.ToDBString(entitydts.SinglePrice); sql += ",Amount=" + SysString.ToDBString(entitydts.Amount); sql += " WHERE 1=1 AND MainID=" + SysConvert.ToInt32(entitydts.IOFormID); sql += " AND Seq=" + SysConvert.ToInt32(entitydts.IOFormSeq); sqlTrans.ExecuteNonQuery(sql); } } 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); CWDuiZhang entity = (CWDuiZhang)p_BE; CWDuiZhangCtl control = new CWDuiZhangCtl(sqlTrans); control.Update(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 RDelete(BaseEntity p_BE, IDBTransAccess sqlTrans) { try { this.CheckCorrect(p_BE); CWDuiZhang entity = (CWDuiZhang)p_BE; CWDuiZhangCtl control = new CWDuiZhangCtl(sqlTrans); ///初始化对账标志 string sql = "Select * From CaiWu_CWDuiZhangDts WHERE 1=1"; sql += " AND MainID=" + SysString.ToDBString(entity.ID); DataTable dt = sqlTrans.Fill(sql); if (dt.Rows.Count != 0) { for (int i = 0; i < dt.Rows.Count; i++) { sql = "Update WH_IOFormDts Set DZFlag=0,DZTime=null,DZOPID='',DZNo=''"; sql += " WHERE 1=1 AND MainID=" + SysConvert.ToInt32(dt.Rows[i]["IOFormID"]); sql += " AND Seq=" + SysConvert.ToInt32(dt.Rows[i]["IOFormSeq"]); sqlTrans.ExecuteNonQuery(sql); } } sql = "DELETE FROM CaiWu_CWDuiZhangDts WHERE MainID=" + entity.ID.ToString(); sqlTrans.ExecuteNonQuery(sql);//删除原单据明细数据 control.Delete(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 { CWDuiZhang MasterEntity = (CWDuiZhang)p_Entity; if (MasterEntity.ID == 0) { return(0); } //新增主表数据 StringBuilder MasterField = new StringBuilder(); StringBuilder MasterValue = new StringBuilder(); MasterField.Append("INSERT INTO CaiWu_CWDuiZhang("); MasterValue.Append(" VALUES("); MasterField.Append("ID" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.ID) + ","); MasterField.Append("CompanyTypeID" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.CompanyTypeID) + ","); MasterField.Append("Code" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.Code) + ","); MasterField.Append("DZTypeID" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.DZTypeID) + ","); MasterField.Append("VendorID" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.VendorID) + ","); MasterField.Append("CurrencyID" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.CurrencyID) + ","); MasterField.Append("DZOPID" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.DZOPID) + ","); MasterField.Append("DZDate" + ","); if (MasterEntity.DZDate != SystemConfiguration.DateTimeDefaultValue) { MasterValue.Append(SysString.ToDBString(MasterEntity.DZDate.ToString("yyyy-MM-dd HH:mm:ss")) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("TotalAmount" + ","); if (MasterEntity.TotalAmount != 0) { MasterValue.Append(SysString.ToDBString(MasterEntity.TotalAmount) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("TotalQty" + ","); if (MasterEntity.TotalQty != 0) { MasterValue.Append(SysString.ToDBString(MasterEntity.TotalQty) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("DZQty" + ","); if (MasterEntity.DZQty != 0) { MasterValue.Append(SysString.ToDBString(MasterEntity.DZQty) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("DZAmount" + ","); if (MasterEntity.DZAmount != 0) { MasterValue.Append(SysString.ToDBString(MasterEntity.DZAmount) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("MakeOPID" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.MakeOPID) + ","); MasterField.Append("MakeDate" + ","); if (MasterEntity.MakeDate != SystemConfiguration.DateTimeDefaultValue) { MasterValue.Append(SysString.ToDBString(MasterEntity.MakeDate.ToString("yyyy-MM-dd HH:mm:ss")) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("DZFlag" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.DZFlag) + ","); MasterField.Append("DelFlag" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.DelFlag) + ","); MasterField.Append("SubmitFlag" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.SubmitFlag) + ","); 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 { CWDuiZhang MasterEntity = (CWDuiZhang)p_Entity; if (MasterEntity.ID == 0) { return(0); } //更新主表数据 StringBuilder UpdateBuilder = new StringBuilder(); UpdateBuilder.Append("UPDATE CaiWu_CWDuiZhang SET "); UpdateBuilder.Append(" ID=" + SysString.ToDBString(MasterEntity.ID) + ","); UpdateBuilder.Append(" CompanyTypeID=" + SysString.ToDBString(MasterEntity.CompanyTypeID) + ","); UpdateBuilder.Append(" Code=" + SysString.ToDBString(MasterEntity.Code) + ","); UpdateBuilder.Append(" DZTypeID=" + SysString.ToDBString(MasterEntity.DZTypeID) + ","); UpdateBuilder.Append(" VendorID=" + SysString.ToDBString(MasterEntity.VendorID) + ","); UpdateBuilder.Append(" CurrencyID=" + SysString.ToDBString(MasterEntity.CurrencyID) + ","); UpdateBuilder.Append(" DZOPID=" + SysString.ToDBString(MasterEntity.DZOPID) + ","); if (MasterEntity.DZDate != SystemConfiguration.DateTimeDefaultValue) { UpdateBuilder.Append(" DZDate=" + SysString.ToDBString(MasterEntity.DZDate.ToString("yyyy-MM-dd HH:mm:ss")) + ","); } else { UpdateBuilder.Append(" DZDate=null,"); } if (MasterEntity.TotalAmount != 0) { UpdateBuilder.Append(" TotalAmount=" + SysString.ToDBString(MasterEntity.TotalAmount) + ","); } else { UpdateBuilder.Append(" TotalAmount=null,"); } if (MasterEntity.TotalQty != 0) { UpdateBuilder.Append(" TotalQty=" + SysString.ToDBString(MasterEntity.TotalQty) + ","); } else { UpdateBuilder.Append(" TotalQty=null,"); } if (MasterEntity.DZQty != 0) { UpdateBuilder.Append(" DZQty=" + SysString.ToDBString(MasterEntity.DZQty) + ","); } else { UpdateBuilder.Append(" DZQty=null,"); } if (MasterEntity.DZAmount != 0) { UpdateBuilder.Append(" DZAmount=" + SysString.ToDBString(MasterEntity.DZAmount) + ","); } else { UpdateBuilder.Append(" DZAmount=null,"); } UpdateBuilder.Append(" MakeOPID=" + SysString.ToDBString(MasterEntity.MakeOPID) + ","); if (MasterEntity.MakeDate != SystemConfiguration.DateTimeDefaultValue) { UpdateBuilder.Append(" MakeDate=" + SysString.ToDBString(MasterEntity.MakeDate.ToString("yyyy-MM-dd HH:mm:ss")) + ","); } else { UpdateBuilder.Append(" MakeDate=null,"); } UpdateBuilder.Append(" DZFlag=" + SysString.ToDBString(MasterEntity.DZFlag) + ","); UpdateBuilder.Append(" DelFlag=" + SysString.ToDBString(MasterEntity.DelFlag) + ","); UpdateBuilder.Append(" SubmitFlag=" + SysString.ToDBString(MasterEntity.SubmitFlag) + ","); 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); } }
/// <summary> /// 检查将要操作的数据是否符合业务规则 /// </summary> /// <param name="p_BE"></param> private void CheckCorrect(BaseEntity p_BE) { CWDuiZhang entity = (CWDuiZhang)p_BE; }