//#region 加载 ///// <summary> ///// 加载 ///// </summary> ///// <param name="sender"></param> ///// <param name="e"></param> //public override void btnLoad_Click(object sender, EventArgs e) //{ // try // { // if (HTFormStatus == FormStatus.新增 || HTFormStatus == FormStatus.修改) // { // if (Common.CheckLookUpEditBlank(drpVendorID)) // { // this.ShowMessage("请选择"+lblVendor.Text.ToString()); // return; // } // if (SysConvert.ToInt32(drpDZType.EditValue) == 0) // { // this.ShowMessage("请选择开票类型"); // return; // } // frmLoadIOForm frm = new frmLoadIOForm(); // frm.DZTypeID = SysConvert.ToInt32(drpDZType.EditValue); // frm.HTLoadConditionStr = " AND ISNULL(DZFlag,0)=1" + " AND VendorID=" + SysString.ToDBString(SysConvert.ToString(drpVendorID.EditValue));//只查询未对账 // frm.ShowDialog(); // string str = string.Empty; // if (frm.DtsID != null && frm.DtsID.Length != 0) // { // for (int i = 0; i < frm.DtsID.Length; i++) // { // if (str != string.Empty) // { // str += ","; // } // str += SysConvert.ToString(frm.DtsID[i]); // } // setItemNews(str); // } // } // } // catch (Exception E) // { // this.ShowMessage(E.Message); // } //} //private void setItemNews(string p_Str) //{ // string[] orderid = p_Str.Split(','); // for (int i = 0; i < orderid.Length; i++) // { // string sql = "SELECT * FROM UV1_WH_IOFormDts WHERE DtsID=" + SysString.ToDBString(SysConvert.ToInt32(orderid[i])); // DataTable dt = SysUtils.Fill(sql); // if (dt.Rows.Count == 1) // { // gridView1.SetRowCellValue(i, "DLOADID", SysConvert.ToString(dt.Rows[0]["ID"])); // gridView1.SetRowCellValue(i, "DLOADSEQ", SysConvert.ToString(dt.Rows[0]["Seq"])); // gridView1.SetRowCellValue(i, "DLOADNO", SysConvert.ToString(dt.Rows[0]["FormNo"])); // gridView1.SetRowCellValue(i, "DLOADDtsID", SysConvert.ToString(dt.Rows[0]["DtsID"])); // gridView1.SetRowCellValue(i, "FormNM", SysConvert.ToString(dt.Rows[0]["FormNM"])); // gridView1.SetRowCellValue(i, "ItemCode", SysConvert.ToString(dt.Rows[0]["ItemCode"])); // gridView1.SetRowCellValue(i, "ItemName", SysConvert.ToString(dt.Rows[0]["ItemName"])); // gridView1.SetRowCellValue(i, "ItemStd", SysConvert.ToString(dt.Rows[0]["ItemStd"])); // gridView1.SetRowCellValue(i, "WHFormNo", SysConvert.ToString(dt.Rows[0]["FormNo"])); // gridView1.SetRowCellValue(i, "WHFormDate", SysConvert.ToString(dt.Rows[0]["FormDate"])); // gridView1.SetRowCellValue(i, "ColorNum", SysConvert.ToString(dt.Rows[0]["ColorNum"])); // gridView1.SetRowCellValue(i, "ColorName", SysConvert.ToString(dt.Rows[0]["ColorName"])); // if (SysConvert.ToString(dt.Rows[0]["DZQty"]) != string.Empty) // { // gridView1.SetRowCellValue(i, "DZQty", SysConvert.ToString(dt.Rows[0]["DZQty"])); // gridView1.SetRowCellValue(i, "DInvoiceQty", SysConvert.ToString(dt.Rows[0]["DZQty"])); // } // if (SysConvert.ToString(dt.Rows[0]["DZAmount"]) != string.Empty) // { // gridView1.SetRowCellValue(i, "DZSinglePrice", SysConvert.ToString(dt.Rows[0]["DZSinglePrice"])); // gridView1.SetRowCellValue(i, "DInvoiceSinglePrice", SysConvert.ToString(dt.Rows[0]["DZSinglePrice"])); // } // if (SysConvert.ToString(dt.Rows[0]["DZAmount"]) != string.Empty) // { // gridView1.SetRowCellValue(i, "DZAmount", SysConvert.ToString(dt.Rows[0]["DZAmount"])); // gridView1.SetRowCellValue(i, "DInvoiceAmount", SysConvert.ToString(dt.Rows[0]["DZAmount"])); // } // if (SysConvert.ToString(dt.Rows[0]["PieceQty"]) != string.Empty) // { // gridView1.SetRowCellValue(i, "PieceQty", SysConvert.ToString(dt.Rows[0]["PieceQty"])); // } // } // } //} //#endregion #region 自定义方法 /// <summary> /// 获得实体 /// </summary> /// <returns></returns> private InvoiceOperation EntityGet() { InvoiceOperation entity = new InvoiceOperation(); entity.ID = HTDataID; entity.SelectByID(); entity.FormNo = txtFormNo.Text.Trim(); entity.OrderCode = txtOrderCode.Text.Trim(); entity.InvoiceNO = txtInvoiceNO.Text.Trim(); entity.MakeOPID = FParamConfig.LoginID; entity.MakeOPName = FParamConfig.LoginName; entity.MakeDate = DateTime.Now.Date; entity.VendorID = SysConvert.ToString(drpVendorID.EditValue); entity.FormDate = DateTime.Now.Date; entity.Remark = txtRemark.Text.Trim(); entity.DVendorCon = txtDVendorCon.Text.Trim(); entity.SaleOPID = SysConvert.ToString(drpSaleOPID.EditValue); entity.TotalQty = SysConvert.ToDecimal(txtTotalQty.Text.Trim()); entity.TotalAmount = SysConvert.ToDecimal(txtTotalAmount.Text.Trim()); entity.DZTypeID = SysConvert.ToInt32(drpDZType.EditValue); entity.PreInvFlag = 1; entity.KPType = 2; return(entity); }
/// <summary> /// 获得实体 /// </summary> /// <returns></returns> private InvoiceOperation EntityGet() { InvoiceOperation entity = new InvoiceOperation(); entity.ID = HTDataID; return(entity); }
/// <summary> /// 删除 /// </summary> /// <param name="p_Entity">实体类</param> /// <returns>操作影响的记录行数</returns> public override int Delete(BaseEntity p_Entity) { try { InvoiceOperation MasterEntity = (InvoiceOperation)p_Entity; if (MasterEntity.ID == 0) { return(0); } //删除主表数据 string Sql = ""; Sql = "DELETE FROM Finance_InvoiceOperation 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> public override void EntitySet() { InvoiceOperation entity = new InvoiceOperation(); entity.ID = HTDataID; bool findFlag = entity.SelectByID(); ismx = entity.MXFlag == 0 ? false : true; txtFormNo.Text = entity.FormNo.ToString(); simpleButton1.Text = ismx ? "指定明细" : "不指定明细"; txtOrderCode.Text = entity.OrderCode.ToString(); txtInvoiceNO.Text = entity.InvoiceNO.ToString(); drpVendorID.EditValue = entity.VendorID; txtRemark.Text = entity.Remark.ToString(); txtDVendorCon.Text = entity.DVendorCon.ToString(); drpSaleOPID.EditValue = entity.SaleOPID; txtTotalQty.Text = entity.TotalQty.ToString(); txtTotalAmount.Text = entity.TotalAmount.ToString(); txtTotalTaxAmount.Text = entity.TotalTaxAmount.ToString(); drpDZType.EditValue = entity.DZTypeID; drpKPType.EditValue = entity.KPType; txtMakeDate.DateTime = entity.MakeDate; HTDataSubmitFlag = entity.SubmitFlag; HTDataDelFlag = entity.DelFlag; if (!findFlag) { } BindGridDts(); BindGridDts2(); }
/// <summary> /// 删除 /// </summary> public override void EntityDelete() { InvoiceOperationRule rule = new InvoiceOperationRule(); InvoiceOperation entity = EntityGet(); rule.RDelete(entity); }
/// <summary> /// 修改 /// </summary> /// <param name="p_BE">要修改的实体</param> /// <param name="sqlTrans">事务类</param> public void RUpdate(BaseEntity p_BE, IDBTransAccess sqlTrans) { try { this.CheckCorrect(p_BE); InvoiceOperation entity = (InvoiceOperation)p_BE; string sql = "SELECT FormNo FROM Finance_InvoiceOperation WHERE FormNo=" + SysString.ToDBString(entity.FormNo); sql += " AND ID<>" + entity.ID; DataTable dt = sqlTrans.Fill(sql); if (dt.Rows.Count > 0) { throw new BaseException("单号已存在,异常操作,请联系管理员检查"); } //sql = "SELECT ID FROM Finance_InvoiceOperation WHERE InvoiceNO=" + SysString.ToDBString(entity.InvoiceNO); //sql += " AND ID<>" + entity.ID; //dt = sqlTrans.Fill(sql); //if (dt.Rows.Count > 0) //{ // throw new BaseException("发票号已存在,请重新输入"); //} InvoiceOperationCtl control = new InvoiceOperationCtl(sqlTrans); control.Update(entity); } catch (BaseException) { throw; } catch (Exception E) { throw new BaseException(E.Message); } }
/// <summary> /// 设置 /// </summary> public override void EntitySet() { InvoiceOperation entity = new InvoiceOperation(); entity.ID = HTDataID; bool findFlag = entity.SelectByID(); txtFormNo.Text = entity.FormNo.ToString(); txtOrderCode.Text = entity.OrderCode.ToString(); txtInvoiceNO.Text = entity.InvoiceNO.ToString(); drpVendorID.EditValue = entity.VendorID; txtRemark.Text = entity.Remark.ToString(); txtDVendorCon.Text = entity.DVendorCon.ToString(); drpSaleOPID.EditValue = entity.SaleOPID; txtTotalQty.Text = entity.TotalQty.ToString(); txtTotalAmount.Text = entity.TotalAmount.ToString(); txtTotalTaxAmount.Text = entity.TotalTaxAmount.ToString(); drpDZType.EditValue = entity.DZTypeID; HTDataSubmitFlag = entity.SubmitFlag; HTDataDelFlag = entity.DelFlag; if (!findFlag) { } BindGridDts(); }
/// <summary> /// 撤销提交 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public override void btnSubmitCancel_Click(object sender, EventArgs e) { try { if (!FCommon.RightCheck(this.FormID, this.RightFormID, this.FormListAID, this.FormListBID, RightSub.新增)) { this.ShowMessage("你没有此操作权限"); return; } if (HTDataID == 0) { this.ShowMessage("请选择要操作的记录"); return; } InvoiceOperationRule rule = new InvoiceOperationRule(); InvoiceOperation entity = new InvoiceOperation(); entity.ID = HTDataID; entity.SelectByID(); if (entity.PreHXQty != 0) { this.ShowMessage("已有核销数据,不允许提交"); return; } rule.RSubmit(HTDataID, 0); FCommon.AddDBLog(this.Text, FormStatus.撤消提交.ToString(), "ID:" + HTDataID, ""); this.SetPosStatus(HTDataID); } catch (Exception E) { this.ShowMessage(E.Message); } }
/// <summary> /// 保存(传入事务处理) /// </summary> /// <param name="p_Entity"></param> /// <param name="p_BE"></param> /// <param name="sqlTrans"></param> public void RSave(InvoiceOperation p_Entity, BaseEntity[] p_BE, IDBTransAccess sqlTrans) { try { string sql = "DELETE FROM Finance_InvoiceOperationDts 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 Finance_InvoiceOperationDts 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++) { InvoiceOperationDts entitydts = (InvoiceOperationDts)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> public void RHXCancel(InvoiceOperation entity, int p_DtsID, IDBTransAccess sqlTrans) { try { string sql = string.Empty; //First 处理发票主表数据 InvoiceOperation entityinvoice = new InvoiceOperation(sqlTrans);//处理收付款主表数据 entityinvoice.ID = entity.ID; entityinvoice.SelectByID(); //Second 删除发票核销明细数据 InvoiceOperationDtsRule dtsRule = new InvoiceOperationDtsRule(); InvoiceOperationDts entityDts = new InvoiceOperationDts(sqlTrans); entityDts.ID = p_DtsID; entityDts.SelectByID(); if (entityDts.PayAmount != 0) { throw new Exception("不能操作,数据有收付款数据了,不能进行撤销"); } dtsRule.RDelete(entityDts, sqlTrans);//删除明细实体 //First 处理发票主表数据 entityinvoice.PreHXFlag = (int)YesOrNo.No; entityinvoice.PreHXQty -= entityDts.DInvoiceQty; entityinvoice.PreHXAmount -= entityDts.DInvoiceAmount; this.RUpdate(entityinvoice, sqlTrans); IOFormDtsRule ioformdtsRule = new IOFormDtsRule(); //处理出入库单据明细数据 IOFormDts entityIOF = new IOFormDts(sqlTrans); //出入库单据明细 entityIOF.ID = entityDts.DLOADDtsID; entityIOF.SelectByID(); //处理发票明细数据;出入库明细数据 if (entityIOF.PayAmount != 0) { throw new Exception("不能操作,数据已有收付款数据 ID:" + entityDts.DLOADDtsID + " " + entityIOF.ItemCode + " " + entityIOF.ColorNum); } sql = "UPDATE WH_IOFormDts SET InvoiceQty=ISNULL(InvoiceQty,0)-" + "(" + SysString.ToDBString(entityDts.DInvoiceQty) + ")"; sql += ",InvoiceAmount=ISNULL(InvoiceAmount,0)-" + "(" + SysString.ToDBString(entityDts.DInvoiceAmount) + ")"; sql += ",DtsInvoiceDelOPID=" + SysString.ToDBString(entity.SaleOPID); sql += ",DtsInvoiceDelTime=null"; sql += ",DtsInvoiceNo=''"; sql += ",DtsInvoiceDelFlag=0";//开票完成标志 sql += " WHERE ID=" + SysString.ToDBString(entityDts.DLOADDtsID); sqlTrans.ExecuteNonQuery(sql); } catch (BaseException) { throw; } catch (Exception E) { throw new BaseException(E.Message); } }
/// <summary> /// 撤销核销处理 /// </summary> public void RHXCancel(InvoiceOperation entity, int p_DtsID) { try { IDBTransAccess sqlTrans = TransSysUtils.GetDBTransAccess(); try { sqlTrans.OpenTrans(); this.RHXCancel(entity, p_DtsID, sqlTrans); sqlTrans.CommitTrans(); } catch (Exception TE) { sqlTrans.RollbackTrans(); throw TE; } } catch (BaseException) { throw; } catch (Exception E) { throw new BaseException(E.Message); } }
/// <summary> /// 新增 /// </summary> public override int EntityAdd() { InvoiceOperationRule rule = new InvoiceOperationRule(); InvoiceOperation entity = EntityGet(); InvoiceOperationDts[] entitydts = EntityDtsGet(); InvoiceYOperationDts[] entityDts2 = EntityDtsGet2(); if (!ismx) { if (entity.KPType == (int)EnumKPType.预开票) { ProcEntitySaveData2(entity, entityDts2); } else { ProcEntitySaveData(entity, entitydts); } if (SysConvert.ToInt32(drpKPType.EditValue) == (int)EnumKPType.期初开票) { entity.TotalAmount = SysConvert.ToDecimal(txtTotalAmount.Text.Trim()); entity.TotalQty = SysConvert.ToDecimal(txtTotalQty.Text.Trim()); entity.TotalTaxAmount = SysConvert.ToDecimal(entity.TotalAmount - entity.TotalAmount / 1.17m, 5); } } else { entity.TotalAmount = SysConvert.ToDecimal(txtTotalAmount.Text.Trim()); entity.TotalQty = SysConvert.ToDecimal(txtTotalQty.Text.Trim()); } entity.SubmitFlag = this.HTSubmitFlagInsertGet(); entity.TotalTaxAmount = SysConvert.ToDecimal(entity.TotalAmount - entity.TotalAmount / 1.17m, 5); rule.RAdd(entity, entitydts, entityDts2); return(entity.ID); }
/// <summary> /// 核销处理 /// </summary> public void RHX(RecPay entity, int p_InvoiceID, decimal p_HXAmount, IDBTransAccess sqlTrans) { try { string sql = string.Empty; //First 处理收付款主表数据 RecPay entitypay = new RecPay(sqlTrans);//处理收付款主表数据 entitypay.ID = entity.ID; entitypay.SelectByID(); if (entitypay.HXAmount + p_HXAmount > entitypay.ExAmount) { throw new Exception("不能操作,核销金额超过了付款未核金额"); } if (entitypay.HXAmount + p_HXAmount == entitypay.ExAmount) { entitypay.HXFlag = (int)YesOrNo.Yes; } entitypay.HXAmount += p_HXAmount; entitypay.NoHXAmount = entitypay.ExAmount - entitypay.HXAmount; this.RUpdate(entitypay, sqlTrans); //Second InvoiceOperationRule invoicerule = new InvoiceOperationRule(); //处理发票主表数据 InvoiceOperation invoiceentity = new InvoiceOperation(sqlTrans); //发票实体 invoiceentity.ID = p_InvoiceID; invoiceentity.SelectByID(); if (invoiceentity.PayAmount + p_HXAmount > invoiceentity.TotalAmount) { throw new Exception("不能操作,核销金额超过了发票未核金额"); } invoiceentity.PayAmount += p_HXAmount; invoicerule.RUpdate(invoiceentity, sqlTrans); //Third 增加付款核销明细数据 RecPayHXDtsRule dtsRule = new RecPayHXDtsRule(); RecPayHXDts dtsentity = new RecPayHXDts(sqlTrans); dtsentity.MainID = entity.ID; dtsentity.HXOPID = entity.MakeOPID; dtsentity.HXOPName = entity.MakeOPName; dtsentity.HXDate = DateTime.Now; dtsentity.HXAmount = p_HXAmount; dtsentity.InvoiceNo = invoiceentity.InvoiceNO; dtsentity.InvoiceOperationID = p_InvoiceID; dtsRule.RAdd(dtsentity, sqlTrans);//增加明细实体 } catch (BaseException) { throw; } catch (Exception E) { throw new BaseException(E.Message); } }
/// <summary> /// 修改 /// </summary> /// <param name="p_BE">要修改的实体</param> /// <param name="sqlTrans">事务类</param> public void RUpdate2(BaseEntity p_BE, BaseEntity[] p_BE2, IDBTransAccess sqlTrans) { try { this.CheckCorrect(p_BE); InvoiceOperation entity = (InvoiceOperation)p_BE; string sql = "SELECT FormNo FROM Finance_InvoiceOperation WHERE FormNo=" + SysString.ToDBString(entity.FormNo); sql += " AND ID<>" + entity.ID; DataTable dt = sqlTrans.Fill(sql); if (dt.Rows.Count > 0) { throw new BaseException("单号已存在,异常操作,请联系管理员检查"); } if (entity.InvoiceNO != "") { sql = "SELECT ID FROM Finance_InvoiceOperation WHERE InvoiceNO=" + SysString.ToDBString(entity.InvoiceNO); sql += " AND ID<>" + entity.ID; dt = sqlTrans.Fill(sql); if (dt.Rows.Count > 0) { throw new BaseException("发票号已存在,请重新输入"); } } InvoiceOperationCtl control = new InvoiceOperationCtl(sqlTrans); control.Update(entity); sql = "DELETE Finance_InvoiceYOperationDts WHERE MainID=" + SysString.ToDBString(entity.ID); sqlTrans.ExecuteNonQuery(sql); for (int i = 0; i < p_BE2.Length; i++) { InvoiceYOperationDtsRule rule = new InvoiceYOperationDtsRule(); InvoiceYOperationDts entityDts = (InvoiceYOperationDts)p_BE2[i]; entityDts.MainID = entity.ID; entityDts.Seq = i + 1; rule.RAdd(entityDts, sqlTrans); } } catch (BaseException) { throw; } catch (Exception E) { throw new BaseException(E.Message); } }
/// <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) { InvoiceOperation entity = (InvoiceOperation)p_BE; bool ret = false; string sql = string.Format(" SELECT {0} FROM {1} WHERE 1=1 AND {0}={2} AND {3}<>{4}", p_FieldName, "Finance_InvoiceOperation", SysString.ToDBString(p_FieldValue), "ID", entity.ID); DataTable dt = p_sqlTrans.Fill(sql); if (dt.Rows.Count != 0) { ret = true; } return(ret); }
/// <summary> /// 核销操作 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnPreHXExcute_Click(object sender, EventArgs e) { try { if (!FCommon.RightCheck(this.FormID, this.RightFormID, this.FormListAID, this.FormListBID, RightSub.新增)) { this.ShowMessage("你没有此操作权限"); return; } if (HTDataID == 0) { this.ShowMessage("请定位主记录"); return; } if (HTDataSubmitFlag != (int)YesOrNo.Yes) { this.ShowMessage("单据未提交,不能操作"); return; } if (saveIOFormDtsID == 0) { this.ShowMessage("请选择对账记录"); return; } if (SysConvert.ToDecimal(txtPreHXQty.Text.Trim()) == 0) { this.ShowMessage("请输入核销数量"); txtPreHXQty.Focus(); return; } InvoiceOperationRule rule = new InvoiceOperationRule(); InvoiceOperation entity = EntityGet(); InvoiceOperationDts entitydts = EntityDtsGetOne(); rule.RHX(entity, entitydts); FCommon.AddDBLog(this.Text, "核销", "ID:" + HTDataID, ""); this.SetPosStatus(HTDataID); this.BindGrid(); } catch (Exception E) { this.ShowMessage(E.Message); } }
/// <summary> /// 新增(传入事务处理) /// </summary> /// <param name="p_BE">要新增的实体</param> /// <param name="sqlTrans">事务类</param> public void RAdd2(BaseEntity p_BE, BaseEntity[] p_BE2, IDBTransAccess sqlTrans) { try { this.CheckCorrect(p_BE); InvoiceOperation entity = (InvoiceOperation)p_BE; string sql = "SELECT FormNo FROM Finance_InvoiceOperation WHERE FormNo=" + SysString.ToDBString(entity.FormNo); DataTable dt = sqlTrans.Fill(sql); if (dt.Rows.Count > 0) { throw new BaseException("单号已存在,请重新生成"); } if (entity.InvoiceNO != "") { sql = "SELECT ID FROM Finance_InvoiceOperation WHERE InvoiceNO=" + SysString.ToDBString(entity.InvoiceNO); dt = sqlTrans.Fill(sql); if (dt.Rows.Count > 0) { throw new BaseException("发票号已存在,请重新输入"); } } InvoiceOperationCtl control = new InvoiceOperationCtl(sqlTrans); entity.ID = (int)EntityIDTable.GetID((long)SysEntity.Finance_InvoiceOperation, sqlTrans); control.AddNew(entity); for (int i = 0; i < p_BE2.Length; i++) { InvoiceYOperationDtsRule rule = new InvoiceYOperationDtsRule(); InvoiceYOperationDts entityDts = (InvoiceYOperationDts)p_BE2[i]; entityDts.MainID = entity.ID; entityDts.Seq = i + 1; rule.RAdd(entityDts, sqlTrans); } FormNoControlRule rulest = new FormNoControlRule(); rulest.RAddSort((int)FormNoControlEnum.发票单号, sqlTrans); } catch (BaseException) { throw; } catch (Exception E) { throw new BaseException(E.Message); } }
/// <summary> /// 撤销核销处理 /// </summary> public void RHXCancel(RecPay entity, int p_DtsID, IDBTransAccess sqlTrans) { try { string sql = string.Empty; //First 处理收付款主表数据 RecPay entitypay = new RecPay(sqlTrans);//处理收付款主表数据 entitypay.ID = entity.ID; entitypay.SelectByID(); //Second 删除付款核销明细数据 RecPayHXDtsRule dtsRule = new RecPayHXDtsRule(); RecPayHXDts dtsentity = new RecPayHXDts(sqlTrans); dtsentity.ID = p_DtsID; dtsentity.SelectByID(); dtsRule.RDelete(dtsentity, sqlTrans);//删除明细实体 //First 处理收付款主表数据 entitypay.HXFlag = (int)YesOrNo.No; entitypay.HXAmount -= dtsentity.HXAmount; entitypay.NoHXAmount = entitypay.ExAmount - entitypay.HXAmount; this.RUpdate(entitypay, sqlTrans); //Third 处理发票主表数据 InvoiceOperationRule invoicerule = new InvoiceOperationRule(); //处理发票主表数据 InvoiceOperation invoiceentity = new InvoiceOperation(sqlTrans); //发票实体 invoiceentity.ID = dtsentity.InvoiceOperationID; invoiceentity.SelectByID(); invoiceentity.PayAmount -= dtsentity.HXAmount; if (invoiceentity.PayAmount < 0) { throw new BaseException("撤销后数据有误,请检查,发票的核销金额小于0"); } invoicerule.RUpdate(invoiceentity, sqlTrans); } 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); InvoiceOperation entity = (InvoiceOperation)p_BE; string sql = "SELECT FormNo FROM Finance_InvoiceOperation WHERE FormNo=" + SysString.ToDBString(entity.FormNo); DataTable dt = sqlTrans.Fill(sql); if (dt.Rows.Count > 0) { throw new BaseException("单号已存在,请重新生成"); } if (entity.InvoiceNO != "") { sql = "SELECT ID FROM Finance_InvoiceOperation WHERE InvoiceNO=" + SysString.ToDBString(entity.InvoiceNO); dt = sqlTrans.Fill(sql); if (dt.Rows.Count > 0) { throw new BaseException("发票号已存在,请重新输入"); } } InvoiceOperationCtl control = new InvoiceOperationCtl(sqlTrans); entity.ID = (int)EntityIDTable.GetID((long)SysEntity.Finance_InvoiceOperation, sqlTrans); control.AddNew(entity); FormNoControlRule rulest = new FormNoControlRule(); if (entity.DZTypeID == 3) { rulest.RAddSort((int)FormNoControlEnum.发票单号, sqlTrans); } else { rulest.RAddSort((int)FormNoControlEnum.发票单号2, sqlTrans); } } catch (BaseException) { throw; } catch (Exception E) { throw new BaseException(E.Message); } }
/// <summary> /// 修改 /// </summary> public override void EntityUpdate() { InvoiceOperationRule rule = new InvoiceOperationRule(); InvoiceOperation entity = EntityGet(); InvoiceYOperationDts[] entityDts = EntityDtsGet(); decimal totalqty = 0; decimal totalamount = 0; for (int i = 0; i < entityDts.Length; i++) { totalqty += entityDts[i].Qty; totalamount += entityDts[i].Amount; } entity.TotalQty = totalqty; entity.TotalAmount = totalamount; entity.TotalTaxAmount = SysConvert.ToDecimal(entity.TotalAmount - entity.TotalAmount / 1.17m, 5); rule.RUpdate2(entity, entityDts); }
/// <summary> /// 撤销核销操作 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnPreHXCancelExcute_Click(object sender, EventArgs e) { try { if (!FCommon.RightCheck(this.FormID, this.RightFormID, this.FormListAID, this.FormListBID, RightSub.新增)) { this.ShowMessage("你没有此操作权限"); return; } if (HTDataID == 0) { this.ShowMessage("请定位主记录"); return; } int dtsID = SysConvert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DtsID")); if (dtsID == 0) { this.ShowMessage("请选择核销记录"); return; } if (DialogResult.Yes != ShowConfirmMessage("确认撤销核销本条记录?")) { return; } InvoiceOperationRule rule = new InvoiceOperationRule(); InvoiceOperation entity = EntityGet(); rule.RHXCancel(entity, dtsID); FCommon.AddDBLog(this.Text, "撤销核销", "ID:" + HTDataID, ""); this.SetPosStatus(HTDataID); this.BindGrid(); } catch (Exception E) { this.ShowMessage(E.Message); } }
/// <summary> /// 处理保存数据汇总数 /// </summary> /// <param name="entity"></param> /// <param name="entitydts"></param> void ProcEntitySaveData2(InvoiceOperation entity, InvoiceYOperationDts[] entitydts) { decimal TotalQty = 0; decimal TotalAmount = 0; decimal PayAmount = 0; decimal totaltaxamount = 0; for (int i = 0; i < entitydts.Length; i++) { TotalQty += SysConvert.ToDecimal(entitydts[i].Qty); TotalAmount += SysConvert.ToDecimal(entitydts[i].Amount); } entity.TotalQty = TotalQty; entity.TotalAmount = TotalAmount; entity.PayAmount = PayAmount; entity.TotalTaxAmount = totaltaxamount; entity.PreHXQty = entity.TotalQty; entity.PreHXAmount = entity.TotalAmount; entity.PreHXFlag = (int)YesOrNo.Yes; }
/// <summary> /// 审核 /// </summary> /// <param name="p_FormID">单据ID</param> /// <param name="p_Type">0/1/2/3:弃审/审核</param> public void RSubmit(int p_FormID, int p_Type, IDBTransAccess sqlTrans) { try { int p_TempType = p_Type;//处理状态 string sql = string.Empty; InvoiceOperation entity = new InvoiceOperation(sqlTrans); entity.ID = p_FormID; entity.SelectByID(); if (entity.SubmitFlag == p_Type)//如果相同异常 { throw new Exception("单据状态重复设置,请关闭程序重新打开操作"); } //更新状态 sql = "UPDATE Finance_InvoiceOperation SET SubmitFlag=" + SysString.ToDBString(p_Type); sql += " WHERE ID=" + SysString.ToDBString(p_FormID); sqlTrans.ExecuteNonQuery(sql); SetInvoiceOperation(p_FormID, p_Type, sqlTrans);//提交操作 //switch (p_Type) //{ // case 1://提交 // break; // case 0://撤销提交 // SetCancelInvoiceOperation(p_FormID, p_Type, sqlTrans); // break; //} } 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); InvoiceOperation entity = (InvoiceOperation)p_BE; InvoiceOperationCtl control = new InvoiceOperationCtl(sqlTrans); string sql = "DELETE FROM Finance_InvoiceOperationDts WHERE MainID=" + entity.ID.ToString(); sqlTrans.ExecuteNonQuery(sql);//删除原单据明细数据 control.Delete(entity); } catch (BaseException) { throw; } catch (Exception E) { throw new BaseException(E.Message); } }
private void frmInvoiceOperationEdit_FormClosing(object sender, FormClosingEventArgs e) { try { if (HTDataID > 0) { InvoiceOperation entity = new InvoiceOperation(); entity.ID = HTDataID; entity.SelectByID(); if (entity.SubmitFlag == 0) { if (DialogResult.Yes != ShowConfirmMessage(this.Text + Environment.NewLine + "没有提交单据,是否确认关闭窗体")) { e.Cancel = true; } } } } catch (Exception E) { this.ShowMessage(E.Message); } }
protected void lkbUpdateInvoice_Click(object sender, EventArgs e) { try { // GridView gv = (GridView)fvInvoice.FindControl("gvItems"); List <GST_TRN_INVOICE_DATA> items = GetGVData(); //var it = Invoice; if (Invoice != null) { //Seller seller = new Seller(); GST_TRN_INVOICE inv = new GST_TRN_INVOICE(); inv.InvoiceDate = DateTime.Now; inv.InvoiceMonth = Convert.ToByte(DateTime.Now.Month); var CurrentSrlNo = unitOfWork.InvoiceRepository.Filter(f => f.SellerUserID == Invoice.AspNetUser.Id).Count() + 1; inv.InvoiceNo = InvoiceOperation.InvoiceNo(Invoice.AspNetUser, Invoice.FinYear_ID.ToString(), CurrentSrlNo.ToString()); inv.SellerUserID = Invoice.SellerUserID; inv.ReceiverUserID = Invoice.ReceiverUserID; inv.ConsigneeUserID = Invoice.ConsigneeUserID; inv.OrderDate = Invoice.OrderDate; inv.VendorID = Invoice.VendorID; inv.TransShipment_ID = Invoice.TransShipment_ID; inv.Freight = Invoice.Freight; inv.Insurance = Invoice.Insurance; inv.PackingAndForwadingCharges = Invoice.PackingAndForwadingCharges; inv.ElectronicReferenceNo = Invoice.ElectronicReferenceNo; inv.ElectronicReferenceNoDate = Invoice.ElectronicReferenceNoDate; inv.InvoiceType = Invoice.InvoiceType; inv.FinYear_ID = Invoice.FinYear_ID; inv.IsInter = Invoice.IsInter; inv.ReceiverFinYear_ID = Invoice.ReceiverFinYear_ID; inv.ParentInvoiceID = Invoice.InvoiceID; inv.TaxBenefitingState = Invoice.AspNetUser2.StateCode; inv.Status = true; // var invoicePeriod=unitOfWork.FinYearRepository.Find(f=>f.Fin_ID== Invoice.FinYear_ID).Finyear_Format; // GST_TRN_INVOICE updateInvoice = new GST_TRN_INVOICE(); inv.InvoiceStatus = Convert.ToByte(EnumConstants.InvoiceStatus.Fresh); inv.InvoiceSpecialCondition = Invoice.InvoiceSpecialCondition; inv.CreatedDate = DateTime.Now; inv.UpdatedDate = DateTime.Now; inv.CreatedBy = Common.LoggedInUserID(); inv.UpdatedBy = Common.LoggedInUserID(); var invoiceCreate = unitOfWork.InvoiceRepository.Create(inv); unitOfWork.Save(); //Update old invoice status that is A or M---------------Start------------- if (Invoice.InvoiceMonth == (byte)DateTime.Now.Month) { var oldInvoice = unitOfWork.InvoiceRepository.Find(f => f.InvoiceID == Invoice.InvoiceID); oldInvoice.InvoiceStatus = Convert.ToByte(EnumConstants.InvoiceStatus.Amended); // Invoice.InvoiceID = updateInvoice.InvoiceID; var invoiceUpdate = unitOfWork.InvoiceRepository.Update(oldInvoice); unitOfWork.Save(); } else { var oldInvoice = unitOfWork.InvoiceRepository.Find(f => f.InvoiceID == Invoice.InvoiceID); oldInvoice.InvoiceStatus = Convert.ToByte(EnumConstants.InvoiceStatus.Modified); // updateInvoice.InvoiceID = updateInvoice.InvoiceID; var invoiceUpdate = unitOfWork.InvoiceRepository.Update(oldInvoice); unitOfWork.Save(); } //-------------End-------- // bool isInter =InvoiceOperation.GetConsumptionDestinationOfGoodsOrServices(Invoice.AspNetUser.StateCode, Invoice.AspNetUser2.StateCode, Invoice.AspNetUser1.StateCode); bool isInter = Invoice.IsInter.Value; bool isStateExampted = unitOfWork.StateRepository.Find(f => f.StateCode == Invoice.AspNetUser2.StateCode).IsExempted.Value; bool isExport = (Invoice.InvoiceSpecialCondition == (byte)EnumConstants.InvoiceSpecialCondition.Export || Invoice.InvoiceSpecialCondition == (byte)EnumConstants.InvoiceSpecialCondition.SEZDeveloper || Invoice.InvoiceSpecialCondition == (byte)EnumConstants.InvoiceSpecialCondition.SEZUnit || Invoice.InvoiceSpecialCondition == (byte)EnumConstants.InvoiceSpecialCondition.DeemedExport); bool isJobwork = (Invoice.InvoiceSpecialCondition == (byte)EnumConstants.InvoiceSpecialCondition.JobWork); bool isImport = (Invoice.InvoiceSpecialCondition == (byte)EnumConstants.InvoiceSpecialCondition.Import); var stateData = unitOfWork.StateRepository.Find(c => c.StateCode == Invoice.AspNetUser.StateCode); var isUTState = stateData.UT.Value; var isExempted = stateData.IsExempted.Value; var invLineItem = from invo in items select new GST_TRN_INVOICE_DATA { InvoiceID = invoiceCreate.InvoiceID, LineID = invo.LineID, // GST_MST_ITEM = invo.Item, Item_ID = invo.GST_MST_ITEM.Item_ID, Qty = invo.Qty, Rate = invo.Rate, TotalAmount = invo.TotalAmount, Discount = invo.Discount, TaxableAmount = invo.TaxableAmount, IGSTRate = isJobwork ? 0 : (isUTState ? 0 : (isInter ? 0 : (isExport ? invo.GST_MST_ITEM.IGST : (isImport ? invo.GST_MST_ITEM.IGST : 0)))), IGSTAmt = isJobwork ? 0 : (isUTState ? 0 : (isInter ? 0 : (isExport ? Calculate.CalculateIGSTLineIDWise(invo.TaxableAmount.HasValue ? invo.TaxableAmount.Value : 0, invo.GST_MST_ITEM.IGST.Value) : (isImport ? Calculate.CalculateIGSTLineIDWise(invo.TaxableAmount.HasValue ? invo.TaxableAmount.Value : 0, invo.GST_MST_ITEM.IGST.Value) : 0)))), CGSTRate = isJobwork ? 0 : (isUTState ? 0 : (isInter ? (isExport ? 0 : invo.GST_MST_ITEM.CGST) : 0)), CGSTAmt = isJobwork ? 0 : (isUTState ? 0 : (isInter ? (isExport ? 0 : Calculate.CalculateCGSTLineIDWise(invo.TaxableAmount.HasValue ? invo.TaxableAmount.Value : 0, invo.GST_MST_ITEM.CGST.Value)) : 0)), SGSTRate = isJobwork ? 0 : (isUTState ? 0 : (isInter ? 0 : (isExport ? 0 : invo.GST_MST_ITEM.SGST))), SGSTAmt = isJobwork ? 0 : (isUTState ? 0 : (isInter ? 0 : (isExport ? 0 : Calculate.CalculateSGSTLineIDWise(invo.TaxableAmount.HasValue ? invo.TaxableAmount.Value : 0, invo.GST_MST_ITEM.SGST.Value)))), UGSTRate = isJobwork ? 0 : (isExport ? 0 : (isUTState ? invo.GST_MST_ITEM.UGST.Value : 0)), UGSTAmt = isJobwork ? 0 : (isExport ? 0 : (isUTState ? Calculate.CalculateUGSTLineIDWise(invo.TaxableAmount.HasValue ? invo.TaxableAmount.Value : 0, invo.GST_MST_ITEM.UGST.Value) : 0)), CessRate = isJobwork ? 0 : invo.GST_MST_ITEM.CESS, CessAmt = isJobwork ? 0 : Calculate.CalculateCESSLineIDWise(invo.TaxableAmount.HasValue ? invo.TaxableAmount.Value : 0, invo.GST_MST_ITEM.CESS.Value) //TotalAmountWithTax = invo.TaxableAmount + IGSTAmt, }; foreach (GST_TRN_INVOICE_DATA item in invLineItem) { item.TotalAmountWithTax = item.TaxableAmount + item.IGSTAmt + item.CGSTAmt + item.SGSTAmt + item.UGSTAmt + item.CessAmt; unitOfWork.InvoiceDataRepository.Create(item); } unitOfWork.Save(); gvInvoice_Items.DataSource = null; gvInvoice_Items.DataBind(); lkbUpdateInvoice.Visible = false; Invoice = new GST_TRN_INVOICE(); this.Master.SuccessMessage = "Data updated successfully."; //uc_sucess.Visible = true; ScriptManager.RegisterStartupScript(Page, Page.GetType(), "viewInvoiceModelSucessMessage", "$('#viewInvoiceModelSucessMessage').modal();", true); } } catch (Exception ex) { } }
/// <summary> /// 检查将要操作的数据是否符合业务规则 /// </summary> /// <param name="p_BE"></param> private void CheckCorrect(BaseEntity p_BE) { InvoiceOperation entity = (InvoiceOperation)p_BE; }
/// <summary> /// 修改 /// </summary> /// <param name="p_Entity">实体类</param> /// <returns>操作影响的记录行数</returns> public override int Update(BaseEntity p_Entity) { try { InvoiceOperation MasterEntity = (InvoiceOperation)p_Entity; if (MasterEntity.ID == 0) { return(0); } //更新主表数据 StringBuilder UpdateBuilder = new StringBuilder(); UpdateBuilder.Append("UPDATE Finance_InvoiceOperation SET "); UpdateBuilder.Append(" ID=" + SysString.ToDBString(MasterEntity.ID) + ","); UpdateBuilder.Append(" CompanyTypeID=" + SysString.ToDBString(MasterEntity.CompanyTypeID) + ","); UpdateBuilder.Append(" FormNo=" + SysString.ToDBString(MasterEntity.FormNo) + ","); UpdateBuilder.Append(" OrderCode=" + SysString.ToDBString(MasterEntity.OrderCode) + ","); UpdateBuilder.Append(" InvoiceNO=" + SysString.ToDBString(MasterEntity.InvoiceNO) + ","); UpdateBuilder.Append(" MakeOPID=" + SysString.ToDBString(MasterEntity.MakeOPID) + ","); UpdateBuilder.Append(" MakeOPName=" + SysString.ToDBString(MasterEntity.MakeOPName) + ","); 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(" CheckOPID=" + SysString.ToDBString(MasterEntity.CheckOPID) + ","); if (MasterEntity.CheckDate != SystemConfiguration.DateTimeDefaultValue) { UpdateBuilder.Append(" CheckDate=" + SysString.ToDBString(MasterEntity.CheckDate.ToString("yyyy-MM-dd HH:mm:ss")) + ","); } else { UpdateBuilder.Append(" CheckDate=null,"); } UpdateBuilder.Append(" SubmitFlag=" + SysString.ToDBString(MasterEntity.SubmitFlag) + ","); UpdateBuilder.Append(" DelFlag=" + SysString.ToDBString(MasterEntity.DelFlag) + ","); UpdateBuilder.Append(" VendorID=" + SysString.ToDBString(MasterEntity.VendorID) + ","); 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(" Remark=" + SysString.ToDBString(MasterEntity.Remark) + ","); UpdateBuilder.Append(" DVendorCon=" + SysString.ToDBString(MasterEntity.DVendorCon) + ","); UpdateBuilder.Append(" SaleOPID=" + SysString.ToDBString(MasterEntity.SaleOPID) + ","); if (MasterEntity.TotalQty != 0) { UpdateBuilder.Append(" TotalQty=" + SysString.ToDBString(MasterEntity.TotalQty) + ","); } else { UpdateBuilder.Append(" TotalQty=null,"); } if (MasterEntity.TotalAmount != 0) { UpdateBuilder.Append(" TotalAmount=" + SysString.ToDBString(MasterEntity.TotalAmount) + ","); } else { UpdateBuilder.Append(" TotalAmount=null,"); } UpdateBuilder.Append(" DZTypeID=" + SysString.ToDBString(MasterEntity.DZTypeID) + ","); if (MasterEntity.PayAmount != 0) { UpdateBuilder.Append(" PayAmount=" + SysString.ToDBString(MasterEntity.PayAmount) + ","); } else { UpdateBuilder.Append(" PayAmount=null,"); } if (MasterEntity.TotalTaxAmount != 0) { UpdateBuilder.Append(" TotalTaxAmount=" + SysString.ToDBString(MasterEntity.TotalTaxAmount) + ","); } else { UpdateBuilder.Append(" TotalTaxAmount=null,"); } if (MasterEntity.PreHXAmount != 0) { UpdateBuilder.Append(" PreHXAmount=" + SysString.ToDBString(MasterEntity.PreHXAmount) + ","); } else { UpdateBuilder.Append(" PreHXAmount=null,"); } if (MasterEntity.PreHXQty != 0) { UpdateBuilder.Append(" PreHXQty=" + SysString.ToDBString(MasterEntity.PreHXQty) + ","); } else { UpdateBuilder.Append(" PreHXQty=null,"); } UpdateBuilder.Append(" PreHXFlag=" + SysString.ToDBString(MasterEntity.PreHXFlag) + ","); UpdateBuilder.Append(" PreInvFlag=" + SysString.ToDBString(MasterEntity.PreInvFlag) + ","); UpdateBuilder.Append(" KPType=" + SysString.ToDBString(MasterEntity.KPType) + ","); UpdateBuilder.Append(" MXFlag=" + SysString.ToDBString(MasterEntity.MXFlag)); 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_FormID"></param> /// <param name="p_Type"></param> /// <param name="sqlTrans"></param> private void SetInvoiceOperation(int p_FormID, int p_Type, IDBTransAccess sqlTrans) { string sql = "SELECT ID,MainID,Seq FROM Finance_InvoiceOperationDts WHERE MainID=" + SysString.ToDBString(p_FormID); sql += " ORDER BY Seq"; DataTable dt = sqlTrans.Fill(sql); if (dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { //对账单 InvoiceOperation entity = new InvoiceOperation(sqlTrans); entity.ID = p_FormID; entity.SelectByID(); ///对账单明细 InvoiceOperationDts entityDts = new InvoiceOperationDts(sqlTrans); entityDts.ID = SysConvert.ToInt32(dr["ID"]); entityDts.SelectByID(); ///仓库单据明细 IOFormDts entityIOF = new IOFormDts(sqlTrans); if (entityDts.MergeFlage == 1) { if (entityDts.DLOADID > 0) { IOForm entityNoDts = new IOForm(sqlTrans); entityNoDts.ID = entityDts.DLOADID; entityNoDts.SelectByID(); if (entityNoDts.SelectByID()) { } else { throw new Exception("操作异常,没有找到出入库记录 ID:" + entityDts.DLOADID); } if (p_Type == (int)YesOrNo.Yes)//提交 { //if (entityDts.DInvoiceQty + entityIOF.InvoiceQty > entityIOF.DZQty || entityDts.DInvoiceAmount + entityIOF.InvoiceAmount > entityIOF.DZAmount)//开票溢出 //{ // throw new Exception("不能操作,开票数超过对账数 或 开票金额超过对账金额 ID:" + entityDts.DLOADDtsID + " " + entityIOF.ItemCode + " " + entityIOF.ColorNum); //} if (entityNoDts.InvoiceDelFlag == (int)YesOrNo.Yes && entityNoDts.TotalQty == entityNoDts.InvoiceQty) { throw new Exception("不能操作,数据已开票结束 ID:" + entityDts.DLOADID); //+ " " + SysConvert.ToString(drs["ItemCode"]) + " " + SysConvert.ToString(drs["ColorNum"]) } sql = "UPDATE WH_IOForm SET InvoiceQty=ISNULL(InvoiceQty,0)+" + "(" + SysString.ToDBString(entityDts.DInvoiceQty) + ")"; sql += ",InvoiceAmount=ISNULL(InvoiceAmount,0)+" + "(" + SysString.ToDBString(SysConvert.ToDecimal(entityDts.DInvoiceAmount)) + ")"; sql += ",InvoiceDelOPID=" + SysString.ToDBString(entity.SaleOPID); sql += ",InvoiceDelTime=" + SysString.ToDBString(entity.FormDate.ToString("yyyy-MM-dd")); sql += ",InvoiceNo=" + SysString.ToDBString(entity.InvoiceNO); if (entityDts.DInvoiceAmount + entityNoDts.InvoiceAmount >= entityNoDts.DZAmount) //开票完成 { sql += ",InvoiceDelFlag=1"; } else { sql += ",InvoiceDelFlag=0"; } sql += " WHERE ID=" + SysString.ToDBString(entityNoDts.ID); sqlTrans.ExecuteNonQuery(sql); if (entityDts.DLoadCheckDtsID > 0) { sql = "UPDATE Finance_CheckOperationDts SET InvoiceFlag=1 WHERE ID=" + SysString.ToDBString(entityDts.DLoadCheckDtsID); sqlTrans.ExecuteNonQuery(sql); } } else//撤销提交 { if (entityNoDts.PayAmount != 0) { throw new Exception("不能操作,数据已有收付款数据 ID:" + entityDts.DLOADID); } sql = "UPDATE WH_IOForm SET InvoiceQty=ISNULL(InvoiceQty,0)-" + "(" + SysString.ToDBString(entityDts.DInvoiceQty) + ")"; sql += ",InvoiceAmount=ISNULL(InvoiceAmount,0)-" + "(" + SysString.ToDBString(entityDts.DInvoiceAmount) + ")"; sql += ",InvoiceDelOPID=" + SysString.ToDBString(entity.SaleOPID); sql += ",InvoiceDelTime=null"; sql += ",InvoiceNo=''"; if (entityNoDts.InvoiceQty == entityDts.DInvoiceQty) { sql += ",InvoiceDelFlag=0";//开票完成标志 } sql += " WHERE ID=" + SysString.ToDBString(entityNoDts.ID); sqlTrans.ExecuteNonQuery(sql); if (entityDts.DLoadCheckDtsID > 0) { sql = "UPDATE Finance_CheckOperationDts SET InvoiceFlag=0 WHERE ID=" + SysString.ToDBString(entityDts.DLoadCheckDtsID); sqlTrans.ExecuteNonQuery(sql); } } } else { if (p_Type == (int)YesOrNo.Yes)//提交 { if (entityDts.DLoadCheckDtsID > 0) { sql = "UPDATE Finance_CheckOperationDts SET InvoiceFlag=1 WHERE ID=" + SysString.ToDBString(entityDts.DLoadCheckDtsID); sqlTrans.ExecuteNonQuery(sql); } } else { if (entityDts.DLoadCheckDtsID > 0) { sql = "UPDATE Finance_CheckOperationDts SET InvoiceFlag=0 WHERE ID=" + SysString.ToDBString(entityDts.DLoadCheckDtsID); sqlTrans.ExecuteNonQuery(sql); } } } } else { entityIOF.ID = entityDts.DLOADDtsID; if (entityDts.DLOADDtsID > 0) { if (entityIOF.SelectByID()) { } else { throw new Exception("操作异常,没有找到出入库记录 ID:" + entityDts.DLOADDtsID); } if (p_Type == (int)YesOrNo.Yes)//提交 { if (entityIOF.DtsInvoiceDelFlag == (int)YesOrNo.Yes && entityIOF.Qty == entityIOF.InvoiceQty) { throw new Exception("不能操作,数据已开票结束 ID:" + entityDts.DLOADDtsID + " " + entityIOF.ItemCode + " " + entityIOF.ColorNum); } //if (entityDts.DInvoiceQty + entityIOF.InvoiceQty > entityIOF.DZQty || entityDts.DInvoiceAmount + entityIOF.InvoiceAmount > entityIOF.DZAmount)//开票溢出 //{ // throw new Exception("不能操作,开票数超过对账数 或 开票金额超过对账金额 ID:" + entityDts.DLOADDtsID + " " + entityIOF.ItemCode + " " + entityIOF.ColorNum); //} sql = "UPDATE WH_IOFormDts SET InvoiceQty=ISNULL(InvoiceQty,0)+" + "(" + SysString.ToDBString(entityDts.DInvoiceQty) + ")"; sql += ",InvoiceAmount=ISNULL(InvoiceAmount,0)+" + "(" + SysString.ToDBString(entityDts.DInvoiceAmount) + ")"; sql += ",DtsInvoiceDelOPID=" + SysString.ToDBString(entity.SaleOPID); sql += ",DtsInvoiceDelTime=" + SysString.ToDBString(entity.FormDate.ToString("yyyy-MM-dd")); sql += ",DtsInvoiceNo=" + SysString.ToDBString(entity.InvoiceNO); if (entityDts.DInvoiceAmount + entityIOF.InvoiceAmount >= entityIOF.DZAmount)//开票完成 { sql += ",DtsInvoiceDelFlag=1"; } else { sql += ",DtsInvoiceDelFlag=0"; } sql += " WHERE ID=" + SysString.ToDBString(entityDts.DLOADDtsID); sqlTrans.ExecuteNonQuery(sql); if (entityDts.DLoadCheckDtsID > 0) { sql = "UPDATE Finance_CheckOperationDts SET InvoiceFlag=1 WHERE ID=" + SysString.ToDBString(entityDts.DLoadCheckDtsID); sqlTrans.ExecuteNonQuery(sql); } } else//撤销提交 { if (entityIOF.PayAmount != 0) { throw new Exception("不能操作,数据已有收付款数据 ID:" + entityDts.DLOADDtsID + " " + entityIOF.ItemCode + " " + entityIOF.ColorNum); } sql = "UPDATE WH_IOFormDts SET InvoiceQty=ISNULL(InvoiceQty,0)-" + "(" + SysString.ToDBString(entityDts.DInvoiceQty) + ")"; sql += ",InvoiceAmount=ISNULL(InvoiceAmount,0)-" + "(" + SysString.ToDBString(entityDts.DInvoiceAmount) + ")"; sql += ",DtsInvoiceDelOPID=" + SysString.ToDBString(entity.SaleOPID); sql += ",DtsInvoiceDelTime=null"; sql += ",DtsInvoiceNo=''"; if (entityIOF.InvoiceQty == entityDts.DInvoiceQty) { sql += ",DtsInvoiceDelFlag=0";//开票完成标志 } sql += " WHERE ID=" + SysString.ToDBString(entityDts.DLOADDtsID); sqlTrans.ExecuteNonQuery(sql); if (entityDts.DLoadCheckDtsID > 0) { sql = "UPDATE Finance_CheckOperationDts SET InvoiceFlag=0 WHERE ID=" + SysString.ToDBString(entityDts.DLoadCheckDtsID); sqlTrans.ExecuteNonQuery(sql); } } } else { if (p_Type == (int)YesOrNo.Yes)//提交 { if (entityDts.DLoadCheckDtsID > 0) { sql = "UPDATE Finance_CheckOperationDts SET InvoiceFlag=1 WHERE ID=" + SysString.ToDBString(entityDts.DLoadCheckDtsID); sqlTrans.ExecuteNonQuery(sql); } } else { if (entityDts.DLoadCheckDtsID > 0) { sql = "UPDATE Finance_CheckOperationDts SET InvoiceFlag=0 WHERE ID=" + SysString.ToDBString(entityDts.DLoadCheckDtsID); sqlTrans.ExecuteNonQuery(sql); } } } } } } }
/// <summary> /// 新增 /// </summary> /// <param name="p_Entity">实体类</param> /// <returns>操作影响的记录行数</returns> public override int AddNew(BaseEntity p_Entity) { try { InvoiceOperation MasterEntity = (InvoiceOperation)p_Entity; if (MasterEntity.ID == 0) { return(0); } //新增主表数据 StringBuilder MasterField = new StringBuilder(); StringBuilder MasterValue = new StringBuilder(); MasterField.Append("INSERT INTO Finance_InvoiceOperation("); MasterValue.Append(" VALUES("); MasterField.Append("ID" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.ID) + ","); MasterField.Append("CompanyTypeID" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.CompanyTypeID) + ","); MasterField.Append("FormNo" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.FormNo) + ","); MasterField.Append("OrderCode" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.OrderCode) + ","); MasterField.Append("InvoiceNO" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.InvoiceNO) + ","); MasterField.Append("MakeOPID" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.MakeOPID) + ","); MasterField.Append("MakeOPName" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.MakeOPName) + ","); 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("CheckOPID" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.CheckOPID) + ","); MasterField.Append("CheckDate" + ","); if (MasterEntity.CheckDate != SystemConfiguration.DateTimeDefaultValue) { MasterValue.Append(SysString.ToDBString(MasterEntity.CheckDate.ToString("yyyy-MM-dd HH:mm:ss")) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("SubmitFlag" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.SubmitFlag) + ","); MasterField.Append("DelFlag" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.DelFlag) + ","); MasterField.Append("VendorID" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.VendorID) + ","); 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("Remark" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.Remark) + ","); MasterField.Append("DVendorCon" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.DVendorCon) + ","); MasterField.Append("SaleOPID" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.SaleOPID) + ","); MasterField.Append("TotalQty" + ","); if (MasterEntity.TotalQty != 0) { MasterValue.Append(SysString.ToDBString(MasterEntity.TotalQty) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("TotalAmount" + ","); if (MasterEntity.TotalAmount != 0) { MasterValue.Append(SysString.ToDBString(MasterEntity.TotalAmount) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("DZTypeID" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.DZTypeID) + ","); MasterField.Append("PayAmount" + ","); if (MasterEntity.PayAmount != 0) { MasterValue.Append(SysString.ToDBString(MasterEntity.PayAmount) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("TotalTaxAmount" + ","); if (MasterEntity.TotalTaxAmount != 0) { MasterValue.Append(SysString.ToDBString(MasterEntity.TotalTaxAmount) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("PreHXAmount" + ","); if (MasterEntity.PreHXAmount != 0) { MasterValue.Append(SysString.ToDBString(MasterEntity.PreHXAmount) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("PreHXQty" + ","); if (MasterEntity.PreHXQty != 0) { MasterValue.Append(SysString.ToDBString(MasterEntity.PreHXQty) + ","); } else { MasterValue.Append("null,"); } MasterField.Append("PreHXFlag" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.PreHXFlag) + ","); MasterField.Append("PreInvFlag" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.PreInvFlag) + ","); MasterField.Append("KPType" + ","); MasterValue.Append(SysString.ToDBString(MasterEntity.KPType) + ","); MasterField.Append("MXFlag" + ")"); MasterValue.Append(SysString.ToDBString(MasterEntity.MXFlag) + ")"); //执行 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); } }