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 CardExchangeForm : BusinessForm { public string oldcardNo = null; private static Logger logger = NLog.LogManager.GetCurrentClassLogger(); public CardExchangeForm() { 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; } 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 OnFinishedClick(object sender, EventArgs e) { SearchMessage(); } public 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; } } } /// /// 输入是否验证通过 /// private bool InputVerify() { if (string.IsNullOrEmpty(this.txtInput.Text.Trim())) { ShowMessage(this.lblInfo, "请输入卡号信息", false); return false; } return true; } /// /// 会员卡信息 /// 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 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; } } cardListTable.PrimaryGrid.DataSource = list; } else { result = false; lblMemerName.Text = ""; lblMemeberMobile.Text = ""; lblLinkPhone.Text = ""; lblSex.Text = ""; lblBirthday.Text = ""; lblDescription.Text = ""; List list = new List(); cardListTable.PrimaryGrid.DataSource = list; ShowMessage(this.lblInfo, response.Item2, true); } } catch (Exception ex) { result = false; ShowMessage(this.lblInfo, "会员卡信息查询异常", true); LOGGER.Error(ex, "会员卡信息查询异常"); } return result; } private void btn_exit_Click(object sender, EventArgs e) { //先关闭父窗体 if (this.Owner != null) { this.Owner.Close(); } //再关闭当前窗体 this.Close(); } private void OnTicketRowActivated(object sender, DevComponents.DotNetBar.SuperGrid.GridRowActivatedEventArgs e) { //卡号 oldcardNo = null; GridPanel grid = e.GridPanel; if (e.NewActiveRow != null) { //先清除其他表数据 GridRow row = e.NewActiveRow as GridRow; grid.SetSelected(e.NewActiveRow, false); grid.SetActiveRow(e.NewActiveRow); oldcardNo = row.Cells["cardNo"].Value.ToString(); } } private void OnBtnCustomClick(object sender, EventArgs e) { var item = sender as NumericTextBox; NumericKeyboard.ShowKeyboard(this, item); } private void BtnExchange(object sender, EventArgs e) { if (oldcardNo == null || "".Equals(oldcardNo)) { ShowMessage(this.lblInfo, "请选择要换的卡", true); return; } if (this.numericTextBox2.Text == null || "".Equals(this.numericTextBox2.Text)) { ShowMessage(this.lblInfo, "新卡号不能为空", true); return; } var newCardNo = this.numericTextBox2.Text; //智能识别刷卡方式 var way = CardUtils.JudgeCardWay(Global.Instance.Worker.TenantId, newCardNo); if (way == MemberCardNoType.未知) { this.ShowMessage(this.lblInfo, "无法识别的卡号,请确认", true); return; } if (way == MemberCardNoType.手机号) { this.ShowMessage(this.lblInfo, "无法识别的卡号,请确认", true); return; } if (way == MemberCardNoType.电子卡号) { this.ShowMessage(this.lblInfo, "无法识别的卡号,请确认", true); return; } //判断卡面号还是巨为生成的卡号 var cardWay = CardUtils.JudgeCardWay(Global.Instance.Worker.TenantId, newCardNo); if (cardWay == MemberCardNoType.卡面号) { var res = CardUtils.QueryRealCardNo(newCardNo); if (res.Item1) { var data = res.Item3; newCardNo = data.CardNo; } else { ShowMessage(this.lblInfo, res.Item2, false); return; } } //打开提示界面 var form = new CardExchangeDialogForm(); form.OnOkClick += Form_OnOkClick; form.ShowDialog(this); } private void Form_OnOkClick(object sender, NotifyEventArgs e) { var newCardNo = this.numericTextBox2.Text; //智能识别刷卡方式 var way = CardUtils.JudgeCardWay(Global.Instance.Worker.TenantId, newCardNo); if (way == MemberCardNoType.未知) { this.ShowMessage(this.lblInfo, "无法识别的卡号,请确认", true); return; } if (way == MemberCardNoType.手机号) { this.ShowMessage(this.lblInfo, "无法识别的卡号,请确认", true); return; } if (way == MemberCardNoType.电子卡号) { this.ShowMessage(this.lblInfo, "无法识别的卡号,请确认", true); return; } //判断卡面号还是巨为生成的卡号 var cardWay = CardUtils.JudgeCardWay(Global.Instance.Worker.TenantId, newCardNo); if (cardWay == MemberCardNoType.卡面号) { var res = CardUtils.QueryRealCardNo(newCardNo); if (res.Item1) { var data = res.Item3; newCardNo = data.CardNo; } else { ShowMessage(this.lblInfo, res.Item2, false); return; } } string passwd = string.IsNullOrEmpty(this.numericTextBox1.Text) ? "" : DesUtils.Encrypt(this.numericTextBox1.Text); try { var request = new CardExchangeRequest(); request.OldCardNo = oldcardNo; request.NewCardNo = newCardNo; request.Password = passwd; request.ShopNo = Global.Instance.Authc.StoreNo; request.PosNo = Global.Instance.Authc.PosNo; request.WorkerNo = Global.Instance.Worker.No; request.SourceSign = "pos"; var response = CardUtils.CardExchange(request); //成功 if (response.Item1) { ShowMessage(this.lblInfo, response.Item2, false); CardExchangeResponse cardExchangeResponse = response.Item3.Data; //打印退款结果 this.ShowToastNotify(this, "开始打印"); //构建收银小票模版参数打印 var vars = CardHelper.BuilderCardExchangeVariable(response.Item3.Data); //补换卡打印份数 int ticketCount = Global.Instance.GlobalConfigIntValue(ConfigConstant.PERIPHERAL_CASHIER_CHANGECARD_COUNT, 1); //打印延迟 int delaySecond = Global.Instance.GlobalConfigIntValue(ConfigConstant.PERIPHERAL_CASHIER_CARD_PRINT_DELAY, 1); Tuple result = CardHelper.PrinterTicket("会员卡补换", vars, true, false, ticketCount, delaySecond); this.ShowToastNotify(this, string.Format("{0}", result.Item2)); this.oldcardNo = null; this.numericTextBox2.Text = ""; this.numericTextBox1.Text = ""; this.txtInput.Text = ""; //刷新页面 lblMemerName.Text = ""; lblMemeberMobile.Text = ""; lblLinkPhone.Text = ""; lblSex.Text = ""; lblBirthday.Text = ""; lblDescription.Text = ""; List list = new List(); cardListTable.PrimaryGrid.DataSource = list; } else { ShowMessage(this.lblInfo, response.Item2, true); } } catch (Exception ex) { ShowMessage(this.lblInfo, "退卡余额信息查询异常", true); LOGGER.Error(ex, "退卡余额信息查询异常"); } } private void OnReadNewCardClick(object sender, EventArgs e) { var result = CardOperateUtils.Instance.ReadCardNo(); if (result.Item1) { this.numericTextBox2.Text = result.Item2; //读卡成功,模拟回车事件 InputSimulatorUtils.SendKey(KeyCodes.Map["return"]); } else { result = CardOperateUtilsOther.Instance.ReadCardNo(); if (result.Item1) { this.numericTextBox2.Text = result.Item2; //读卡成功,模拟回车事件 InputSimulatorUtils.SendKey(KeyCodes.Map["return"]); } else { this.ShowMessage(lblInfo, result.Item2); } } } private void in_oldPwd_Enter(object sender, EnterEventArg e) { this.numericTextBox2.Focus(); this.numericTextBox2.SelectAll(); } } }