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.

564 lines
21 KiB
C#

9 months ago
using DevComponents.DotNetBar.Controls;
using DevComponents.DotNetBar.SuperGrid;
using NLog;
using POSV.Bean;
using POSV.Card;
using POSV.Component;
using POSV.Helper;
using POSV.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
namespace POSV.Member
{
public partial class PointExchangeForm : BusinessForm
{
private static Logger logger = NLog.LogManager.GetCurrentClassLogger();
public int type = -1;
public string schemeId = null;//兑换方案ID
public string memberId = null;//会员ID
public string cardNo = null;//会员卡号
public string giftDetailId = null;//礼品赠送ID
public string typeName = null;
public List<PointExchangeSchemesResponse> schemeList = null;
//礼品赠送列表
List<PointExchangeSchemeDetailGift> listGift = null;
public PointExchangeForm()
{
InitializeComponent();
this.controlBox.Text = "会员积分兑换";
this.controlBox.ShowApplicationVersion = false;
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (this.DesignMode) return;
this.Focus();
this.txtInput.Focus();
this.txtInput.SelectAll();
this.ActiveControl = this.txtInput;
this.cmbCreType.SelectedIndexChanged += OnPalnSelectedIndexChanged;
this.comboBoxGif.SelectedIndexChanged += OnGiftSelectedIndexChanged;
}
private void OnCloseTouchClick(object sender, EventArgs e)
{
//先关闭父窗体
if (this.Owner != null)
{
this.Owner.Close();
}
//再关闭当前窗体
this.Close();
}
private void OnControlBoxKeyboardClick(object sender, EventArgs e)
{
try
{
KeyboardType keyboardType = KeyboardType.;
Type type = this.ActiveControl.GetType();
PropertyInfo pinfo = type.GetProperty("Keyboard");
if (pinfo != null)
{
keyboardType = (KeyboardType)pinfo.GetValue(this.ActiveControl, null);
}
var keyboard = Application.OpenForms["VirtualKeyboard"];
if (keyboard == null)
{
keyboard = new VirtualKeyboard(keyboardType);
}
((VirtualKeyboard)keyboard).ShowVirtualKeyboard(this, keyboardType);
}
catch (Exception ex)
{
LOGGER.Error(ex, "打开屏幕键盘异常");
}
}
private void OnReadCardClick(object sender, EventArgs e)
{
var result = CardOperateUtils.Instance.ReadCardNo();
if (result.Item1)
{
this.txtInput.Text = result.Item2;
//读卡成功,模拟回车事件
InputSimulatorUtils.SendKey(KeyCodes.Map["return"]);
}
else
{
result = CardOperateUtilsOther.Instance.ReadCardNo();
if (result.Item1)
{
this.txtInput.Text = result.Item2;
//读卡成功,模拟回车事件
InputSimulatorUtils.SendKey(KeyCodes.Map["return"]);
}
else
{
this.ShowMessage(lblInfo, result.Item2);
}
}
}
private void SearchMessage()
{
var isVerify = InputVerify();
if (isVerify)
{
var voucherNo = this.txtInput.Text;
//智能识别刷卡方式
var way = CardUtils.JudgeCardWay(Global.Instance.Worker.TenantId, voucherNo);
if (way == MemberCardNoType.)
{
this.ShowMessage(this.lblInfo, "无法识别的卡号,请确认", true);
return;
}
switch (way)
{
case MemberCardNoType.:
{
CardInfoMessage("mobile");
}
break;
case MemberCardNoType.:
{
CardInfoMessage("scanCode");
}
break;
case MemberCardNoType.:
{
CardInfoMessage("cardNo");
}
break;
case MemberCardNoType.:
{
CardInfoMessage("surfaceNo");
}
break;
}
}
}
/// <summary>
/// 会员卡信息
/// </summary>
private bool CardInfoMessage(string property)
{
bool result = false;
try
{
var request = new MemberInfoQueryRequest();
request.Property = property;
request.Keyword = this.txtInput.Text.Trim();
request.ShopNo = Global.Instance.Authc.StoreNo;
request.PosNo = Global.Instance.Authc.PosNo;
request.WorkerNo = Global.Instance.Worker.No;
var response = CardUtils.MemberInfoQuery(request);
//成功
if (response.Item1)
{
result = true;
ShowMessage(this.lblInfo, response.Item2, false);
MemberInfoQueryResponse memberInfoQueryResponse = response.Item3;
lblMemerName.Text = memberInfoQueryResponse.Name;
lblMemeberMobile.Text = memberInfoQueryResponse.Mobile;
lblLinkPhone.Text = memberInfoQueryResponse.LinkPhone;
switch (memberInfoQueryResponse.Sex)
{
case 0:
lblSex.Text = "女";
break;
case 1:
lblSex.Text = "男";
break;
default:
lblSex.Text = "保密";
break;
}
lblBirthday.Text = memberInfoQueryResponse.Birthday;
lblDescription.Text = memberInfoQueryResponse.Description;
List<MemberCard> list = memberInfoQueryResponse.CardList;
foreach (MemberCard memberCard in list)
{
switch (memberCard.Status)
{
case 1:
memberCard.CardStatus = "正常";
break;
case 2:
memberCard.CardStatus = "预售";
break;
case 3:
memberCard.CardStatus = "挂失";
break;
case 4:
memberCard.CardStatus = "冻结";
break;
case 5:
memberCard.CardStatus = "销户";
break;
default:
memberCard.CardStatus = "未知";
break;
}
}
memberId = memberInfoQueryResponse.Id;
cardListTable.PrimaryGrid.DataSource = list;
}
else
{
result = false;
lblMemerName.Text = "";
lblMemeberMobile.Text = "";
lblLinkPhone.Text = "";
lblSex.Text = "";
lblBirthday.Text = "";
lblDescription.Text = "";
memberId = null;
List<MemberCard> list = new List<MemberCard>();
cardListTable.PrimaryGrid.DataSource = list;
ShowMessage(this.lblInfo, response.Item2, true);
}
}
catch (Exception ex)
{
result = false;
ShowMessage(this.lblInfo, "会员卡信息查询异常", true);
LOGGER.Error(ex, "会员卡信息查询异常");
}
return result;
}
/// <summary>
/// 输入是否验证通过
/// </summary>
private bool InputVerify()
{
if (string.IsNullOrEmpty(this.txtInput.Text.Trim()))
{
ShowMessage(this.lblInfo, "请输入卡号信息", false);
return false;
}
return true;
}
private void OnTicketRowActivated(object sender, DevComponents.DotNetBar.SuperGrid.GridRowActivatedEventArgs e)
{
//切换会员卡的时候重置方案相关ID
schemeId = null;//兑换方案ID
cardNo = null;// 会员卡号
GridPanel grid = e.GridPanel;
if (e.NewActiveRow != null)
{
//先清除其他表数据
GridRow row = e.NewActiveRow as GridRow;
grid.SetSelected(e.NewActiveRow, false);
grid.SetActiveRow(e.NewActiveRow);
cardNo = row.Cells["cardNo"].Value.ToString();
string preAmount = row.Cells["totalAmount"].Value.ToString();
string perJifen = row.Cells["totalPoint"].Value.ToString();
this.preAmountTextBox.Text = preAmount;//兑换前余额
this.perJifenTextBox.Text = perJifen;//兑换前积分
try
{
var request = new PointExchangeSchemesRequest();
request.ShopNo = Global.Instance.Authc.StoreNo;
request.PosNo = Global.Instance.Authc.PosNo;
var response = CardUtils.PointExchangeSchemes(request);
//成功
if (response.Item1)
{
schemeList = response.Item3.List;
List<PointExchangeSchemesResponse> temp_SchemeList = new List<PointExchangeSchemesResponse>();
if (this.type > 0)
{
temp_SchemeList = schemeList.FindAll(x => x.Type.Equals(this.type));
}
else
{
temp_SchemeList = schemeList;
}
this.cmbCreType.DisplayMember = "Name";
this.cmbCreType.ValueMember = "Id";
this.cmbCreType.DataSource = temp_SchemeList;
if (temp_SchemeList != null && temp_SchemeList.Count > 0)
{
schemeId = temp_SchemeList[0].Id;
var request1 = new PointExchangeSchemeDetailRequest();
request1.SchemeId = schemeId;
request1.ShopNo = Global.Instance.Authc.StoreNo;
request1.PosNo = Global.Instance.Authc.PosNo;
var response1 = CardUtils.PointExchangeSchemeDetail(request1);
if (response1.Item1)
{
//充值金额赠送方案
resetPlanDetail(response1.Item3.Data);
}
}
else
{
schemeId = null;
this.afterAmountTextBox.Text = StringUtils.GetString(StringUtils.GetDecimal(this.preAmountTextBox.Text));//兑换后余额
this.afterJifenTextBox.Text = StringUtils.GetString(StringUtils.GetDecimal(this.perJifenTextBox.Text));//兑换后积分
this.descriptionTextBox.Text = "";
this.comboBoxGif.DataSource = new List<PointExchangeSchemeDetailGift>();
}
}
else
{
ShowMessage(this.lblInfo, "获取充值方案异常", true);
}
}
catch (Exception ex)
{
ShowMessage(this.lblInfo, "获取充值方案异常", true);
LOGGER.Error(ex, "获取充值方案异常");
}
}
}
private void OnPalnSelectedIndexChanged(object sender, EventArgs e)
{
var obj = sender as ComboBoxEx;
schemeId = StringUtils.GetString(obj.SelectedValue);
var request1 = new PointExchangeSchemeDetailRequest();
request1.SchemeId = schemeId;
request1.ShopNo = Global.Instance.Authc.StoreNo;
request1.PosNo = Global.Instance.Authc.PosNo;
var response1 = CardUtils.PointExchangeSchemeDetail(request1);
if (response1.Item1)
{
//充值金额赠送方案
resetPlanDetail(response1.Item3.Data);
}
}
public void resetPlanDetail(PointExchangeSchemeDetailResponse response)
{
if (response.Type == 1)
{
this.afterAmountTextBox.Text = StringUtils.GetString(StringUtils.GetDecimal(this.preAmountTextBox.Text) + StringUtils.GetDecimal(response.Worth));//兑换后余额
}
else
{
this.afterAmountTextBox.Text = StringUtils.GetString(StringUtils.GetDecimal(this.preAmountTextBox.Text));//兑换后余额
}
this.afterJifenTextBox.Text = StringUtils.GetString(StringUtils.GetDecimal(this.perJifenTextBox.Text) - StringUtils.GetDecimal(response.PointValue));//兑换后积分
this.descriptionTextBox.Text = response.Description;
if (response.Type == 1)
{
typeName = "兑换现金";
}
else if (response.Type == 2)
{
typeName = "兑换礼品";
}
else if (response.Type == 3)
{
typeName = "兑换代金券";
}
this.listGift = response.Gifts;
if (listGift != null)
{
this.comboBoxGif.DisplayMember = string.Format("DisPlayName");
this.comboBoxGif.ValueMember = "Id";
this.comboBoxGif.DataSource = listGift;
}
else {
this.comboBoxGif.DisplayMember = string.Format("DisPlayName");
this.comboBoxGif.ValueMember = "Id";
this.comboBoxGif.DataSource = new List<PointExchangeSchemeDetailGift>();
}
if (StringUtils.GetDecimal(this.afterJifenTextBox.Text) < 0)
{
ShowMessage(this.lblInfo, "积分值不足", false);
}
}
private void OnGiftSelectedIndexChanged(object sender, EventArgs e)
{
var obj = sender as ComboBoxEx;
giftDetailId = StringUtils.GetString(obj.SelectedValue);
}
private void BtnExchange(object sender, EventArgs e)
{
string passwd = string.IsNullOrEmpty(this.numericTextBox1.Text) ? "" : DesUtils.Encrypt(this.numericTextBox1.Text);
if (cardNo == null || "".Equals(cardNo))
{
ShowMessage(this.lblInfo, "请选择要兑换的卡", true);
return;
}
if (this.schemeId == null || "".Equals(this.schemeId))
{
ShowMessage(this.lblInfo, "请选择积分兑换方案", true);
return;
}
if (passwd == null || "".Equals(passwd))
{
ShowMessage(this.lblInfo, "请输入卡密码", true);
return;
}
if (StringUtils.GetDecimal(this.afterJifenTextBox.Text) < 0)
{
ShowMessage(this.lblInfo, "积分值不足", true);
return;
}
var request = new PointExchangeDoRequest();
request.SchemeId = this.schemeId;
request.MemberId = this.memberId;
request.Password = passwd;
request.ShopNo = Global.Instance.Authc.StoreNo;
request.PosNo = Global.Instance.Authc.PosNo;
request.CardNo = this.cardNo;
request.WorkerNo = Global.Instance.Worker.No;
request.SourceSign = "pos";
var response = CardUtils.PointExchangeDo(request);
if (response.Item1)
{
ShowMessage(this.lblInfo, "积分兑换成功", true);
//打印积分兑换结果
PointExchangeDoResponse pointExchangeDoResponse = response.Item3.Data;
//打印退款结果
this.ShowToastNotify(this, "开始打印");
pointExchangeDoResponse.Type = typeName;
pointExchangeDoResponse.Description = this.descriptionTextBox.Text;
//构建收银小票模版参数打印
var vars = CardHelper.BuilderPointExchangeVariable(pointExchangeDoResponse);
//积分兑换打印份数
int ticketCount = Global.Instance.GlobalConfigIntValue(ConfigConstant.PERIPHERAL_CASHIER_EXRECHARGE_COUNT, 1);
//打印延迟
int delaySecond = Global.Instance.GlobalConfigIntValue(ConfigConstant.PERIPHERAL_CASHIER_CARD_PRINT_DELAY, 1);
Tuple<bool, string> result = CardHelper.PrinterTicket("积分兑换", vars, true, false, ticketCount, delaySecond);
this.ShowToastNotify(this, string.Format("{0}", result.Item2));
this.numericTextBox1.Text = "";
//刷新页面
SearchMessage();
}
else
{
ShowMessage(this.lblInfo, response.Item2, false);
}
}
private void BtnExitClick(object sender, EventArgs e)
{
OnCloseTouchClick(sender, e);
}
private void cb_change_click(object sender, EventArgs e)
{
var obj = sender as CheckBoxX;
var indexT = obj.Tag as string;
if ("全部".Equals(indexT))
{
type = -1;
}
if ("兑换礼品".Equals(indexT))
{
type = 2;
}
if ("兑换卡余额".Equals(indexT))
{
type = 1;
}
if ("兑换卡券".Equals(indexT))
{
type = 3;
}
if (cardNo == null || "".Equals(cardNo))
{
return;
}
if (schemeList==null) {
schemeList = new List<PointExchangeSchemesResponse>();
}
List<PointExchangeSchemesResponse> temp_SchemeList = new List<PointExchangeSchemesResponse>();
if (this.type > 0)
{
temp_SchemeList = schemeList.FindAll(x => x.Type.Equals(this.type));
}
else
{
temp_SchemeList = schemeList;
}
this.cmbCreType.DisplayMember = "Name";
this.cmbCreType.ValueMember = "Id";
this.cmbCreType.DataSource = temp_SchemeList;
if (temp_SchemeList != null && temp_SchemeList.Count > 0)
{
schemeId = temp_SchemeList[0].Id;
var request1 = new PointExchangeSchemeDetailRequest();
request1.SchemeId = schemeId;
request1.ShopNo = Global.Instance.Authc.StoreNo;
request1.PosNo = Global.Instance.Authc.PosNo;
var response1 = CardUtils.PointExchangeSchemeDetail(request1);
if (response1.Item1)
{
//充值金额赠送方案
resetPlanDetail(response1.Item3.Data);
}
else
{
ShowMessage(this.lblInfo, "获取兑换方案明细失败", true);
}
}
else
{
schemeId = null;
this.afterAmountTextBox.Text = StringUtils.GetString(StringUtils.GetDecimal(this.preAmountTextBox.Text));//兑换后余额
this.afterJifenTextBox.Text = StringUtils.GetString(StringUtils.GetDecimal(this.perJifenTextBox.Text));//兑换后积分
this.descriptionTextBox.Text = "";
this.comboBoxGif.DataSource = new List<PointExchangeSchemeDetailGift>();
}
}
private void OnFinishedClick(object sender, EventArgs e)
{
SearchMessage();
}
private void OnBtnCustomClick(object sender, EventArgs e)
{
var item = sender as NumericTextBox;
NumericKeyboard.ShowKeyboard(this, item);
}
}
}