using System;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.Collections;
using Cosmos.Win;
using Cosmos.BaseFrame;
using Cosmos.UserFrame;
using Cosmos.ServiceProvider;
using Cosmos.Common;
using Cosmos.CommonManager;
using System.IO;
using System.Diagnostics;
/*-----------------------------------------------------------------------------------------------*/
// 설 명 : 중국 알리페이/위챗페이
// 작 성 자 :
// 변경 이력 :
/*-----------------------------------------------------------------------------------------------*/
namespace Cosmos.Win
{
public partial class frmWeChatPay : frm_PayMainBack
{
#region 변수 선언
private SManager sManager = new SManager(); // 이 객체를 통해 업무 Service 호출
private StateServer StateObject = (StateServer)StateServer.GetInstance(); // StateObject : StateServer Object (객체)
private PosStatus m_cPosStatus = new PosStatus(); // 기본정보 참조
private TranStatus m_cTrnStatus = new TranStatus(); // 거래정보 참조
private DeviceStatus m_cDevStatus = new DeviceStatus(); // 디바이스 관리
private PosOLEDevice.DelegateOlePos delegatePos;
private IICReaderUs m_cDeviceICReader = null;
private ISignPadUs m_cDeviceSignPad = null;
private IDataProcessUs m_cDataService = null;
private IPaymentUs m_cWeChatPay = null;
private IDataCommonUs m_cDataCommon = null; // POS 공통함수 인터페이스
private bool bNotDoubleClik = false; // 더블 클릭 방지용
private string m_sPosMenuKey;
///
/// 제휴포인트 사용(OCB,OILBANK,BLUE MEMBER...)
///
public string SetPosMenuKey { set { this.m_sPosMenuKey = value; } }
///
/// 입력구분
///
private string m_sInPutType = "";
///
/// 입력데이터
///
private string m_sInPutData = "";
///
/// 카드데이터(암호화)
///
private string m_sInEncData = "";
///
/// 대상 금액
///
private double m_nDestAmt = 0;
///
/// 알리페이/위챗페이 접속 port
///
private string m_sPort = "";
#endregion 변수 선언
#region 생성자 & 소멸자 & 폼초기화
public frmWeChatPay()
{
InitializeComponent();
base.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw, true);
//this.UpdateStyles();
m_cPosStatus = (PosStatus)StateObject.POS; // POS 기본정보
m_cTrnStatus = (TranStatus)StateObject.TRAN; // POS 거래정보
m_cDevStatus = (DeviceStatus)StateObject.DEVICE;
m_cDeviceICReader = (IICReaderUs)sManager.InitServiceInstance(ServiceLists.AGENT_OLEDEVICE.DLL, ServiceLists.AGENT_OLEDEVICE.DEVICE_ICREADER);
m_cDeviceSignPad = (ISignPadUs)sManager.InitServiceInstance(ServiceLists.AGENT_OLEDEVICE.DLL, ServiceLists.AGENT_OLEDEVICE.DEVICE_SIGNPAD);
m_cDataService = (IDataProcessUs)sManager.InitServiceInstance(ServiceLists.ASV_DATA_PROCESS.DLL, ServiceLists.ASV_DATA_PROCESS.DATA_SERVICE);
m_cWeChatPay = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.WECHATPAY);
m_cDataCommon = (IDataCommonUs)sManager.InitServiceInstance(ServiceLists.ASV_DATA_PROCESS.DLL, ServiceLists.ASV_DATA_PROCESS.DATA_COMMON);
delegatePos = new PosOLEDevice.DelegateOlePos(OnDeviceEvent);
}
private void frmWeChatPay_Load(object sender, EventArgs e)
{
UserLog.WriteLogFile(UserCom.LOG_IOS, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", "");
InitControl();
}
private void frmWeChatPay_Activated(object sender, EventArgs e)
{
PosOLEDevice.SetEventHandle(delegatePos);
}
private void frmWeChatPay_Deactivate(object sender, EventArgs e)
{
PosOLEDevice.SetEventHandle(null);
}
private void frmWeChatPay_FormClosing(object sender, FormClosingEventArgs e)
{
//LS_ApprDeamon(true);
UserLog.WriteLogFile(UserCom.LOG_IOS, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", lblTitle.Text);
}
///
/// 폼 컨트롤 초기화
///
private void InitControl()
{
try
{
// 이미지 로딩 처리
//picBack.Image = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.POP_SIZE_S);
//this.Size = new Size(788, 402);
//this.Location = new Point(216, 173);
//picBack.Image = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.POP_SIZE_S);
this.Location = new Point(0, 50);
this.Size = new Size(1024, 525);
//this.BackColor = Color.FromArgb(114, 114, 114);
FormManager.SetFormAllControlFont(this, m_cPosStatus.Base.FONT);
FormManager.SetTextBoxGlobalInfo(this, m_cPosStatus.Global.m_stCultureMaster.nGroupingDigits, m_cPosStatus.Global.m_stCultureMaster.strGroupingSymbol
, m_cPosStatus.Global.m_stCultureMaster.nDecimalDigits, m_cPosStatus.Global.m_stCultureMaster.strDecimalSymbol);
btnExit.Image = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.BTN_CLOSE);
if (btnExit.Image != null) btnExit.Text = "";
IDataCommonUs m_cDataCommon = (IDataCommonUs)sManager.InitServiceInstance(ServiceLists.ASV_DATA_PROCESS.DLL, ServiceLists.ASV_DATA_PROCESS.DATA_COMMON);
InitPayMainBack(m_cPosStatus, m_cDataCommon, m_sPosMenuKey, PosConst.MOT_MSG_TYPE.PAY_STEP_3, "");
//테마색상 적용!
btnEnter.BackColor = CmUtil.GetColorToString(m_cPosStatus.ScnMst.ThemeColor);
if (m_sPosMenuKey == PosKey.MENU_KEY.WECHATPAY) lblTitle.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0971);
lblCardNo.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0173);
lblCardNM.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0196);
lblUsePoint.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0127);
btnEnter.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0057);
txtCardNo.Text = "";
txtCardNM.Text = "";
txtUsePoint.Text = "0";
txtUsePoint.Text = m_cPosStatus.Global.NumericTOCurrency(m_cTrnStatus.Sale.RemainPayAmt); // 받을금액
WeChatPayApprDeamon(false); // 승인 데몬 기동
m_sInPutType = ""; // 입력구분
m_sInPutData = ""; // 입력데이터
m_sInEncData = ""; // 카드데이터
bNotDoubleClik = false;
// 기능 버튼 설정 체크
FormManager.SetbtnMenu(txtCardNo, false, btnMenu1, btnMenu2, btnMenu3, btnMenu4);
txtCardNo.ReadOnly = false;
txtCardNo.Select();
}
catch (Exception ex)
{
WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
}
}
#endregion
#region 버튼 입력 처리
///
/// 버튼 입력 처리
///
///
///
private void btnProc_Click(object sender, EventArgs e)
{
try
{
if (bNotDoubleClik) return;
bNotDoubleClik = true;
if (((Cosmos.UI.CsmButton)sender) == btnEnter) // 승인
{
CompleteTxtInPut();
}
padInPut.SetActiveFocus();
}
catch (Exception ex)
{
WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
bNotDoubleClik = false;
}
bNotDoubleClik = false ;
}
///
/// 닫기
///
///
///
private void btnExit_Click(object sender, EventArgs e)
{
try
{
txtEditBox_EditBoxKeyDownEvent(null, PosKey.MENU_KEY.ESC_PREVIOUS);
}
catch (Exception ex)
{
WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
}
}
#endregion
#region 텍스트박스 키 입력 이벤트 처리
///
/// 텍스트박스 키 입력 이벤트 처리
///
///
///
private void txtEditBox_EditBoxKeyDownEvent(object sender, string sFuncValue)
{
try
{
if (sFuncValue == PosKey.MENU_KEY.ENTER)
{
if (((Cosmos.UI.CsmPosEditBox)sender) == txtCardNo)
{
if (CheckTxtInPut(sender) == false) return;
// 바코드 리딩 후 결제금액으로 포커스 이동하지 않도록 수정(이태훈J 요청, 2017.07.25)
//txtUsePoint.Focus();
}
if (((Cosmos.UI.CsmPosEditBox)sender) == txtUsePoint)
{
if (CheckTxtInPut(sender) == false) return;
CompleteTxtInPut(); // 승인 처리
}
}
else if (sFuncValue == PosKey.MENU_KEY.CLEAR)
{
if (((Cosmos.UI.CsmPosEditBox)sender).ReadOnly == false) ((Cosmos.UI.CsmPosEditBox)sender).Text = "";
if (((Cosmos.UI.CsmPosEditBox)sender) == txtCardNo)
{
m_sInPutType = "";
m_sInPutData = "";
m_sInEncData = "";
txtCardNo.ReadOnly = false;
}
}
else if (sFuncValue == PosKey.MENU_KEY.ESC_PREVIOUS)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
}
catch (Exception ex)
{
WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
}
}
///
/// 텍스트박스 활성화 처리
///
///
///
private void txtEditBox_EnterEvent(object sender, EventArgs e)
{
try
{
padInPut.SetActiveControl = (Control)sender;
}
catch (Exception ex)
{
WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
}
}
#endregion
#region 텍스트박스 입력 유효성 체크
///
/// 텍스트박스 입력 유효성 체크
///
///
///
private bool CheckTxtInPut(object sender)
{
try
{
// 카드번호 길이 체크
if (sender == null || ((Cosmos.UI.CsmPosEditBox)sender) == txtCardNo)
{
string sCardNo = m_cDataCommon.MSR_CardNoCheck(txtCardNo.Value, "", ref m_sInPutData);
txtCardNo.Value = sCardNo;
if (m_cPosStatus.Base.CmpCd.ToUpper().Equals("PCCN"))
{
UserLog.WriteLogFile(UserCom.LOG_OP, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", "@@WeChatPay CardNo=" + txtCardNo.Value);
}
// 위챗페이 최소18, 최대18
if (CmUtil.MidH(txtCardNo.Value, 0, 2) == "13")
{
if (txtCardNo.Value.Length != 18)
{
WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0037);
txtCardNo.Focus();
return false;
}
txtCardNM.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0971);
}
// Rhee, 20171113, 알리페이 지불코드 양식변경 Start
// 기존
// 알리페이 최소17, 최대18
//else if (CmUtil.MidH(txtCardNo.Value, 0, 2) == "28")
//{
// if (txtCardNo.Value.Length < 17)
// {
// WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0037);
// txtCardNo.Focus();
// return false;
// }
// txtCardNM.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0172);
//}
// 변경
else if ((CmUtil.MidH(txtCardNo.Value, 0, 2) == "25") || (CmUtil.MidH(txtCardNo.Value, 0, 2) == "26") || (CmUtil.MidH(txtCardNo.Value, 0, 2) == "27")
|| (CmUtil.MidH(txtCardNo.Value, 0, 2) == "28") || (CmUtil.MidH(txtCardNo.Value, 0, 2) == "29") || (CmUtil.MidH(txtCardNo.Value, 0, 2) == "30"))
{
// 알리페이 최소16, 최대24
if (txtCardNo.Value.Length < 16 || txtCardNo.Value.Length > 24)
{
WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0037);
txtCardNo.Focus();
return false;
}
txtCardNM.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0172);
}
// Rhee, 20171113, 알리페이 지불코드 양식변경 End
// #Rhee, 20170922 중국 은련페이 추가 start
// 은련페이 최소18, 최대19
else if (CmUtil.MidH(txtCardNo.Value, 0, 2) == "62")
{
if (txtCardNo.Value.Length < 18)
{
WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0037);
txtCardNo.Focus();
return false;
}
txtCardNM.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_1037);
}
// #Rhee, 20170922 중국 은련페이 추가 end
else
{
WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0037);
txtCardNo.Focus();
return false;
}
if (txtCardNM.Text.Trim() != "") lblTitle.Text = txtCardNM.Text;
txtCardNM.Update();
}
// 사용포인트 체크
if (sender == null || ((Cosmos.UI.CsmPosEditBox)sender) == txtUsePoint)
{
if (txtUsePoint.Value.Length > 10 || m_cDataService.DoubleParse(txtUsePoint.Value) == 0)
{
WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0036);
txtUsePoint.Focus();
return false;
}
if (CmUtil.AmountCut(m_cDataService.DoubleParse(txtUsePoint.Text), CmUtil.IntParse(m_cPosStatus.Mst.PayRudDwLoc)) != m_cDataService.DoubleParse(txtUsePoint.Text))
{
WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0036);
txtUsePoint.Focus();
return false;
}
if (m_cTrnStatus.Sale.RemainPayAmt < m_cDataService.DoubleParse(txtUsePoint.Value))
{
WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0036);
txtUsePoint.Focus();
return false;
}
}
//// 승인 데몬 체크
//if (LS_ApprDeamon(false) != UserCom.RST_OK)
//{
// WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0608);
// return false;
//}
}
catch (Exception ex)
{
WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
return false;
}
return true;
}
#endregion
#region 입력 완료 처리
///
/// 포인트 사용 승인 처리
///
///
///
private bool CompleteTxtInPut()
{
string sRet = UserCom.RST_ERR;
try
{
if (CheckTxtInPut(null) == false) return false;
string sInPutType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_BARCODE;
string sInPutData = txtCardNo.Value;
// 승인 처리
sRet = m_cWeChatPay.SetPayment(new string[] { m_sPosMenuKey, sInPutType, txtCardNo.Text, sInPutData, m_cDataService.DoubleParse(txtUsePoint.Value).ToString(), "" });
if (sRet != UserCom.RST_OK) return false;
this.DialogResult = DialogResult.OK;
this.Close();
return true;
}
catch (Exception ex)
{
WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
}
return false;
}
///
/// 포인트 조회 처리
///
///
private bool SearchTxtInPut()
{
string sRet = UserCom.RST_ERR;
try
{
}
catch (Exception ex)
{
WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
}
return false;
}
#endregion
#region DeviceEvent 관련
///
/// DeviceEvent 관련
///
///
///
///
///
public void OnDeviceEvent(string sDevice, string sData1, string sData2, string sData3)
{
try
{
switch (sDevice)
{
case PosConst.OPOS_DEVICE.MSR:
this.Invoke(new EventHandler(OnMSREvent));
break;
case PosConst.OPOS_DEVICE.SCANNER:
this.Invoke(new EventHandler(OnScannerEvent));
break;
}
}
catch (Exception ex)
{
WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
}
}
///
/// MSR Event
///
///
///
private void OnMSREvent(object source, EventArgs e)
{
try
{
string sMsrData = m_cDevStatus.Msr.Track2Data;
if (sMsrData.Length > 0 && m_sInPutData == "")
{
m_sInPutType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_SWIP;
m_sInPutData = sMsrData;
txtCardNo.Text = m_sInPutData;
//txtCardNo.ReadOnly = true;
if (m_cTrnStatus.Head.TradeDiv == ItemConst.TRAN_DIV.NORMAL) SearchTxtInPut();
}
}
catch (Exception ex)
{
WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
}
}
///
/// 스캐너 이벤트 처리
///
///
///
private void OnScannerEvent(object source, EventArgs e)
{
try
{
string sScanData = m_cDevStatus.Scanner.DataLabel;
if (sScanData.Length > 0 && m_sInPutData == "")
{
m_sInPutType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_BARCODE;
m_sInPutData = sScanData;
txtCardNo.Text = m_sInPutData;
//txtCardNo.ReadOnly = true;
if (m_cTrnStatus.Head.TradeDiv == ItemConst.TRAN_DIV.NORMAL) SearchTxtInPut();
}
}
catch (Exception ex)
{
WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
}
}
#endregion
private void lblCardNo_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
}
}
private void txtCardNo_EditBoxTextChangedEvnet(object sender, EventArgs e)
{
txtCardNM.Text = "";
}
#region 중국 알리페이/위챗페이 승인 데몬 기동 및 중지
///
/// 중국 알리페이/위챗페이 승인 데몬 기동 및 중지
///
///
///
private string WeChatPayApprDeamon(bool bClose)
{
string sRet = UserCom.RST_ERR;
Process[] arPgm = null;
try
{
// 중국
if (m_cPosStatus.Mst.CntryDiv != ItemConst.CNTRY_DIV.CN) return UserCom.RST_OK;
if (bClose == true)
{
// 승인 데몬 종료
arPgm = Process.GetProcessesByName("fmclient");
foreach (Process pPgm in arPgm)
{
pPgm.Kill();
}
}
else
{
// 승인 데몬 조회
arPgm = Process.GetProcessesByName("fmclient");
foreach (Process pPgm in arPgm)
{
return UserCom.RST_OK;
}
// 승인 데몬 실행
ProcessStartInfo startInfo = new ProcessStartInfo(Directory.GetCurrentDirectory().ToString() + @"\fmclient.exe");
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.CreateNoWindow = false;
Process.Start(startInfo);
}
return UserCom.RST_OK;
}
catch (Exception ex)
{
WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
}
return sRet;
}
#endregion
}
}