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.

189 lines
6.8 KiB
C#

using System;
using System.Collections.Generic;
using POSV.WebService;
using POSV.Entity;
using POSV.Utils;
using Newtonsoft.Json.Linq;
namespace POSV.Component
{
public partial class ShopApiConfigParameter : AbstractParameter
{
public ShopApiConfigParameter()
{
InitializeComponent();
GetConfigData();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (this.DesignMode) return;
}
public Tuple<bool, string> TestConfig()
{
Tuple<bool, string> tuple = new Tuple<bool, string>(false, "");
if (string.IsNullOrEmpty(this.txtSTATIONNAME.Text))
{
return tuple = new Tuple<bool, string>(false, "请填写车站名称"); ;
}
if (string.IsNullOrEmpty(this.txtSTATIONID.Text))
{
return tuple = new Tuple<bool, string>(false, "请填写车站ID"); ;
}
if (string.IsNullOrEmpty(this.txtSHOPNAME.Text))
{
return tuple = new Tuple<bool, string>(false, "请填写商店名称"); ;
}
if (string.IsNullOrEmpty(this.txtSHOPNO.Text))
{
return tuple = new Tuple<bool, string>(false, "请填写商店ID"); ;
}
if (string.IsNullOrEmpty(this.txtBRANCH.Text))
{
return tuple = new Tuple<bool, string>(false, "请填写所属公司"); ;
}
if (string.IsNullOrEmpty(this.txtKey.Text))
{
return tuple = new Tuple<bool, string>(false, "请填写Key秘钥"); ;
}
if (string.IsNullOrEmpty(this.txtaddress.Text))
{
return tuple = new Tuple<bool, string>(false, "请填写连接地址"); ;
}
List<StationTradeChange> _stationTrades = new List<StationTradeChange>();
StationTradeChange _stationTrade = new StationTradeChange();
_stationTrade.ShopNo = this.txtSHOPNO.Text;
_stationTrade.ShopName = this.txtSHOPNAME.Text;
_stationTrade.StationId = this.txtSTATIONID.Text;
_stationTrade.StationName = this.txtSTATIONNAME.Text;
_stationTrade.Branch = this.txtBRANCH.Text;
_stationTrades.Add(_stationTrade);
try
{
var _data = WebServiceUtils.UploadStationTradeChange(this.txtaddress.Text, _stationTrades, this.txtKey.Text).ToString();
if (_data.Contains("必填"))
{
return tuple = new Tuple<bool, string>(false, _data);
}
return tuple = new Tuple<bool, string>(true, "连接成功");
}
catch (Exception ex)
{
return new Tuple<bool, string>(false, "连接失败");
}
}
public void GetConfigData()
{
var _data = Global.Instance.GlobalConfigStringValue(ConfigConstant.ERP_API_CONFIG, "");
var _enabled = Global.Instance.GlobalConfigStringValue(ConfigConstant.ERP_API_ENABLED, "false");
if (_enabled.ToLower().Equals("true"))
{
this.enableServiceCenter.Value = true;
}
if (string.IsNullOrEmpty(_data))
{
return;
}
JObject jObject = JObject.Parse(_data);
this.txtSTATIONNAME.Text = jObject["STATIONNAME"].ToString();
this.txtSTATIONID.Text = jObject["STATIONID"].ToString();
this.txtSHOPNAME.Text = jObject["SHOPNAME"].ToString();
this.txtSHOPNO.Text = jObject["SHOPNO"].ToString();
this.txtBRANCH.Text = jObject["BRANCH"].ToString();
this.txtKey.Text = jObject["KEY"].ToString();
this.txtaddress.Text = jObject["ADDRESS"].ToString();
}
public Tuple<bool, string> Save()
{
Tuple<bool, string> tuple = new Tuple<bool, string>(false, "");
if (string.IsNullOrEmpty(this.txtSTATIONNAME.Text))
{
return tuple = new Tuple<bool, string>(false, "请填写车站名称"); ;
}
if (string.IsNullOrEmpty(this.txtSTATIONID.Text))
{
return tuple = new Tuple<bool, string>(false, "请填写车站ID"); ;
}
if (string.IsNullOrEmpty(this.txtSHOPNAME.Text))
{
return tuple = new Tuple<bool, string>(false, "请填写商店名称"); ;
}
if (string.IsNullOrEmpty(this.txtSHOPNO.Text))
{
return tuple = new Tuple<bool, string>(false, "请填写商店ID"); ;
}
if (string.IsNullOrEmpty(this.txtBRANCH.Text))
{
return tuple = new Tuple<bool, string>(false, "请填写所属公司"); ;
}
if (string.IsNullOrEmpty(this.txtKey.Text))
{
return tuple = new Tuple<bool, string>(false, "请填写Key秘钥"); ;
}
if (string.IsNullOrEmpty(this.txtaddress.Text))
{
return tuple = new Tuple<bool, string>(false, "请填写连接地址"); ;
}
var _data = new
{
STATIONNAME = this.txtSTATIONNAME.Text,
STATIONID = this.txtSTATIONID.Text,
SHOPNAME = this.txtSHOPNAME.Text,
SHOPNO = this.txtSHOPNO.Text,
BRANCH = this.txtBRANCH.Text,
KEY = this.txtKey.Text,
ADDRESS = this.txtaddress.Text
};
var config1 = new Config();
config1.Id = IdWorkerUtils.Instance.NextId();
config1.Group = ConfigConstant.ERPCONFIG;
config1.TenantId = Global.Instance.Authc.TenantId;
config1.Keys = ConfigConstant.ERP_API_ENABLED;
config1.Values = string.Format("{0}", enableServiceCenter.Value);
var config = new Config();
config.Id = IdWorkerUtils.Instance.NextId();
config.Group = ConfigConstant.ERPCONFIG;
config.TenantId = Global.Instance.Authc.TenantId;
config.Keys = ConfigConstant.ERP_API_CONFIG;
config.Values = string.Format("{0}", Utils.JsonUtils.Serialize(_data));
try
{
using (var db = Global.Instance.OpenDataBase)
{
db.Save(config);
db.Save(config1);
}
Global.Instance.ReloadConfig(ConfigConstant.ERPCONFIG);
return tuple = new Tuple<bool, string>(true, "保存成功"); ;
}
catch (Exception ex)
{
string message = "erp配置参数";
LOGGER.Error(ex, message);
}
return tuple;
}
}
}