using Aspose.Cells;
using DBCommon;
using PaymentImport.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Common;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PaymentImport
{
public partial class PaymentImport : Form
{
public PaymentImport()
{
InitializeComponent();
DataTable dt = GetAccount();
this.cboAccount.DataSource = dt;
this.cboAccount.DisplayMember = "cAcc_Name";
this.cboAccount.ValueMember = "cAcc_Id";
}
string strConnet = "Data Source=172.18.1.16;Initial Catalog=UFSystem;Persist Security Info=True;User Id=sa;Password=ACac123";//初始化系统库
//string strConnet = "Data Source=NB215;Initial Catalog=UFSystem;Persist Security Info=True;User Id=sa;Password=118";//初始化系统库
string strConn = "";
private void BtnImport_Click(object sender, EventArgs e)
{
string strAccount = this.cboAccount.SelectedValue.ToString();
strConn = "Data Source=172.18.1.16;Initial Catalog=UFDATA_" + strAccount + "_2018;Persist Security Info=True;User Id=sa;Password=ACac123";
//strConn = "Data Source=NB215;Initial Catalog=UFDATA_" + strAccount + "_2018;Persist Security Info=True;User Id=sa;Password=118";
//打开文件
OpenFileDialog openFile = new OpenFileDialog();
DialogResult result = openFile.ShowDialog();
if (result == DialogResult.OK)
{
DbHelper sqlDB = new DbHelper(strConn);
Trans sqlTran = new Trans(strConn);
try
{
string path = openFile.FileName;//获取文件路径
Workbook WB = new Workbook(path);
Worksheet WS = WB.Worksheets[0];
Cells cells = WS.Cells;
for (int i = 2; i < cells.Count; i++)
{
if (cells["A" + i].StringValue.Trim() == "")
{
break;
}
Decimal dcAmount = Convert.ToDecimal(cells["G" + i].StringValue.Trim());
string strVouchId = cells["O" + i].StringValue.Trim();
string strCode= cells["P" + i].StringValue.Trim();
string strcDigest= cells["Q" + i].StringValue.Trim();
DataTable dtCode = GetCode(strCode, sqlTran);
DataTable dtApp = GetApp(strVouchId, sqlTran);
if (dtApp.Rows.Count == 0)
{
throw new Exception("第" + i + "行付款申请单号不正确,请检查!");
}
if (dtCode.Rows.Count == 0)
{
throw new Exception("第" + i + "行结算科目不正确,请检查!");
}
if (Convert.ToDecimal(dtApp.Rows[0]["SUMiApplyAmt"]) != dcAmount)
{
throw new Exception("第" + i + "行付款金额不正确!");
}
if (CheckIsVouch(strVouchId, sqlTran) == 1)
{
throw new Exception("第" + i + "行付款申请单号已经生成了付款单不能再次导入!");
}
else
{
DBCommon.ClassDBCommon clsDB = new ClassDBCommon();
///导入程序
Ap_CloseBill ap_CloseBill = new Ap_CloseBill();
ap_CloseBill.cVouchType = "49";
ap_CloseBill.cVouchID = DateTime.Now.ToString("yyyyMMddHHmmssfff");
ap_CloseBill.dVouchDate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00.000");
ap_CloseBill.iPeriod = Convert.ToByte(DateTime.Now.ToString("MM"));
ap_CloseBill.cDwCode = dtApp.Rows[0]["cDwCode"].ToString();
ap_CloseBill.cDeptCode = dtApp.Rows[0]["cDepCode"].ToString();
ap_CloseBill.cPerson = dtApp.Rows[0]["cPerson"].ToString();
ap_CloseBill.cItem_Class = dtApp.Rows[0]["cItem_Class"].ToString();
ap_CloseBill.cItemCode = dtApp.Rows[0]["cItemCode"].ToString();
ap_CloseBill.cSSCode = "1";//结算方式
ap_CloseBill.cNoteNo = null;
ap_CloseBill.cCoVouchType = null;
ap_CloseBill.cCoVouchID = null;
//ap_CloseBill.cDigest = dtApp.Rows[0]["cDigest"].ToString();
ap_CloseBill.cDigest = strcDigest;
ap_CloseBill.cBankAccount = null;
ap_CloseBill.cexch_name = dtApp.Rows[0]["cexch_name"].ToString();
ap_CloseBill.iExchRate = Convert.ToDouble(dtApp.Rows[0]["iExchRate"]);
ap_CloseBill.iAmount = Convert.ToDecimal(dtApp.Rows[0]["SUMiApplyAmt"]);
ap_CloseBill.iAmount_f = Convert.ToDecimal(dtApp.Rows[0]["SUMiApplyAmt_f"]);
ap_CloseBill.iRAmount = Convert.ToDecimal(dtApp.Rows[0]["SUMiApplyAmt"]);
ap_CloseBill.iRAmount_f = Convert.ToDecimal(dtApp.Rows[0]["SUMiApplyAmt_f"]);
ap_CloseBill.cOperator = "demo";
ap_CloseBill.cCancelMan = null;
ap_CloseBill.cRPMan = null;
ap_CloseBill.bPrePay = false;
ap_CloseBill.bStartFlag = false;
ap_CloseBill.cOrderNo = "";//采购订单号
ap_CloseBill.cCode = strCode;
ap_CloseBill.cPreCode = null;
ap_CloseBill.iPayForOther = false;
ap_CloseBill.cSrcFlag = null;
ap_CloseBill.cPzID = null;
ap_CloseBill.cFlag = "AP";
ap_CloseBill.bSend = false;
ap_CloseBill.bReceived = false;
ap_CloseBill.csItemCode = null;
//ap_CloseBill.iID = Convert.ToInt32(dtApp.Rows[0]["MAXiID"]);
int iFatherId = Convert.ToInt32(GetVouchId(strAccount).Rows[0]["iFatherId"]) + 1;
string strId = "1" + iFatherId.ToString().PadLeft(9, '0');
ap_CloseBill.iID = Convert.ToInt32(strId);
ap_CloseBill.cCancelNo = null;
ap_CloseBill.cBank = null;
ap_CloseBill.cNatBank = null;
ap_CloseBill.cNatBankAccount = null;
ap_CloseBill.bFromBank = false;
ap_CloseBill.bToBank = false;
ap_CloseBill.bSure = false;
ap_CloseBill.VT_ID = 8053;
ap_CloseBill.cCheckMan = null;
ap_CloseBill.cDefine1 = dtApp.Rows[0]["cDefine1"].ToString();
ap_CloseBill.cDefine2 = dtApp.Rows[0]["cDefine2"].ToString();
ap_CloseBill.cDefine3 = null;
ap_CloseBill.cDefine4 = null;
ap_CloseBill.cDefine5 = null;
ap_CloseBill.cDefine6 = null;
ap_CloseBill.cDefine7 = null;
ap_CloseBill.cDefine8 = null;
ap_CloseBill.cDefine9 = dtApp.Rows[0]["cDefine9"].ToString();
ap_CloseBill.cDefine10 = "";
ap_CloseBill.cDefine11 = "";
ap_CloseBill.cDefine12 = null;
ap_CloseBill.cDefine13 = null;
ap_CloseBill.cDefine14 = null;
ap_CloseBill.cDefine15 = null;
ap_CloseBill.cDefine16 = null;
ap_CloseBill.cItemName = null;
ap_CloseBill.cContractType = null;
ap_CloseBill.cContractID = null;
ap_CloseBill.iAmount_s = Convert.ToDouble(dtApp.Rows[0]["SUMiApplyAmt_s"]);
ap_CloseBill.IsWfControlled = false;
ap_CloseBill.iSource = 0;
ap_CloseBill.sDLCode = null;
ap_CloseBill.RegisterFlag = 0;
ap_CloseBill.iverifystate = null;
ap_CloseBill.ireturncount = null;
ap_CloseBill.dcreatesystime = DateTime.Now;
ap_CloseBill.dverifysystime = null;
ap_CloseBill.dmodifysystime = null;
ap_CloseBill.cmodifier = null;
ap_CloseBill.dmoddate = null;
ap_CloseBill.dverifydate = null;
ap_CloseBill.ibg_overflag = 0;
//ap_CloseBill.cbg_auditor =;
//ap_CloseBill.cbg_audittime =;
ap_CloseBill.controlresult = null;
//ap_CloseBill.cbg_itemcode =;
//ap_CloseBill.cbg_itemname =;
//ap_CloseBill.cbg_caliberkey1 =;
//ap_CloseBill.cbg_caliberkeyname1 =;
//ap_CloseBill.cbg_caliberkey2 =;
//ap_CloseBill.cbg_caliberkeyname2 =;
//ap_CloseBill.cbg_caliberkey3 =;
//ap_CloseBill.cbg_caliberkeyname3 =;
//ap_CloseBill.cbg_calibercode1 =;
//ap_CloseBill.cbg_calibername1 =;
//ap_CloseBill.cbg_calibercode2 =;
//ap_CloseBill.cbg_calibername2 =;
//ap_CloseBill.cbg_calibercode3 =;
//ap_CloseBill.cbg_calibername3 =;
ap_CloseBill.ibg_ctrl = null;
//ap_CloseBill.cbg_auditopinion =;
ap_CloseBill.cApplyCode = strVouchId;
ap_CloseBill.cPZNum = null;
ap_CloseBill.doutbilldate = null;
//ap_CloseBill.cbg_caliberkey4 =;
//ap_CloseBill.cbg_caliberkeyname4 =;
//ap_CloseBill.cbg_caliberkey5 =;
//ap_CloseBill.cbg_caliberkeyname5 =;
//ap_CloseBill.cbg_caliberkey6 =;
//ap_CloseBill.cbg_caliberkeyname6 =;
//ap_CloseBill.cbg_calibercode4 =;
//ap_CloseBill.cbg_calibername4 =;
//ap_CloseBill.cbg_calibercode5 =;
//ap_CloseBill.cbg_calibername5 =;
//ap_CloseBill.cbg_calibercode6 =;
//ap_CloseBill.cbg_calibername6 =;
ap_CloseBill.iPrintCount = 0;
ap_CloseBill.cReserveDeptCode = null;
ap_CloseBill.bDealMode = null;
ap_CloseBill.iBusType = null;
ap_CloseBill.iPayType = 0;
ap_CloseBill.cagentcuscode = null;
ap_CloseBill.csysbarcode = "||ap49|" + ap_CloseBill.cVouchID;
ap_CloseBill.cCurrentAuditor = null;
ap_CloseBill.lAcctID = null;
ap_CloseBill.iNotRateAmount = Convert.ToDecimal(dtApp.Rows[0]["SUMiNotRateApplyAmt"]);
ap_CloseBill.iNotRateAmount_f = Convert.ToDecimal(dtApp.Rows[0]["SUMiNotRateApplyAmt_f"]);
//ap_CloseBill.Ufts = DateTime.Now.Ticks.ToString();
if (!clsDB.InsertProcess(ap_CloseBill, sqlTran, sqlDB))
{
throw new Exception("新增付款单主表失败!");
}
UpVouchId(strAccount,1,0);
DataTable dtAppAmount = GetAppAmount(strVouchId, sqlTran);
//写入付款单子表
foreach (DataRow item in dtAppAmount.Rows)
{
DataTable dtAppDetail = GetAppDetail(item["cOrderNo"].ToString(), item["cItemCode"].ToString(), sqlTran);
//int Id = GetCloseBillId(sqlTran);//获取Ap_CloseBills最大ID号+1
Ap_CloseBills ap_CloseBills = new Ap_CloseBills();
ap_CloseBills.iID = ap_CloseBill.iID;
int iChildId = Convert.ToInt32(GetVouchId(strAccount).Rows[0]["iChildId"]) + 1;
string strChildId = "1" + iChildId.ToString().PadLeft(9, '0');
ap_CloseBills.ID = Convert.ToInt32(strChildId);
ap_CloseBills.iType = 0;//款项类型0为应付款,1为预付款
ap_CloseBills.bPrePay = true;
ap_CloseBills.cCusVen = dtApp.Rows[0]["cDwCode"].ToString();
ap_CloseBills.iAmt_f = Convert.ToDecimal(item["iApplyAmt_f"]);
ap_CloseBills.iAmt = Convert.ToDecimal(item["iApplyAmt"]);
ap_CloseBills.iRAmt_f = Convert.ToDecimal(item["iApplyAmt_f"]);
ap_CloseBills.iRAmt = Convert.ToDecimal(item["iApplyAmt"]);
//取消科目判断,全部为应付款
//if (dtApp.Rows[0]["cSource"].ToString() == "采购订单")
//{
// ap_CloseBills.cKm = "112301";
//}
//else if (dtApp.Rows[0]["cSource"].ToString() == "采购发票")
//{
// ap_CloseBills.cKm = "220201";
//}
//else
//{
// throw new Exception("无法获取到科目信息!");
//}
ap_CloseBills.cKm = "220201";
ap_CloseBills.cXmClass = null;
ap_CloseBills.cXm = null;
ap_CloseBills.cDepCode = dtAppDetail.Rows[0]["cDepCode"].ToString();
ap_CloseBills.cPersonCode = dtAppDetail.Rows[0]["cPerson"].ToString();
ap_CloseBills.cOrderID = dtAppDetail.Rows[0]["cOrderNo"].ToString();
ap_CloseBills.cItemName = null;
ap_CloseBills.cConType = null;
ap_CloseBills.cConID = null;
ap_CloseBills.iAmt_s = Convert.ToDouble(item["iApplyAmt_s"]);
ap_CloseBills.iRAmt_s = Convert.ToDouble(item["iApplyAmt_s"]);
ap_CloseBills.iOrderType = 0;
ap_CloseBills.cDLCode = null;
ap_CloseBills.ccItemCode = null;
ap_CloseBills.RegisterFlag = 0;
ap_CloseBills.cDefine22 = dtAppDetail.Rows[0]["cDefine22"].ToString();
ap_CloseBills.cDefine23 = dtAppDetail.Rows[0]["cDefine23"].ToString();
ap_CloseBills.cDefine24 = dtAppDetail.Rows[0]["cDefine24"].ToString();
ap_CloseBills.cDefine25 = "";
if (dtAppDetail.Rows[0]["cDefine26"]==DBNull.Value)
{
ap_CloseBills.cDefine26 = 0;
}
else
{
ap_CloseBills.cDefine26 = Convert.ToDouble(dtAppDetail.Rows[0]["cDefine26"]);
}
if (dtAppDetail.Rows[0]["cDefine27"]==DBNull.Value)
{
ap_CloseBills.cDefine27 = 0;
}
else
{
ap_CloseBills.cDefine27 = Convert.ToDouble(dtAppDetail.Rows[0]["cDefine27"]);
}
ap_CloseBills.cDefine28 = dtAppDetail.Rows[0]["cItemCode"].ToString();//将项目号写入自定义项,用于关联到付款单子表Id
ap_CloseBills.cDefine29 = dtAppDetail.Rows[0]["cDefine29"].ToString();
ap_CloseBills.cDefine30 = dtAppDetail.Rows[0]["cDefine30"].ToString();
ap_CloseBills.cDefine31 = dtAppDetail.Rows[0]["cDefine31"].ToString();
ap_CloseBills.cDefine32 = dtAppDetail.Rows[0]["cDefine32"].ToString();
ap_CloseBills.cDefine33 = dtAppDetail.Rows[0]["cDefine33"].ToString();
ap_CloseBills.cDefine34 = null;
ap_CloseBills.cDefine35 = null;
ap_CloseBills.cDefine36 = null;
ap_CloseBills.cDefine37 = null;
ap_CloseBills.cStageCode = null;
ap_CloseBills.cCoVouchID = strVouchId;
ap_CloseBills.cExecID = null;
ap_CloseBills.cMemo = null;
ap_CloseBills.iSrcClosesID = 0;
ap_CloseBills.ifaresettled_f = 0;
ap_CloseBills.cEBOrderCode = null;
if (!clsDB.InsertProcess(ap_CloseBills, sqlTran, sqlDB))
{
throw new Exception("新增付款单子表失败!");
}
UpVouchId(strAccount, 0, 1);
DataTable dtAppDe = GetAppDe(strVouchId, ap_CloseBills.cOrderID, item["cItemCode"].ToString(), sqlTran);
foreach (DataRow ApyTemp in dtAppDe.Rows)
{
//插入付款明细
AP_PayDetail ap_PayDetail = new AP_PayDetail();
ap_PayDetail.iID = ap_CloseBill.iID;
ap_PayDetail.PID = Convert.ToInt32(ApyTemp["PID"]);
ap_PayDetail.PIDs = Convert.ToInt32(ApyTemp["AutoID"]);
ap_PayDetail.ID = ap_CloseBills.ID;
ap_PayDetail.cSource = ApyTemp["cSource"].ToString();
ap_PayDetail.iBVid = Convert.ToInt32(ApyTemp["iBVid"]);
//ap_PayDetail.BalancesGuid = "";
//ap_PayDetail.cSSCode = "";
ap_PayDetail.iPayAmt_f = Convert.ToDecimal(ApyTemp["iApplyAmt_f"]);
ap_PayDetail.iPayAmt = Convert.ToDecimal(ApyTemp["iApplyAmt"]);
//ap_PayDetail.iPayAmt_s = Convert.ToDouble(ApyTemp["iApplyAmt_s"]);
ap_PayDetail.iPayAmt_s = 0;
ap_PayDetail.iSrcPayAmt_f = Convert.ToDecimal(ApyTemp["iApplyAmt_f"]);
ap_PayDetail.iSrcPayAmt = Convert.ToDecimal(ApyTemp["iSrcApplyAmt"]);
ap_PayDetail.dPayDate = DateTime.Now;
ap_PayDetail.iCancelAmt_f = 0;
ap_PayDetail.iCancelAmt = 0;
ap_PayDetail.iSrcCancelAmt_f = 0;
ap_PayDetail.iSrcCancelAmt = 0;
//ap_PayDetail.dCancelDate = "";
//ap_PayDetail.cNote = "";
ap_PayDetail.iPOsID = Convert.ToInt32(ApyTemp["iBVid"]);
ap_PayDetail.iTaxRate = 0;
//ap_PayDetail.iNotRatePayAmt = Convert.ToDecimal(ApyTemp["iNotRateApplyAmt"]);
//ap_PayDetail.iNotRatePayAmt_f = Convert.ToDecimal(ApyTemp["iNotRateApplyAmt_f"]);
ap_PayDetail.iNotRatePayAmt = Convert.ToDecimal(ApyTemp["iSrcApplyAmt"]);
ap_PayDetail.iNotRatePayAmt_f = Convert.ToDecimal(ApyTemp["iApplyAmt_f"]);
ap_PayDetail.iDiscountTaxType = 0;
if (!clsDB.InsertProcess(ap_PayDetail, sqlTran, sqlDB))
{
throw new Exception("新增付款明细表失败!");
}
}
}
}
if (UpApplyPayVouchs(strVouchId, sqlTran) != 1)
{
throw new Exception("更新付款申请单子表(实际付款时间)失败!");
}
}
sqlTran.Commit();
MessageBox.Show("导入成功!", "导入提示!");
}
catch (Exception exc)
{
sqlTran.RollBack();
MessageBox.Show("失败提示!" + exc.Message, "导入提示!");
}
//finally
//{
//strConn.Close();
//strConn.Dispose();
//}
}
}
/// <summary>
/// 检查付款申请单号是否已经做了付款单
/// </summary>
/// <param name="Amount"></param>
/// <param name="VouchId"></param>
/// <returns></returns>
public int CheckIsVouch(string VouchId, Trans sqlTran)
{
DbHelper dbHelper = new DbHelper(strConn);
int intResult = 0;
try
{
string strSQL = @" SELECT Count(*) as CountSum FROM dbo.Ap_CloseBills WHERE cCoVouchID=@cCoVouchID";
DbCommand sqlCmd_SelectCode = dbHelper.GetSqlStringCommond(strSQL);
dbHelper.AddInParameter(sqlCmd_SelectCode, "@cCoVouchID", DbType.String, VouchId);
intResult = (int)dbHelper.ExecuteScalar(sqlCmd_SelectCode, sqlTran);
if (intResult > 0)
{
intResult = 1;
}
else
{
intResult = 0;
}
}
catch (Exception ex)
{
MessageBox.Show("出现错误!" + ex.Message);
}
return intResult;
}
/// <summary>
/// 根据付款申请单号获取主表信息
/// </summary>
/// <param name=""></param>
/// <returns></returns>
public DataTable GetApp(string cVouchID, Trans sqlTran)
{
DbHelper sqlDBs = new DbHelper(strConn);
string strSql = @"SELECT AP_ApplyPayVouch.PID,
AP_ApplyPayVouch.cVouchType,
AP_ApplyPayVouch.cVouchID,
AP_ApplyPayVouch.dVouchDate,
AP_ApplyPayVouch.cSource,
AP_ApplyPayVouch.cFlag,
AP_ApplyPayVouch.cDwCode,
AP_ApplyPayVouch.cDepCode,
AP_ApplyPayVouch.cPerson,
AP_ApplyPayVouch.cSSCode,
AP_ApplyPayVouch.cCode,
AP_ApplyPayVouch.cItemCode,
AP_ApplyPayVouch.cItemName,
AP_ApplyPayVouch.cItem_Class,
AP_ApplyPayVouch.cexch_name,
AP_ApplyPayVouch.iExchRate,
AP_ApplyPayVouch.bStartFlag,
AP_ApplyPayVouch.cBank,
AP_ApplyPayVouch.cBankAccount,
AP_ApplyPayVouch.cNatBank,
AP_ApplyPayVouch.cNatBankAccount,
AP_ApplyPayVouch.cDigest,
AP_ApplyPayVouch.VT_ID,
AP_ApplyPayVouch.Ufts,
AP_ApplyPayVouch.iState,
AP_ApplyPayVouch.IsWfControlled,
AP_ApplyPayVouch.iverifystate,
AP_ApplyPayVouch.ireturncount,
AP_ApplyPayVouch.cDefine1,
AP_ApplyPayVouch.cDefine2,
AP_ApplyPayVouch.cDefine3,
AP_ApplyPayVouch.cDefine4,
AP_ApplyPayVouch.cDefine5,
AP_ApplyPayVouch.cDefine6,
AP_ApplyPayVouch.cDefine7,
AP_ApplyPayVouch.cDefine8,
AP_ApplyPayVouch.cDefine9,
AP_ApplyPayVouch.cDefine10,
AP_ApplyPayVouch.cDefine11,
AP_ApplyPayVouch.cDefine12,
AP_ApplyPayVouch.cDefine13,
AP_ApplyPayVouch.cDefine14,
AP_ApplyPayVouch.cDefine15,
AP_ApplyPayVouch.cDefine16,
AP_ApplyPayVouch.cOperator,
AP_ApplyPayVouch.cCheckMan,
AP_ApplyPayVouch.dcreatesystime,
AP_ApplyPayVouch.dverifydate,
AP_ApplyPayVouch.dverifysystime,
AP_ApplyPayVouch.cmodifier,
AP_ApplyPayVouch.dmoddate,
AP_ApplyPayVouch.dmodifysystime,
AP_ApplyPayVouch.cCloser,
AP_ApplyPayVouch.dCloseDate,
AP_ApplyPayVouch.cbg_itemcode,
AP_ApplyPayVouch.cbg_itemname,
AP_ApplyPayVouch.cbg_caliberkey1,
AP_ApplyPayVouch.cbg_caliberkeyname1,
AP_ApplyPayVouch.cbg_caliberkey2,
AP_ApplyPayVouch.cbg_caliberkeyname2,
AP_ApplyPayVouch.cbg_caliberkey3,
AP_ApplyPayVouch.cbg_caliberkeyname3,
AP_ApplyPayVouch.cbg_calibercode1,
AP_ApplyPayVouch.cbg_calibername1,
AP_ApplyPayVouch.cbg_calibercode2,
AP_ApplyPayVouch.cbg_calibername2,
AP_ApplyPayVouch.cbg_calibercode3,
AP_ApplyPayVouch.cbg_calibername3,
AP_ApplyPayVouch.ibg_overflag,
AP_ApplyPayVouch.cbg_auditor,
AP_ApplyPayVouch.cbg_audittime,
AP_ApplyPayVouch.controlresult,
AP_ApplyPayVouch.cGatheringPlan,
AP_ApplyPayVouch.dCreditStart,
AP_ApplyPayVouch.iCreditPeriod,
AP_ApplyPayVouch.dGatheringDate,
AP_ApplyPayVouch.cbg_caliberkey4,
AP_ApplyPayVouch.cbg_caliberkeyname4,
AP_ApplyPayVouch.cbg_caliberkey5,
AP_ApplyPayVouch.cbg_caliberkeyname5,
AP_ApplyPayVouch.cbg_caliberkey6,
AP_ApplyPayVouch.cbg_caliberkeyname6,
AP_ApplyPayVouch.cbg_calibercode4,
AP_ApplyPayVouch.cbg_calibername4,
AP_ApplyPayVouch.cbg_calibercode5,
AP_ApplyPayVouch.cbg_calibername5,
AP_ApplyPayVouch.cbg_calibercode6,
AP_ApplyPayVouch.cbg_calibername6,
AP_ApplyPayVouch.iPrintCount,
AP_ApplyPayVouch.iBusType,
AP_ApplyPayVouch.iPayType,
AP_ApplyPayVouch.cagentcuscode,
AP_ApplyPayVouch.csysbarcode,
AP_ApplyPayVouch.cCurrentAuditor,
AP_ApplyPayVouch.cSubId,
(
SELECT SUM(iApplyAmt) --本币申请总金额
FROM dbo.AP_ApplyPayVouchs
WHERE PID =
(
SELECT PID FROM dbo.AP_ApplyPayVouch WHERE cVouchID = @cVouchID
)
) AS SUMiApplyAmt, --本币金额
(
SELECT SUM(iApplyAmt_f) --原币申请总金额
FROM dbo.AP_ApplyPayVouchs
WHERE PID =
(
SELECT PID FROM dbo.AP_ApplyPayVouch WHERE cVouchID = @cVouchID
)
) AS SUMiApplyAmt_f, --原币金额
(
SELECT SUM(iApplyAmt) --本币申请总金额
FROM dbo.AP_ApplyPayVouchs
WHERE PID =
(
SELECT PID FROM dbo.AP_ApplyPayVouch WHERE cVouchID = @cVouchID
)
) AS SUMiApplyAmt, --本币余额
(
SELECT SUM(iApplyAmt_f) --原币申请总金额
FROM dbo.AP_ApplyPayVouchs
WHERE PID =
(
SELECT PID FROM dbo.AP_ApplyPayVouch WHERE cVouchID = @cVouchID
)
) AS SUMiApplyAmt_f,
(
SELECT SUM(iApplyAmt_s) --付款申请单总数量
FROM dbo.AP_ApplyPayVouchs
WHERE PID =
(
SELECT PID FROM dbo.AP_ApplyPayVouch WHERE cVouchID = @cVouchID
)
) AS SUMiApplyAmt_s,
(
SELECT SUM(iNotRateApplyAmt) --本币无税申请总金额
FROM dbo.AP_ApplyPayVouchs
WHERE PID =
(
SELECT PID FROM dbo.AP_ApplyPayVouch WHERE cVouchID = @cVouchID
)
) AS SumiNotRateApplyAmt, --本币无税申请金额
(
SELECT SUM(iNotRateApplyAmt_f) --原币币无税申请总金额
FROM dbo.AP_ApplyPayVouchs
WHERE PID =
(
SELECT PID FROM dbo.AP_ApplyPayVouch WHERE cVouchID = @cVouchID
)
) AS SumiNotRateApplyAmt_f, --原币无税申请金额
(
SELECT MAX(iID) + 1 FROM dbo.Ap_CloseBill
) AS MAXiID
FROM AP_ApplyPayVouch
WHERE cVouchID = @cVouchID";
DbCommand sqlCmd_SelectCode = sqlDBs.GetSqlStringCommond(strSql);
sqlDBs.AddInParameter(sqlCmd_SelectCode, "@cVouchID", DbType.String, cVouchID);
DataTable dt = sqlDBs.ExecuteDataTable(sqlCmd_SelectCode, sqlTran);
return dt;
}
/// <summary>
/// 检查所填写的会计科目是否正确
/// </summary>
/// <param name="cCode"></param>
/// <param name="sqlTran"></param>
/// <returns></returns>
public DataTable GetCode(string cCode, Trans sqlTran)
{
DbHelper sqlDBs = new DbHelper(strConn);
string strSql = @"SELECT * FROM code WHERE bend =1 AND ccode=@ccode";
DbCommand sqlCmd_SelectCode = sqlDBs.GetSqlStringCommond(strSql);
sqlDBs.AddInParameter(sqlCmd_SelectCode, "@ccode", DbType.String, cCode);
DataTable dt = sqlDBs.ExecuteDataTable(sqlCmd_SelectCode, sqlTran);
return dt;
}
public DataTable GetAppDe(string cVouchID, string cOrderNo, string cItemCode, Trans sqlTran)
{
DbHelper sqlDBs = new DbHelper(strConn);
string strSql = @"SELECT AP_ApplyPayVouchs.AutoID,
AP_ApplyPayVouchs.PID,
AP_ApplyPayVouchs.cSource,
AP_ApplyPayVouchs.cCoVouchType,
AP_ApplyPayVouchs.cCoVouchID,
AP_ApplyPayVouchs.iBVid,
AP_ApplyPayVouchs.BalancesGuid,
AP_ApplyPayVouchs.cDepCode,
AP_ApplyPayVouchs.cPerson,
AP_ApplyPayVouchs.iOrderType,
AP_ApplyPayVouchs.cOrderNo,
AP_ApplyPayVouchs.cContractType,
AP_ApplyPayVouchs.cContractID,
AP_ApplyPayVouchs.cItemCode,
AP_ApplyPayVouchs.cItemName,
AP_ApplyPayVouchs.cItem_Class,
AP_ApplyPayVouchs.iApplyAmt_f,
AP_ApplyPayVouchs.iApplyAmt,
AP_ApplyPayVouchs.iApplyAmt_s,
AP_ApplyPayVouchs.cSrcExchName,
AP_ApplyPayVouchs.iSrcApplyAmt_f,
AP_ApplyPayVouchs.iSrcApplyAmt,
AP_ApplyPayVouchs.iAuditAmt_f,
AP_ApplyPayVouchs.iAuditAmt,
AP_ApplyPayVouchs.iSrcAuditAmt_f,
AP_ApplyPayVouchs.iSrcAuditAmt,
AP_ApplyPayVouchs.iPayAmt_f,
AP_ApplyPayVouchs.iPayAmt,
AP_ApplyPayVouchs.dPrePayDate,
AP_ApplyPayVouchs.dActPayDate,
AP_ApplyPayVouchs.cbg_itemcode,
AP_ApplyPayVouchs.cbg_itemname,
AP_ApplyPayVouchs.cbg_caliberkey1,
AP_ApplyPayVouchs.cbg_caliberkeyname1,
AP_ApplyPayVouchs.cbg_caliberkey2,
AP_ApplyPayVouchs.cbg_caliberkeyname2,
AP_ApplyPayVouchs.cbg_caliberkey3,
AP_ApplyPayVouchs.cbg_caliberkeyname3,
AP_ApplyPayVouchs.cbg_calibercode1,
AP_ApplyPayVouchs.cbg_calibername1,
AP_ApplyPayVouchs.cbg_calibercode2,
AP_ApplyPayVouchs.cbg_calibername2,
AP_ApplyPayVouchs.cbg_calibercode3,
AP_ApplyPayVouchs.cbg_calibername3,
AP_ApplyPayVouchs.ibg_ctrl,
AP_ApplyPayVouchs.cbg_auditopinion,
AP_ApplyPayVouchs.cDefine22,
AP_ApplyPayVouchs.cDefine23,
AP_ApplyPayVouchs.cDefine24,
AP_ApplyPayVouchs.cDefine25,
AP_ApplyPayVouchs.cDefine26,
AP_ApplyPayVouchs.cDefine27,
AP_ApplyPayVouchs.cDefine28,
AP_ApplyPayVouchs.cDefine29,
AP_ApplyPayVouchs.cDefine30,
AP_ApplyPayVouchs.cDefine31,
AP_ApplyPayVouchs.cDefine32,
AP_ApplyPayVouchs.cDefine33,
AP_ApplyPayVouchs.cDefine34,
AP_ApplyPayVouchs.cDefine35,
AP_ApplyPayVouchs.cDefine36,
AP_ApplyPayVouchs.cDefine37,
AP_ApplyPayVouchs.cLineCloser,
AP_ApplyPayVouchs.dLineCloseDate,
AP_ApplyPayVouchs.cStageCode,
AP_ApplyPayVouchs.cInvCode,
AP_ApplyPayVouchs.iPOsID,
AP_ApplyPayVouchs.cbg_caliberkey4,
AP_ApplyPayVouchs.cbg_caliberkeyname4,
AP_ApplyPayVouchs.cbg_caliberkey5,
AP_ApplyPayVouchs.cbg_caliberkeyname5,
AP_ApplyPayVouchs.cbg_caliberkey6,
AP_ApplyPayVouchs.cbg_caliberkeyname6,
AP_ApplyPayVouchs.cbg_calibercode4,
AP_ApplyPayVouchs.cbg_calibername4,
AP_ApplyPayVouchs.cbg_calibercode5,
AP_ApplyPayVouchs.cbg_calibername5,
AP_ApplyPayVouchs.cbg_calibercode6,
AP_ApplyPayVouchs.cbg_calibername6,
AP_ApplyPayVouchs.cExpCode,
AP_ApplyPayVouchs.cbsysbarcode,
AP_ApplyPayVouchs.iOriSum,
AP_ApplyPayVouchs.iSum,
AP_ApplyPayVouchs.iOriTaxCost,
AP_ApplyPayVouchs.inattaxprice,
AP_ApplyPayVouchs.iTaxRate,
AP_ApplyPayVouchs.iNotRateApplyAmt,
AP_ApplyPayVouchs.iNotRateApplyAmt_f,
AP_ApplyPayVouchs.iSrcNRApplyAmt,
AP_ApplyPayVouchs.iSrcNRApplyAmt_f,
AP_ApplyPayVouchs.iDiscountTaxType
FROM AP_ApplyPayVouch
JOIN dbo.AP_ApplyPayVouchs
ON AP_ApplyPayVouchs.PID = AP_ApplyPayVouch.PID
AND AP_ApplyPayVouch.cVouchID = @cVouchID
WHERE cOrderNo =@cOrderNo
AND AP_ApplyPayVouchs.cItemCode = @cItemCode";
DbCommand sqlCmd_SelectCode = sqlDBs.GetSqlStringCommond(strSql);
sqlDBs.AddInParameter(sqlCmd_SelectCode, "@cVouchID", DbType.String, cVouchID);
sqlDBs.AddInParameter(sqlCmd_SelectCode, "@cOrderNo", DbType.String, cOrderNo);
sqlDBs.AddInParameter(sqlCmd_SelectCode, "@cItemCode", DbType.String, cItemCode);
DataTable dt = sqlDBs.ExecuteDataTable(sqlCmd_SelectCode, sqlTran);
return dt;
}
/// <summary>
/// 根据分组后的订单号查询第一条信息
/// </summary>
/// <param name="cOrderNo"></param>
/// <param name="sqlTran"></param>
/// <returns></returns>
public DataTable GetAppDetail(string cOrderNo, string cItemCode, Trans sqlTran)
{
DbHelper sqlDBs = new DbHelper(strConn);
string strSql = @"SELECT TOP 1 *, (SELECT SUM(iApplyAmt_s) FROM AP_ApplyPayVouchs WHERE cOrderNo=@cOrderNo GROUP BY cOrderNo) AS iAmt_s FROM AP_ApplyPayVouchs WHERE cOrderNo=@cOrderNo AND cItemCode=@cItemCode";
DbCommand sqlCmd_SelectCode = sqlDBs.GetSqlStringCommond(strSql);
sqlDBs.AddInParameter(sqlCmd_SelectCode, "@cOrderNo", DbType.String, cOrderNo);
sqlDBs.AddInParameter(sqlCmd_SelectCode, "@cItemCode", DbType.String, cItemCode);
DataTable dt = sqlDBs.ExecuteDataTable(sqlCmd_SelectCode, sqlTran);
return dt;
}
/// <summary>
/// 查询ID号
/// </summary>
/// <param name="sqlTran"></param>
/// <returns></returns>
//public int GetCloseBillId(Trans sqlTran)
//{
// DbHelper sqlDBs = new DbHelper(strConn);
// string strSql = @"SELECT MAX(ID) + 1 FROM dbo.Ap_CloseBills";
// DbCommand sqlCmd_Select = sqlDBs.GetSqlStringCommond(strSql);
// int intResult = (int)sqlDBs.ExecuteScalar(sqlCmd_Select, sqlTran);
// return intResult;
//}
/// <summary>
///
/// </summary>
/// <param name="AutoID"></param>
/// <param name="cVouchID"></param>
/// <param name="cItemCode"></param>
/// <param name="cOrderNo"></param>
/// <param name="sqlTran"></param>
/// <returns></returns>
/// <summary>
/// 根据付款申请单号查询申请总金额
/// </summary>
/// <param name="cVouchID"></param>
/// <param name="sqlTran"></param>
/// <returns></returns>
public DataTable GetAppAmount(string cVouchID, Trans sqlTran)
{
DbHelper sqlDBs = new DbHelper(strConn);
string strSql = @"SELECT cOrderNo,
cItemCode,
SUM(iApplyAmt_f) AS iApplyAmt_f,--原币申请金额
SUM(iApplyAmt) AS iApplyAmt, --本币申请金额
SUM(iApplyAmt_s) AS iApplyAmt_s, --申请数量
SUM(iSrcApplyAmt_f) AS iSrcApplyAmt_f, --源单原币申请金额
SUM(iSrcApplyAmt) AS iSrcApplyAmt,----源单本币申请金额
SUM(iNotRateApplyAmt_f) AS iNotRateApplyAmt_f,--无税原币申请金额
SUM(iNotRateApplyAmt) AS iNotRateApplyAmt--无税本币申请金额
FROM dbo.AP_ApplyPayVouchs
WHERE AP_ApplyPayVouchs.PID =
(SELECT PID FROM dbo.AP_ApplyPayVouch WHERE cVouchID=@cVouchID)
GROUP BY cOrderNo,cItemCode ORDER BY cOrderNo";
DbCommand sqlCmd_SelectCode = sqlDBs.GetSqlStringCommond(strSql);
sqlDBs.AddInParameter(sqlCmd_SelectCode, "@cVouchID", DbType.String, cVouchID);
DataTable dt = sqlDBs.ExecuteDataTable(sqlCmd_SelectCode, sqlTran);
return dt;
}
/// <summary>
/// 更新付款申请单子表实际付款时间
/// </summary>
/// <param name="AutoID"></param>
/// <param name="cVouchID"></param>
/// <param name="sqlTran"></param>
/// <returns></returns>
public int UpApplyPayVouchs(string cVouchID, Trans sqlTran)
{
DbHelper sqlDBs = new DbHelper(strConn);
string strSqlUp = @"UPDATE [dbo].[AP_ApplyPayVouchs]
SET [dActPayDate] = GETDATE()
WHERE PID =(SELECT PID FROM dbo.AP_ApplyPayVouch WHERE cVouchID = @cVouchID)";
string strCount = @"SELECT COUNT(*) AS CountSum
FROM dbo.AP_ApplyPayVouchs
WHERE PID =
(
SELECT PID FROM dbo.AP_ApplyPayVouch WHERE cVouchID = @cVouchID
)";
DbCommand sqlUpdate = sqlDBs.GetSqlStringCommond(strSqlUp);
DbCommand sqlCount = sqlDBs.GetSqlStringCommond(strCount);
sqlDBs.AddInParameter(sqlUpdate, "@cVouchID", DbType.String, cVouchID);
sqlDBs.AddInParameter(sqlCount, "@cVouchID", DbType.String, cVouchID);
int intResult = sqlDBs.ExecuteNonQuery(sqlUpdate, sqlTran) - 1;
int intCount = (int)sqlDBs.ExecuteScalar(sqlCount, sqlTran);
if (intResult == intCount)
{
return 1;
}
else
{
return 0;
}
}
public DataTable GetAccount()
{
DbHelper sqlDBs = new DbHelper(strConnet);
string strSql = @"SELECT cAcc_Id,cAcc_Name FROM dbo.UA_Account WHERE cAcc_Id IN ('002','003','005') ";
DbCommand sqlCmd_SelectCode = sqlDBs.GetSqlStringCommond(strSql);
DataTable dt = sqlDBs.ExecuteDataTable(sqlCmd_SelectCode);
return dt;
}
public DataTable GetVouchId(string cAcc_Id)
{
DbHelper sqlDBs = new DbHelper(strConnet);
string strSql = @"SELECT * FROM dbo.UA_Identity WHERE cVouchType='SK' and cAcc_Id=@cAcc_Id";
DbCommand sqlCmd_SelectCode = sqlDBs.GetSqlStringCommond(strSql);
sqlDBs.AddInParameter(sqlCmd_SelectCode, "@cAcc_Id", DbType.String, cAcc_Id);
DataTable dt = sqlDBs.ExecuteDataTable(sqlCmd_SelectCode);
return dt;
}
public int UpVouchId(string cAcc_Id,int iFatherId,int iChildId)
{
DbHelper sqlDBs = new DbHelper(strConnet);
string strSqlUp = @"UPDATE dbo.UA_Identity SET iFatherId=iFatherId+@iFatherId,iChildId=iChildId+@iChildId WHERE cVouchType='SK' AND cAcc_Id=@cAcc_Id";
DbCommand sqlUpdate = sqlDBs.GetSqlStringCommond(strSqlUp);
sqlDBs.AddInParameter(sqlUpdate, "@cAcc_Id", DbType.String, cAcc_Id);
sqlDBs.AddInParameter(sqlUpdate, "@iFatherId", DbType.String, iFatherId);
sqlDBs.AddInParameter(sqlUpdate, "@iChildId", DbType.String, iChildId);
int intResult = sqlDBs.ExecuteNonQuery(sqlUpdate);
return intResult;
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7" />
</startup>
<connectionStrings>
<add name="connString" connectionString="Data Source=NB215;Initial Catalog=UFSystem;Persist Security Info=True;User Id=sa;Password=118"/>
</connectionStrings>
<appSettings>
<add key="DbHelperProvider" value="System.Data.SqlClient" />
</appSettings>
</configuration>