using DevComponents.DotNetBar.Controls; using DevComponents.DotNetBar.SuperGrid; using POSV.Card; using POSV.Entity; using POSV.Template; 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.Stock { public partial class DispatchTicketReceiveForm : BusinessForm { //仓库列表 private List storageList = new List(); private string storageId = null; //选择的明细列表 DispatchTicketResponse dispatchTicketResponse; List detailList; public DispatchTicketReceiveForm(DispatchTicketResponse dispatchTicketResponse, List detailList) { InitializeComponent(); this.dispatchTicketResponse = dispatchTicketResponse; this.detailList = detailList; this.controlBox1.Text = "配送单验收"; this.controlBox1.ShowApplicationVersion = false; } protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (this.DesignMode) return; this.busNoTextBox.Text = dispatchTicketResponse.No; this.askGoodsNoTextBox.Text = dispatchTicketResponse.AskGoodsNo; this.statusBox.Text = "待收货"; this.linkManBox.Text = dispatchTicketResponse.LinkMan; this.linkTelephoneTextBox.Text = dispatchTicketResponse.LinkTelephone; this.addressTextBox.Text = dispatchTicketResponse.Address; this.logisticsNoTextBox.Text = dispatchTicketResponse.LogisticsNo; this.logisticsNameBox.Text = dispatchTicketResponse.LogisticsName; this.orderMoneyTextBox.Text = string.Format("{0}", dispatchTicketResponse.Money); this.logisticsFeeTextBox.Text = string.Format("{0}", dispatchTicketResponse.LogisticsFee); this.totalMoneyTextBox.Text = string.Format("{0}", dispatchTicketResponse.Money); this.receiveUserBox.Text = Global.Instance.BusinessPlanLog.WorkerNo; this.receiveDateTextBox.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); //仓库列表 InitStorageMenu(); foreach (DispatchTicketDetailResponse response in detailList) { response.DifferenceAmount = "0.00"; response.DifferenceMoney = "0.00"; response.ReceiveAmount = response.DispatchAmount; response.SubtotalPrice = response.DispatchAmount; } detailListTable.PrimaryGrid.DataSource = detailList; //可编辑cell颜色特殊标注 var panel = this.detailListTable.PrimaryGrid; Color bgColor = ColorTranslator.FromHtml("193,255,192"); panel.Columns["receiveAmount"].CellStyles.Default.Background.Color1 = bgColor; panel.Columns["description"].CellStyles.Default.Background.Color1 = bgColor; } private void InitStorageMenu() { StoreStorage storeStorage = new StoreStorage(); storeStorage.Id = ""; storeStorage.No = ""; storeStorage.Name = "全部仓库"; storageList.Add(storeStorage); try { using (var db = Global.Instance.OpenDataBase) { StringBuilder sqlBuf = new StringBuilder(); sqlBuf.Append(" select id,no,name from pos_store_storage ;"); storageList.AddRange(db.Fetch(sqlBuf.ToString())); } } catch (Exception ex) { LOGGER.Error(ex); } RefreshMain(); } private void RefreshMain() { this.comboBoxEx1.DisplayMember = "name"; this.comboBoxEx1.ValueMember = "id"; this.comboBoxEx1.DataSource = storageList; this.comboBoxEx1.SelectedIndexChanged += OnStorageSelectedIndexChanged; } private void OnStorageSelectedIndexChanged(object sender, EventArgs e) { var obj = sender as ComboBoxEx; storageId = StringUtils.GetString(obj.SelectedValue); } 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 btn_exit_Click(object sender, EventArgs e) { //先关闭父窗体 if (this.Owner != null) { this.Owner.Close(); } //再关闭当前窗体 this.Close(); } public delegate void EventHandler(object sender); public event EventHandler OnTicktQuery; private void exitClick(object sender, EventArgs e) { //先关闭父窗体 if (this.Owner != null) { this.Owner.Close(); } //再关闭当前窗体 this.Close(); } private void applyClick(object sender, EventArgs e) { this.buttonX1.Focus(); if (storageId == null || "".Equals(storageId)) { this.ShowToastNotify(this, "请选择入库仓库"); return; } try { DispatchTicketReceiveRequest request = new DispatchTicketReceiveRequest(); request.StoreId = Global.Instance.BusinessPlanLog.StoreId; request.No = dispatchTicketResponse.No; request.DispatchId = dispatchTicketResponse.Id; request.DispatchNo = dispatchTicketResponse.No; request.StorageId = storageId; request.ReceiveUser = Global.Instance.BusinessPlanLog.WorkerNo; request.ReceiveDate = this.receiveDateTextBox.Text; request.Description = this.memoTextBox.Text; //遍历获取列表信息 var rows = this.detailListTable.PrimaryGrid.Rows; List addDetail = new List(); if (rows.Count > 0) { foreach (var temRow in rows) { GridRow row = temRow as GridRow; var ProductId = StringUtils.GetString(row.Cells["ProductId"].Value); var ProductNo = StringUtils.GetString(row.Cells["productNo"].Value); var ProductName = StringUtils.GetString(row.Cells["productName"].Value); var SpecId = StringUtils.GetString(row.Cells["SpecId"].Value); var SpecName = StringUtils.GetString(row.Cells["specName"].Value); var ProductDescription = StringUtils.GetString(row.Cells["productDescription"].Value); var DispatchUnitId = StringUtils.GetString(row.Cells["dispatchUnitId"].Value); var DispatchUnitName = StringUtils.GetString(row.Cells["dispatchUnitName"].Value); var Price = StringUtils.GetDecimal(row.Cells["price"].Value); var AskgoodsAmount = StringUtils.GetDecimal(row.Cells["askgoodsAmount"].Value); var DispatchAmount = StringUtils.GetDecimal(row.Cells["dispatchAmount"].Value); var ReceiveAmount = StringUtils.GetDecimal(row.Cells["receiveAmount"].Value); var SubtotalPrice = StringUtils.GetDecimal(row.Cells["subtotalPrice"].Value); var DifferenceAmount = StringUtils.GetDecimal(row.Cells["differenceAmount"].Value); var DifferencePrice = StringUtils.GetDecimal(row.Cells["differenceMoney"].Value); var Description = StringUtils.GetString(row.Cells["description"].Value); DispatchTicketReceive dispatchTicketReceive = new DispatchTicketReceive(); dispatchTicketReceive.ProductId = ProductId; dispatchTicketReceive.ProductNo = ProductNo; dispatchTicketReceive.ProductName = ProductName; dispatchTicketReceive.SpecId = SpecId; dispatchTicketReceive.SpecName = SpecName; dispatchTicketReceive.ProductDescription = ProductDescription; dispatchTicketReceive.DispatchUnitId = DispatchUnitId; dispatchTicketReceive.DispatchUnitName = DispatchUnitName; dispatchTicketReceive.DispatchPrice = Price; dispatchTicketReceive.AskgoodsAmount = AskgoodsAmount; dispatchTicketReceive.DispatchAmount = DispatchAmount; dispatchTicketReceive.ReceiveAmount = ReceiveAmount; dispatchTicketReceive.SubtotalPrice = SubtotalPrice; dispatchTicketReceive.DifferenceAmount = DifferenceAmount; dispatchTicketReceive.DifferencePrice = DifferencePrice; dispatchTicketReceive.Description = Description; addDetail.Add(dispatchTicketReceive); } } request.Detail = addDetail; var response = StockUtils.DispatchTicketReceive(request); //成功 if (response.Item1) { OnTicktQuery?.Invoke(sender); this.ShowToastNotify(this, response.Item2); //保存成功关闭当前窗口 if (this.Owner != null) { this.Owner.Close(); } //再关闭当前窗体 this.Close(); } else { this.ShowToastNotify(this, response.Item2); } } catch (Exception ex) { this.ShowToastNotify(this, "配送验收异常"); LOGGER.Error(ex, "配送验收异常"); } } private void OnCellValueChanged(object sender, GridCellValueChangedEventArgs e) { var cell = e.GridCell; if (cell.GridColumn.Name == "receiveAmount") { var row = cell.GridRow; var price = StringUtils.GetDecimal(row.Cells["price"].Value);//配送价 var dispatchAmount = StringUtils.GetDecimal(row.Cells["dispatchAmount"].Value);//配送数量 var money = StringUtils.GetDecimal(row.Cells["money"].Value);//配送金额 var amount = StringUtils.GetDecimal(row.Cells["receiveAmount"].Value);//收货数量 var subtotalPrice = price * amount; row.Cells["subtotalPrice"].Value = StringUtils.FormatDataTwoDigit(subtotalPrice); row.Cells["differenceAmount"].Value = StringUtils.FormatDataTwoDigit(amount - dispatchAmount);//差异数量= 验收数量-配送数量 row.Cells["differenceMoney"].Value = StringUtils.FormatDataTwoDigit(money - subtotalPrice);//差异金额= 验收金额-配送金额 if (amount - dispatchAmount != 0) { row.CellStyles.Default.TextColor = Color.Red; } else { row.CellStyles.Default.TextColor = Color.Black; } } } private void OnBeginEdit(object sender, GridEditEventArgs e) { var cell = e.GridCell; var cellPoint = this.detailListTable.PointToScreen(cell.LocationRelative); if (cell.GridColumn.Name == "receiveAmount") { cellPoint.Y -= this.detailListTable.VScrollOffset; var p = NumericKeyboard.CalculateLocation(cellPoint, cell.GridColumn.Width); NumericKeyboard.ShowKeyboard(this, p); } else { var txtForm = new TxtKeyboardForm(StringUtils.GetString(cell.Value)); txtForm.NotifyChanged += (o, args) => { cell.Value = args.Data; }; var trans = new TransparentForm(this, .5, txtForm); trans.Show(this); } } private void OnCloseEdit(object sender, GridCloseEditEventArgs e) { NumericKeyboard.CloseKeyboard(); } } }