149 lines
6.2 KiB
C#
149 lines
6.2 KiB
C#
using System;
|
|
using System.Configuration;
|
|
using System.ComponentModel;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Net;
|
|
using System.Net.NetworkInformation;
|
|
using System.Net.Sockets;
|
|
using System.Windows.Forms;
|
|
using SocketTransfer.SDK;
|
|
|
|
#if DEBUG
|
|
using System.IO;
|
|
#endif
|
|
|
|
namespace SocketTransfer
|
|
{
|
|
public partial class Receiver : Form
|
|
{
|
|
protected string _connectstring = ConfigurationManager.AppSettings["connectstring"].ToString();
|
|
|
|
public Receiver()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
bool isStart = false;
|
|
private void BtnListen_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (!isStart)
|
|
{
|
|
socketor1.Start(new IPEndPoint(IPAddress.Parse(textBoxIP.Text), int.Parse(textBoxPort.Text)));
|
|
BtnListen.Text = "停止";
|
|
isStart = true;
|
|
return;
|
|
}
|
|
|
|
if (isStart)
|
|
{
|
|
socketor1.Stop();
|
|
BtnListen.Text = "监听";
|
|
isStart = false;
|
|
return;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message);
|
|
}
|
|
}
|
|
|
|
private void Receiver_Load(object sender, EventArgs e)
|
|
{
|
|
string strIPAddress = string.Empty;
|
|
IPAddress[] arrIPAddresses = System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName());
|
|
foreach (IPAddress _IPAddress in arrIPAddresses)
|
|
{
|
|
if (!_IPAddress.AddressFamily.Equals(AddressFamily.InterNetwork))
|
|
continue;
|
|
strIPAddress = _IPAddress.ToString();
|
|
break;
|
|
}
|
|
if (!string.IsNullOrEmpty(strIPAddress))
|
|
textBoxIP.Text = strIPAddress;
|
|
else
|
|
textBoxIP.Text = "127.0.0.1";
|
|
textBoxPort.Text = "6060";
|
|
|
|
BtnListen_Click(BtnListen, e);
|
|
}
|
|
|
|
private void socketor1_Receive(object sender, SocketEventArgs e)
|
|
{
|
|
SocketReceive _SocketReceive = new SocketReceive(e.Buffer);
|
|
_SocketReceive.ResetSize();
|
|
#if DEBUG
|
|
string dir = Application.StartupPath + "//Log";
|
|
string fil = dir + "//Listen" + DateTime.Now.ToString("yyyyMMdd") + ".log";
|
|
if (!Directory.Exists(dir))
|
|
{
|
|
System.IO.Directory.CreateDirectory(dir);
|
|
}
|
|
FileStream filestream = new FileStream(fil, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
|
|
StreamWriter writer = new StreamWriter(filestream, System.Text.Encoding.Default);
|
|
writer.BaseStream.Seek(0, SeekOrigin.End);
|
|
writer.WriteLine("{0}", _SocketReceive.Encoding.GetString(_SocketReceive.Source).Trim('\0'));
|
|
writer.Flush();
|
|
writer.Close();
|
|
filestream.Close();
|
|
#endif
|
|
EndAccountReceive _EndAccountReceive = new EndAccountReceive(e.Buffer);
|
|
propertyGrid1.SelectedObject = _EndAccountReceive;
|
|
e.Feedback = EventsCommodity.DoEvent(e.Buffer);
|
|
EndAccountSend _EndAccountSend = new EndAccountSend(e.Feedback);
|
|
propertyGrid2.SelectedObject = _EndAccountSend;
|
|
InsertEndAccount(_EndAccountReceive, _EndAccountSend);
|
|
}
|
|
|
|
private void InsertEndAccount(EndAccountReceive _EndAccountReceive, EndAccountSend _EndAccountSend)
|
|
{
|
|
OracleHelper _OracleHelper = new OracleHelper();
|
|
_OracleHelper.ConnString = _connectstring;
|
|
try
|
|
{
|
|
if (_OracleHelper.ExcuteSqlGetDataSet("SELECT 1 FROM HIGHWAY_EXCHANGE.T_ENDACCOUNT WHERE SERVERPARTCODE = '" +
|
|
_EndAccountSend.SERVERPARTCODE + "' AND SHOPCODE = '" + _EndAccountSend.SHOPCODE + "' AND MACHINECODE = '" +
|
|
_EndAccountSend.MACHINECODE + "' AND ENDACCOUNT_STARTDATE = TO_DATE('" + _EndAccountSend.ENDACCOUNT_STARTDATE +
|
|
"','YYYY/MM/DD HH24:MI:SS') AND ENDACCOUNT_DATE = TO_DATE('" + _EndAccountSend.ENDACCOUNT_DATE +
|
|
"','YYYY/MM/DD HH24:MI:SS')", "T_ENDACCOUNT").Tables[0].Rows.Count == 0)
|
|
{
|
|
try
|
|
{
|
|
_OracleHelper.ExcuteSql(@"INSERT INTO HIGHWAY_EXCHANGE.T_ENDACCOUNT (
|
|
ENDACCOUNT_ID,ENDACCOUNT_STARTDATE,ENDACCOUNT_DATE,SERVERPARTCODE,SHOPCODE,MACHINECODE,
|
|
ENDPERSONCODE,TICKETCOUNT,TOTALCOUNT,TOTALSELLAMOUNT,TOTALOFFAMOUNT,CASH,CREDITCARD,
|
|
TICKETBILL,VIPPERSON,COSTBILL,OTHERPAY,CASHPAY,FLAG)
|
|
VALUES (" + _EndAccountReceive.ENDACCOUNT_ID + ",TO_DATE('" + _EndAccountReceive.ENDACCOUNT_STARTDATE +
|
|
"','YYYY/MM/DD HH24:MI:SS'),TO_DATE('" + _EndAccountReceive.ENDACCOUNT_DATE +
|
|
"','YYYY/MM/DD HH24:MI:SS'),'" + _EndAccountReceive.SERVERPARTCODE + "','" +
|
|
_EndAccountReceive.SHOPCODE + "','" + _EndAccountReceive.MACHINECODE + "','" +
|
|
_EndAccountReceive.ENDPERSONCODE + "'," + _EndAccountReceive.TICKETCOUNT + "," +
|
|
_EndAccountReceive.TOTALCOUNT + "," + _EndAccountReceive.TOTALSELLAMOUNT + "," +
|
|
_EndAccountReceive.TOTALOFFAMOUNT + "," + _EndAccountReceive.CASH + "," +
|
|
_EndAccountReceive.CREDITCARD + "," + _EndAccountReceive.TICKETBILL + "," +
|
|
_EndAccountReceive.VIPPERSON + "," + _EndAccountReceive.COSTBILL + "," +
|
|
_EndAccountReceive.OTHERPAY + "," + _EndAccountReceive.CASHPAY + "," + _EndAccountReceive.FLAG + ")");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.WriteReceiveLog(ex.Message);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.WriteReceiveLog(ex.Message);
|
|
}
|
|
}
|
|
}
|
|
}
|