You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

306 lines
11 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using POSV.Card;
using POSV.Entity;
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 AskGoodsPredictionTurnover : BusinessForm
{
public AskGoodsPredictionTurnover()
{
InitializeComponent();
}
AskgoodsTurnoverResponse askgoodsTurnoverResponse = new AskgoodsTurnoverResponse();
public List<Entity.Stock.FoodMaterialDetailEntity> foods = new List<Entity.Stock.FoodMaterialDetailEntity>();
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.GetPredictionTurnover();
}
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, "打开屏幕键盘异常");
}
}
/// <summary>
/// 查询预计营业额
/// </summary>
private void GetPredictionTurnover()
{
AskgoodsTurnoverRequest request = new AskgoodsTurnoverRequest();
request.StoreId = Global.Instance.BusinessPlanLog.StoreId;
var _data = StockUtils.AskgoodsPreictdionTurnover(request);
if (_data.Item1)
{
this.askgoodsTurnoverResponse = _data.Item3;
this.askgoodsTurnoverResponse.PredictionTurnover.ForEach(f =>
{
f.PreDictionAmountFloat = f.PreDictionAmount;
});
this.turnoverTable.PrimaryGrid.DataSource = this.askgoodsTurnoverResponse.PredictionTurnover;
}
else
{
this.ShowToastNotify(this, _data.Item2);
}
}
/// <summary>
/// 获取数据库商品
/// </summary>
private void AbrufbildungDetail()
{
List<Entity.Stock.FoodMaterialDetailEntity> _entity = new List<Entity.Stock.FoodMaterialDetailEntity>();
AskgoodsPredictionProductRequest request = new AskgoodsPredictionProductRequest();
using (var db = Global.Instance.OpenDataBase)
{
StringBuilder sqlBuld = new StringBuilder();
sqlBuld.Append(" select " +
" pos_product.id as 'productId'," +
" pos_product_spec.id as 'specId'," +
" pos_product.name as 'productName'," +
" pos_product.\"no\" as 'productNo'," +
" pos_product_spec.name as 'specName'," +
" pos_product_stock.packUnitId as 'dispatchUnitId'," +
" pos_product_stock.packUnitName as 'dispatchUnitName'," +
" pos_product.spell as 'spell'," +
" pos_product.memo as 'memo'," +
" pos_product_stock.packUnitId as 'packUnitId'," +
" pos_product_stock.packUnitName as 'packUnitName'," +
" pos_product_spec.thUseLevel as 'thUseLevel'" +
" from pos_product_spec" +
" LEFT JOIN pos_product on pos_product.id = pos_product_spec.productId" +
" LEFT JOIN pos_product_stock on pos_product_stock.productId = pos_product_spec.productId" +
" where thUseLevel > 0 ");
_entity = db.Query<Entity.Stock.FoodMaterialDetailEntity>(sqlBuld.ToString()).ToList();
}
if (_entity.Count <= 0)
{
this.ShowToastNotify(this, "无万用量数据");
return;
}
var _ids = _entity.Select(f => f.SpecId);
request.StoreId = Global.Instance.BusinessPlanLog.StoreId;
request.ProductIds = string.Join(",", _ids);
var _data = StockUtils.AskgoodsPredictionProductStock(request);
if (_data.Item1)
{
//(营业额 / 10000 * 万元用量 -当前库存 - 待入库数量 = 实际要货数量
var _ch = this.ToChinese(askgoodsTurnoverResponse.AdvanceDay, askgoodsTurnoverResponse.GoodsDay);
var _turnover = this.askgoodsTurnoverResponse.PredictionTurnover.Where(f => _ch.Contains(f.WeekDay));
//if (_turnover.Count() != int.Parse(this.askgoodsTurnoverResponse.GoodsDay))
//{
// this.ShowToastNotify(this, "获取计划要货数据不等于设置计划要货数,数据异常请联系管理员");
// return;
//}
foreach (var item in _turnover)
{
foreach (var _costitem in _data.Item3.costTickets)
{
var _specitem = _entity.FirstOrDefault(f => f.ProductId == _costitem.ProductId);
if (_specitem == null)
{
continue;
}
if (_specitem.thUseLevel == 0)
{
continue;
}
// _specitem.Description = "智能要货";
var _DispatchStockdata = _data.Item3.DispatchTickets.FirstOrDefault(f => f.ProductId == _costitem.ProductId);
decimal DispatchStock = 0.00M;
if (_DispatchStockdata == null)
{
DispatchStock = 0;
}
else
{
DispatchStock = decimal.Parse(_DispatchStockdata.DispatchStock);
}
_specitem.Amount = (item.PreDictionAmountFloat / 10000 * _specitem.thUseLevel) - decimal.Parse(_costitem.YeterdayStock) - DispatchStock;
_specitem.Amount = Math.Floor(_specitem.Amount);
if (_specitem.Amount < 0)
{
continue;
}
foods.Add(_specitem);
}
}
}
else
{
}
}
/// <summary>
/// 阿拉伯转中文
/// </summary>
/// <returns></returns>
private List<string> ToChinese(string advanceDay, string goodsDay)
{
var _advanceDay = (System.DateTime.Now.DayOfWeek + 1) + int.Parse(advanceDay);
List<string> DayOfWeeks = new List<string>();
for (int i = 0; i < int.Parse(goodsDay); i++)
{
switch ((int)_advanceDay)
{
case 7:
DayOfWeeks.Add("日");
break;
case 1:
DayOfWeeks.Add("一");
break;
case 2:
DayOfWeeks.Add("二");
break;
case 3:
DayOfWeeks.Add("三");
break;
case 4:
DayOfWeeks.Add("四");
break;
case 5:
DayOfWeeks.Add("五");
break;
case 6:
DayOfWeeks.Add("六");
break;
}
if ((int)_advanceDay == 7)
{
//Monday值等于1
_advanceDay = DayOfWeek.Monday;
}
else
{
_advanceDay++;
}
}
return DayOfWeeks;
}
private void btnFloating_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.proportionTextBox.Text))
{
this.ShowToastNotify(this, "请输入浮动比例");
return;
}
if (this.proportionTextBox.DecimalValue <= 0 || this.proportionTextBox.DecimalValue > 100)
{
this.ShowToastNotify(this, "请输入1-100的数值");
return;
}
this.askgoodsTurnoverResponse.PredictionTurnover.ForEach(f =>
{
var _txt = sender as DevComponents.DotNetBar.ButtonX;
if (_txt == null)
{
return;
};
f.PreDictionAmountExplain = _txt.Text + " - " + this.proportionTextBox.DecimalValue + "%";
if (_txt.Text.Equals("上浮"))
{
f.PreDictionAmountFloat = f.PreDictionAmount + (f.PreDictionAmount * (this.proportionTextBox.DecimalValue * 0.01M));
}
else
{
f.PreDictionAmountFloat = f.PreDictionAmount - (f.PreDictionAmount * (this.proportionTextBox.DecimalValue * 0.01M));
}
});
this.turnoverTable.PrimaryGrid.DataSource = this.askgoodsTurnoverResponse.PredictionTurnover;
}
private void btnClose_Click(object sender, EventArgs e)
{
OnCloseTouchClick(sender, e);
}
private void btnConfirm_Click(object sender, EventArgs e)
{
AbrufbildungDetail();
OnCloseTouchClick(sender, e);
}
}
}