2025-03-27 15:05:14 +08:00

401 lines
20 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI;
using SuperMap.RealEstate.Web.UI;
using SuperMap.RealEstate.Web.UI.WebControls;
using SuperMap.RealEstate.Web.Utility;
using SuperMap.RealEstate.CoreFrameWork;
using CMB = SuperMap.RealEstate.Coop.Merchant.Business;
using MSPB = SuperMap.RealEstate.MobileServicePlatform.Business;
using Newtonsoft.Json;
using HZQR.Common;
using ZXing.Common;
using ZXing.QrCode;
using ZXing;
namespace SuperMap.RealEstate.ExchangeData
{
/// <summary>
/// T_MACHINECONFIGURATION_机器参数配置表 的WebUserControl
/// <summary>
public partial class MACHINECONFIGURATION : UserControl<Business.MACHINECONFIGURATION>
{
EncodingOptions options = null;
BarcodeWriter writer = null;
#region ->
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack) return;
//绑定服务区、门店数据
SERVERPART_CODE.Clear();
SHOPCODE.Clear();
if (!string.IsNullOrWhiteSpace(Request["MACHINEUSEAG_ID"]))
{
Business.MACHINEUSEAG _MACHINEUSEAG = new Business.MACHINEUSEAG(Transaction);
_MACHINEUSEAG.MACHINEUSEAG_ID_Encrypt = Request["MACHINEUSEAG_ID"];
if (_MACHINEUSEAG.Select())
{
if (_MACHINEUSEAG.OWNERUNIT_ID != null)
{
OWNERUNIT_ID.SelectedValue = _MACHINEUSEAG.OWNERUNIT_ID.ToString();
//绑定服务区
foreach (MSPB.OWNERSERVERPART _OWNERSERVERPART in new MSPB.OWNERSERVERPART(Transaction).FillCollection(
"WHERE OWNERUNIT_ID = " + OWNERUNIT_ID.SelectedValue + " ORDER BY SERVERPART_CODE"))
{
ListItemEx listItemEx = new ListItemEx();
listItemEx.Text = _OWNERSERVERPART.SERVERPART_NAME;
listItemEx.Value = _OWNERSERVERPART.SERVERPART_CODE;
SERVERPART_CODE.Items.Add(listItemEx);
if (_OWNERSERVERPART.SERVERPART_CODE == _MACHINEUSEAG.SERVERPARTCODE)
{
SERVERPART_CODE.SelectedValue = _MACHINEUSEAG.SERVERPARTCODE;
//绑定门店
foreach (MSPB.SERVERPARTSHOP _SERVERPARTSHOP in new MSPB.SERVERPARTSHOP(Transaction).FillCollection(
"WHERE SHOPCODE IS NOT NULL AND ISVALID = 1 AND SHOPTRADE NOT IN ('9032','9999') AND PROVINCE_CODE = " +
_OWNERSERVERPART.PROVINCE_BUSINESSCODE + " AND SERVERPART_ID = " + _OWNERSERVERPART.SERVERPART_ID +
" ORDER BY SHOPREGION,SHOPTRADE,SHOPCODE"))
{
ListItemEx listItemExShop = new ListItemEx();
listItemExShop.Text = _SERVERPARTSHOP.SHOPNAME;
listItemExShop.Value = _SERVERPARTSHOP.SHOPCODE;
SHOPCODE.Items.Add(listItemExShop);
}
if (!string.IsNullOrWhiteSpace(_MACHINEUSEAG.SHOPCODE))
{
SHOPCODE.SelectedValue = _MACHINEUSEAG.SHOPCODE;
}
}
}
}
MACHINECODE.Text = _MACHINEUSEAG.MACHINECODE;
MACHINEBASEINFO_ID.Text = _MACHINEUSEAG.MACHINEBASEINFO_ID.ToString();
EXPIRY_DATE.Text = _MACHINEUSEAG.EXPIRY_DATE.TryParseToString();
//初始化并加载列表
GridViewEx1.SelectingWithInit<CMB.BUSINESSSHOPCODE>(ObjectDataSource1, GridPageEx1,
DictionaryHelper.GetDictionary(Transaction, "MOBILEPAYOPERATORS").AsNewKeys("PAYMENT_CHANNEL"));
//工具条按钮事件
GridViewEx1.SetOpenControl(ButtonNew, "BUSINESSSHOPCODEPage.aspx?SERVERPARTCODE=" +
_MACHINEUSEAG.SERVERPARTCODE.ToEncrypt() + "&SHOPCODE=" + _MACHINEUSEAG.SHOPCODE.ToEncrypt());
}
}
if (!string.IsNullOrEmpty(Request["MACHINE_MACADDRESS"]))
{
MACHINE_MACADDRESS.Text = Request["MACHINE_MACADDRESS"].ToDecrypt();
foreach (Business.MACHINECONFIGURATION _MACHINECONFIGURATION in new Business.MACHINECONFIGURATION(Transaction).FillCollection(
"WHERE MACHINE_MACADDRESS = '" + Request["MACHINE_MACADDRESS"].ToDecrypt() + "'"))
{
if (FindControl(_MACHINECONFIGURATION.CONFIGURATION_NAME) is TextBoxEx)
{
TextBoxEx textBoxEx = FindControl(_MACHINECONFIGURATION.CONFIGURATION_NAME) as TextBoxEx;
textBoxEx.Text = _MACHINECONFIGURATION.CONFIGURATION_VALUES;
}
else if (FindControl(_MACHINECONFIGURATION.CONFIGURATION_NAME) is DropDownListEx)
{
DropDownListEx dropDownListEx = FindControl(_MACHINECONFIGURATION.CONFIGURATION_NAME) as DropDownListEx;
dropDownListEx.SelectedValue = _MACHINECONFIGURATION.CONFIGURATION_VALUES;
}
}
}
//获取移动支付服务商、主支付通道端口、数据传输端口
if (!string.IsNullOrWhiteSpace(MACHINE_MACADDRESS.Text))
{
DataTable dtConfig = new Business.MACHINECONFIGURATION(Transaction).FillDataTable(
"WHERE MACHINE_MACADDRESS = '" + MACHINE_MACADDRESS.Text + "'");
if (dtConfig.Rows.Count > 0)
{
//服务器IP
if (dtConfig.Select("CONFIGURATION_NAME = 'server_ip'").Length > 0)
{
DataRow drConfig = dtConfig.Select("CONFIGURATION_NAME = 'server_ip'")[0];
MobilePayOperators.SelectedValue = drConfig["CONFIGURATION_VALUES"].ToString();
}
//移动支付服务商
if (dtConfig.Select("CONFIGURATION_NAME = 'MobilePayOperators'").Length > 0)
{
DataRow drConfig = dtConfig.Select("CONFIGURATION_NAME = 'MobilePayOperators'")[0];
MobilePayOperators.SelectedValue = drConfig["CONFIGURATION_VALUES"].ToString();
}
//主支付通道端口
if (dtConfig.Select("CONFIGURATION_NAME = 'service_port'").Length > 0)
{
ServicePort.Text = dtConfig.Select("CONFIGURATION_NAME = 'service_port'")[0]["CONFIGURATION_VALUES"].ToString();
}
//数据传输端口
if (dtConfig.Select("CONFIGURATION_NAME = 'DataServicePort'").Length > 0)
{
DataServicePort.Text = dtConfig.Select("CONFIGURATION_NAME = 'DataServicePort'")[0]["CONFIGURATION_VALUES"].ToString();
}
}
}
//生成随机数
CheckCode.Text = Utils.StringAppend("", true, 1, 4, false, 0, 0);
}
#endregion
#region -> (Page_Load之前)DropDownList的数据源绑定等
public override void InitializeWebControl()
{
//绑定业主单位
OWNERUNIT_ID.Clear();
CMB.OWNERUNIT.BindingOwnerUnitDDL(Transaction, OWNERUNIT_ID.Items, 0);
//绑定移动支付服务商
MobilePayOperators.Items.Clear();
DictionaryHelper.BindingDropDownList("MOBILEPAYOPERATORS", MobilePayOperators.Items, Transaction);
}
#endregion
#region ->
public override bool LoadData()
{
//如果是工作流组件请自行修改载入的逻辑,以下是功能模块的默认代码
if (!String.IsNullOrEmpty(Request["ID"]))
{
CurrObject.MACHINECONFIGURATION_ID_Encrypt = Request["ID"];
return this.Select();
}
//默认返回值工作流组件返回True,功能模块返回False。
return (WorkFlowPage != null);
}
#endregion
#region ->
protected void OWNERUNIT_ID_CallBackSetControl(object sender, ClientSetEventArgs e)
{
SHOPCODE.Clear();
SERVERPART_CODE.Clear();
foreach (MSPB.OWNERSERVERPART _OWNERSERVERPART in new MSPB.OWNERSERVERPART(Transaction).FillCollection(
"WHERE OWNERUNIT_ID = " + e.Argument + " ORDER BY SERVERPART_CODE"))
{
ListItemEx listItemEx = new ListItemEx();
listItemEx.Text = _OWNERSERVERPART.SERVERPART_NAME;
listItemEx.Value = _OWNERSERVERPART.SERVERPART_CODE;
SERVERPART_CODE.Items.Add(listItemEx);
if (!string.IsNullOrWhiteSpace(SERVERPART_CODE.SelectedValue))
{
foreach (MSPB.SERVERPARTSHOP _SERVERPARTSHOP in new MSPB.SERVERPARTSHOP(Transaction).FillCollection(
"WHERE SHOPCODE IS NOT NULL AND ISVALID = 1 AND SHOPTRADE NOT IN ('9032','9999') AND PROVINCE_CODE = " +
_OWNERSERVERPART.PROVINCE_CODE + " AND SERVERPART_ID = " + _OWNERSERVERPART.SERVERPART_ID +
" ORDER BY SHOPREGION,SHOPTRADE,SHOPCODE"))
{
ListItemEx listItemExShop = new ListItemEx();
listItemExShop.Text = _SERVERPARTSHOP.SHOPNAME;
listItemExShop.Value = _SERVERPARTSHOP.SHOPCODE;
SHOPCODE.Items.Add(listItemExShop);
}
}
}
e.SetDropDownListEx(SERVERPART_CODE);
e.SetDropDownListEx(SHOPCODE);
}
#endregion
#region ->
protected void SERVERPARTCODE_CallBackSetControl(object sender, ClientSetEventArgs e)
{
SHOPCODE.Clear();
MSPB.OWNERSERVERPART _OWNERSERVERPART = new MSPB.OWNERSERVERPART(Transaction);
_OWNERSERVERPART.AddSearchParameter("OWNERUNIT_ID", OWNERUNIT_ID.SelectedValue);
_OWNERSERVERPART.AddSearchParameter("SERVERPART_CODE", e.Argument);
if (_OWNERSERVERPART.Search())
{
foreach (MSPB.SERVERPARTSHOP _SERVERPARTSHOP in new MSPB.SERVERPARTSHOP(Transaction).FillCollection(
"WHERE SHOPCODE IS NOT NULL AND ISVALID = 1 AND SHOPTRADE NOT IN ('9032','9999') AND PROVINCE_CODE = " +
_OWNERSERVERPART.PROVINCE_BUSINESSCODE + " AND SERVERPART_ID = " + _OWNERSERVERPART.SERVERPART_ID +
" ORDER BY SHOPREGION,SHOPTRADE,SHOPCODE"))
{
ListItemEx listItemExShop = new ListItemEx();
listItemExShop.Text = _SERVERPARTSHOP.SHOPNAME;
listItemExShop.Value = _SERVERPARTSHOP.SHOPCODE;
SHOPCODE.Items.Add(listItemExShop);
}
}
e.SetDropDownListEx(SHOPCODE);
}
#endregion
#region ->
//查询
protected void ButtonSearch_CallBackClick(object sender, ClientSetEventArgs e)
{
GridViewEx1.Selecting<CMB.BUSINESSSHOPCODE>(ObjectDataSource1, GridPageEx1);
//设置UI变化
e.SetValue(GridViewEx1);
e.SetValue(GridPageEx1);
}
//翻页事件
protected void GridPageEx1_CallBackPageChanged(object src, ClientSetEventArgs e)
{
GridViewEx1.Pagging<CMB.BUSINESSSHOPCODE>(ObjectDataSource1, GridPageEx1);
//设置UI变化
e.SetValue(GridViewEx1);
}
//查询SQL设置
protected void GridViewEx1_SelectMethodParameters(object sender, SelectMethodParametersArgs e)
{
//查询服务区编码
if (!string.IsNullOrWhiteSpace(Request["SERVERPARTCODE"]))
{
e.AddAndParams("SERVERPART_CODE", Request["SERVERPARTCODE"].ToDecrypt());
}
//查询门店编码
if (!string.IsNullOrWhiteSpace(Request["SHOPCODE"]))
{
e.AddAndParams("SERVERPARTSHOP_CODE", Request["SHOPCODE"].ToDecrypt());
}
else
{
e.AddAndParams("1", 2);
}
//排序
e.AddOrderByParams("OPERATE_DATE", true);
}
#endregion
#region ->
protected void BuildQCode_Click(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(SERVERPART_CODE.SelectedValue) || string.IsNullOrWhiteSpace(SHOPCODE.SelectedValue) ||
string.IsNullOrWhiteSpace(MobilePayOperators.SelectedValue) || string.IsNullOrWhiteSpace(server_ip.Text) ||
string.IsNullOrWhiteSpace(ServicePort.Text) || string.IsNullOrWhiteSpace(DataServicePort.Text))
{
Page.Alert("请填写服务区、门店、移动支付服务商、主支付通道端口、数据传输端口、服务器IP再点击生成二维码");
return;
}
Models.ConfigurationModel _ConfigurationModel = new Models.ConfigurationModel();
_ConfigurationModel.ServerpartCode = SERVERPART_CODE.SelectedValue;
_ConfigurationModel.ServerpartName = HttpUtility.UrlEncode(SERVERPART_CODE.SelectedItem.Text);
_ConfigurationModel.ShopCode = SHOPCODE.SelectedValue;
_ConfigurationModel.ShopName = HttpUtility.UrlEncode(SHOPCODE.SelectedItem.Text);
_ConfigurationModel.MobilePayOperators = MobilePayOperators.SelectedValue;
_ConfigurationModel.MachineCode = MACHINECODE.Text;
_ConfigurationModel.ServerIP = server_ip.Text;
_ConfigurationModel.ServicePort = ServicePort.Text;
_ConfigurationModel.DataServicePort = DataServicePort.Text;
_ConfigurationModel.ExpiryDate = EXPIRY_DATE.Text;
_ConfigurationModel.CheckCode = CheckCode.Text;
QrUrl.Text = JsonConvert.SerializeObject(_ConfigurationModel);
LoadImage(QrUrl.Text);
}
private void LoadImage(string Url)
{
options = new QrCodeEncodingOptions
{
DisableECI = true,
CharacterSet = "UTF-8",
Width = 200,
Height = 200
};
writer = new BarcodeWriter();
writer.Format = BarcodeFormat.QR_CODE;
writer.Options = options;
Bitmap bitmap = writer.Write(Url);
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
string base64 = Convert.ToBase64String(ms.ToArray());
ImgQr.ImageUrl = "data:image/png;base64," + base64;
}
}
#endregion
#region ->
public void SaveMachineConfig()
{
using (Business.MACHINECONFIGURATION _MACHINECONFIGURATION = new Business.MACHINECONFIGURATION(Transaction))
{
//移动支付服务商
if (!string.IsNullOrWhiteSpace(MobilePayOperators.SelectedValue))
{
_MACHINECONFIGURATION.ResetProperty();
SaveConfigurationModel(_MACHINECONFIGURATION, "MobilePayOperators", MobilePayOperators.SelectedValue);
}
//主支付通道端口
if (!string.IsNullOrWhiteSpace(ServicePort.Text))
{
_MACHINECONFIGURATION.ResetProperty();
SaveConfigurationModel(_MACHINECONFIGURATION, "ServicePort", ServicePort.Text);
}
//数据传输端口
if (!string.IsNullOrWhiteSpace(DataServicePort.Text))
{
_MACHINECONFIGURATION.ResetProperty();
SaveConfigurationModel(_MACHINECONFIGURATION, "DataServicePort", DataServicePort.Text);
}
//服务器ip
if (!string.IsNullOrWhiteSpace(server_ip.Text))
{
_MACHINECONFIGURATION.ResetProperty();
SaveConfigurationModel(_MACHINECONFIGURATION, "server_ip", server_ip.Text);
}
//软件有效期
if (!string.IsNullOrWhiteSpace(server_ip.Text))
{
_MACHINECONFIGURATION.ResetProperty();
SaveConfigurationModel(_MACHINECONFIGURATION, "expirydate", EXPIRY_DATE.Text);
}
}
if (!string.IsNullOrWhiteSpace(Request["MACHINEUSEAG_ID"]))
{
Business.MACHINEUSEAG _MACHINEUSEAG = new Business.MACHINEUSEAG(Transaction);
_MACHINEUSEAG.MACHINEUSEAG_ID_Encrypt = Request["MACHINEUSEAG_ID"];
if (_MACHINEUSEAG.Select())
{
_MACHINEUSEAG.OWNERUNIT_ID = OWNERUNIT_ID.SelectedValue.TryParseToInt();
_MACHINEUSEAG.SERVERPART_NAME = SERVERPART_CODE.SelectedItem.Text;
_MACHINEUSEAG.SERVERPARTCODE = SERVERPART_CODE.SelectedValue;
_MACHINEUSEAG.SERVERPARTSHOP_NAME = SHOPCODE.SelectedItem.Text;
_MACHINEUSEAG.SHOPCODE = SHOPCODE.SelectedValue;
_MACHINEUSEAG.MACHINECODE = MACHINECODE.Text;
_MACHINEUSEAG.EXPIRY_DATE = EXPIRY_DATE.Text.TryParseToDateTime();
_MACHINEUSEAG.STAFF_ID = Page.PassportInfo.ID;
_MACHINEUSEAG.STAFF_NAME = Page.PassportInfo.Name;
_MACHINEUSEAG.OPERATE_DATE = DateTime.Now;
_MACHINEUSEAG.Update();
}
}
}
private void SaveConfigurationModel(Business.MACHINECONFIGURATION _MACHINECONFIGURATION,
string _CONFIGURATION_NAME, string _CONFIGURATION_VALUES)
{
_MACHINECONFIGURATION.AddSearchParameter("MACHINE_MACADDRESS", MACHINE_MACADDRESS.Text);
_MACHINECONFIGURATION.AddSearchParameter("CONFIGURATION_NAME", _CONFIGURATION_NAME);
if (_MACHINECONFIGURATION.Search())
{
_MACHINECONFIGURATION.CONFIGURATION_VALUES = _CONFIGURATION_VALUES;
_MACHINECONFIGURATION.CONFIGURATION_DATE = DateTime.Now;
_MACHINECONFIGURATION.Update();
}
else
{
_MACHINECONFIGURATION.ResetProperty();
_MACHINECONFIGURATION.MACHINEBASEINFO_ID = MACHINEBASEINFO_ID.Text.TryParseToInt();
_MACHINECONFIGURATION.MACHINE_MACADDRESS = MACHINE_MACADDRESS.Text;
_MACHINECONFIGURATION.CONFIGURATION_NAME = _CONFIGURATION_NAME;
_MACHINECONFIGURATION.CONFIGURATION_VALUES = _CONFIGURATION_VALUES;
_MACHINECONFIGURATION.CONFIGURATION_DATE = DateTime.Now;
_MACHINECONFIGURATION.Insert();
}
}
#endregion
}
}