You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1556 lines
80 KiB
C#

10 months ago
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using DSWeb.Models;
using DSWeb.EntityDA;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Globalization;
using DSWeb.WorkFlow;
using DSWeb.Log;
namespace DSWeb.Settlements
{
public partial class DoApplication : System.Web.UI.Page
{
private string strBillNO;
private string strUserID;
private string strCacheName;
private string strSettleCurrency;
private decimal usdToRmb;
private decimal rmbToUsd;
private string strModuleName;//模块名称
private string strCompanyID;//公司GID
private string strDeptName;//部门名称
private string strShowName;
private string stroplb;//业务类别
protected void Page_Load(object sender, EventArgs e)
{
if (Session["USERID"] != null)
{
this.strUserID = Session["USERID"].ToString();
}
if (Session["SHOWNAME"] != null)
{
this.strShowName = Session["SHOWNAME"].ToString();
}
if (Session["COMPANYID"] != null)
{
strCompanyID = Session["COMPANYID"].ToString();
}
if (Session["DEPTNAME"] != null)
{
strDeptName = Session["DEPTNAME"].ToString();
}
if (Request.QueryString["oplb"] != null)
{
stroplb = Request.QueryString["oplb"].ToString();
}
if (Request.QueryString["mod"] != null)
{
strModuleName = Request.QueryString["mod"].ToString();
}
if (Request.QueryString["obj"] != null)
{
strCacheName = Request.QueryString["obj"].ToString();
}
if (Request.QueryString["currency"] != null)
{
strSettleCurrency = Request.QueryString["currency"].ToString();
h_settlecurrency.Value = strSettleCurrency;
}
if (Request.QueryString["uex"] != null)
{
rmbToUsd = decimal.Parse(Request.QueryString["uex"].ToString());
h_rmbtousd.Value = rmbToUsd.ToString();
}
if (Request.QueryString["rex"] != null)
{
usdToRmb = decimal.Parse(Request.QueryString["rex"].ToString());
h_usdtormb.Value = usdToRmb.ToString();
}
InitDoSettlement();
//if (!h_enter.Value.Trim().Equals("1"))
if(ViewState["enter"] == null)
{
ResovlePostSessionTable(strCacheName);
ViewState["enter"] = "0";//已经完成初始化
}
else
{
if (h_enter.Value.Trim().Equals("1"))
{
SavePaySettleRequest(strCacheName);
}
else if (h_enter.Value.Trim().Equals("2"))
{
if (ViewState["enter"] != null)
{
PostPaySettleRequest(strCacheName);
}
}
//RecordFeePayApplication();
}
}
#region 提交付费申请
/// <summary>
/// 提交付费申请
/// </summary>
private void PostPaySettleRequest(string tempPostSessionName)
{
DataTable bsnoTable = null;
DataTable feeTable = null;
DataTable totalTable = null;
DataSet postSet = null;
if (Session[tempPostSessionName] != null)
{
postSet = (DataSet)Session[tempPostSessionName];
}
bsnoTable = (DataTable)postSet.Tables[0];
feeTable = (DataTable)postSet.Tables[1];
totalTable = (DataTable)postSet.Tables[2];
if (bsnoTable == null || feeTable == null || totalTable == null || bsnoTable.Rows.Count < 1 || feeTable.Rows.Count < 1 || totalTable.Rows.Count < 1)
{
ViewState["enter"] = "2";
Page.ClientScript.RegisterStartupScript(this.GetType(), "key2", "<script>alert('缓存信息出错,申请提交失败,请重新登录系统!');refresh()</script>");
return;
}
int result = 0;//为0表示只有一种业务类型大于0表示有多个
string bsnotypeName = GetOplbnameByBsno(bsnoTable.Rows[0]["BSNO"].ToString().Trim());
for (int i = 1; i < bsnoTable.Rows.Count; i++)
{
if (bsnotypeName != GetOplbnameByBsno(bsnoTable.Rows[i]["BSNO"].ToString().Trim()))
{
result++;
break;
}
else
{
continue;
}
}
FeePaySettleApplicationDA feePaySettleApplicationDA = new FeePaySettleApplicationDA();
string strFeePayApplicationID = Guid.NewGuid().ToString();
if (ViewState["SaveState"] == null && ViewState["PAYSETTLESTATE"] == null)
{
string strCustomerName = "";
//付费申请费用明细信息
IList<FeeDoEntity> feeDoEntities = new List<FeeDoEntity>();
for (int j = 0; j < bsnoTable.Rows.Count; j++)
{
for (int i = 0; i < feeTable.Rows.Count; i++)
{
if (i == 0)
{
strCustomerName = feeTable.Rows[i]["CUSTOMERNAME"].ToString();
}
if (bsnoTable.Rows[j]["BSNO"].ToString().Trim() != feeTable.Rows[i]["BSNO"].ToString().Trim())
{
continue;
}
FeeDoEntity feeDoEntity = new FeeDoEntity();
feeDoEntity.FeeID = feeTable.Rows[i]["GID"].ToString();
feeDoEntity.FeeType = int.Parse(feeTable.Rows[i]["FEETYPE"].ToString());
feeDoEntity.Currency = feeTable.Rows[i]["CURRENCY"].ToString();
feeDoEntity.Amount = decimal.Parse(feeTable.Rows[i]["AMOUNT"].ToString());
feeDoEntity.DoAmount = decimal.Parse(feeTable.Rows[i]["CTL"].ToString());
feeDoEntity.UnsettleAmount = decimal.Parse(feeTable.Rows[i]["UCTL"].ToString());
feeDoEntity.CustomerName = feeTable.Rows[i]["CUSTOMERNAME"].ToString();
feeDoEntity.FeeName = feeTable.Rows[i]["FEENAME"].ToString();
feeDoEntity.OriginalFeeName = feeTable.Rows[i]["FEENAME"].ToString();
feeDoEntity.OriginalFeeCSTL = decimal.Parse(feeTable.Rows[i]["CTL"].ToString());
if (strSettleCurrency == "1")//RMB
{
feeDoEntity.ExchangeRate = usdToRmb;
}
else if (strSettleCurrency == "2")//USD
{
if (rmbToUsd == 0 || rmbToUsd.ToString().Trim().Equals("0.00000") || rmbToUsd == 1 || rmbToUsd.ToString().Trim().Equals("1.00000"))
{
feeDoEntity.ExchangeRate = decimal.Parse(feeTable.Rows[i]["EXCHANGERATE"].ToString());
}
else
{
feeDoEntity.ExchangeRate = rmbToUsd;
}
}
else
{
feeDoEntity.ExchangeRate = decimal.Parse(feeTable.Rows[i]["EXCHANGERATE"].ToString());
}
feeDoEntity.BSNO = bsnoTable.Rows[j]["BSNO"].ToString();
feeDoEntity.MBLNO = bsnoTable.Rows[j]["MBLNO"].ToString();
feeDoEntity.HBLNO = bsnoTable.Rows[j]["HBLNO"].ToString();
feeDoEntity.BillNO = "";
feeDoEntity.GID = Guid.NewGuid().ToString();
feeDoEntity.Category = 4;
feeDoEntity.BSType = 1;
feeDoEntity.BillStatus = 2;
feeDoEntity.Remark = "";
feeDoEntity.CompanyID = strCompanyID;
feeDoEntities.Add(feeDoEntity);
}
}
//付费申请表信息
FeePayApplicationEntity feePayApplicationEntity = new FeePayApplicationEntity();
feePayApplicationEntity.GID = strFeePayApplicationID;
decimal totalRmb = decimal.Parse(totalTable.Rows[0]["TOTALRMB"].ToString());
decimal totalUsd = decimal.Parse(totalTable.Rows[0]["TOTALUSD"].ToString());
decimal FinalRmd = 0;
decimal FinalUsd = 0;
if (strSettleCurrency == "1")
{
//人民币结算
FinalRmd = (StatisticSettleAmount(totalUsd, usdToRmb) + totalRmb);
//折算汇率
feePayApplicationEntity.Rate = totalUsd != 0 ? usdToRmb : 1;
}
else if (strSettleCurrency == "2")
{
//美元结算
FinalUsd = (StatisticSettleAmount(totalRmb, rmbToUsd) + totalUsd);
//折算汇率
feePayApplicationEntity.Rate = totalRmb != 0 ? rmbToUsd : 1;
}
else if (strSettleCurrency == "3")
{
FinalRmd = totalRmb;
FinalUsd = totalUsd;
feePayApplicationEntity.Rate = 1;
}
feePayApplicationEntity.AmountRMB = FinalRmd;
feePayApplicationEntity.AmountUSD = FinalUsd;
//feePayApplicationEntity.AccountRMB = "";
//feePayApplicationEntity.AccountUSD = "";
feePayApplicationEntity.BillStatus = 3;
feePayApplicationEntity.ChequePayable = txt_chequeNo.Value.Trim();
feePayApplicationEntity.Applicant = strUserID;
feePayApplicationEntity.ApplyTime = DateTime.Parse(txt_applyTime.Value.Trim());
feePayApplicationEntity.PayableTime = txt_payableDate.Value.Trim().Equals("") ? System.DateTime.MinValue : DateTime.Parse(txt_payableDate.Value.Trim());
feePayApplicationEntity.CustomerName = strCustomerName;//结算单位
feePayApplicationEntity.SettleType = int.Parse(this.sel_settlemode.Value);
feePayApplicationEntity.Remark = txt_remark.Value.Trim();
feePayApplicationEntity.CompanyID = strCompanyID;
feePayApplicationEntity.CHEQUENUMREMARK = this.chequenumermark.Text.Trim();//支票号备注
int iResult = feePaySettleApplicationDA.InsertFeePayApplication(feeDoEntities, feePayApplicationEntity);
if (iResult == 1)
{
ViewState["enter"] = "1";
strBillNO = feePaySettleApplicationDA.GetBillNoByPaySettleAppID(strFeePayApplicationID);
WorkFlowHelper workFlowHelper = new WorkFlowHelper();
WorkFlowEntity workFlowEntity = new WorkFlowEntity();
//WorkFlowEntity workFlowEntity = workFlowHelper.FindWorkFlow(WorkFlowType.PAYSETTLEAUDIT, strCompanyID);
if (stroplb.ToLower() == "op_seae")
{
if (result == 0)//单业务类型
{
workFlowEntity = workFlowHelper.FindWorkFlow(WorkFlowType.PAYSETTLEAUDIT, strCompanyID);
}
else//多业务类型
{
workFlowEntity = workFlowHelper.FindWorkFlow(WorkFlowType.FeeSeaAllPaySettleAudit, strCompanyID);
}
}
else if (stroplb.ToLower() == "op_seai")
{
if (result == 0)//单业务类型
{
workFlowEntity = workFlowHelper.FindWorkFlow(WorkFlowType.SeaiPAYSETTLEAUDIT, strCompanyID);
}
else//多业务类型
{
workFlowEntity = workFlowHelper.FindWorkFlow(WorkFlowType.FeeSeaAllPaySettleAudit, strCompanyID);
}
}
else if (stroplb.ToLower() == "import_main")
{
workFlowEntity = workFlowHelper.FindWorkFlow(WorkFlowType.FeeSeaAllPaySettleAudit, strCompanyID);
}
else if (stroplb.ToLower() == "tmswlbshead" || stroplb.ToLower() == "tmswlpchead")//51 陆运
{
workFlowEntity = workFlowHelper.FindWorkFlow(WorkFlowType.tMsWlPAYSETTLEAUDIT, strCompanyID);
}
else if (stroplb.ToLower() == "wms_fee" || stroplb.ToLower() == "wms" || stroplb.ToLower() == "wms_out")//61
{
workFlowEntity = workFlowHelper.FindWorkFlow(WorkFlowType.WmszxPAYSETTLEAUDIT, strCompanyID);
}
else if (stroplb.ToLower() == "op_apply")
{
if (result == 0)//单业务类型
{
workFlowEntity = workFlowHelper.FindWorkFlow(WorkFlowType.APPLYPAYSETTLEAUDIT, strCompanyID);
}
else
{
workFlowEntity = workFlowHelper.FindWorkFlow(WorkFlowType.FeeSeaAllPaySettleAudit, strCompanyID);
}
}
IList<WorkFlowDoEntity> workFlowDoEntities = new List<WorkFlowDoEntity>();
if (workFlowEntity != null)
{
//消息系统
IList<MessageEntity> messageEntities = new List<MessageEntity>();
MessageDA messageDA = new MessageDA();
WorkFlowDoEntity workFlowDoEntity = null;
WorkFlowDoDA workFlowDoDA = new WorkFlowDoDA();
workFlowDoEntity = workFlowDoDA.GetSigleWorkFlowDoByBillNO(workFlowEntity.GID, strBillNO);
if (workFlowDoEntity == null)
{
if (workFlowDoEntity.GID == null)
{
//workFlowDoEntity = new WorkFlowDoEntity();
//遍历所有工作流下步骤,获取第一步骤GID信息
foreach (WorkFlowStepEntity step in workFlowEntity.WorkFlowSteps)
{
if (step.StepNO == 1)
{
WorkFlowDoEntity paySettleWorkFlowDoEntity = new WorkFlowDoEntity();
paySettleWorkFlowDoEntity.GID = Guid.NewGuid().ToString();
paySettleWorkFlowDoEntity.WorkFlowID = workFlowEntity.GID;
paySettleWorkFlowDoEntity.StepID = step.GID;
paySettleWorkFlowDoEntity.StepNO = step.StepNO;
paySettleWorkFlowDoEntity.Auditor = step.Auditor;
paySettleWorkFlowDoEntity.BillNO = strBillNO;
paySettleWorkFlowDoEntity.IsFinish = false;
paySettleWorkFlowDoEntity.Applicant = strUserID;
workFlowDoEntities.Add(paySettleWorkFlowDoEntity);
MessageEntity messageEntity = new MessageEntity();
messageEntity.GID = Guid.NewGuid().ToString();
if (result == 0)
{
messageEntity.Name = "FeePayAudit";
}
else
{
messageEntity.Name = "FeeSeaAllPaySettleAudit";
}
messageEntity.Description = "付费申请审核";
messageEntity.IsRead = false;
messageEntity.ReadCount = 0;
messageEntity.MessageContent = strShowName + " 业务编号:" + strBillNO + " 提交待审核 [付费申请] ";
messageEntity.TaskID = strBillNO;
messageEntity.Receiver = step.Auditor;
messageEntity.TaskUrl = messageEntity.TaskUrl = "settlements/feepayaudit.aspx";
messageEntity.Type = messageDA.GetMessageType(MessageType.FEEPAYAPP);
messageEntity.RecvType = 2;//申请审核类型
messageEntities.Add(messageEntity);
}
}
workFlowDoDA.InsertWorkFlowDo(workFlowDoEntities);
feePaySettleApplicationDA.UpdatePayApplicationStatus(strBillNO, 3, strCompanyID);
if (messageEntities.Count > 0)
{
messageDA.CreateMessage(MessageType.FEEPAYAPP, messageEntities);
}
}
}
else
{
if (workFlowDoEntity.GID == null)
{
//workFlowDoEntity = new WorkFlowDoEntity();
//遍历所有工作流下步骤,获取第一步骤GID信息
foreach (WorkFlowStepEntity step in workFlowEntity.WorkFlowSteps)
{
if (step.StepNO == 1)
{
WorkFlowDoEntity paySettleWorkFlowDoEntity = new WorkFlowDoEntity();
paySettleWorkFlowDoEntity.GID = Guid.NewGuid().ToString();
paySettleWorkFlowDoEntity.WorkFlowID = workFlowEntity.GID;
paySettleWorkFlowDoEntity.StepID = step.GID;
paySettleWorkFlowDoEntity.StepNO = step.StepNO;
paySettleWorkFlowDoEntity.Auditor = step.Auditor == null ? step.DefaultAuditor : step.Auditor;
paySettleWorkFlowDoEntity.FeeID = "";
paySettleWorkFlowDoEntity.BSNO = "";
paySettleWorkFlowDoEntity.FeeStatus = 0;
paySettleWorkFlowDoEntity.DoQuerySql = "";
paySettleWorkFlowDoEntity.BillNO = strBillNO;
paySettleWorkFlowDoEntity.IsFinish = false;
paySettleWorkFlowDoEntity.Applicant = strUserID;
workFlowDoEntities.Add(paySettleWorkFlowDoEntity);
MessageEntity messageEntity = new MessageEntity();
messageEntity.GID = Guid.NewGuid().ToString();
if (result == 0)
{
messageEntity.Name = "FeePayAudit";
}
else
{
messageEntity.Name = "FeeSeaAllPaySettleAudit";
}
messageEntity.Description = "付费申请审核";
messageEntity.IsRead = false;
messageEntity.ReadCount = 0;
messageEntity.MessageContent = strShowName + " 业务编号:" + strBillNO + " 提交待审核 [付费申请] ";
messageEntity.TaskID = strBillNO;
messageEntity.Receiver = step.Auditor;
messageEntity.TaskUrl = messageEntity.TaskUrl = "settlements/feepayaudit.aspx";
messageEntity.Type = messageDA.GetMessageType(MessageType.FEEPAYAPP);
messageEntity.RecvType = 2;//申请审核类型
messageEntities.Add(messageEntity);
}
}
workFlowDoDA.InsertWorkFlowDo(workFlowDoEntities);
feePaySettleApplicationDA.UpdatePayApplicationStatus(strBillNO, 3, strCompanyID);
if (messageEntities.Count > 0)
{
messageDA.CreateMessage(MessageType.FEEPAYAPP, messageEntities);
}
}
}
}
ViewState["enter"] = "1";
this.btn_enter.Disabled = true;
this.btn_save.Disabled = true;
LogEntity logEntity = new LogEntity();
logEntity.GID = Guid.NewGuid().ToString();
logEntity.Name = "添加付费申请信息";
logEntity.LogType = "INSERT 插入操作";
logEntity.CreateUserID = strUserID;
logEntity.LogContent = strShowName + String.Format(Logger.Instance.GetLogContentTemplate(Logger.LogTypes.INSERT), "付费申请", "申请编号:" + strBillNO);
Logger.Instance.WriteLog(logEntity);
ViewState["PaySettleAppID"] = strFeePayApplicationID;
Page.ClientScript.RegisterStartupScript(this.GetType(), "key1", "<script>alert('申请提交成功');openAction('" + strFeePayApplicationID + "');</script>");
}
else
{
ViewState["enter"] = "2";
Page.ClientScript.RegisterStartupScript(this.GetType(), "key2", "<script>alert('申请提交失败');refresh()</script>");
}
}
else
{
string strRunSettleID = "";
string strBillNO = "";
if (ViewState["RunSettleID"] != null)
{
strRunSettleID = ViewState["RunSettleID"].ToString();
string strRemark = this.txt_remark.Value.Trim();
int iResult = feePaySettleApplicationDA.PostSavedPaySettleRequest(strFeePayApplicationID,strRunSettleID, strUserID, strRemark,strCompanyID);
if (iResult == 1)
{
strBillNO = feePaySettleApplicationDA.GetBillNoByPaySettleAppID(strFeePayApplicationID);
//工作流
WorkFlowHelper workFlowHelper = new WorkFlowHelper();
WorkFlowEntity workFlowEntity = new WorkFlowEntity();
//WorkFlowEntity workFlowEntity = workFlowHelper.FindWorkFlow(WorkFlowType.PAYSETTLEAUDIT, strCompanyID);
if (stroplb.ToLower() == "op_seae")
{
//workFlowEntity = workFlowHelper.FindWorkFlow(WorkFlowType.PAYSETTLEAUDIT, strCompanyID);
if (result == 0)//单业务类型
{
workFlowEntity = workFlowHelper.FindWorkFlow(WorkFlowType.PAYSETTLEAUDIT, strCompanyID);
}
else//多业务类型
{
workFlowEntity = workFlowHelper.FindWorkFlow(WorkFlowType.FeeSeaAllPaySettleAudit, strCompanyID);
}
}
else if (stroplb.ToLower() == "op_seai")
{
//workFlowEntity = workFlowHelper.FindWorkFlow(WorkFlowType.SeaiPAYSETTLEAUDIT, strCompanyID);
if (result == 0)//单业务类型
{
workFlowEntity = workFlowHelper.FindWorkFlow(WorkFlowType.SeaiPAYSETTLEAUDIT, strCompanyID);
}
else//多业务类型
{
workFlowEntity = workFlowHelper.FindWorkFlow(WorkFlowType.FeeSeaAllPaySettleAudit, strCompanyID);
}
}
else if (stroplb.ToLower() == "tmswlbshead" || stroplb.ToLower() == "tmswlpchead")//51 陆运
{
workFlowEntity = workFlowHelper.FindWorkFlow(WorkFlowType.tMsWlPAYSETTLEAUDIT, strCompanyID);
}
else if (stroplb.ToLower() == "wms_fee" || stroplb.ToLower() == "wms" || stroplb.ToLower() == "wms_out")//61 仓储
{
workFlowEntity = workFlowHelper.FindWorkFlow(WorkFlowType.WmszxPAYSETTLEAUDIT, strCompanyID);
}
else if (stroplb.ToLower() == "import_main")
{
workFlowEntity = workFlowHelper.FindWorkFlow(WorkFlowType.FeeSeaAllPaySettleAudit, strCompanyID);
}
else if (stroplb.ToLower() == "op_apply")
{
if (result == 0)//单业务类型
{
workFlowEntity = workFlowHelper.FindWorkFlow(WorkFlowType.APPLYPAYSETTLEAUDIT, strCompanyID);
}
else
{
workFlowEntity = workFlowHelper.FindWorkFlow(WorkFlowType.FeeSeaAllPaySettleAudit, strCompanyID);
}
}
IList<WorkFlowDoEntity> workFlowDoEntities = new List<WorkFlowDoEntity>();
if (workFlowEntity != null)
{
//消息系统
IList<MessageEntity> messageEntities = new List<MessageEntity>();
MessageDA messageDA = new MessageDA();
WorkFlowDoEntity workFlowDoEntity = null;
WorkFlowDoDA workFlowDoDA = new WorkFlowDoDA();
workFlowDoEntity = workFlowDoDA.GetSigleWorkFlowDoByBillNO(workFlowEntity.GID, strBillNO);
if (workFlowDoEntity == null)
{
if (workFlowDoEntity.GID == null)
{
//workFlowDoEntity = new WorkFlowDoEntity();
//遍历所有工作流下步骤,获取第一步骤GID信息
foreach (WorkFlowStepEntity step in workFlowEntity.WorkFlowSteps)
{
if (step.StepNO == 1)
{
WorkFlowDoEntity paySettleWorkFlowDoEntity = new WorkFlowDoEntity();
paySettleWorkFlowDoEntity.GID = Guid.NewGuid().ToString();
paySettleWorkFlowDoEntity.WorkFlowID = workFlowEntity.GID;
paySettleWorkFlowDoEntity.StepID = step.GID;
paySettleWorkFlowDoEntity.StepNO = step.StepNO;
paySettleWorkFlowDoEntity.Auditor = step.Auditor;
paySettleWorkFlowDoEntity.BillNO = strBillNO;
paySettleWorkFlowDoEntity.IsFinish = false;
paySettleWorkFlowDoEntity.Applicant = strUserID;
workFlowDoEntities.Add(paySettleWorkFlowDoEntity);
MessageEntity messageEntity = new MessageEntity();
messageEntity.GID = Guid.NewGuid().ToString();
if (result == 0)
{
messageEntity.Name = "FeePayAudit";
}
else
{
messageEntity.Name = "FeeSeaAllPaySettleAudit";
}
messageEntity.Description = "付费申请审核";
messageEntity.IsRead = false;
messageEntity.ReadCount = 0;
messageEntity.MessageContent = strShowName + " 业务编号:" + strBillNO + " 提交待审核 [付费申请] ";
messageEntity.TaskID = strBillNO;
messageEntity.Receiver = step.Auditor;
messageEntity.TaskUrl = messageEntity.TaskUrl = "settlements/feepayaudit.aspx";
messageEntity.Type = messageDA.GetMessageType(MessageType.FEEPAYAPP);
messageEntity.RecvType = 2;//申请审核类型
messageEntities.Add(messageEntity);
}
}
workFlowDoDA.InsertWorkFlowDo(workFlowDoEntities);
feePaySettleApplicationDA.UpdatePayApplicationStatus(strBillNO, 3,strCompanyID);
if (messageEntities.Count > 0)
{
messageDA.CreateMessage(MessageType.FEEPAYAPP, messageEntities);
}
}
}
else
{
if (workFlowDoEntity.GID == null)
{
//workFlowDoEntity = new WorkFlowDoEntity();
//遍历所有工作流下步骤,获取第一步骤GID信息
foreach (WorkFlowStepEntity step in workFlowEntity.WorkFlowSteps)
{
if (step.StepNO == 1)
{
WorkFlowDoEntity paySettleWorkFlowDoEntity = new WorkFlowDoEntity();
paySettleWorkFlowDoEntity.GID = Guid.NewGuid().ToString();
paySettleWorkFlowDoEntity.WorkFlowID = workFlowEntity.GID;
paySettleWorkFlowDoEntity.StepID = step.GID;
paySettleWorkFlowDoEntity.StepNO = step.StepNO;
paySettleWorkFlowDoEntity.Auditor = step.Auditor == null ? step.DefaultAuditor : step.Auditor;
paySettleWorkFlowDoEntity.FeeID = "";
paySettleWorkFlowDoEntity.BSNO = "";
paySettleWorkFlowDoEntity.FeeStatus = 0;
paySettleWorkFlowDoEntity.DoQuerySql = "";
paySettleWorkFlowDoEntity.BillNO = strBillNO;
paySettleWorkFlowDoEntity.IsFinish = false;
paySettleWorkFlowDoEntity.Applicant = strUserID;
workFlowDoEntities.Add(paySettleWorkFlowDoEntity);
MessageEntity messageEntity = new MessageEntity();
messageEntity.GID = Guid.NewGuid().ToString();
if (result == 0)
{
messageEntity.Name = "FeePayAudit";
}
else
{
messageEntity.Name = "FeeSeaAllPaySettleAudit";
}
messageEntity.Description = "付费申请审核";
messageEntity.IsRead = false;
messageEntity.ReadCount = 0;
messageEntity.MessageContent = strShowName + " 业务编号:" + strBillNO + " 提交待审核 [付费申请] ";
messageEntity.TaskID = strBillNO;
messageEntity.Receiver = step.Auditor;
messageEntity.TaskUrl = messageEntity.TaskUrl = "settlements/feepayaudit.aspx";
messageEntity.Type = messageDA.GetMessageType(MessageType.FEEPAYAPP);
messageEntity.RecvType = 2;//申请审核类型
messageEntities.Add(messageEntity);
}
}
workFlowDoDA.InsertWorkFlowDo(workFlowDoEntities);
feePaySettleApplicationDA.UpdatePayApplicationStatus(strBillNO, 3,strCompanyID);
if (messageEntities.Count > 0)
{
messageDA.CreateMessage(MessageType.FEEPAYAPP, messageEntities);
}
}
}
}
ViewState["enter"] = "1";
this.btn_enter.Disabled = true;
this.btn_save.Disabled = true;
LogEntity logEntity = new LogEntity();
logEntity.GID = Guid.NewGuid().ToString();
logEntity.Name = "添加付费申请信息";
logEntity.LogType = "INSERT 插入操作";
logEntity.CreateUserID = strUserID;
logEntity.LogContent = strShowName+ String.Format(Logger.Instance.GetLogContentTemplate(Logger.LogTypes.INSERT), "付费申请", "申请编号:" + strBillNO);
Logger.Instance.WriteLog(logEntity);
ViewState["PaySettleAppID"] = strFeePayApplicationID;
Page.ClientScript.RegisterStartupScript(this.GetType(), "key1", "<script>alert('申请提交成功');openAction('" + strFeePayApplicationID + "');</script>");
}
else
{
ViewState["enter"] = "2";
Page.ClientScript.RegisterStartupScript(this.GetType(), "key2", "<script>alert('申请提交失败');refresh()</script>");
}
}
}
}
#endregion
/// <summary>
/// 获取业务类型
/// </summary>
/// <param name="bsno"></param>
/// <returns></returns>
protected string GetOplbnameByBsno(string bsno)
{
T_ALL_DA tallda = new T_ALL_DA();
return tallda.GetStrSQL("OPLBNAME", "SELECT OPLBNAME FROM VW_Settlement WHERE BSNO='" + bsno.Trim() + "'");
}
#region 保存付费申请
/// <summary>
/// 保存付费申请
/// </summary>
private void SavePaySettleRequest(string tempPostSessionName)
{
int billtype = 0;//1收费2付费
DataTable bsnoTable = null;
DataTable feeTable = null;
DataTable totalTable = null;
DataSet postSet = null;
if (Session[tempPostSessionName] != null)
{
postSet = (DataSet)Session[tempPostSessionName];
}
bsnoTable = (DataTable)postSet.Tables[0];
feeTable = (DataTable)postSet.Tables[1];
totalTable = (DataTable)postSet.Tables[2];
RunFeeDoDA runFeeDoDA = new RunFeeDoDA();
if (ViewState["SaveState"] == null)
{
string strCustomerName = "";
string strRunSettleID = Guid.NewGuid().ToString();
//付费申请费用明细信息
IList<RunFeeDoEntity> runFeeDoEntities = new List<RunFeeDoEntity>();
for (int j = 0; j < bsnoTable.Rows.Count; j++)
{
for (int i = 0; i < feeTable.Rows.Count; i++)
{
if (i == 0)
{
strCustomerName = feeTable.Rows[i]["CUSTOMERNAME"].ToString();
}
if (bsnoTable.Rows[j]["BSNO"].ToString().Trim() != feeTable.Rows[i]["BSNO"].ToString().Trim())
{
continue;
}
RunFeeDoEntity runFeeDoEntity = new RunFeeDoEntity();
runFeeDoEntity.FeeID = feeTable.Rows[i]["GID"].ToString();
runFeeDoEntity.FeeType = int.Parse(feeTable.Rows[i]["FEETYPE"].ToString());
billtype = runFeeDoEntity.FeeType;
runFeeDoEntity.Currency = feeTable.Rows[i]["CURRENCY"].ToString();
runFeeDoEntity.Amount = decimal.Parse(feeTable.Rows[i]["AMOUNT"].ToString());
runFeeDoEntity.DoAmount = decimal.Parse(feeTable.Rows[i]["CTL"].ToString());
runFeeDoEntity.UnsettleAmount = decimal.Parse(feeTable.Rows[i]["UCTL"].ToString());
runFeeDoEntity.CustomerName = feeTable.Rows[i]["CUSTOMERNAME"].ToString();
runFeeDoEntity.FeeName = feeTable.Rows[i]["FEENAME"].ToString();
runFeeDoEntity.OriginalFeeName = feeTable.Rows[i]["CUSTOMERNAME"].ToString();
runFeeDoEntity.OriginalFeeCSTL = decimal.Parse(feeTable.Rows[i]["CTL"].ToString());
if (strSettleCurrency == "1")
{
runFeeDoEntity.ExchangeRate = usdToRmb;
}
else if (strSettleCurrency == "2")
{
runFeeDoEntity.ExchangeRate = rmbToUsd;
}
runFeeDoEntity.BSNO = bsnoTable.Rows[j]["BSNO"].ToString();
runFeeDoEntity.MBLNO = bsnoTable.Rows[j]["MBLNO"].ToString();
runFeeDoEntity.HBLNO = bsnoTable.Rows[j]["HBLNO"].ToString();
runFeeDoEntity.GID = Guid.NewGuid().ToString();
runFeeDoEntity.Category = 4;
runFeeDoEntity.BSType = 1;
runFeeDoEntity.BillStatus = 2;
runFeeDoEntity.Remark = "";
runFeeDoEntity.OrigCurrency = "";
runFeeDoEntity.RunSettleID = strRunSettleID;
runFeeDoEntity.InvoiceSettleNO = "";
runFeeDoEntity.CreateUser = strUserID;
runFeeDoEntities.Add(runFeeDoEntity);
}
}
RunFeeSettlementEntity runFeeSettlementEntity = new RunFeeSettlementEntity();
runFeeSettlementEntity.GID = strRunSettleID;
runFeeSettlementEntity.BillStatus = 1;
runFeeSettlementEntity.CreateUser = strUserID;
runFeeSettlementEntity.PayableTime = txt_payableDate.Value.Trim().Equals("") ? System.DateTime.MinValue : DateTime.Parse(txt_payableDate.Value.Trim());
runFeeSettlementEntity.CustomerName = strCustomerName;//结算单位
runFeeSettlementEntity.SettleType = int.Parse(this.sel_settlemode.Value);
runFeeSettlementEntity.Remark = txt_remark.Value.Trim();
runFeeSettlementEntity.BillType = billtype;//由runFeeDoEntity.FeeType决定
runFeeSettlementEntity.Type = 1;//付费申请
runFeeSettlementEntity.VoucherNO = "";//凭证号
runFeeSettlementEntity.FinancialVoucher = "";
runFeeSettlementEntity.CompanyID = strCompanyID;
runFeeSettlementEntity.CHEQUENUMREMARK = this.chequenumermark.Text.Trim();//支票号备注
decimal totalRmb = decimal.Parse(totalTable.Rows[0]["TOTALRMB"].ToString());
decimal totalUsd = decimal.Parse(totalTable.Rows[0]["TOTALUSD"].ToString());
decimal FinalRmd = 0;
decimal FinalUsd = 0;
if (strSettleCurrency == "1")
{
//人民币结算
FinalRmd = (StatisticSettleAmount(totalUsd, usdToRmb) + totalRmb);
//折算汇率
runFeeSettlementEntity.Rate = totalUsd != 0 ? usdToRmb : 1;
}
else if (strSettleCurrency == "2")
{
//美元结算
FinalUsd = (StatisticSettleAmount(totalRmb, rmbToUsd) + totalUsd);
//折算汇率
runFeeSettlementEntity.Rate = totalRmb != 0 ? rmbToUsd : 1;
}
else if (strSettleCurrency == "3")
{
FinalRmd = totalRmb;
FinalUsd = totalUsd;
runFeeSettlementEntity.Rate = 1;
}
runFeeSettlementEntity.AmountRMB = FinalRmd;
runFeeSettlementEntity.AmountUSD = FinalUsd;
runFeeSettlementEntity.AccountRMB = "";
runFeeSettlementEntity.AccountUSD = "";
runFeeSettlementEntity.ChequeNo = this.txt_chequeNo.Value.Trim();
runFeeSettlementEntity.ChequeNoUsd = this.txt_chequeNo.Value.Trim();
int iResult = runFeeDoDA.InsertRunSettle(runFeeDoEntities, runFeeSettlementEntity,strUserID,strShowName,"UNPAYAPP");
if (iResult == 1)
{
ViewState["enter"] = "1";//已经保存成功
ViewState["SaveState"] = "1";//已经保存成功
ViewState["RunSettleID"] = runFeeSettlementEntity.GID;//保存运行结算表GID
Page.ClientScript.RegisterStartupScript(this.GetType(), "key1", "<script>alert('申请保存成功');refresh()</script>");
}
else
{
ViewState["enter"] = "1";
ViewState.Remove("SaveState");
Page.ClientScript.RegisterStartupScript(this.GetType(), "key2", "<script>alert('申请保存失败');refresh()</script>");
}
}
else
{
string strRunSettleID = "";
RunFeeSettlementEntity origRunFeeSettlementEntity = new RunFeeSettlementEntity();
RunFeeSettlementEntity newRunFeeSettlementEntity = new RunFeeSettlementEntity();
if (ViewState["RunSettleID"] != null)
{
strRunSettleID = ViewState["RunSettleID"].ToString();
RunFeeSettlementDA runFeeSettlementDA = new RunFeeSettlementDA();
origRunFeeSettlementEntity = runFeeSettlementDA.GetRunFeeSettlementByGID(strRunSettleID);
if (origRunFeeSettlementEntity != null)
{
if (origRunFeeSettlementEntity.GID != null)
{
LogEntity logEntity = new LogEntity();
logEntity.GID = Guid.NewGuid().ToString();
logEntity.Name = "更新付费申请信息";
logEntity.LogType = "UPDATE 更新操作";
logEntity.CreateUserID = strUserID;//测试使用数据,正式发布请删除
int iSettleType = int.Parse(this.sel_settlemode.Value);
if (origRunFeeSettlementEntity.SettleType != int.Parse(this.sel_settlemode.Value))
{
logEntity.LogContent += String.Format(Logger.Instance.GetLogContentTemplate(Logger.LogTypes.UPDATE), "结算方式", GetSettleTypeName(origRunFeeSettlementEntity.SettleType), GetSettleTypeName(iSettleType));
}
string strChequeNo = this.txt_chequeNo.Value.Trim();
if ((origRunFeeSettlementEntity.ChequeNo ?? "") != strChequeNo)
{
logEntity.LogContent += String.Format(Logger.Instance.GetLogContentTemplate(Logger.LogTypes.UPDATE), "支票抬头", origRunFeeSettlementEntity.ChequeNo, strChequeNo);
logEntity.LogContent += String.Format(Logger.Instance.GetLogContentTemplate(Logger.LogTypes.UPDATE), "支票抬头", origRunFeeSettlementEntity.ChequeNoUsd, strChequeNo);
}
DateTime dPayableTime = txt_payableDate.Value.Trim().Equals("") ? System.DateTime.MinValue : DateTime.Parse(txt_payableDate.Value.Trim());
if (origRunFeeSettlementEntity.PayableTime != dPayableTime)
{
logEntity.LogContent += String.Format(Logger.Instance.GetLogContentTemplate(Logger.LogTypes.UPDATE), "要求支付日期",
(origRunFeeSettlementEntity.PayableTime == DateTime.MinValue ? "" : origRunFeeSettlementEntity.PayableTime.ToString("yyyy-MM-dd hh:mm:ss")),
(dPayableTime == DateTime.MinValue ? "" : dPayableTime.ToString("yyyy-MM-dd hh:mm:ss")));
}
int iResult = runFeeSettlementDA.UpdateRunSettleByGID(strRunSettleID, iSettleType, strChequeNo, strChequeNo, dPayableTime, strUserID, "");
if (logEntity.LogContent != null)
{
if (iResult == 1)
{
logEntity.LogContent = strShowName + " " + logEntity.LogContent;
Logger.Instance.WriteLog(logEntity);
}
}
}
}
}
}
}
#endregion
private void InitDoSettlement()
{
txt_applicant.Value = strShowName;
txt_applyTime.Value = DateTime.Now.ToString();
txt_billStatus.Value = "锁定";
}
#region #####
/// <summary>
/// 记录付费申请信息
/// </summary>
/// <returns></returns>
//private int RecordFeePayApplication()
//{
// int iResult = 0;
// string settleFee = "";
// string settleTotal = "";
// string customerName = "";
// settleTotal = h_settleinfo.Value;
// strFeeCache = h_feecache.Value;
// if (strFeeCache.IndexOf("[") >= 0 && strFeeCache.IndexOf("]") > 0)
// {
// strBillNO = CreateSettleCode();
// settleFee = strFeeCache.Substring(strFeeCache.IndexOf("[") + 1, strFeeCache.IndexOf("]") - strFeeCache.IndexOf("[") - 1);
// IList<FeeDoEntity> feeDoEntities = new List<FeeDoEntity>();
// IList<FeeEntity> feeEntities = new List<FeeEntity>();
// FeeDA feeDA = new FeeDA();
// //settleFee = settleFee.Replace(, "#");
// string[] strFees = settleFee.Split(new string[] { "},{" }, System.StringSplitOptions.RemoveEmptyEntries);
// if (strFees.Length > 0)
// {
// for (int i = 0; i < strFees.Length; i++)
// {
// strFees[i] = strFees[i].ToString().Replace("{", "");
// strFees[i] = strFees[i].ToString().Replace("}", "");
// string[] strCell = strFees[i].Split(new char[] { ',' });
// if (strCell.Length > 0)
// {
// FeeDoEntity feeDoEntity = new FeeDoEntity();
// for (int j = 0; j < strCell.Length; j++)
// {
// string[] strArg = strCell[j].Split(new char[] { ':' });
// switch (strArg[0].Replace("\"", ""))
// {
// case "id":
// feeDoEntity.FeeID = strArg[1].ToString().Replace("\"", "").Trim();
// break;
// case "type":
// feeDoEntity.FeeType = int.Parse(strArg[1].ToString().Replace("\"", "").Trim());
// break;
// case "cur":
// feeDoEntity.Currency = strArg[1].ToString().Replace("\"", "").Trim();
// break;
// case "stl":
// feeDoEntity.Amount = decimal.Parse(strArg[1].ToString().Replace("\"", "").Trim());
// break;
// case "cstl":
// feeDoEntity.DoAmount = decimal.Parse(strArg[1].ToString().Replace("\"", "").Trim());
// break;
// case "ustl":
// feeDoEntity.UnsettleAmount = decimal.Parse(strArg[1].ToString().Replace("\"", "").Trim());
// break;
// case "cus":
// if (customerName.Equals(""))
// {
// customerName = UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim());
// this.txt_customerName.Value = customerName;
// }
// feeDoEntity.CustomerName = UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim());
// break;
// case "fname":
// feeDoEntity.FeeName = UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim());
// break;
// case "bsno":
// feeDoEntity.BSNO = strArg[1].ToString().Replace("\"", "").Trim();
// break;
// case "orig":
// if (!strArg[1].ToString().Replace("\"", "").Trim().Equals(""))
// {
// feeDoEntity.Orig = int.Parse(strArg[1].ToString().Replace("\"", "").Trim());
// }
// break;
// case "oname":
// if (!strArg[1].ToString().Replace("\"", "").Trim().Equals(""))
// {
// feeDoEntity.OriginalFeeName = UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim());
// }
// break;
// case "ocstl":
// if (!strArg[1].ToString().Replace("\"", "").Trim().Equals(""))
// {
// feeDoEntity.OriginalFeeCSTL = decimal.Parse(strArg[1].ToString().Replace("\"", "").Trim());
// }
// break;
// default:
// break;
// }
// }
// if (strSettleCurrency != feeDoEntity.Currency)
// {
// if (strSettleCurrency == "RMB")
// {
// feeDoEntity.ExchangeRate = usdToRmb;
// }
// else if (strSettleCurrency == "USD")
// {
// feeDoEntity.ExchangeRate = rmbToUsd;
// }
// }
// //feeDoEntity.BSNO = "";
// feeDoEntity.MBLNO = "";
// feeDoEntity.HBLNO = "";
// //feeDoEntity.CustomerName = "";
// //feeDoEntity.FeeName = "";
// feeDoEntity.BillNO = strBillNO;
// feeDoEntity.GID = Guid.NewGuid().ToString();
// feeDoEntity.Category = 4;
// feeDoEntity.BSType = 1;
// feeDoEntity.BillStatus = 2;
// feeDoEntity.Remark = "";
// feeDoEntities.Add(feeDoEntity);
// }
// }
// }
// if (feeDoEntities.Count > 0)
// {
// IList<FeeSettlementEntity> feeSettlementEntities = new List<FeeSettlementEntity>();
// FeePayApplicationEntity feePayApplicationEntity = new FeePayApplicationEntity();
// feePayApplicationEntity.GID = Guid.NewGuid().ToString();
// if (settleTotal != "")
// {
// string tempSettle = settleTotal.Substring(settleTotal.IndexOf("[") + 1, settleTotal.IndexOf("]") - settleTotal.IndexOf("[") - 1);
// string[] tempSettleFees = tempSettle.Split(new string[] { "},{" }, System.StringSplitOptions.RemoveEmptyEntries);
// if (tempSettleFees.Length > 0)
// {
// for (int i = 0; i < tempSettleFees.Length; i++)
// {
// tempSettleFees[i] = tempSettleFees[i].ToString().Replace("{", "");
// tempSettleFees[i] = tempSettleFees[i].ToString().Replace("}", "");
// string[] strCell = tempSettleFees[i].Split(new char[] { ',' });
// if (strCell.Length > 0)
// {
// string strCurrency = "";
// for (int j = 0; j < strCell.Length; j++)
// {
// string[] strArg = strCell[j].Split(new char[] { ':' });
// switch (strArg[0].Replace("\"", ""))
// {
// case "id":
// //feeSettlementEntity.GID = strArg[1].ToString().Replace("\"", "").Trim();
// break;
// case "cur":
// strCurrency = strArg[1].ToString().Replace("\"", "").Trim();
// break;
// case "amount":
// if (strCurrency.Equals("RMB"))
// {
// feePayApplicationEntity.AmountRMB = decimal.Parse(strArg[1].ToString().Replace("\"", "").Trim());
// }
// else if (strCurrency.Equals("USD"))
// {
// feePayApplicationEntity.AmountUSD = decimal.Parse(strArg[1].ToString().Replace("\"", "").Trim());
// }
// break;
// //case "account":
// // if (strCurrency.Equals("RMB"))
// // {
// // feePayApplicationEntity.AccountRMB = strArg[1].ToString().Replace("\"", "").Trim();
// // }
// // else if (strCurrency.Equals("USD"))
// // {
// // feePayApplicationEntity.AccountUSD = strArg[1].ToString().Replace("\"", "").Trim();
// // }
// // break;
// case "bank":
// break;
// default:
// break;
// }
// }
// }
// if (tempSettleFees.Length > 1)
// {
// feePayApplicationEntity.Rate = 1;
// }
// else
// {
// if (feePayApplicationEntity.AmountRMB > 0)
// {
// feePayApplicationEntity.Rate = decimal.Parse(h_usdtormb.Value);
// }
// else
// {
// feePayApplicationEntity.Rate = decimal.Parse(h_rmbtousd.Value);
// }
// }
// }
// }
// }
// //if (feeSettlementEntity.AccountUSD == null)
// //{
// // feePayApplicationEntity.AccountUSD = "";
// //}
// //if (feeSettlementEntity.AccountRMB == null)
// //{
// // feePayApplicationEntity.AccountRMB = "";
// //}
// feePayApplicationEntity.BillNO = strBillNO;
// feePayApplicationEntity.BillStatus = 2;
// feePayApplicationEntity.ChequePayable = txt_chequePayable.Value.Trim();
// feePayApplicationEntity.Applicant = strUserID;
// feePayApplicationEntity.ApplyTime = DateTime.Parse(txt_applyTime.Value.Trim());
// feePayApplicationEntity.PayableTime = txt_payableDate.Value.Trim().Equals("") ? System.DateTime.MinValue : DateTime.Parse(txt_payableDate.Value.Trim());
// feePayApplicationEntity.CustomerName = customerName;//结算单位
// feePayApplicationEntity.SettleType = int.Parse(this.sel_settlemode.Value);
// feePayApplicationEntity.Remark = txt_remark.Value.Trim();
// //feeSettlementEntities.Add(feePayApplicationEntity);
// FeePaySettleApplicationDA feePaySettleApplicationDA = new FeePaySettleApplicationDA();
// iResult = feePaySettleApplicationDA.InsertFeePayApplication(feeDoEntities, feePayApplicationEntity);
// //如果更新成功,则进行流程判断,查看当前付费申请是否有工作流控制
// if (iResult == 1)
// {
// this.h_billno.Value = strBillNO;
// //工作流
// WorkFlowHelper workFlowHelper = new WorkFlowHelper();
// WorkFlowEntity workFlowEntity = workFlowHelper.FindWorkFlow(WorkFlowType.PAYSETTLEAUDIT,strCompanyID);
// IList<WorkFlowDoEntity> workFlowDoEntities = new List<WorkFlowDoEntity>();
// if (workFlowEntity != null)
// {
// //消息系统
// IList<MessageEntity> messageEntities = new List<MessageEntity>();
// MessageDA messageDA = new MessageDA();
// WorkFlowDoEntity workFlowDoEntity = null;
// WorkFlowDoDA workFlowDoDA = new WorkFlowDoDA();
// workFlowDoEntity = workFlowDoDA.GetSigleWorkFlowDoByBillNO(workFlowEntity.GID, strBillNO);
// if (workFlowDoEntity == null)
// {
// if (workFlowDoEntity.GID == null)
// {
// //workFlowDoEntity = new WorkFlowDoEntity();
// //遍历所有工作流下步骤,获取第一步骤GID信息
// foreach (WorkFlowStepEntity step in workFlowEntity.WorkFlowSteps)
// {
// if (step.StepNO == 1)
// {
// WorkFlowDoEntity paySettleWorkFlowDoEntity = new WorkFlowDoEntity();
// paySettleWorkFlowDoEntity.GID = Guid.NewGuid().ToString();
// paySettleWorkFlowDoEntity.WorkFlowID = workFlowEntity.GID;
// paySettleWorkFlowDoEntity.StepID = step.GID;
// paySettleWorkFlowDoEntity.StepNO = step.StepNO;
// paySettleWorkFlowDoEntity.Auditor = step.Auditor;
// paySettleWorkFlowDoEntity.BillNO = strBillNO;
// paySettleWorkFlowDoEntity.IsFinish = false;
// paySettleWorkFlowDoEntity.Applicant = strUserID;
// workFlowDoEntities.Add(paySettleWorkFlowDoEntity);
// MessageEntity messageEntity = new MessageEntity();
// messageEntity.GID = Guid.NewGuid().ToString();
// messageEntity.Name = "FeePayAudit";
// messageEntity.Description = "付费申请审核";
// messageEntity.IsRead = false;
// messageEntity.ReadCount = 0;
// messageEntity.MessageContent = strShowName + " 业务编号:" + strBillNO + " 提交待审核 [付费申请] ";
// messageEntity.TaskID = strBillNO;
// messageEntity.Receiver = step.Auditor;
// messageEntity.TaskUrl = messageEntity.TaskUrl = "settlements/feepayaudit.aspx";
// messageEntity.Type = messageDA.GetMessageType(MessageType.FEEPAYAPP);
// messageEntity.RecvType = 2;//申请审核类型
// messageEntities.Add(messageEntity);
// }
// }
// workFlowDoDA.InsertWorkFlowDo(workFlowDoEntities);
// feePaySettleApplicationDA.UpdatePayApplicationStatus(strBillNO,3);
// if (messageEntities.Count > 0)
// {
// messageDA.CreateMessage(MessageType.FEEPAYAPP, messageEntities);
// }
// }
// }
// else
// {
// if (workFlowDoEntity.GID == null)
// {
// //workFlowDoEntity = new WorkFlowDoEntity();
// //遍历所有工作流下步骤,获取第一步骤GID信息
// foreach (WorkFlowStepEntity step in workFlowEntity.WorkFlowSteps)
// {
// if (step.StepNO == 1)
// {
// WorkFlowDoEntity paySettleWorkFlowDoEntity = new WorkFlowDoEntity();
// paySettleWorkFlowDoEntity.GID = Guid.NewGuid().ToString();
// paySettleWorkFlowDoEntity.WorkFlowID = workFlowEntity.GID;
// paySettleWorkFlowDoEntity.StepID = step.GID;
// paySettleWorkFlowDoEntity.StepNO = step.StepNO;
// paySettleWorkFlowDoEntity.Auditor = step.Auditor == null ? step.DefaultAuditor : step.Auditor;
// paySettleWorkFlowDoEntity.FeeID = "";
// paySettleWorkFlowDoEntity.BSNO = "";
// paySettleWorkFlowDoEntity.FeeStatus = 0;
// paySettleWorkFlowDoEntity.DoQuerySql = "";
// paySettleWorkFlowDoEntity.BillNO = strBillNO;
// paySettleWorkFlowDoEntity.IsFinish = false;
// paySettleWorkFlowDoEntity.Applicant = strUserID;
// workFlowDoEntities.Add(paySettleWorkFlowDoEntity);
// MessageEntity messageEntity = new MessageEntity();
// messageEntity.GID = Guid.NewGuid().ToString();
// messageEntity.Name = "FeePayAudit";
// messageEntity.Description = "付费申请审核";
// messageEntity.IsRead = false;
// messageEntity.ReadCount = 0;
// messageEntity.MessageContent = strShowName + " 业务编号:" + strBillNO + " 提交待审核 [付费申请] ";
// messageEntity.TaskID = strBillNO;
// messageEntity.Receiver = step.Auditor;
// messageEntity.TaskUrl = messageEntity.TaskUrl = "settlements/feepayaudit.aspx";
// messageEntity.Type = messageDA.GetMessageType(MessageType.FEEPAYAPP);
// messageEntity.RecvType = 2;//申请审核类型
// messageEntities.Add(messageEntity);
// }
// }
// workFlowDoDA.InsertWorkFlowDo(workFlowDoEntities);
// feePaySettleApplicationDA.UpdatePayApplicationStatus(strBillNO, 3);
// if (messageEntities.Count > 0)
// {
// messageDA.CreateMessage(MessageType.FEEPAYAPP, messageEntities);
// }
// }
// }
// }
// txt_billNO.Value = feePayApplicationEntity.BillNO;
// this.btn_enter.Disabled = true;//提交申请按钮置灰,不可选按
// this.sel_settlemode.Disabled = true;//结算方式锁定,不可选
// this.txt_chequePayable.Disabled = true;//支票抬头置灰
// this.txt_payableDate.Disabled = true;//要求支付时间置灰,不可输入
// this.txt_remark.Disabled = true;//备注置灰,不可输入
// h_enter.Value = "0";//处理状态初始化
// }
// }
// }
// return iResult;
//}
#endregion
#region 获取缓存付费申请合计信息
/// <summary>
/// 获取缓存付费申请合计信息
/// </summary>
/// <param name="tempPostSessionName">缓存名称</param>
private void ResovlePostSessionTable(string tempPostSessionName)
{
DataTable bsnoTable = null;
DataTable feeTable = null;
DataTable totalTable = null;
DataSet postSet = null;
if (Session[tempPostSessionName] != null)
{
postSet = (DataSet)Session[tempPostSessionName];
}
bsnoTable = (DataTable)postSet.Tables[0];
feeTable = (DataTable)postSet.Tables[1];
totalTable = (DataTable)postSet.Tables[2];
StringBuilder totalBuilder = new StringBuilder();
totalBuilder.Append("{");
totalBuilder.Append("\"totals\":");
totalBuilder.Append("[");
totalBuilder.Append("{");
decimal totalRmb = decimal.Parse(totalTable.Rows[0]["TOTALRMB"].ToString());
decimal totalUsd = decimal.Parse(totalTable.Rows[0]["TOTALUSD"].ToString());
decimal FinalRmd = 0;
decimal FinalUsd = 0;
if (strSettleCurrency == "1")
{
//人民币结算
FinalRmd = (StatisticSettleAmount(totalUsd, usdToRmb) + totalRmb);
}
else if (strSettleCurrency == "2")
{
//美元结算
FinalUsd = (StatisticSettleAmount(totalRmb, rmbToUsd) + totalUsd);
}
else if (strSettleCurrency == "3")
{
FinalRmd = totalRmb;
FinalUsd = totalUsd;
}
totalBuilder.Append("\"recvrmb\":" + totalTable.Rows[0]["RECVRMB"].ToString() + ",");
totalBuilder.Append("\"recvusd\":" + totalTable.Rows[0]["RECVUSD"].ToString() + ",");
totalBuilder.Append("\"payrmb\":" + totalTable.Rows[0]["PAYRMB"].ToString() + ",");
totalBuilder.Append("\"payusd\":" + totalTable.Rows[0]["PAYUSD"].ToString() + ",");
totalBuilder.Append("\"totalrmb\":" + FinalRmd.ToString() + ",");
totalBuilder.Append("\"totalusd\":" + FinalUsd.ToString() + "");
totalBuilder.Append("}");
totalBuilder.Append("]");
totalBuilder.Append("}");
h_total.Value = totalBuilder.ToString();
}
#endregion
private string CreateSettleCode()
{
int CodeLength = 4;
string strSettleCode = "";
//获取分公司的票号头字符
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string tempBANKSHEAD = T_ALL_DA.GetStrSQL("BANKSHEAD", "SELECT TOP 1 BANKSHEAD FROM company WHERE GID='" + strCompanyID.Trim() + "'");
string strFeeType = tempBANKSHEAD+"AC";
FeeDoDA feeDoDA = new FeeDoDA();
DateTime nowDateTime = feeDoDA.getServerDateTime();
string strYear = nowDateTime.Year.ToString();
string strMonth = nowDateTime.Month.ToString().Length < 2 ? "0" + nowDateTime.Month.ToString() : nowDateTime.Month.ToString();
//string strDay = nowDateTime.Day.ToString();
string strDateTime = strYear + strMonth;
string strCodePrefix = strFeeType + strDateTime;
string strSql = "SELECT TOP 1 BILLNO FROM ch_fee_payapplication WHERE BILLNO LIKE '" + strFeeType + strDateTime + "%' ORDER BY BILLNO DESC";
DataTable billTable = feeDoDA.GetExcuteSql(strSql).Tables[0];
ArrayList codeArg = new ArrayList();
for (int i = 0; i < CodeLength; i++)
{
codeArg.Add(0);
}
string strCode = "";//编号
if (billTable.Rows.Count > 0)
{
string oldCode = billTable.Rows[0][0].ToString();
if (oldCode.IndexOf(strCodePrefix) >= 0)
{
oldCode = oldCode.Substring(strCodePrefix.Length, oldCode.Length - strCodePrefix.Length);
if (oldCode.Length == CodeLength)
{
for (int i = 0; i < oldCode.Length; i++)
{
if (oldCode[i].ToString().IndexOf("0") == 0)
{
oldCode = oldCode.Remove(i, 1);
i = -1;
continue;
}
else
{
break;
}
}
}
}
int newNum = int.Parse(oldCode);
newNum = newNum + 1;
string strNewNum = newNum.ToString();
int codeArgCount = codeArg.Count - 1;
for (int i = strNewNum.Length - 1; i >= 0; i--)
{
codeArg[codeArgCount] = strNewNum[i];
codeArgCount--;
}
//for (int i = 0; i < strNewNum.Length; i++)
//{
// codeArg[i] = strNewNum[i];
//}
}
else
{
int iOld = int.Parse(codeArg[codeArg.Count - 1].ToString());
codeArg[codeArg.Count - 1] = (iOld + 1).ToString();
}
for (int i = 0; i < codeArg.Count; i++)
{
strCode += codeArg[i].ToString();
}
strSettleCode = strFeeType + strDateTime + strCode;
return strSettleCode;
}
public string UnicodeToGB(string text)
{
MatchCollection mc = Regex.Matches(text, "([\\w]+)|(\\\\u([\\w]{4}))");
if (mc != null && mc.Count > 0)
{
StringBuilder sb = new StringBuilder();
foreach (Match m2 in mc)
{
string v = m2.Value;
if (v.IndexOf("\\") >= 0)
{
string word = v.Substring(2);
byte[] codes = new byte[2];
int code = Convert.ToInt32(word.Substring(0, 2), 16);
int code2 = Convert.ToInt32(word.Substring(2), 16);
codes[0] = (byte)code2;
codes[1] = (byte)code;
sb.Append(Encoding.Unicode.GetString(codes));
}
else
{
sb.Append(v);
}
}
return sb.ToString();
}
else
{
return text;
}
}
#region 不同币别金额换算
/// <summary>
/// 不同币别金额换算
/// </summary>
/// <param name="tempOrigAmount">原币别金额</param>
/// <param name="tempRate">汇率</param>
/// <returns>返回折算后的金额</returns>
private decimal StatisticSettleAmount(decimal tempOrigAmount,decimal tempRate)
{
decimal result = 0;
result = decimal.Parse(C1Round((double.Parse((tempOrigAmount * tempRate).ToString())),2).ToString());
return result;
}
#endregion
#region 金额四舍五入
/// <summary>
/// 金额四舍五入
/// </summary>
/// <param name="value">金额值</param>
/// <param name="digit">小数点后位数</param>
/// <returns>返回Double型四舍五入金额</returns>
public double C1Round(double value, int digit)
{
double vt = Math.Pow(10, digit);
double vx = value * vt;
vx += 0.5;
return (Math.Floor(vx) / vt);
}
#endregion
private string GetSettleTypeName(int iSettleType)
{
string strResult = "";
switch (iSettleType)
{
case 1:
strResult = "现金";
break;
case 2:
strResult = "支票";
break;
case 3:
strResult = "电汇";
break;
case 4:
strResult = "转账";
break;
case 5:
strResult = "承兑汇票";
break;
}
return strResult;
}
}
}