using DevComponents.DotNetBar; using DevComponents.DotNetBar.Controls; using DevComponents.DotNetBar.SuperGrid; using POSV.Bean; using POSV.Card; using POSV.Component; 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 CardAmountChangeForm : BusinessForm { public string cardNo = null; public CardAmountChangeForm() { InitializeComponent(); this.controlBox.Text = "金额变动查询"; this.controlBox.ShowApplicationVersion = false; } protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (this.DesignMode) return; DefaultGridStyle.setDefaultGridStyle(this.cardListTable); DefaultGridStyle.setDefaultGridStyle(this.historyListTable); this.Focus(); this.txtInput.Focus(); this.txtInput.SelectAll(); this.ActiveControl = this.txtInput; this.startPicker.Value = DateTime.Now.Date; this.endPicker.Value = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 23:59:59")); } private void OnQueryPageChangeWithObject(object obj) { //获得当前页 int cur = pagerControl1.CurrentPage; //获得每页显示的记录数 int rows = pagerControl1.RowsPerPage; PagerControl pager = obj as PagerControl; if (pager != null) { CardAmountChange(cur, rows); } } 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 OnFinishedClick(object sender, EventArgs e) { 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; 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; 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) { 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(); } //获得当前页 int cur = pagerControl1.CurrentPage; //获得每页显示的记录数 int rows = pagerControl1.RowsPerPage; CardAmountChange(cur, rows); } private void btn_time_Click(object sender, EventArgs e) { if (cardNo == null || "".Equals(cardNo)) { ShowMessage(this.lblInfo, "请先选中要查询的卡号", false); return; } var obj = sender as ButtonX; var date = obj.Tag as string; switch (date) { case "today": this.startPicker.Value = DateTime.Now.Date; this.endPicker.Value = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 23:59:59")); break; case "yesterday": this.startPicker.Value = DateTime.Now.AddDays(-1).Date; this.endPicker.Value = DateTime.Parse(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd 23:59:59")); break; case "curWeek": //本周 var dayOfWeek = (int)DateTime.Now.DayOfWeek - 1; if (dayOfWeek == -1) { //周日 dayOfWeek = 6; } this.startPicker.Value = DateTime.Now.AddDays(-dayOfWeek).Date; this.endPicker.Value = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 23:59:59")); break; case "lastWeek": //上周 dayOfWeek = (int)DateTime.Now.DayOfWeek - 1; if (dayOfWeek == -1) { //周日 dayOfWeek = 6; } this.startPicker.Value = DateTime.Now.AddDays(-dayOfWeek - 7).Date; this.endPicker.Value = DateTime.Parse(DateTime.Now.AddDays(-dayOfWeek - 1).ToString("yyyy-MM-dd 23:59:59")); break; case "curMonth": //当月 var day = DateTime.Now.Day - 1; this.startPicker.Value = DateTime.Now.AddDays(-day).Date; this.endPicker.Value = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 23:59:59")); break; case "lastMonth": //当月 day = DateTime.Now.Day - 1; this.startPicker.Value = DateTime.Now.AddDays(-day).AddMonths(-1).Date; this.endPicker.Value = DateTime.Parse(DateTime.Now.AddDays(-day - 1).ToString("yyyy-MM-dd 23:59:59")); break; case "lastDay": //前一天 var txtDate = Convert.ToDateTime(this.startPicker.Value); this.startPicker.Value = txtDate.AddDays(-1).Date; this.endPicker.Value = DateTime.Parse(txtDate.AddDays(-1).ToString("yyyy-MM-dd 23:59:59")); break; } //获得当前页 int cur = pagerControl1.CurrentPage; //获得每页显示的记录数 int rows = pagerControl1.RowsPerPage; CardAmountChange(cur, rows); } private void btn_query_Click(object sender, EventArgs e) { if (cardNo == null || "".Equals(cardNo)) { ShowMessage(this.lblInfo, "请先选中要查询的卡号", false); return; } //获得当前页 int cur = pagerControl1.CurrentPage; //获得每页显示的记录数 int rows = pagerControl1.RowsPerPage; CardAmountChange(cur, rows); } public void CardAmountChange(int PageNum, int pageSize) { try { var request = new CardAmountChangeRequest(); request.CardNo = cardNo; request.StartTime = this.startPicker.Value.ToString("yyyy-MM-dd HH:mm:ss"); request.EndTime = this.endPicker.Value.ToString("yyyy-MM-dd HH:mm:ss"); request.PageNum = PageNum; request.pageSize = pageSize; request.ShopNo = Global.Instance.Authc.StoreNo; request.PosNo = Global.Instance.Authc.PosNo; request.WorkerNo = Global.Instance.Worker.No; var response = CardUtils.CardAmountChange(request); //成功 if (response.Item1) { ShowMessage(this.lblInfo, response.Item2, false); List cardAmountChangeResponse = response.Item7; foreach (CardAmountChangeResponse changeResponse in cardAmountChangeResponse) { switch (changeResponse.Type) { case "recharge": changeResponse.TypeName = "充值"; break; case "consume": changeResponse.TypeName = "消费"; break; case "cancel": changeResponse.TypeName = "退款"; break; default: changeResponse.TypeName = "其他"; break; } } this.pagerControl1.TotalPage = response.Item4; this.pagerControl1.CurrentPage = response.Item5; this.pagerControl1.RecordCount = response.Item3; this.pagerControl1.RowsPerPage = response.Item6; historyListTable.PrimaryGrid.DataSource = cardAmountChangeResponse; } else { List list = new List(); cardListTable.PrimaryGrid.DataSource = list; ShowMessage(this.lblInfo, response.Item2, true); } } catch (Exception ex) { ShowMessage(this.lblInfo, "卡金额变动查询异常", true); 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); } } } } }