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.
530 lines
18 KiB
C#
530 lines
18 KiB
C#
using DevComponents.DotNetBar;
|
|
using DevComponents.DotNetBar.Metro;
|
|
using POSV.Card;
|
|
using POSV.Component;
|
|
using POSV.Entity;
|
|
using POSV.Entity.Stock;
|
|
using POSV.MessageEvent;
|
|
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 StoreStockCheckSelectProductForm : BusinessForm
|
|
{
|
|
|
|
private int DefaultCategoryItemWidth = 100;
|
|
|
|
private Size DefaultMainMenuSize = Size.Empty;
|
|
|
|
private Size DefaultSubMenuSize = Size.Empty;
|
|
|
|
private int DefaultPaddingLeftRight = -2;
|
|
|
|
private List<FoodMaterialSeriesEntity> seriesList = new List<FoodMaterialSeriesEntity>();
|
|
|
|
private List<FoodMaterialTypeEntity> typeList = new List<FoodMaterialTypeEntity>();
|
|
|
|
private string storageId = "";
|
|
|
|
private List<string> selectMaterialList = new List<string>();
|
|
|
|
private string productTypeIds;
|
|
|
|
private string _TypeLimit;
|
|
|
|
public StoreStockCheckSelectProductForm(string storageId, List<string> ids, string typeLimit)
|
|
{
|
|
InitializeComponent();
|
|
|
|
selectMaterialList = ids ?? new List<string>();
|
|
this.storageId = storageId;
|
|
|
|
_TypeLimit = typeLimit;
|
|
|
|
this.controlBox1.Text = "选择商品";
|
|
this.controlBox1.ShowApplicationVersion = false;
|
|
|
|
this.mainCategoryPage.OnPageChange += OnMainCategoryPageChange;
|
|
this.subCategoryPage.OnPageChange += OnSubCategoryPageChange;
|
|
|
|
this.productSelectControl1.FoodMaterialCheckedChanged += ProductSelectControl1_FoodMaterialCheckedChanged;
|
|
}
|
|
|
|
private void ProductSelectControl1_FoodMaterialCheckedChanged(object sender, Component.FoodMaterialEventArgs e)
|
|
{
|
|
var product = e.Entity;
|
|
|
|
try
|
|
{
|
|
StockCheckProductValidRequest request = new StockCheckProductValidRequest();
|
|
request.StoreId = Global.Instance.BusinessPlanLog.StoreId;
|
|
request.StorageId = this.storageId;
|
|
request.SpecIds = product.SpecId;
|
|
var response = StockUtils.StockCheckProductValid(request);
|
|
//成功
|
|
if (response.Item1 && response.Item3.List != null && response.Item3.List.Count <= 0)
|
|
{
|
|
this.ShowToastNotify(this, "未审核盘点明细已包含此原料");
|
|
return;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.ShowToastNotify(this, "获取可盘点商品信息失败");
|
|
|
|
LOGGER.Error(ex, "获取可盘点商品信息失败");
|
|
}
|
|
if (!selectMaterialList.Contains(String.Format("{0}-{1}", storageId, product.SpecId)))
|
|
{
|
|
selectMaterialList.Add(String.Format("{0}-{1}", storageId, product.SpecId));
|
|
OnProductClick?.Invoke(sender, new MaterialDetailEventArgs(product));
|
|
}
|
|
|
|
}
|
|
|
|
private void OnMainCategoryPageChange(object sender, EventArgs e)
|
|
{
|
|
RefreshMain();
|
|
}
|
|
|
|
private void OnSubCategoryPageChange(object sender, EventArgs e)
|
|
{
|
|
RefreshSub();
|
|
}
|
|
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
{
|
|
base.OnLoad(e);
|
|
|
|
if (this.DesignMode) return;
|
|
|
|
DefaultMainMenuSize = new Size(DefaultCategoryItemWidth, this.mainCategoryPage.Height);
|
|
|
|
DefaultSubMenuSize = new Size(DefaultCategoryItemWidth, this.subCategoryPage.Height);
|
|
|
|
InitMainMenu();
|
|
}
|
|
|
|
private void InitMainMenu()
|
|
{
|
|
try
|
|
{
|
|
string sql = null;
|
|
if (_TypeLimit == ">=10")
|
|
{
|
|
sql = @" select typePath from pos_product where type >= 10 and stockFlag = 1 and stopFlag=0 group by typePath ;";
|
|
}
|
|
else
|
|
{
|
|
sql = @" select typePath from pos_product where stockFlag = 1 and stopFlag=0 group by typePath ;";
|
|
}
|
|
using (var db = Global.Instance.OpenDataBase)
|
|
{
|
|
List<Product> productList = db.Fetch<Product>(sql);
|
|
productTypeIds = "";
|
|
foreach (Product product in productList)
|
|
{
|
|
if (string.IsNullOrEmpty(productTypeIds))
|
|
{
|
|
productTypeIds = string.Format("{0}", product.TypePath);
|
|
}
|
|
else
|
|
{
|
|
productTypeIds += string.Format(",{0}", product.TypePath);
|
|
}
|
|
}
|
|
sql = string.Format(" select id,tenantId,parentId,path,no,name,color from pos_product_type where id in ({0}) and (parentId is null or parentId ='') order by no asc ;", productTypeIds);
|
|
seriesList = db.Fetch<FoodMaterialSeriesEntity>(sql);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LOGGER.Error(ex);
|
|
}
|
|
RefreshMain();
|
|
}
|
|
|
|
private void RefreshMain()
|
|
{
|
|
ItemContainer ic = new ItemContainer();
|
|
|
|
MetroTileItem firstItem = null;
|
|
if (seriesList != null && seriesList.Count > 0)
|
|
{
|
|
this.mainCategoryPage.TotalCount = seriesList.Count;
|
|
this.mainCategoryPage.itemWidth = DefaultCategoryItemWidth;
|
|
//分页
|
|
var pageSeriesList = this.mainCategoryPage.ListPager<FoodMaterialSeriesEntity>(seriesList);
|
|
|
|
ic.MultiLine = false;
|
|
ic.ItemSpacing = 1;
|
|
ic.ResizeItemsToFit = false; //很关键
|
|
|
|
foreach (var series in pageSeriesList)
|
|
{
|
|
MetroTileItem item = new MetroTileItem();
|
|
|
|
item.CheckBehavior = eMetroTileCheckBehavior.None;
|
|
item.Checked = false;
|
|
|
|
item.OptionGroup = "MainMenu";
|
|
|
|
item.TileStyle.TextAlignment = eStyleTextAlignment.Center;
|
|
item.Text = series.Name;
|
|
item.TileSize = DefaultMainMenuSize;
|
|
|
|
item.TileStyle.TextColor = Color.White;
|
|
item.TileStyle.BackColor = ColorTranslator.FromHtml("#333333");
|
|
item.TileStyle.BackColor2 = ColorTranslator.FromHtml("#333333");
|
|
item.TileStyle.BorderColor = Color.Transparent;
|
|
item.TileStyle.BorderColor2 = Color.Transparent;
|
|
|
|
item.TileStyle.PaddingLeft = DefaultPaddingLeftRight;
|
|
item.TileStyle.PaddingRight = DefaultPaddingLeftRight;
|
|
|
|
item.Tag = series;
|
|
|
|
if (firstItem == null)
|
|
{
|
|
firstItem = item;
|
|
}
|
|
|
|
item.MouseDown += OnMainMenuMouseDown;
|
|
item.CheckedChanged += OnMainItemCheckedChange;
|
|
ic.SubItems.Add(item);
|
|
}
|
|
|
|
}
|
|
this.mainCategoryPage.RefreshUI(ic);
|
|
|
|
if (firstItem != null)
|
|
{
|
|
firstItem.Checked = true;
|
|
}
|
|
}
|
|
|
|
private void OnMainItemCheckedChange(object sender, EventArgs e)
|
|
{
|
|
MetroTileItem obj = sender as MetroTileItem;
|
|
if (obj.Checked)
|
|
{
|
|
obj.TileStyle.BackColor = ColorTranslator.FromHtml("#993366");
|
|
obj.TileStyle.BackColor2 = ColorTranslator.FromHtml("#993366");
|
|
|
|
//加载子类
|
|
var series = obj.Tag as FoodMaterialSeriesEntity;
|
|
|
|
using (var db = Global.Instance.OpenDataBase)
|
|
{
|
|
string sql = string.Format(" select id,tenantId,parentId,path,no,name,color from pos_product_type where id in ({0}) and parentId is not null and parentId<>'' and path like '{1}%' order by no asc ;", productTypeIds, series.Path);
|
|
typeList = db.Fetch<FoodMaterialTypeEntity>(sql);
|
|
}
|
|
|
|
RefreshSub();
|
|
//加载大类下商品
|
|
LoadMaterialDetail(series.Path);
|
|
}
|
|
else
|
|
{
|
|
obj.TileStyle.BackColor = ColorTranslator.FromHtml("#333333");
|
|
obj.TileStyle.BackColor2 = ColorTranslator.FromHtml("#333333");
|
|
}
|
|
}
|
|
|
|
private void PreLoadProduct(string sql)
|
|
{
|
|
List<FoodMaterialDetailEntity> detailList = new List<FoodMaterialDetailEntity>();
|
|
|
|
using (var db = Global.Instance.OpenDataBase)
|
|
{
|
|
detailList = db.Query<FoodMaterialDetailEntity>(sql).ToList();
|
|
if (detailList == null)
|
|
{
|
|
detailList = new List<FoodMaterialDetailEntity>();
|
|
}
|
|
|
|
}
|
|
List<string> nowSelectMaterialList = new List<string>();
|
|
foreach (string id in selectMaterialList)
|
|
{
|
|
string[] specId = id.Split('-');
|
|
if (this.storageId.Equals(specId[0]))
|
|
{
|
|
nowSelectMaterialList.Add(specId[1]);
|
|
}
|
|
}
|
|
this.productSelectControl1.SelectedIds = nowSelectMaterialList;
|
|
this.productSelectControl1.BindDataSource(detailList);
|
|
}
|
|
|
|
private void LoadMaterialDetail(string typePath)
|
|
{
|
|
|
|
string sql = null;
|
|
if (_TypeLimit == ">=10")
|
|
{
|
|
sql = SqlConstant.YHProductExt + " and a.type>=10 and a.typePath like '{0}%' order by a.no;";
|
|
}
|
|
else
|
|
{
|
|
sql = SqlConstant.YHProductExt + " and a.typePath like '{0}%' order by a.no;";
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(typePath))
|
|
{
|
|
PreLoadProduct(string.Format(sql, typePath));
|
|
}
|
|
//else
|
|
//{
|
|
// if (!string.IsNullOrEmpty(keyWord))
|
|
// {
|
|
// using (var db = Global.Instance.OpenDataBase)
|
|
// {
|
|
// sqlBuld.Append(" and ( a.spell like '%{0}%' or a.no like '%{1}%' or a.name like '%{2}%')");
|
|
// string sql = string.Format(sqlBuld.ToString(), keyWord, keyWord, keyWord);
|
|
// detailList = db.Query<FoodMaterialDetailEntity>(sql).ToList();
|
|
// if (detailList == null)
|
|
// {
|
|
// detailList = new List<FoodMaterialDetailEntity>();
|
|
// }
|
|
// }
|
|
// }
|
|
//}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 发送选择的原料信息
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnDetailMouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
MetroTileItem obj = sender as MetroTileItem;
|
|
FoodMaterialDetailEntity detail = (FoodMaterialDetailEntity)obj.Tag;
|
|
|
|
obj.TileStyle.BackColor = ColorTranslator.FromHtml("#993366");
|
|
obj.TileStyle.BackColor2 = ColorTranslator.FromHtml("#993366");
|
|
|
|
//加入选中项
|
|
if (!selectMaterialList.Contains(String.Format("{0}-{1}", storageId, detail.SpecId)))
|
|
{
|
|
selectMaterialList.Add(String.Format("{0}-{1}", storageId, detail.SpecId));
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private void RefreshSub()
|
|
{
|
|
ItemContainer ic = new ItemContainer();
|
|
|
|
if (typeList.Count > 0)
|
|
{
|
|
this.subCategoryPage.TotalCount = typeList.Count;
|
|
this.subCategoryPage.itemWidth = DefaultCategoryItemWidth;
|
|
//分页
|
|
var pageTypeList = this.subCategoryPage.ListPager<FoodMaterialTypeEntity>(typeList);
|
|
|
|
ic.MultiLine = false;
|
|
ic.ItemSpacing = 1;
|
|
ic.ResizeItemsToFit = false; //很关键
|
|
|
|
|
|
foreach (var type in pageTypeList)
|
|
{
|
|
MetroTileItem item = new MetroTileItem();
|
|
|
|
item.CheckBehavior = eMetroTileCheckBehavior.None;
|
|
item.Checked = false;
|
|
|
|
item.OptionGroup = "SubMenu";
|
|
|
|
item.TileStyle.TextAlignment = eStyleTextAlignment.Center;
|
|
item.Text = type.Name;
|
|
item.TileSize = DefaultSubMenuSize;
|
|
|
|
item.TileStyle.TextColor = Color.White;
|
|
item.TileStyle.BackColor = Color.Teal;
|
|
item.TileStyle.BackColor2 = Color.Teal;
|
|
item.TileStyle.BorderColor = Color.Transparent;
|
|
item.TileStyle.BorderColor2 = Color.Transparent;
|
|
|
|
item.TileStyle.PaddingLeft = DefaultPaddingLeftRight;
|
|
item.TileStyle.PaddingRight = DefaultPaddingLeftRight;
|
|
|
|
item.Tag = type;
|
|
|
|
item.MouseDown += OnSubMenuMouseDown;
|
|
item.CheckedChanged += OnSubMenuCheckedChanged;
|
|
ic.SubItems.Add(item);
|
|
}
|
|
|
|
}
|
|
|
|
this.subCategoryPage.RefreshUI(ic);
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 加载子菜单
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnMainMenuMouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
MetroTileItem obj = sender as MetroTileItem;
|
|
obj.Checked = true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 加载小类原料
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnSubMenuMouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
MetroTileItem obj = sender as MetroTileItem;
|
|
obj.Checked = true;
|
|
}
|
|
|
|
private void OnSubMenuCheckedChanged(object sender, EventArgs e)
|
|
{
|
|
MetroTileItem obj = sender as MetroTileItem;
|
|
if (obj.Checked)
|
|
{
|
|
obj.TileStyle.BackColor = ColorTranslator.FromHtml("#993366");
|
|
obj.TileStyle.BackColor2 = ColorTranslator.FromHtml("#993366");
|
|
|
|
//加载商品信息
|
|
var type = obj.Tag as FoodMaterialTypeEntity;
|
|
LoadMaterialDetail(type.Path);
|
|
}
|
|
else
|
|
{
|
|
obj.TileStyle.BackColor = Color.Teal;
|
|
obj.TileStyle.BackColor2 = Color.Teal;
|
|
}
|
|
}
|
|
|
|
private void OnCloseTouchClick(object sender, EventArgs e)
|
|
{
|
|
//先关闭父窗体
|
|
if (this.Owner != null)
|
|
{
|
|
this.Owner.Close();
|
|
}
|
|
//再关闭当前窗体
|
|
this.Close();
|
|
}
|
|
|
|
private void ExitClick(object sender, EventArgs e)
|
|
{
|
|
//先关闭父窗体
|
|
if (this.Owner != null)
|
|
{
|
|
this.Owner.Close();
|
|
}
|
|
//再关闭当前窗体
|
|
this.Close();
|
|
}
|
|
|
|
private void in_KeyWord_Enter(object sender, Component.EnterEventArg e)
|
|
{
|
|
//加载关键词下的原料
|
|
string keyWord = this.txtSearch.Text;
|
|
LoadMaterialDetail(null);
|
|
}
|
|
|
|
public delegate void EventHandler(object sender, MaterialDetailEventArgs e);
|
|
|
|
public event EventHandler OnProductClick;
|
|
|
|
private void OnShowKeyboardClick(object sender, EventArgs e)
|
|
{
|
|
if (SimpleKeyboard.Showing())
|
|
{
|
|
SimpleKeyboard.CloseKeyboard();
|
|
}
|
|
else
|
|
{
|
|
|
|
var location = this.doubleBufferPanelX1.PointToScreen(Point.Empty);
|
|
location.Y -= 300;
|
|
|
|
var size = new Size(this.doubleBufferPanelX1.Width, 300);
|
|
|
|
//var action = new Action<string>((args) => {
|
|
// this.txtSearch.Text = (args != null ? args.ToString() : string.Empty);
|
|
//});
|
|
//SimpleKeyboard.ShowKeyboard(this , location , size , true, action);
|
|
|
|
SimpleKeyboard.ShowKeyboard(this, location, size, false, null);
|
|
}
|
|
}
|
|
|
|
private void OnTextChanged(object sender, EventArgs e)
|
|
{
|
|
var search = this.txtSearch.Text.Trim();
|
|
if (string.IsNullOrEmpty(search))
|
|
{
|
|
return;
|
|
}
|
|
|
|
SearchProduct(search);
|
|
}
|
|
|
|
private void SearchProduct(string search)
|
|
{
|
|
|
|
Task.Factory.StartNew(() =>
|
|
{
|
|
this.Invoke(new Action(() =>
|
|
{
|
|
string template = string.Empty;
|
|
if (_TypeLimit == ">=10")
|
|
{
|
|
template = SqlConstant.YHProductExt + " and a.type>=10 ";
|
|
}
|
|
else
|
|
{
|
|
template = SqlConstant.YHProductExt;
|
|
}
|
|
template += " and (a.spell like '%{0}%' or a.barCode like '%{1}%' or a.no like '%{2}%') order by a.no;";
|
|
string sql = string.Format(template, search, search, search);
|
|
|
|
PreLoadProduct(sql);
|
|
|
|
}));
|
|
return true;
|
|
|
|
}).ContinueWith(task =>
|
|
{
|
|
if (task.Result)
|
|
{
|
|
this.Invoke(new Action(() =>
|
|
{
|
|
MsgEvent.Send(Constant.PRODUCTSELECT_KEYBOARD_NOTIFY, KeyboardAction.Search);
|
|
//if (autoSubmit)
|
|
//{
|
|
// MsgEvent.Send(Constant.PRODUCT_KEYBOARD_NOTIFY, KeyboardAction.Enter);
|
|
//}
|
|
}));
|
|
}
|
|
|
|
});
|
|
}
|
|
|
|
}
|
|
}
|