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.

247 lines
9.5 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 System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using JwKdsV.Entity.OrderPackage;
using JwKdsV.Core;
using System.Text.RegularExpressions;
namespace JwKdsV.Component
{
public partial class OrderItemPanel : UserControl
{
private ServiceOrderItem _item;
public bool isLast = false;
public OrderItemPanel()
{
InitializeComponent();
}
public void SetOrderItem(OrderType orderType, ServiceOrderItem item)
{
_item = item;
string name = item.ProductName;
//if (item.IsSuit == 3)
//{
// //套餐明细
// name = "[套]" + name;
//}
if (!string.IsNullOrEmpty(item.MakeDesc))
{
var makeColor = Global.Instance.GlobalConfigStringValue(ConfigConstant.CONFIG_BUSINESS_MAKECOLOR, "Red");
//name = string.Format("<br/><font color='{0}'>{1}</font>", makeColor, item.MakeDesc);
switch (orderType)
{
case OrderType.:
case OrderType.饿:
string[] makeArray = item.MakeDesc.Split(',');
string tempMake = "";
foreach (string str in makeArray)
{
if (!str.Contains("餐盒费"))
{
tempMake = tempMake + str + ",";
}
}
if (tempMake != null && tempMake.Length > 0)
{
tempMake = tempMake.Substring(0, tempMake.Length - 1);
}
this.makeLabel.Text = ToSBC(tempMake);
break;
default:
this.makeLabel.Text = ToSBC(item.MakeDesc);
break;
}
this.makeLabel.ForeColor = ColorTranslator.FromHtml(makeColor);
this.makeLabel.Visible = true;
this.makeLabel.WordWrap = true;
}
this.nameLabel.Text = name;
this.nameLabel.WordWrap = true;
//var names = StringHelper.WrapText2(name, this.nameLabel.Width, this.nameLabel.Width, this.nameLabel.Font);
//this.nameLabel.Text = string.Join(System.Environment.NewLine, names);
if (item.Quantity>0) {
this.numLabel.Text = string.Format("×{0}", item.Quantity);
}
else
{
this.numLabel.Text = "";
}
//划菜临时标识,特殊颜色显示
if (_item.HuacaiTempSign == 1)
{
var huadanColor = Global.Instance.GlobalConfigStringValue(ConfigConstant.CONFIG_BUSINESS_HUADANCOLOR);
this.BackColor = ColorTranslator.FromHtml(huadanColor);
}
RefreshHeight();
}
/// 转全角的函数(SBC case)
///
///任意字符串
///全角字符串
///
///全角空格为12288半角空格为32
///其他字符半角(33-126)与全角(65281-65374)的对应关系是均相差65248
///
public static string ToSBC(string input)
{
return input.Replace(",","");
}
private void RefreshHeight()
{
//重新计算高度
Graphics g = this.CreateGraphics();
Size preferredSize = g.MeasureString(this.nameLabel.Text, this.nameLabel.Font).ToSize();
var rowNum = preferredSize.Width / this.nameLabel.Width;
var more = preferredSize.Width % this.nameLabel.Width;
if (more > 0)
{
rowNum++;
}
if (this.makeLabel.Visible)
{
Size makeSize = g.MeasureString(this.makeLabel.Text, this.makeLabel.Font).ToSize();
var makeNum = makeSize.Width / this.makeLabel.Width;
var makeMore = makeSize.Width % this.makeLabel.Width;
if (makeMore > 0)
{
makeNum++;
}
this.makeLabel.Height = makeSize.Height * makeNum;
rowNum += makeNum;
}
var realHeight = (preferredSize.Height + 2) * rowNum;
if (realHeight > this.Height)
{
this.Height = realHeight;
}
g.Dispose();
}
/// <summary>
/// 更新超时UI
/// </summary>
public void RefreshTimeOut()
{
if(_item != null)
{
switch (Global.Instance.kdsCategory)
{
case POSV.Common.KDSCategory.:
{
if (string.IsNullOrEmpty(_item.HuacaiTime) && _item.MakeDuration > 0)
{
var timeoutWarn = Global.Instance.GlobalConfigStringValue(ConfigConstant.CONFIG_BUSINESS_TIMEOUTWARN, "true");
if(timeoutWarn == "true")
{
var warnColor = Global.Instance.GlobalConfigStringValue(ConfigConstant.CONFIG_BUSINESS_ONEWARNCOLOR, "Red");
var startDate = DateTime.Now;
DateTime.TryParse(_item.SaleDate, out startDate);
if(startDate.AddMinutes(_item.MakeDuration).CompareTo(DateTime.Now) < 0)
{
if (this.IsDisposed || !this.IsHandleCreated) return;
this.Invoke(new Action(() =>
{
this.ForeColor = ColorTranslator.FromHtml(warnColor);
//this.BackColor = ColorTranslator.FromHtml(warnColor);
}));
}
}
}
}
break;
case POSV.Common.KDSCategory.:
{
if (string.IsNullOrEmpty(_item.ChupinTime) && _item.ChupinDuration > 0 && !string.IsNullOrEmpty(_item.HuacaiTime))
{
var timeoutWarn = Global.Instance.GlobalConfigStringValue(ConfigConstant.CONFIG_BUSINESS_TIMEOUTWARN, "true");
if (timeoutWarn == "true")
{
var warnColor = Global.Instance.GlobalConfigStringValue(ConfigConstant.CONFIG_BUSINESS_ONEWARNCOLOR, "Red");
var startDate = DateTime.Now;
DateTime.TryParse(_item.HuacaiTime, out startDate);
if (startDate.AddMinutes(_item.ChupinDuration).CompareTo(DateTime.Now) < 0)
{
if (this.IsDisposed || !this.IsHandleCreated) return;
this.Invoke(new Action(() =>
{
this.ForeColor = ColorTranslator.FromHtml(warnColor);
//this.BackColor = ColorTranslator.FromHtml(warnColor);
}));
}
}
}
}
break;
}
}
}
private void OrderItemPanel_Paint(object sender, PaintEventArgs e)
{
if (!isLast)
{
var pen = new Pen(Color.DarkGray);
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
e.Graphics.DrawLine(pen, 2, this.Height - 1, this.Width - 2, this.Height - 1);
}
}
private void OnFontChanged(object sender, EventArgs e)
{
if (this.Font.Size > 30)
{
this.numLabel.Font = new Font("宋体", 30F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); ;
}
else
{
this.numLabel.Font = this.Font;
}
this.nameLabel.Font = this.Font;
this.makeLabel.Font = this.Font;
}
/// <summary>
/// label点击
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnThisClick(object sender, EventArgs e)
{
if(_item.HuacaiTempSign == 0)
{
_item.HuacaiTempSign = 1;
lock (Global.Instance.SyncLock)
{
using(var db = Global.Instance.OpenDataBase)
{
db.Execute(string.Format("update pos_order_item set huacaiTempSign = 1 where id = '{0}';", _item.Id));
}
}
var huadanColor = Global.Instance.GlobalConfigStringValue(ConfigConstant.CONFIG_BUSINESS_HUADANCOLOR);
this.BackColor = ColorTranslator.FromHtml(huadanColor);
}
}
}
}