using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using DevComponents.DotNetBar.Controls; using DevComponents.DotNetBar.SuperGrid; using NLog; using JwKdsV.Entity; using JwKdsV.Entity.Product; using JwKdsV.Core; using JwKdsV.Component; using JwKdsV.Core.Utils; namespace JwKdsV { public partial class SaleClearForm : BaseForm { public SaleClearForm() { InitializeComponent(); this.Name = "SaleClearForm"; this.keyboardPanel.Height = 0; this.keyboardPanel.Visible = false; this.detailPanel.Visible = false; this.dateTime.Value = DateTime.Now.AddDays(1); InitializeGrid(); this.categoryControl.CategoryCheckedChanged += OnCategoryCheckedChanged; this.dateTime.ValueChanged += OnDateTimeValueChanged; } private void InitializeGrid() { try { gridControl.RowActivated -= GridControlRowActivated; gridControl.RowActivated += GridControlRowActivated; gridControl.CellDoubleClick -= GridCellDoubleClick; gridControl.CellDoubleClick += GridCellDoubleClick; gridControl.CellClick -= GridControlCellClick; gridControl.CellClick += GridControlCellClick; } catch (Exception ex) { logger.Error(ex, "初始化沽清列表异常"); } finally { this.leftContainer.Invalidate(); } } protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (this.DesignMode) return; this.checkBoxX28.Checked = true; Task.Factory.StartNew(() => { this.Invoke(new Action(() => { try { //先获取最新的沽清数据 SaleClearUtils.Instance.InitSaleClear(); var lists = Global.Product._productList; this.productControl.PageNumber = 1; this.productControl.BindDataSource(lists, KeyboardAction.None); } catch (Exception ex) { logger.Error(ex, "加载商品信息异常"); } })); }).ContinueWith(task => { this.Invoke(new Action(() => { RefreshGrid(); })); }); } private void OnCategoryCheckedChanged(object sender, Component.CategoryEventArgs e) { var productType = e.Data; try { var lists = Global.Product._productList; var selectProduct = new List(); if (!Constant.ALL_PRODUCT_TAG.Equals(productType.No)) { selectProduct = lists.FindAll(x => !string.IsNullOrEmpty(x.TypePath) && x.TypePath.StartsWith(productType.Path)); } this.productControl.PageNumber = 1; this.productControl.BindDataSource(selectProduct, KeyboardAction.None); } catch (Exception ex) { logger.Error(ex, "加载商品信息异常"); } } private void OnProductCheckedChanged(object sender, Component.ProductEventArgs e) { bool isGo = true; //**********************开始******************************* var product = e.Product; if (isGo) { ProcessSaleClearModify(product); } } private void ProcessSaleClearModify(ProductExt product, SaleClear saleClear = null) { if (saleClear == null) { if (SaleClearUtils.Instance.Maps.ContainsKey(product.Id)) { saleClear = SaleClearUtils.Instance.Maps[product.Id]; } } var dialogForm = new SaleClearModify(product, saleClear); dialogForm.AcceptButtonClick += (o, args) => { RefreshGrid(); }; dialogForm.CancelButtonClick += (o, args) => { }; dialogForm.ShowDialog(this); //qy //TransparentForm trans = new TransparentForm(this, dialogForm); //trans.Show(this); } private void RefreshGrid() { try { List rows = new List(); var startTime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00"); var endTime = DateTime.Now.ToString("yyyy-MM-dd 23:59:00"); //指定日期 if (checkBoxX1.Checked) { startTime = dateTime.Value.ToString("yyyy-MM-dd 00:00:00"); endTime = dateTime.Value.ToString("yyyy-MM-dd 23:59:00"); } //启用消息中心并且可访问 var result = MessageCenterUtils.Instance.GetSaleClearList(startTime); rows = result.Item3; GridPanel panel = gridControl.PrimaryGrid; //清理数据 panel.Rows.Clear(); foreach (var r in rows) { GridRow gridRow = new GridRow(r.Id, r.ProductName, r.Quantity, r.UnitName); gridRow.RowHeight = 40; gridRow.Tag = r; panel.Rows.Add(gridRow); panel.SetSelected(gridRow, true); panel.SetActiveRow(gridRow); } //滚动条 this.gridControl.HScrollBarVisible = false; this.gridControl.VScrollBarVisible = true; this.gridControl.VScrollBar.Width = 0; } catch (Exception ex) { logger.Error(ex, "加载沽清列表异常"); } finally { } } private void GridControlRowActivated(object sender, GridRowActivatedEventArgs e) { if (e.NewActiveRow != null) { GridPanel panel = e.GridPanel; panel.SetSelected(e.OldActiveRow, false); panel.SetSelected(e.NewActiveRow, true); panel.SetActiveRow(e.NewActiveRow); if (e.NewActiveRow.Tag is SaleClear) { SaleClear saleClear = e.NewActiveRow.Tag as SaleClear; this.ShowSaleClearDetail(saleClear); } } } private void ShowSaleClearDetail(SaleClear saleClear) { this.lblTotalQuantity.Text = string.Format(this.lblTotalQuantity.Tag.ToString(), saleClear.TotalQuantity); this.lblNotifyQuantity.Text = string.Format(this.lblNotifyQuantity.Tag.ToString(), saleClear.NotifyQuantity); this.lblSaleQuantity.Text = string.Format(this.lblSaleQuantity.Tag.ToString(), saleClear.SaleQuantity); this.lblDateTimer.Text = string.Format(this.lblDateTimer.Tag.ToString(), saleClear.StartTime, saleClear.EndTime); } private void GridCellDoubleClick(object sender, GridCellDoubleClickEventArgs e) { if (e.MouseEventArgs.Button == MouseButtons.Left && e.GridCell.GridRow.Tag is SaleClear) { SaleClear saleClear = e.GridCell.GridRow.Tag as SaleClear; var lists = Global.Product._productList; ProductExt product = lists.FindLast(x => !string.IsNullOrEmpty(x.Id) && x.Id.Equals(saleClear.ProductId)); if (product != null) { this.ProcessSaleClearModify(product, saleClear); } } } private void GridControlCellClick(object sender, GridCellClickEventArgs e) { if (e.MouseEventArgs.Button == MouseButtons.Left && e.GridCell.GridRow.Tag is SaleClear) { SaleClear saleClear = e.GridCell.GridRow.Tag as SaleClear; this.ShowSaleClearDetail(saleClear); } } protected override void OnFormClosing(FormClosingEventArgs e) { e.Cancel = false; } private void OnShowOrHideTouchClick(object sender, EventArgs e) { this.detailPanel.Visible = !this.detailPanel.Visible; } private void OnSearchCustomClick(object sender, EventArgs e) { if (SimpleKeyboard.Showing()) { this.keyboardPanel.Height = 0; this.keyboardPanel.Visible = false; SimpleKeyboard.CloseKeyboard(); } else { this.keyboardPanel.Height = 250; this.keyboardPanel.Visible = true; var location = this.keyboardPanel.PointToScreen(Point.Empty); var size = this.keyboardPanel.Size; SimpleKeyboard.ShowKeyboard(this, location, size, false, null); } } private void OnSearchTextChanged(object sender, EventArgs e) { var search = this.txtSearch.Text.Trim(); Task.Factory.StartNew(() => { this.Invoke(new Action(() => { try { var lists = Global.Product._productList; var selectProduct = new List(); selectProduct = lists.FindAll(x => (!string.IsNullOrEmpty(x.Spell) && x.Spell.Contains(search)) || (!string.IsNullOrEmpty(x.BarCode) && x.BarCode.Contains(search)) || (!string.IsNullOrEmpty(x.No) && x.No.Contains(search))); this.productControl.PageNumber = 1; this.productControl.BindDataSource(selectProduct, KeyboardAction.Search); } catch (Exception ex) { logger.Error(ex, "加载商品信息异常"); } })); }).ContinueWith(task => { //this.Invoke(new Action(() => //{ // MsgEvent.Send(Constant.PRODUCT_KEYBOARD_NOTIFY , KeyboardAction.Search); //})); }); } private void OnSearchPanelVisibleChanged(object sender, EventArgs e) { this.txtSearch.Focus(); this.txtSearch.Text = string.Empty; } private void OnSearchCheckedChanged(object sender, EventArgs e) { this.RefreshGrid(); } private void OnDateTimeValueChanged(object sender, EventArgs e) { this.checkBoxX1.Checked = false; this.checkBoxX1.Checked = true; } private void OnPageChangeClick(object sender, EventArgs e) { var obj = sender as TouchLabelX; string tag = obj.Tag as string; //购物车换页 if (tag == "up") { this.gridControl.VScrollOffset -= this.gridControl.Height - 120; } else if (tag == "down") { this.gridControl.VScrollOffset += this.gridControl.Height - 120; } } } }