/// <summary> /// 修改 /// </summary> /// <param name="p_BE">要修改的实体</param> /// <param name="sqlTrans">事务类</param> public void RUpdate(BaseEntity p_BE, IDBTransAccess sqlTrans) { try { this.CheckCorrect(p_BE); CWInvoice entity = (CWInvoice)p_BE; CWInvoiceCtl control = new CWInvoiceCtl(sqlTrans); string sql = string.Empty; sql = " SELECT InvoiceNo FROM CaiWu_CWInvoice WHERE 1=1 AND InvoiceNo=" + SysString.ToDBString(entity.InvoiceNo) + " AND ID<>" + SysString.ToDBString(entity.ID); if (sqlTrans.Fill(sql).Rows.Count != 0) { throw new Exception("该发票号已经存在,请重新生成"); } else { control.Update(entity); } } 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 { CWInvoice MasterEntity = (CWInvoice)p_Entity; if (MasterEntity.ID == 0) { return(0); } //删除主表数据 string Sql = ""; Sql = "DELETE FROM CaiWu_CWInvoice 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 RAdd(BaseEntity p_BE, IDBTransAccess sqlTrans) { try { this.CheckCorrect(p_BE); CWInvoice entity = (CWInvoice)p_BE; CWInvoiceCtl control = new CWInvoiceCtl(sqlTrans); string sql = string.Empty; sql = " SELECT InvoiceNo FROM CaiWu_CWInvoice WHERE 1=1 AND InvoiceNo=" + SysString.ToDBString(entity.InvoiceNo); if (sqlTrans.Fill(sql).Rows.Count != 0) { throw new Exception("发票号已经存在,请重新生成"); } //entity.ID = (int)EntityIDTable.GetID((long)SysEntity.CaiWu_CWInvoice, sqlTrans); control.AddNew(entity); //sql = " UPDATE Enum_FormNoControl SET CurSort=CurSort+1 WHERE ID=" + (int)FormNoControlEnum.发票号码;//更新CurSort 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 RDelete(BaseEntity p_BE, IDBTransAccess sqlTrans) { try { this.CheckCorrect(p_BE); CWInvoice entity = (CWInvoice)p_BE; CWInvoiceCtl control = new CWInvoiceCtl(sqlTrans); string sql = "Select * From CaiWu_CWInvoiceDts 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++) { #region 处理对账和仓库开票的数据回填 //处理对账单中的对账标志 sql = "UPDATE CaiWu_CWDuiZhang Set DZFlag=0 WHERE Code=" + SysString.ToDBString(dt.Rows[i]["DZCode"].ToString()); sqlTrans.ExecuteNonQuery(sql); sql = "Select * From CaiWu_CWDuiZhangDts WHERE 1=1 "; sql += " AND MainID=" + " (SELECT ID FROM CaiWu_CWDuiZhang WHERE Code=" + SysString.ToDBString(dt.Rows[i]["DZCode"].ToString()) + ")"; DataTable dt2 = sqlTrans.Fill(sql); if (dt2.Rows.Count != 0) { for (int j = 0; j < dt2.Rows.Count; j++) { ///处理仓库发票标志 sql = "Update WH_IOFormDts Set DtsInvoiceDelFlag=0,DtsInvoiceDelTime=null,DtsInvoiceDelOPID='',DtsInvoiceNo='',InvoiceQty=0"; sql += " WHERE 1=1 AND MainID=" + SysString.ToDBString(dt2.Rows[j]["IOFormID"].ToString()); sql += " AND Seq=" + SysString.ToDBString(dt2.Rows[j]["IOFormSeq"].ToString()); sqlTrans.ExecuteNonQuery(sql); } } } #endregion } sql = "DELETE FROM CaiWu_CWInvoiceDts 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 { CWInvoice MasterEntity = (CWInvoice)p_Entity; if (MasterEntity.ID == 0) { return(0); } //新增主表数据 StringBuilder MasterField = new StringBuilder(); StringBuilder MasterValue = new StringBuilder(); MasterField.Append("INSERT INTO CaiWu_CWInvoice("); MasterValue.Append(" VALUES("); MasterField.Append("ID" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.ID) + ","); MasterField.Append("CompanyTypeID" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.CompanyTypeID) + ","); MasterField.Append("InvoiceNo" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.InvoiceNo) + ","); MasterField.Append("InvoiceTypeID" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.InvoiceTypeID) + ","); MasterField.Append("VendorID" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.VendorID) + ","); MasterField.Append("CurrencyID" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.CurrencyID) + ","); MasterField.Append("InvoiceOPID" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.InvoiceOPID) + ","); MasterField.Append("InvoiceDate" + ","); if (MasterEntity.InvoiceDate != SystemConfiguration.DateTimeDefaultValue) { MasterValue.Append(SysString.ToDBString(MasterEntity.InvoiceDate.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("InvoiceQty" + ","); if (MasterEntity.InvoiceQty != 0) { MasterValue.Append(SysString.ToDBString(MasterEntity.InvoiceQty) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("InvoiceAmount" + ","); if (MasterEntity.InvoiceAmount != 0) { MasterValue.Append(SysString.ToDBString(MasterEntity.InvoiceAmount) + ","); } 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("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 { CWInvoice MasterEntity = (CWInvoice)p_Entity; if (MasterEntity.ID == 0) { return(0); } //更新主表数据 StringBuilder UpdateBuilder = new StringBuilder(); UpdateBuilder.Append("UPDATE CaiWu_CWInvoice SET "); UpdateBuilder.Append(" ID=" + SysString.ToDBString(MasterEntity.ID) + ","); UpdateBuilder.Append(" CompanyTypeID=" + SysString.ToDBString(MasterEntity.CompanyTypeID) + ","); UpdateBuilder.Append(" InvoiceNo=" + SysString.ToDBString(MasterEntity.InvoiceNo) + ","); UpdateBuilder.Append(" InvoiceTypeID=" + SysString.ToDBString(MasterEntity.InvoiceTypeID) + ","); UpdateBuilder.Append(" VendorID=" + SysString.ToDBString(MasterEntity.VendorID) + ","); UpdateBuilder.Append(" CurrencyID=" + SysString.ToDBString(MasterEntity.CurrencyID) + ","); UpdateBuilder.Append(" InvoiceOPID=" + SysString.ToDBString(MasterEntity.InvoiceOPID) + ","); if (MasterEntity.InvoiceDate != SystemConfiguration.DateTimeDefaultValue) { UpdateBuilder.Append(" InvoiceDate=" + SysString.ToDBString(MasterEntity.InvoiceDate.ToString("yyyy-MM-dd HH:mm:ss")) + ","); } else { UpdateBuilder.Append(" InvoiceDate=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.InvoiceQty != 0) { UpdateBuilder.Append(" InvoiceQty=" + SysString.ToDBString(MasterEntity.InvoiceQty) + ","); } else { UpdateBuilder.Append(" InvoiceQty=null,"); } if (MasterEntity.InvoiceAmount != 0) { UpdateBuilder.Append(" InvoiceAmount=" + SysString.ToDBString(MasterEntity.InvoiceAmount) + ","); } else { UpdateBuilder.Append(" InvoiceAmount=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(" 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_Entity"></param> /// <param name="p_BE"></param> /// <param name="sqlTrans"></param> public void RSave(CWInvoice p_Entity, BaseEntity[] p_BE, IDBTransAccess sqlTrans) { try { #region 初始化对账标志 //初始化对账标志 string sql = "Select * From CaiWu_CWInvoiceDts 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 CaiWu_CWDuiZhang Set DZFlag=0 "; sql += " WHERE 1=1 AND Code=" + SysString.ToDBString(dt.Rows[i]["DZCode"].ToString()); sqlTrans.ExecuteNonQuery(sql); ///初始化仓库发票标志 sql = "Select * From CaiWu_CWDuiZhangDts WHERE 1=1"; sql += " AND MainID=" + " (SELECT ID FROM CaiWu_CWDuiZhang WHERE Code=" + SysString.ToDBString(dt.Rows[i]["DZCode"].ToString()) + ")"; DataTable dt1 = sqlTrans.Fill(sql); if (dt1.Rows.Count != 0) { for (int m = 0; m < dt1.Rows.Count; m++) { sql = "Update WH_IOFormDts Set DtsInvoiceDelFlag=0,DtsInvoiceDelTime=null,DtsInvoiceDelOPID='',DtsInvoiceNo='',InvoiceQty=0"; sql += " WHERE 1=1 AND MainID=" + SysConvert.ToInt32(dt1.Rows[m]["IOFormID"]); sql += " AND Seq=" + SysConvert.ToInt32(dt1.Rows[m]["IOFormSeq"]); sqlTrans.ExecuteNonQuery(sql); } } } } #endregion sql = "DELETE FROM CaiWu_CWInvoiceDts WHERE MainID=" + p_Entity.ID.ToString(); sqlTrans.ExecuteNonQuery(sql);//删除原单据明细数据 for (int i = 0; i < p_BE.Length; i++) { CWInvoiceDts entitydts = (CWInvoiceDts)p_BE[i]; sql = "SELECT ISNULL(MAX(Seq),0)+1 As MSEQ FROM CaiWu_CWInvoiceDts 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); #region 处理对账和仓库开票的数据回填 //处理对账单中的对账标志 sql = "UPDATE CaiWu_CWDuiZhang Set DZFlag=1 WHERE Code=" + SysString.ToDBString(entitydts.DZCode); sqlTrans.ExecuteNonQuery(sql); sql = "Select * From CaiWu_CWDuiZhangDts WHERE 1=1 "; sql += " AND MainID=" + " (SELECT ID FROM CaiWu_CWDuiZhang WHERE Code=" + SysString.ToDBString(entitydts.DZCode) + ")"; DataTable dt2 = sqlTrans.Fill(sql); if (dt2.Rows.Count != 0) { for (int j = 0; j < dt2.Rows.Count; j++) { ///处理仓库发票标志 sql = "Update WH_IOFormDts Set DtsInvoiceDelFlag=1"; if (p_Entity.InvoiceDate != SystemConfiguration.DateTimeDefaultValue) { sql += " ,DtsInvoiceDelTime=" + SysString.ToDBString(p_Entity.InvoiceDate); } else { sql += " ,DtsInvoiceDelTime=null"; } sql += ",InvoiceQty=" + SysString.ToDBString(p_Entity.InvoiceQty); sql += ",DtsInvoiceDelOPID=" + SysString.ToDBString(p_Entity.InvoiceOPID); sql += ",DtsInvoiceNo=" + SysString.ToDBString(p_Entity.InvoiceNo); sql += " WHERE 1=1 AND MainID=" + SysString.ToDBString(dt2.Rows[j]["IOFormID"].ToString()); sql += " AND Seq=" + SysString.ToDBString(dt2.Rows[j]["IOFormSeq"].ToString()); sqlTrans.ExecuteNonQuery(sql); } } #endregion } } catch (BaseException) { throw; } catch (Exception E) { throw new BaseException(E.Message); } }
/// <summary> /// 检查将要操作的数据是否符合业务规则 /// </summary> /// <param name="p_BE"></param> private void CheckCorrect(BaseEntity p_BE) { CWInvoice entity = (CWInvoice)p_BE; }