Files
ATV_STDLabelAttach/Handler/Project/Class/StatusMessage.cs
2025-07-17 16:11:46 +09:00

185 lines
5.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Project.Class
{
public enum eStatusMesage : byte
{
Front = 0,
Rear,
TopJig,
Main,
}
public class StatusMessage
{
Dictionary<eStatusMesage, StatusMessageFormat> message;
public StatusMessage()
{
this.message = new Dictionary<eStatusMesage, StatusMessageFormat>();
}
public StatusMessageFormat get(eStatusMesage msg)
{
lock (this.message)
{
if (this.message.ContainsKey(msg) == false)
{
var nemsg = new StatusMessageFormat
{
Message = string.Empty
};
this.message.Add(msg, nemsg);
return nemsg;
}
else
return this.message[msg];
}
}
public void Clear()
{
}
public void set(eStatusMesage msg, StatusMessageFormat data)
{
lock (this.message)
{
if (this.message.ContainsKey(msg) == false)
this.message.Add(msg, data);
else
this.message[msg] = data;
}
}
public void set(eStatusMesage msg, string data, int progval = 0, int progmax = 0)
{
if (data.StartsWith("[") && data.Contains("]"))
{
var buf = data.Split(']');
var cate = buf[0].Substring(1);
var body = string.Join("]", buf, 1, buf.Length - 1);
set(msg, cate, body, Color.Black, progval, progmax);
}
else set(msg, string.Empty, data, Color.Black, progval, progmax);
}
//public void set(eStatusMesage msg, string cate, string data, int progval = 0, int progmax = 0)
//{
// set(msg, cate, data, Color.Black, progval, progmax);
//}
public void set(eStatusMesage msg, string cate, string data, Color fColor, int progval = 0, int progmax = 0)
{
lock (this.message)
{
if (this.message.ContainsKey(msg) == false)
{
var nemsg = new StatusMessageFormat
{
Category = cate,
Message = data,
fColor = fColor,
ProgressMax = progmax,
ProgressValue = progval
};
this.message.Add(msg, nemsg);
}
else
{
var m = this.message[msg];
m.Category = cate;
m.Message = data;
m.fColor = fColor;
if (progval != 0 || progmax != 0)
{
m.ProgressValue = progval;
m.ProgressMax = progmax;
}
}
}
}
public void set(eStatusMesage msg, string data, Color fColor, Color bColor1, Color bColor2)
{
lock (this.message)
{
if (this.message.ContainsKey(msg) == false)
{
var nemsg = new StatusMessageFormat
{
Message = data,
fColor = fColor,
bColor1 = bColor1,
bColor2 = bColor2
};
this.message.Add(msg, nemsg);
}
else
{
var m = this.message[msg];
m.Message = data;
m.fColor = fColor;
m.bColor2 = bColor2;
m.bColor1 = bColor1;
}
}
}
}
public class StatusMessageFormat
{
public string Category { get; set; }
public string Message { get; set; }
public Color fColor { get; set; }
public Color bColor1 { get; set; }
public Color bColor2 { get; set; }
public int ProgressValue { get; set; }
public int ProgressMax { get; set; }
public int ProgressPerc
{
get
{
if (ProgressMax == 0 || ProgressValue == 0) return 0;
return (int)(ProgressValue / (ProgressMax * 1.0));
}
}
public StatusMessageFormat()
{
Clear();
}
void setMessage(string t, string m, Color c)
{
this.Category = t;
this.Message = m;
this.fColor = c;
}
void setMessage(string m, Color c)
{
this.Category = string.Empty;
this.Message = m;
this.fColor = c;
}
public void Clear()
{
ProgressValue = 0;
ProgressMax = 0;
Category = string.Empty;
Message = string.Empty;
fColor = Color.Black;
bColor1 = Color.White;
bColor2 = Color.White;
}
}
}