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.

251 lines
8.9 KiB
C#

using DevComponents.DotNetBar;
using DevComponents.DotNetBar.Controls;
using DevComponents.DotNetBar.Metro;
using DevComponents.DotNetBar.SuperGrid;
using POSV.Card;
using POSV.Entity;
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 ProductStockForm : BusinessForm
{
private List<StoreStorage> storageList = new List<StoreStorage>();
private string storageId = null;
public int GoodsType = 0;//状态
public ProductStockForm()
{
InitializeComponent();
this.controlBox1.Text = "门店库存查询";
this.controlBox1.ShowApplicationVersion = false;
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (this.DesignMode) return;
this.Focus();
this.noTextBox.Focus();
this.noTextBox.SelectAll();
this.ActiveControl = this.noTextBox;
GoodsType = -1;
//仓库列表
InitStorageMenu();
}
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<StoreStorage>(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);
}
public void ProductStockQuery(int PageNum, int pageSize)
{
try
{
var request = new ProductStockRequest();
request.StoreId = Global.Instance.Authc.StoreId;
request.StorageId = storageId;
request.GoodsType = GoodsType;
request.Keyword = this.noTextBox.Text;
request.PageNumber = PageNum;
request.PageSize = pageSize;
var response = StockUtils.ProductStock(request);
//成功
if (response.Item1)
{
this.ShowToastNotify(this, response.Item2);
List<ProductStockResponse> productStockResponse = response.Item3.List;
this.pagerControl1.TotalPage = response.Item3.PageCount;
this.pagerControl1.CurrentPage = response.Item3.PageNumber;
this.pagerControl1.RecordCount = response.Item3.TotalCount;
this.pagerControl1.RowsPerPage = response.Item3.PageSize;
foreach (ProductStockResponse productStock in productStockResponse) {
string stockDescription = "";
if (productStock.SalesUnitId.Equals(productStock.PackUnitId)) {
stockDescription = string.Format("{0}{1}", StringUtils.FormatDataTwoDigit(productStock.StockAmount), productStock.SalesUnitName);
}
else {
int PackUnitAmount = (int)productStock.StockAmount;
decimal SalesUnitAmount = (productStock.StockAmount - PackUnitAmount) * productStock.PsScale;
stockDescription = string.Format("{0}{1}{2}{3}", PackUnitAmount, productStock.PackUnitName, StringUtils.FormatDataTwoDigit(SalesUnitAmount), productStock.SalesUnitName);
}
productStock.SalesAmount = StringUtils.FormatDataTwoDigit(productStock.StockAmount * productStock.PsScale);
productStock.StockDescription = stockDescription;
}
stockListTable.PrimaryGrid.DataSource = productStockResponse;
}
else
{
List<ProductStockResponse> list = new List<ProductStockResponse>();
stockListTable.PrimaryGrid.DataSource = list;
this.ShowToastNotify(this, response.Item2);
}
}
catch (Exception ex)
{
this.ShowToastNotify(this, "门店库存查询异常");
LOGGER.Error(ex, "门店库存查询异常");
}
}
private void exitClick(object sender, EventArgs e)
{
//先关闭父窗体
if (this.Owner != null)
{
this.Owner.Close();
}
//再关闭当前窗体
this.Close();
}
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 in_keyword_Enter(object sender, Component.EnterEventArg e)
{
//获得当前页
int cur = pagerControl1.CurrentPage;
//获得每页显示的记录数
int rows = pagerControl1.RowsPerPage;
ProductStockQuery(cur, rows);
}
private void queryClick(object sender, EventArgs e)
{
//获得当前页
int cur = pagerControl1.CurrentPage;
//获得每页显示的记录数
int rows = pagerControl1.RowsPerPage;
ProductStockQuery(cur, rows);
}
private void cb_change_click(object sender, EventArgs e)
{
var obj = sender as CheckBoxX;
var indexT = obj.Tag as string;
if ("全部".Equals(indexT) && obj.Checked)
{
GoodsType = -1;
}
if ("普通商品".Equals(indexT) && obj.Checked)
{
GoodsType = 0;
}
if ("成品".Equals(indexT) && obj.Checked)
{
GoodsType = 1;
}
if ("原料".Equals(indexT) && obj.Checked)
{
GoodsType = 10;
}
if ("辅料".Equals(indexT) && obj.Checked)
{
GoodsType = 11;
}
if ("半成品".Equals(indexT) && obj.Checked)
{
GoodsType = 12;
}
//获得当前页
int cur = pagerControl1.CurrentPage;
//获得每页显示的记录数
int rows = pagerControl1.RowsPerPage;
ProductStockQuery(cur, rows);
}
//private void OnDataBindingComplete(object sender, DevComponents.DotNetBar.SuperGrid.GridDataBindingCompleteEventArgs e)
//{
// var rows = e.GridPanel.Rows;
// foreach (GridRow row in rows)
// {
// row.Cells["stockAmount"].Value = StringUtils.FormatDataTwoDigit(Convert.ToDecimal(row.Cells["stockAmount"].Value));
// row.Cells["stockCost"].Value = StringUtils.FormatDataTwoDigit(Convert.ToDecimal(row.Cells["stockCost"].Value));
// }
//}
private void OnPageChange(object obj)
{
queryClick(obj, null);
}
}
}