using DevComponents.DotNetBar.SuperGrid; using POSV.Boduo.Stock; using POSV.Card; using POSV.Entity; using POSV.Entity.Stock; 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.Threading.Tasks; using System.Windows.Forms; namespace POSV.Stock { public partial class AskGoodsAddForm : BusinessForm { private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); private List ids = new List(); private List details = new List(); public AskGoodsAddForm() { InitializeComponent(); this.controlBox1.Text = "要货单新增"; this.controlBox1.ShowApplicationVersion = false; } protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (this.DesignMode) return; this.busNoTextBox.Text = string.Format("Y{0}{1}", Global.Instance.Authc.PosNo, DateTime.Now.ToString("yyyyMMddHHmmss") ); this.storeNameTextBox.Text = Global.Instance.Worker.StoreInfo.Name; this.statusBox.Text = "新建"; this.setManTextBox.Text = Global.Instance.BusinessPlanLog.WorkerNo; this.setDateTextBox.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); this.productMoneyTextBox.Text = string.Format("{0}", 0.00); this.dispatchMoneyTextBox.Text = string.Format("{0}", 0.00); this.totalMoneyTextBox.Text = string.Format("{0}", 0.00); //可编辑cell颜色特殊标注 var panel = this.detailListTable.PrimaryGrid; Color bgColor = ColorTranslator.FromHtml("193,255,192"); panel.Columns["amount"].CellStyles.Default.Background.Color1 = bgColor; panel.Columns["description"].CellStyles.Default.Background.Color1 = bgColor; } 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(); } private void btn_selectProduct(object sender, EventArgs e) { var form = new SelectProductForm(ids, ">=10"); form.OnProductClick += Form_OnProductClick; TransparentForm trans = new TransparentForm(this, form); trans.Show(this); } private void Form_OnProductClick(object sender, MaterialDetailEventArgs e) { var detail = e.Detail; var rows = this.detailListTable.PrimaryGrid.Rows; bool isExist = false; //过滤已存在的原料信息 if (rows.Count > 0) { foreach (var temRow in rows) { GridRow row = temRow as GridRow; if (detail.SpecId.Equals(row["SpecId"].Value.ToString())) { isExist = true; break; } } } if (!isExist) { decimal price = 0; //获取原料价格 ProductDispatchpriceRequest request = new ProductDispatchpriceRequest(); request.StoreId = Global.Instance.BusinessPlanLog.StoreId; request.SpecIds = detail.SpecId; var response = StockUtils.ProductDispatchprice(request); //成功 if (response.Item1) { List list = response.Item3; foreach (ProductDispatchpriceResponse dispatchpriceResponse in list) { if (dispatchpriceResponse.SpecId.Equals(detail.SpecId)) { price = StringUtils.FormatDataTwoDigitObject(dispatchpriceResponse.DispatchPrice); } } } else { price = 0; } //获取原料门店库存 ProductStockSumRequest request1 = new ProductStockSumRequest(); request1.StoreId = Global.Instance.BusinessPlanLog.StoreId; request1.SpecIds = detail.SpecId; var response1 = StockUtils.ProductStockSum(request1); decimal stockAmount = 0; //成功 if (response1.Item1) { List list = response1.Item3; foreach (ProductStockSumResponse productStockSumResponse in list) { if (productStockSumResponse.SpecId.Equals(detail.SpecId)) { stockAmount = StringUtils.FormatDataTwoDigitObject(StringUtils.FormatDataTwoDigit(productStockSumResponse.StockAmount)); } } } else { stockAmount = 0; } detail.Price = price; detail.StockAmount = stockAmount; GridRow row = new GridRow(detail.ProductId, detail.SpecId, detail.ProductNo, detail.ProductName, detail.SpecName, detail.Memo, detail.PackUnitName, detail.StockAmount, detail.DispatchUnitName, "0", detail.Price, "0", "", "删除"); row.Tag = detail; rows.Add(row); details.Add(detail); } } /// /// 保存单据 /// /// /// private void btn_saveProduct(object sender, EventArgs e) { this.buttonX4.Focus(); try { if (details.Count <= 0) { this.ShowToastNotify(this, "请选择原料"); return; } AskgoodsTicketAddRequest request = new AskgoodsTicketAddRequest(); request.StoreId = Global.Instance.BusinessPlanLog.StoreId; AskgoodsTicketAdd askgoodsTicketAdd = new AskgoodsTicketAdd(); askgoodsTicketAdd.No = this.busNoTextBox.Text; askgoodsTicketAdd.StoreId = Global.Instance.Authc.StoreId; askgoodsTicketAdd.Description = this.memoTextBox.Text; askgoodsTicketAdd.ProductMoney = StringUtils.FormatDataTwoDigitObject(this.productMoneyTextBox.Text); askgoodsTicketAdd.DispatchMoney = StringUtils.FormatDataTwoDigitObject(this.dispatchMoneyTextBox.Text); askgoodsTicketAdd.TotalMoney = StringUtils.FormatDataTwoDigitObject(this.totalMoneyTextBox.Text); askgoodsTicketAdd.SetMan = Global.Instance.BusinessPlanLog.WorkerNo; //便利获取原料信息 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 SpecId = StringUtils.GetString(row.Cells["SpecId"].Value); var Amount = StringUtils.FormatDataTwoDigitObject(row.Cells["amount"].Value); var productName = StringUtils.GetString(row.Cells["productName"].Value); bool AskGoodsCount = Global.Instance.GlobalConfigBoolValue(ConfigConstant.CONFIG_CASHIER_ASKGOODSCOUNT, false); if (Amount <= 0) { if (!AskGoodsCount) { var dialog = new DialogForm("错误提示", string.Format("<{0}>要货数量<{1}>,请调整", productName, Amount), MessageBoxIcon.Error, MessageBoxButtons.OK); dialog.ShowDialog(this); row.IsSelected = true; return; } } var Price = StringUtils.FormatDataTwoDigitObject(row.Cells["price"].Value); var Money = StringUtils.FormatDataTwoDigitObject(row.Cells["money"].Value); var Description = StringUtils.GetString(row.Cells["description"].Value); AskgoodsTicketAddDetail askgoodsTicketAddDetail = new AskgoodsTicketAddDetail(); askgoodsTicketAddDetail.ProductId = ProductId; askgoodsTicketAddDetail.SpecId = SpecId; askgoodsTicketAddDetail.Amount = Amount; askgoodsTicketAddDetail.Price = Price; askgoodsTicketAddDetail.Money = Money; askgoodsTicketAddDetail.Description = Description; addDetail.Add(askgoodsTicketAddDetail); } } askgoodsTicketAdd.Detail = addDetail; request.AskgoodsTicketAdd = askgoodsTicketAdd; var response = StockUtils.AskgoodsTicketAdd(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 == "amount") { var row = cell.GridRow; var price = StringUtils.FormatDataTwoDigitObject(row.Cells["price"].Value); var amount = StringUtils.FormatDataTwoDigitObject(row.Cells["amount"].Value); if(amount < 0) { this.ShowToastNotify(this, "数量非法"); row.Cells["amount"].Value = 0; amount = 0; } var money = price* amount; row.Cells["money"].Value = StringUtils.FormatDataTwoDigitObject(money); decimal productMoney = 0.00M; //便利获取原料总额 var rows = this.detailListTable.PrimaryGrid.Rows; if (rows.Count > 0) { foreach (var temRow in rows) { GridRow amountRow = temRow as GridRow; var Money = StringUtils.FormatDataTwoDigitObject(amountRow.Cells["money"].Value); productMoney = productMoney + Money; } } this.productMoneyTextBox.Text = StringUtils.GetString(StringUtils.FormatDataTwoDigitObject(productMoney)); this.totalMoneyTextBox.Text = StringUtils.GetString(StringUtils.FormatDataTwoDigitObject(this.productMoneyTextBox.Text)+ StringUtils.FormatDataTwoDigitObject(this.dispatchMoneyTextBox.Text)); } } private void btn_selectTemplate(object sender, EventArgs e) { var form = new AskgoodsTemplateForm(ids); form.OnMaterialDetailClick += Form_OnProductClick; TransparentForm trans = new TransparentForm(this, form); trans.Show(this); } public delegate void EventHandler(object sender); public event EventHandler OnTicktQuery; private void OnBeginEdit(object sender, GridEditEventArgs e) { var cell = e.GridCell; var cellPoint = this.detailListTable.PointToScreen(cell.LocationRelative); if (cell.GridColumn.Name == "amount") { 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(); } private void OnCellClick(object sender, GridCellClickEventArgs e) { if ("operation" == e.GridCell.GridColumn.Name) { GridRow selectRow = (GridRow)this.detailListTable.PrimaryGrid.ActiveRow; if (selectRow != null) { var detail = selectRow.Tag as FoodMaterialDetailEntity; this.detailListTable.PrimaryGrid.Rows.Remove(selectRow); ids.Remove(detail.SpecId); details.Remove(detail); } decimal productMoney = 0.00M; //便利获取原料总额 var rows = this.detailListTable.PrimaryGrid.Rows; if (rows.Count > 0) { foreach (var temRow in rows) { GridRow amountRow = temRow as GridRow; var Money = StringUtils.FormatDataTwoDigitObject(amountRow.Cells["money"].Value); productMoney = productMoney + Money; } } this.productMoneyTextBox.Text = StringUtils.GetString(StringUtils.FormatDataTwoDigitObject(productMoney)); this.totalMoneyTextBox.Text = StringUtils.GetString(StringUtils.FormatDataTwoDigitObject(this.productMoneyTextBox.Text) + StringUtils.FormatDataTwoDigitObject(this.dispatchMoneyTextBox.Text)); } } private void btnIntelligent_Click(object sender, EventArgs e) { var form = new AskGoodsPredictionTurnover( ); TransparentForm trans = new TransparentForm(this, form); trans.ShowDialog(); var rows = this.detailListTable.PrimaryGrid.Rows; foreach (var detail in form.foods) { decimal price = 0; //获取原料价格 ProductDispatchpriceRequest request = new ProductDispatchpriceRequest(); request.StoreId = Global.Instance.BusinessPlanLog.StoreId; request.SpecIds = detail.SpecId; var response = StockUtils.ProductDispatchprice(request); //成功 if (response.Item1) { List list = response.Item3; foreach (ProductDispatchpriceResponse dispatchpriceResponse in list) { if (dispatchpriceResponse.SpecId.Equals(detail.SpecId)) { price = StringUtils.FormatDataTwoDigitObject(dispatchpriceResponse.DispatchPrice); } } } else { price = 0; } //获取原料门店库存 ProductStockSumRequest request1 = new ProductStockSumRequest(); request1.StoreId = Global.Instance.BusinessPlanLog.StoreId; request1.SpecIds = detail.SpecId; var response1 = StockUtils.ProductStockSum(request1); decimal stockAmount = 0; //成功 if (response1.Item1) { List list = response1.Item3; foreach (ProductStockSumResponse productStockSumResponse in list) { if (productStockSumResponse.SpecId.Equals(detail.SpecId)) { stockAmount = StringUtils.FormatDataTwoDigitObject(StringUtils.FormatDataTwoDigit(productStockSumResponse.StockAmount)); } } } else { stockAmount = 0; } detail.Price = price; detail.StockAmount = stockAmount; GridRow row = new GridRow(detail.ProductId, detail.SpecId, detail.ProductNo, detail.ProductName, detail.SpecName, detail.Memo, detail.PackUnitName, detail.StockAmount, detail.DispatchUnitName, detail.Amount, detail.Price, "0", detail.Description, "删除"); row.Tag = detail; rows.Add(row); details.Add(detail); } } } }