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.

353 lines
12 KiB
C#

using DevComponents.DotNetBar;
using DevComponents.DotNetBar.Metro;
using POSV.Card;
using POSV.Component;
using POSV.Entity.WeiXinDc;
using POSV.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace POSV.WeiXin
{
public partial class WeiXinProductForm : BusinessForm
{
private int DefaultCategoryItemWidth = 100;
private Size DefaultMainMenuSize = Size.Empty;
private int DefaultPaddingLeftRight = -2;
private List<WxdcGoodsCategoryEntity> seriesList = new List<WxdcGoodsCategoryEntity>();
private List<string> selectGoodsIdList = new List<string>();
private string _categoryId;
WeiXinShopInfoResponse poiInfo = null;
public WeiXinProductForm()
{
InitializeComponent();
this.controlBox1.Text = "选择商品";
this.controlBox1.ShowApplicationVersion = false;
this.mainCategoryPage.OnPageChange += OnMainCategoryPageChange;
this.weiXinProductSelectControl1.WxdcCheckedChanged += WeiXinProductSelectControl1_ProductCheckedChanged;
}
private void WeiXinProductSelectControl1_ProductCheckedChanged(object sender, WxdcEventArgs e)
{
var product = e.Entity;
if (!selectGoodsIdList.Contains(product.ProductId))
{
selectGoodsIdList.Add(product.ProductId);
}
}
private void OnMainCategoryPageChange(object sender, EventArgs e)
{
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<WxdcGoodsCategoryEntity>(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 += OnSubMenuCheckedChanged;
ic.SubItems.Add(item);
}
}
this.mainCategoryPage.RefreshUI(ic);
if (firstItem != null)
{
firstItem.Checked = true;
}
}
/// <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;
}
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 WxdcGoodsCategoryEntity;
LoadMaterialDetail(type.Id);
}
else
{
obj.TileStyle.BackColor = Color.Teal;
obj.TileStyle.BackColor2 = Color.Teal;
}
}
private void LoadMaterialDetail(string categoryId)
{
this._categoryId = categoryId;
WxdcGoodsListRequest request = new WxdcGoodsListRequest();
request.StoreId = poiInfo.Id;
request.CategoryId = categoryId;
request.PageNumber = 1;
request.PageSize = 1500;
var response = WeiXinOrderUtils.WxdcGoods(request);
if (response != null && response.Item1)
{
List<WxdcGoodsEntity> detailList = new List<WxdcGoodsEntity>();
detailList = response.Item3.List;
this.weiXinProductSelectControl1.SelectedIds = selectGoodsIdList;
this.weiXinProductSelectControl1.PageNumber = 1;
this.weiXinProductSelectControl1.BindDataSource(detailList);
}
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
DefaultMainMenuSize = new Size(DefaultCategoryItemWidth, this.mainCategoryPage.Height);
//第一步加载门店信息
QueryWeixinPoiInfo();
}
private void QueryWeixinPoiInfo()
{
WeiXinShopInfoRequest request = new WeiXinShopInfoRequest();
request.StoreId = Global.Instance.BusinessPlanLog.StoreId;
var response = WeiXinOrderUtils.WeiXinShopInfo(request);
if (response != null && response.Item1)
{
var responseMessage = response.Item3;
if (responseMessage != null && responseMessage.Data != null)
{
poiInfo = responseMessage.Data;
this.StoreNameLabelX.Text = poiInfo.Name;//门店名称
switch (poiInfo.IsOpen)
{
case 0:
this.isOpenLabelX.Text = "门店歇业";
break;
case 1:
this.isOpenLabelX.Text = "正在营业";
break;
default:
this.isOpenLabelX.Text = "门店歇业";
break;
}
this.openTimeLabelX.Text = StringUtils.GetString(poiInfo.OpenTime);
WxdcGoodsCategoryListRequest request1 = new WxdcGoodsCategoryListRequest();
request1.StoreId = poiInfo.Id;
var response1 = WeiXinOrderUtils.WxdcGoodsCategory(request1);
if (response1 != null && response.Item1) {
seriesList = response1.Item3.List;
RefreshMain();
}
}
}
}
private void OnControlBoxCloseClick(object sender, EventArgs e)
{
OnCloseTouchClick(sender, e);
}
private void OnControlBoxMinClick(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
private void OnCloseTouchClick(object sender, EventArgs e)
{
//先关闭父窗体
if (this.Owner != null)
{
this.Owner.Close();
}
//再关闭当前窗体
this.Close();
}
private void BtnClose(object sender, EventArgs e)
{
OnCloseTouchClick(sender, e);
}
//开卖
private void BtnSellIn(object sender, EventArgs e)
{
if (selectGoodsIdList==null || selectGoodsIdList.Count<=0) {
this.ShowToastNotify(this, "请选择要开卖的单品");
return;
}
WxdcGoodsSellinRequest request = new WxdcGoodsSellinRequest();
request.StoreId = poiInfo.Id;
string productIds = "";
foreach (string id in selectGoodsIdList) {
productIds= productIds+id +",";
}
if (!"".Equals(productIds)) {
request.ProductIds = productIds.Substring(0, productIds.Length-1);
}
var response = WeiXinOrderUtils.WxdcGoodsSellin(request);
if (response != null && response.Item1)
{
this.ShowToastNotify(this, "操作成功");
selectGoodsIdList = new List<string>();
LoadMaterialDetail(this._categoryId);
}
else
{
this.ShowToastNotify(this, response.Item2);
}
}
//全部开卖
private void BtnSellAll(object sender, EventArgs e)
{
var dialog = new DialogForm("微信商品提醒", "是否全部开卖?", MessageBoxIcon.Question, MessageBoxButtons.OKCancel);
if (dialog.ShowDialog(this) == DialogResult.OK)
{
WxdcGoodsSellinRequest request = new WxdcGoodsSellinRequest();
request.StoreId = poiInfo.Id;
var response = WeiXinOrderUtils.WxdcGoodsSellin(request);
if (response != null && response.Item1)
{
this.ShowToastNotify(this, "操作成功");
selectGoodsIdList = new List<string>();
LoadMaterialDetail(this._categoryId);
}
else
{
this.ShowToastNotify(this, response.Item2);
}
}
}
//售罄
private void BtnSellOut(object sender, EventArgs e)
{
if (selectGoodsIdList == null || selectGoodsIdList.Count <= 0)
{
this.ShowToastNotify(this, "请选择要停售的单品");
return;
}
WxdcGoodsSellOutRequest request = new WxdcGoodsSellOutRequest();
request.StoreId = poiInfo.Id;
string productIds = "";
foreach (string id in selectGoodsIdList)
{
productIds = productIds + id + ",";
}
if (!"".Equals(productIds))
{
request.ProductIds = productIds.Substring(0, productIds.Length - 1);
}
var response = WeiXinOrderUtils.WxdcGoodsSellOut(request);
if (response != null && response.Item1)
{
this.ShowToastNotify(this, "操作成功");
selectGoodsIdList = new List<string>();
LoadMaterialDetail(this._categoryId);
}
else
{
this.ShowToastNotify(this, response.Item2);
}
}
//全部售罄
private void BtnSellOutAll(object sender, EventArgs e)
{
var dialog = new DialogForm("微信商品提醒", "是否全部售罄?", MessageBoxIcon.Question, MessageBoxButtons.OKCancel);
if (dialog.ShowDialog(this) == DialogResult.OK)
{
WxdcGoodsSellOutRequest request = new WxdcGoodsSellOutRequest();
request.StoreId = poiInfo.Id;
var response = WeiXinOrderUtils.WxdcGoodsSellOut(request);
if (response != null && response.Item1)
{
this.ShowToastNotify(this, "操作成功");
selectGoodsIdList = new List<string>();
LoadMaterialDetail(this._categoryId);
}
else
{
this.ShowToastNotify(this, response.Item2);
}
}
}
}
}