|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Net.NetworkInformation;
|
|
|
using System.Text;
|
|
|
using System.Linq;
|
|
|
using System.Data;
|
|
|
using System.Data.Common;
|
|
|
using System.Threading;
|
|
|
using Mesnac.Action.Base;
|
|
|
using Mesnac.Controls.Base;
|
|
|
using System.Windows.Forms;
|
|
|
using Mesnac.Codd.Session;
|
|
|
using System.IO;
|
|
|
using Mesnac.Action.Feeding.BasicInfo;
|
|
|
|
|
|
namespace Mesnac.Action.Feeding
|
|
|
{
|
|
|
#region 生产计划通用功能封装
|
|
|
|
|
|
#region 生产计划业务封装类
|
|
|
/// <summary>
|
|
|
/// 生产计划通用内容类
|
|
|
/// </summary>
|
|
|
public class PlanCommon
|
|
|
{
|
|
|
#region 字段与属性
|
|
|
/// <summary>
|
|
|
/// 生产计划日志文件路径
|
|
|
/// </summary>
|
|
|
//public static readonly string PlanLogFile = Path.Combine(Application.StartupPath, "Log", "PlanLog.data");
|
|
|
private static bool _isInit = false;
|
|
|
private static PlanLog _planLog = null;
|
|
|
private static bool _isShift = false;
|
|
|
|
|
|
private static string _execShift;
|
|
|
/// <summary>
|
|
|
/// 执行班次
|
|
|
/// </summary>
|
|
|
public static string ExecShift
|
|
|
{
|
|
|
get { return PlanCommon._execShift; }
|
|
|
set { PlanCommon._execShift = value; }
|
|
|
}
|
|
|
|
|
|
private static string _execDate;
|
|
|
/// <summary>
|
|
|
/// 执行日期
|
|
|
/// </summary>
|
|
|
public static string ExecDate
|
|
|
{
|
|
|
get { return PlanCommon._execDate; }
|
|
|
set { PlanCommon._execDate = value; }
|
|
|
}
|
|
|
|
|
|
private static string _execClass;
|
|
|
/// <summary>
|
|
|
/// 执行班次
|
|
|
/// </summary>
|
|
|
public static string ExecClass
|
|
|
{
|
|
|
get { return _execClass; }
|
|
|
set { _execClass = value; }
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 是否初始化
|
|
|
/// </summary>
|
|
|
public static bool IsInit
|
|
|
{
|
|
|
get { return PlanCommon._isInit; }
|
|
|
set { PlanCommon._isInit = value; }
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 是否交接班标记
|
|
|
/// </summary>
|
|
|
public static bool IsShift
|
|
|
{
|
|
|
get { return PlanCommon._isShift; }
|
|
|
set { PlanCommon._isShift = value; }
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 计划日志对象
|
|
|
/// </summary>
|
|
|
public static PlanLog PlanLog
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
if (PlanCommon._planLog == null)
|
|
|
{
|
|
|
//if (File.Exists(PlanCommon.PlanLogFile))
|
|
|
//{
|
|
|
// PlanCommon._planLog = Global.Deserialize<PlanLog>(PlanCommon.PlanLogFile);
|
|
|
//}
|
|
|
try
|
|
|
{
|
|
|
PlanLog _planLog = new PlanLog();
|
|
|
FeedingAction action = new FeedingAction();
|
|
|
string currentPlanDate = action.GetSysValue("CurrentPlanDate"); //获取当前计划日期
|
|
|
string currentPlanId = action.GetSysValue("CurrentPlanID"); //获取当前计划号
|
|
|
string currentShiftID = action.GetSysValue("CurrentShiftID"); //获取当前班次
|
|
|
string currentClassID = action.GetSysValue("CurrentClassID"); //获取当前班组
|
|
|
if (!String.IsNullOrEmpty(currentPlanDate))
|
|
|
{
|
|
|
_planLog.LastSelectDate = Convert.ToDateTime(currentPlanDate);
|
|
|
}
|
|
|
if (!String.IsNullOrEmpty(currentShiftID))
|
|
|
{
|
|
|
_planLog.LastSelectShiftID = Convert.ToInt32(currentShiftID);
|
|
|
}
|
|
|
if (!String.IsNullOrEmpty(currentClassID))
|
|
|
{
|
|
|
_planLog.LastClassID = Convert.ToInt32(currentClassID);
|
|
|
}
|
|
|
if (!String.IsNullOrEmpty(currentPlanId))
|
|
|
{
|
|
|
_planLog.LastPlanID = currentPlanId.Trim();
|
|
|
}
|
|
|
PlanCommon._planLog = _planLog;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("从SysKeyValue中获取计划日志失败:" + ex.Message, ex);
|
|
|
}
|
|
|
}
|
|
|
return PlanCommon._planLog;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
PlanCommon._planLog = value;
|
|
|
try
|
|
|
{
|
|
|
FeedingAction action = new FeedingAction();
|
|
|
if (PlanCommon._planLog != null)
|
|
|
{
|
|
|
action.UpdateSysValue("CurrentPlanDate", String.Format("{0:yyyy-MM-dd}", PlanCommon._planLog.LastSelectDate));
|
|
|
action.UpdateSysValue("CurrentPlanID", PlanCommon._planLog.LastPlanID);
|
|
|
action.UpdateSysValue("CurrentShiftID", PlanCommon._planLog.LastSelectShiftID.ToString());
|
|
|
action.UpdateSysValue("CurrentClassID", PlanCommon._planLog.LastClassID.ToString());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
action.UpdateSysValue("CurrentPlanDate", String.Format("{0:yyyy-MM-dd}", DateTime.Now));
|
|
|
action.UpdateSysValue("CurrentPlanID", String.Empty);
|
|
|
action.UpdateSysValue("CurrentShiftID", String.Empty);
|
|
|
action.UpdateSysValue("CurrentClassID", String.Empty);
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("保存计划日志到SysKeyValue表中失败:" + ex.Message, ex);
|
|
|
}
|
|
|
//if (PlanCommon._planLog == null)
|
|
|
//{
|
|
|
// if (File.Exists(PlanCommon.PlanLogFile))
|
|
|
// {
|
|
|
// File.Delete(PlanCommon.PlanLogFile);
|
|
|
// }
|
|
|
//}
|
|
|
//else
|
|
|
//{
|
|
|
// Global.Serialize<PlanLog>(PlanCommon._planLog, PlanCommon.PlanLogFile); //序列化至文件
|
|
|
//}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region "按字符串位数补0"
|
|
|
/// <summary>
|
|
|
/// 按字符串位数补0
|
|
|
/// </summary>
|
|
|
/// <param name="CharTxt">字符串</param>
|
|
|
/// <param name="CharLen">字符长度</param>
|
|
|
/// <returns></returns>
|
|
|
public static string FillZero(string CharTxt, int CharLen)
|
|
|
{
|
|
|
if (CharTxt.Length < CharLen)
|
|
|
{
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
for (int i = 0; i < CharLen - CharTxt.Length; i++)
|
|
|
{
|
|
|
sb.Append("0");
|
|
|
}
|
|
|
sb.Append(CharTxt);
|
|
|
return sb.ToString();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return CharTxt;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 检测是否能够连接网络数据库
|
|
|
/// <summary>
|
|
|
/// 检测是否能够连接网络数据库
|
|
|
/// </summary>
|
|
|
/// <returns>能连接返回true,否则返回false</returns>
|
|
|
public static bool IsCanConnectServer()
|
|
|
{
|
|
|
bool isConnect = true;
|
|
|
try
|
|
|
{
|
|
|
lock (String.Empty)
|
|
|
{
|
|
|
FeedingAction action = new FeedingAction();
|
|
|
DbHelper serverHelper = action.NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Server);
|
|
|
if (serverHelper == null)
|
|
|
{
|
|
|
isConnect = false;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string strSql = "select getDate()";
|
|
|
serverHelper.DbSession.Command.CommandTimeout = 1; //设置命令超时为2秒
|
|
|
serverHelper.CommandType = System.Data.CommandType.Text;
|
|
|
serverHelper.ClearParameter();
|
|
|
serverHelper.CommandText = strSql;
|
|
|
object result = serverHelper.ToScalar();
|
|
|
if (result != null && result != System.DBNull.Value)
|
|
|
{
|
|
|
isConnect = true;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
isConnect = false;
|
|
|
}
|
|
|
serverHelper.CloseConnection();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
//ICSharpCode.Core.LoggingService.Error("连接网络数据库连接失败...");
|
|
|
isConnect = false;
|
|
|
}
|
|
|
return isConnect;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 检测某个IP或域名是否可以Ping通
|
|
|
|
|
|
/// <summary>
|
|
|
/// 检测某个IP或域名是否可以Ping通
|
|
|
/// </summary>
|
|
|
/// <param name="strIpOrDName">IP或域名</param>
|
|
|
/// <returns>真为通,假为不同</returns>
|
|
|
public static bool PingIpOrDomainName(string strIpOrDName)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
Ping objPingSender = new Ping();
|
|
|
PingOptions objPinOptions = new PingOptions();
|
|
|
objPinOptions.DontFragment = true;
|
|
|
string data = "";
|
|
|
byte[] buffer = Encoding.UTF8.GetBytes(data);
|
|
|
int intTimeout = 120;
|
|
|
PingReply objPinReply = objPingSender.Send(strIpOrDName, intTimeout, buffer, objPinOptions);
|
|
|
string strInfo = objPinReply.Status.ToString();
|
|
|
if (strInfo == "Success")
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 显示错误列表
|
|
|
/// <summary>
|
|
|
/// 显示错误列表
|
|
|
/// </summary>
|
|
|
/// <param name="errorList"></param>
|
|
|
public static void ShowErrorList(List<string> errorList)
|
|
|
{
|
|
|
//显示错误提示
|
|
|
if (errorList != null && errorList.Count > 0)
|
|
|
{
|
|
|
DatabaseAction action = new DatabaseAction();
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
foreach (string msg in errorList)
|
|
|
{
|
|
|
sb.AppendLine(msg);
|
|
|
}
|
|
|
action.ShowMsg(sb.ToString(), LanguageService.Instance.Read(1), MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 合并消息列表
|
|
|
/// <summary>
|
|
|
/// 合并消息列表
|
|
|
/// </summary>
|
|
|
/// <param name="msgList">要合并的消息列表</param>
|
|
|
/// <returns>返回合并的消息字符串</returns>
|
|
|
public static string CombineMsgList(List<string> msgList)
|
|
|
{
|
|
|
if (msgList != null && msgList.Count > 0)
|
|
|
{
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
foreach (string msg in msgList)
|
|
|
{
|
|
|
sb.AppendLine(msg);
|
|
|
}
|
|
|
return sb.ToString();
|
|
|
}
|
|
|
return String.Empty;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region GenerateNextPlanID 通过网络数据库计划表PptPlan获取下一个可用的计划号 (6位日期、2位机台、1位班次、1位网络/本机、2位流水)
|
|
|
/// <summary>
|
|
|
/// 通过网络数据库计划表PptPlan获取下一个可用的计划号 (6位日期、2位机台、1位班次、1位网络/本机、2位流水)
|
|
|
/// </summary>
|
|
|
/// <param name="dbType">生成计划号的数据库,网络、本地</param>
|
|
|
/// <param name="equipCode">机台号</param>
|
|
|
/// <param name="planDate">计划生产日期</param>
|
|
|
/// <param name="shiftID">班次</param>
|
|
|
/// <returns>返回生成的12位计划号</returns>
|
|
|
public static string GenerateNextPlanID(Mesnac.Basic.DataSourceFactory.MCDbType dbType, string equipCode, DateTime planDate, int shiftID)
|
|
|
{
|
|
|
DatabaseAction action = new DatabaseAction();
|
|
|
DbHelper dbHelper;
|
|
|
dbHelper = action.NewDbHelper(dbType);
|
|
|
//if (!action.DbHelpers.TryGetValue(action.GetDataSourceName(Mesnac.Action.Base.DatabaseAction.DbType.Server), out dbHelper))
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
action.LogError("获取数据连接失败...");
|
|
|
return String.Empty;
|
|
|
}
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
string strSql = String.Empty;
|
|
|
if (dbType == Basic.DataSourceFactory.MCDbType.Server)
|
|
|
{
|
|
|
//strSql = "select Max(PlanID) from PptPlan where RecipeEquipCode=@RecipeEquipCode and CONVERT(varchar,PlanDate,112)=@PlanDate and ShiftID=@ShiftID and substring(Plan_ID,10,1)='L'";
|
|
|
strSql = "select Max(Plan_ID) from Ppt_Plan where Equip_code=@RecipeEquipCode and left(Plan_ID,6)=right(@PlanDate,6) and Shift_ID=@ShiftID and substring(Plan_ID,10,1)='L'";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//strSql = "select Max(plan_id) from ppt_plan where equip_code=@RecipeEquipCode and CONVERT(varchar,down_date,112)=@PlanDate and shift=@ShiftID";
|
|
|
strSql = "select Max(plan_id) from ppt_plan where equip_code=@RecipeEquipCode and left(plan_id,6)=right(@PlanDate,6) and shift=@ShiftID";
|
|
|
}
|
|
|
dbHelper.AddParameter("@RecipeEquipCode", equipCode);
|
|
|
dbHelper.AddParameter("@PlanDate", String.Format("{0:yyyyMMdd}", planDate));
|
|
|
dbHelper.AddParameter("@ShiftID", shiftID);
|
|
|
|
|
|
dbHelper.CommandText = strSql;
|
|
|
object result = dbHelper.ToScalar();
|
|
|
if (result == null || result == System.DBNull.Value)
|
|
|
{
|
|
|
string code = equipCode.Substring(3, 2); //获取机台后2位
|
|
|
return String.Format("{0:yyMMdd}{1}{2}L01", planDate, code, shiftID);
|
|
|
}
|
|
|
string lastTwo = result.ToString().Substring(10, 2); //截取最后2位
|
|
|
int newValue = Convert.ToInt32(lastTwo) + 1;
|
|
|
string nextPlanID = result.ToString().Substring(0, 10) + FillZero(newValue.ToString(), 2);
|
|
|
return nextPlanID;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region GetNewActionOrder 通过本地数据库计划表PptPlan的ActionOrder字段获取下一个可用的ActionOrder值
|
|
|
/// <summary>
|
|
|
/// 通过本地数据库计划表PptPlan的ActionOrder字段获取下一个可用的ActionOrder值
|
|
|
/// </summary>
|
|
|
/// <returns>返回生成的ActionOrder值</returns>
|
|
|
public static int GetNewActionOrder(string equipCode, DateTime planDate, int shiftID)
|
|
|
{
|
|
|
DatabaseAction action = new DatabaseAction();
|
|
|
DbHelper dbHelper;
|
|
|
dbHelper = action.NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
action.LogError("获取数据连接失败...");
|
|
|
return 0;
|
|
|
}
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
//string strSql = "select MAX(ActionOrder) from PptPlan where RecipeEquipCode=@RecipeEquipCode and CONVERT(varchar,PlanDate,112)=@PlanDate and ShiftID=@ShiftID";
|
|
|
//string strSql = "select MAX(ActionOrder) from ppt_plan where equip_code=@RecipeEquipCode and CONVERT(varchar,down_date,112)=@PlanDate and shift=@ShiftID";
|
|
|
string strSql = "select MAX(ActionOrder) from ppt_plan where equip_code=@RecipeEquipCode and left(plan_id,6)=right(@PlanDate,6) and shift=@ShiftID";
|
|
|
dbHelper.AddParameter("@RecipeEquipCode", equipCode);
|
|
|
dbHelper.AddParameter("@PlanDate", String.Format("{0:yyyyMMdd}", planDate));
|
|
|
dbHelper.AddParameter("@ShiftID", shiftID);
|
|
|
dbHelper.CommandText = strSql;
|
|
|
object result = dbHelper.ToScalar();
|
|
|
if (result == null || result == System.DBNull.Value)
|
|
|
{
|
|
|
return 1;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return Convert.ToInt32(result) + 1;
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region GetNextPlanID 获取当前计划的下一个计划号,用于计划排序
|
|
|
/// <summary>
|
|
|
/// 获取当前计划的下一个计划号,用于计划排序
|
|
|
/// </summary>
|
|
|
/// <param name="currPlanID">当前计划号</param>
|
|
|
/// <param name="equipCode">机台号</param>
|
|
|
/// <param name="planDate">计划生产日期</param>
|
|
|
/// <param name="shiftID">班次</param>
|
|
|
/// <returns></returns>
|
|
|
public static string GetNextPlanID(string currPlanID, string equipCode, DateTime planDate, int shiftID)
|
|
|
{
|
|
|
DatabaseAction action = new DatabaseAction();
|
|
|
DbHelper dbHelper;
|
|
|
dbHelper = action.NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
action.LogError("获取数据连接失败...");
|
|
|
return String.Empty;
|
|
|
}
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
//string sqlStr = "select top 1 plan_id from ppt_plan where ActionOrder > (select ActionOrder from ppt_plan where plan_id = @PlanID) and CONVERT(varchar,down_date,112) = @PlanDate and equip_code = @RecipeEquipCode and shift = @ShiftID order by ActionOrder asc";
|
|
|
string sqlStr = "select top 1 plan_id from ppt_plan where ActionOrder > (select ActionOrder from ppt_plan where plan_id = @PlanID) and left(plan_id,6) = right(@PlanDate,6) and equip_code = @RecipeEquipCode and shift = @ShiftID order by ActionOrder asc";
|
|
|
dbHelper.AddParameter("@PlanID", currPlanID);
|
|
|
dbHelper.AddParameter("@PlanDate", String.Format("{0:yyyyMMdd}", planDate));
|
|
|
dbHelper.AddParameter("@RecipeEquipCode", equipCode);
|
|
|
dbHelper.AddParameter("@ShiftID", shiftID);
|
|
|
dbHelper.CommandText = sqlStr;
|
|
|
object result = dbHelper.ToScalar();
|
|
|
if (result == null || result == System.DBNull.Value)
|
|
|
{
|
|
|
return String.Empty;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return result as string;
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region GetPrevPlanID 获取当前计划的前一个计划号,用户计划排序
|
|
|
/// <summary>
|
|
|
/// 获取当前计划的前一个计划号,用户计划排序
|
|
|
/// </summary>
|
|
|
/// <param name="currPlanID">当前计划号</param>
|
|
|
/// <param name="equipCode">机台号</param>
|
|
|
/// <param name="planDate">计划生产日期</param>
|
|
|
/// <param name="shiftID">班次</param>
|
|
|
/// <returns></returns>
|
|
|
public static string GetPrevPlanID(string currPlanID, string equipCode, DateTime planDate, int shiftID)
|
|
|
{
|
|
|
DatabaseAction action = new DatabaseAction();
|
|
|
DbHelper dbHelper;
|
|
|
dbHelper = action.NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
action.LogError("获取数据连接失败...");
|
|
|
return String.Empty;
|
|
|
}
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
//string strSql = "select top 1 plan_id from ppt_plan where ActionOrder < (select ActionOrder from ppt_plan where plan_id = @PlanID) and CONVERT(varchar,down_date,112) = @PlanDate and equip_code= @RecipeEquipCode and shift = @ShiftID order by ActionOrder desc";
|
|
|
string strSql = "select top 1 plan_id from ppt_plan where ActionOrder < (select ActionOrder from ppt_plan where plan_id = @PlanID) and left(plan_id,6) = right(@PlanDate,6) and equip_code= @RecipeEquipCode and shift = @ShiftID order by ActionOrder desc";
|
|
|
dbHelper.AddParameter("@PlanDate", String.Format("{0:yyyyMMdd}", planDate));
|
|
|
dbHelper.AddParameter("@RecipeEquipCode", equipCode);
|
|
|
dbHelper.AddParameter("@ShiftID", shiftID);
|
|
|
dbHelper.AddParameter("@PlanID", currPlanID);
|
|
|
dbHelper.CommandText = strSql;
|
|
|
object result = dbHelper.ToScalar();
|
|
|
if (result == null || result == System.DBNull.Value)
|
|
|
{
|
|
|
return String.Empty;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return result as string;
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region SwapActionOrder 更新2个计划的ActionOrder值,使2个计划的ActionOrder值进行对调
|
|
|
/// <summary>
|
|
|
/// 更新2个计划的ActionOrder值,使2个计划的ActionOrder值进行对调
|
|
|
/// </summary>
|
|
|
/// <param name="planID1">对应第一个计划的计划号</param>
|
|
|
/// <param name="planID2">对应第二个计划的计划号</param>
|
|
|
public static void SwapActionOrder(string planID1, string planID2)
|
|
|
{
|
|
|
DatabaseAction action = new DatabaseAction();
|
|
|
DbHelper dbHelper;
|
|
|
dbHelper = action.NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
action.LogError("获取数据连接失败...");
|
|
|
return;
|
|
|
}
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
string strSql1 = "select ActionOrder from ppt_plan where plan_id = @PlanID";
|
|
|
dbHelper.CommandText = strSql1;
|
|
|
dbHelper.AddParameter("@PlanID", planID1);
|
|
|
object result1 = dbHelper.ToScalar();
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandText = strSql1;
|
|
|
dbHelper.AddParameter("@PlanID", planID2);
|
|
|
object result2 = dbHelper.ToScalar();
|
|
|
|
|
|
dbHelper.ClearParameter();
|
|
|
string strSql2 = "Update ppt_plan set ActionOrder = @ActionOrder where plan_id = @PlanID";
|
|
|
dbHelper.CommandText = strSql2;
|
|
|
dbHelper.AddParameter("@ActionOrder", result2);
|
|
|
dbHelper.AddParameter("@PlanID", planID1);
|
|
|
dbHelper.ExecuteNonQuery();
|
|
|
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandText = strSql2;
|
|
|
dbHelper.AddParameter("@ActionOrder", result1);
|
|
|
dbHelper.AddParameter("@PlanID", planID2);
|
|
|
dbHelper.ExecuteNonQuery();
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 获取计划状态
|
|
|
/// <summary>
|
|
|
/// 获取计划状态
|
|
|
/// </summary>
|
|
|
/// <param name="planID">计划号</param>
|
|
|
/// <returns>返回计划状态</returns>
|
|
|
public static PlanStates GetPlanState(string planID)
|
|
|
{
|
|
|
DatabaseAction action = new DatabaseAction();
|
|
|
DbHelper dbHelper;
|
|
|
dbHelper = action.NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
action.LogError("获取数据连接失败...");
|
|
|
return PlanStates.UnKnow;
|
|
|
}
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
string strSql = "select plan_id as PlanID,plan_state as PlanState,plan_num as PlanNum,real_num as RealNum from ppt_plan where plan_id = @PlanID";
|
|
|
dbHelper.CommandText = strSql;
|
|
|
dbHelper.AddParameter("@PlanID", planID);
|
|
|
DataTable table = dbHelper.ToDataTable();
|
|
|
if (table.Rows.Count == 1)
|
|
|
{
|
|
|
int planState = Convert.ToInt32(table.Rows[0]["PlanState"]); //获取计划状态
|
|
|
int planNum = Convert.ToInt32(table.Rows[0]["PlanNum"]); //获取计划数
|
|
|
int realNum = Convert.ToInt32(table.Rows[0]["RealNum"]); //获取完成数
|
|
|
if (realNum >= planNum)
|
|
|
{
|
|
|
return PlanStates.Completed;
|
|
|
}
|
|
|
return (PlanStates)planState;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return PlanStates.UnKnow;
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 获取某条生产计划GetPlanData
|
|
|
/// <summary>
|
|
|
/// 获取某条生产计划
|
|
|
/// </summary>
|
|
|
/// <param name="planID">计划号</param>
|
|
|
/// <returns>返回对应计划的DataRow</returns>
|
|
|
public static DataRow GetPlanData(Mesnac.Basic.DataSourceFactory.MCDbType dbType, string planID)
|
|
|
{
|
|
|
FeedingAction action = new FeedingAction();
|
|
|
DbHelper dbHelper;
|
|
|
dbHelper = action.NewDbHelper(dbType);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
action.LogError("获取数据连接失败...");
|
|
|
return null;
|
|
|
}
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
string strSql = String.Empty;
|
|
|
if (dbType == Basic.DataSourceFactory.MCDbType.Server)
|
|
|
{
|
|
|
//strSql = "select * from Ppt_Plan where Plan_ID = @PlanID";
|
|
|
strSql = "select Plan_id as PlanID,pri_level as PriLevel,mater_code as RecipeMaterialCode,shift_class as ClassID,equip_code as RecipeEquipCode,edt_code as RecipeVersionID,plan_num as PlanNum,real_num as RealNum,plan_state as PlanState,revise_sgn as ReviseSgn,Shift_id as ShiftID,Plan_date as PlanDate,recipe_code as RecipeMaterialName,plan_weight as PlanWeight,total_weight as TotalWeight,real_weight as RealWeight,Real_Endtime as RealEndtime,oper_code as OperCode,oper_datetime as OperDatetime,Serial_num as ActionOrder from ppt_plan where Plan_id = @PlanID";
|
|
|
}
|
|
|
else if (dbType == Basic.DataSourceFactory.MCDbType.Local)
|
|
|
{
|
|
|
strSql = "select plan_id as PlanID,pri_level as PriLevel,mater_code as RecipeMaterialCode,shift_class as ClassID,equip_code as RecipeEquipCode,edt_code as RecipeVersionID,plan_num as PlanNum,real_num as RealNum,plan_state as PlanState,revise_sgn as ReviseSgn,shift as ShiftID,down_date as PlanDate,recipe_code as RecipeMaterialName,plan_weight as PlanWeight,total_weight as TotalWeight,real_weight as RealWeight,real_datetime as RealEndtime,oper_code as OperCode,oper_datetime as OperDatetime,ActionOrder from ppt_plan where plan_id = @PlanID";
|
|
|
}
|
|
|
dbHelper.CommandText = strSql;
|
|
|
dbHelper.AddParameter("@PlanID", planID);
|
|
|
DataTable table = dbHelper.ToDataTable();
|
|
|
if (table != null && table.Rows.Count == 1)
|
|
|
{
|
|
|
return table.Rows[0];
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 获取计划数
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取计划数
|
|
|
/// </summary>
|
|
|
/// <param name="dbType">数据访问对象</param>
|
|
|
/// <param name="planID">计划号</param>
|
|
|
/// <returns>成功返回计划数,失败返回-1</returns>
|
|
|
public static int GetPlanNum(Mesnac.Basic.DataSourceFactory.MCDbType dbType, string planID)
|
|
|
{
|
|
|
FeedingAction action = new FeedingAction();
|
|
|
DbHelper dbHelper;
|
|
|
dbHelper = action.NewDbHelper(dbType);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
action.LogError("获取数据连接失败...");
|
|
|
return -1;
|
|
|
}
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
string strSql = String.Empty;
|
|
|
if (dbType == Basic.DataSourceFactory.MCDbType.Server)
|
|
|
{
|
|
|
//strSql = "select PlanNum from PptPlan where PlanID = @PlanID";
|
|
|
strSql = "select Plan_num as PlanNum from Ppt_Plan where Plan_id = @PlanID";
|
|
|
}
|
|
|
else if (dbType == Basic.DataSourceFactory.MCDbType.Local)
|
|
|
{
|
|
|
strSql = "select plan_num as PlanNum from ppt_plan where plan_id = @PlanID";
|
|
|
}
|
|
|
dbHelper.CommandText = strSql;
|
|
|
dbHelper.AddParameter("@PlanID", planID);
|
|
|
object result = dbHelper.ToScalar();
|
|
|
if (result != null && result != System.DBNull.Value)
|
|
|
{
|
|
|
int IntResult = 0;
|
|
|
int.TryParse(result.ToString(), out IntResult);
|
|
|
return IntResult;
|
|
|
}
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 判断某个计划是否存在
|
|
|
|
|
|
/// <summary>
|
|
|
/// 判断某个计划是否存在
|
|
|
/// </summary>
|
|
|
/// <param name="dbType">网络库、本地库</param>
|
|
|
/// <param name="planID">计划号</param>
|
|
|
/// <returns>存在返回true,否则返回false</returns>
|
|
|
public static bool PlanExists(Mesnac.Basic.DataSourceFactory.MCDbType dbType, string equipCode, string planID)
|
|
|
{
|
|
|
DatabaseAction action = new DatabaseAction();
|
|
|
DbHelper dbHelper;
|
|
|
dbHelper = action.NewDbHelper(dbType);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
action.LogError("获取数据连接失败...");
|
|
|
return false;
|
|
|
}
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
string strSql = string.Empty;
|
|
|
if (dbType == Basic.DataSourceFactory.MCDbType.Server)
|
|
|
{
|
|
|
strSql = "select count(plan_ID) from Ppt_Plan where Equip_code = @EquipCode and Plan_ID = @PlanID";
|
|
|
}
|
|
|
else if (dbType == Basic.DataSourceFactory.MCDbType.Local)
|
|
|
{
|
|
|
strSql = "select count(plan_id) from ppt_plan where equip_code = @EquipCode and plan_id = @PlanID";
|
|
|
}
|
|
|
dbHelper.CommandText = strSql;
|
|
|
dbHelper.AddParameter("@EquipCode", equipCode);
|
|
|
dbHelper.AddParameter("@PlanID", planID);
|
|
|
object result = dbHelper.ToScalar();
|
|
|
if (result != null && result != DBNull.Value && Convert.ToInt32(result) > 0)
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 判断某个计划是否存在
|
|
|
/// </summary>
|
|
|
/// <param name="dbType">网络库、本地库</param>
|
|
|
/// <param name="equipCode">机台号</param>
|
|
|
/// <param name="planDate">计划日期</param>
|
|
|
/// <param name="shiftID">班次</param>
|
|
|
/// <param name="planID">计划号</param>
|
|
|
/// <returns>存在返回true,不存在返回false</returns>
|
|
|
public static bool PlanExists(Mesnac.Basic.DataSourceFactory.MCDbType dbType, string equipCode, DateTime planDate, int shiftID, string planID)
|
|
|
{
|
|
|
DatabaseAction action = new DatabaseAction();
|
|
|
DbHelper dbHelper;
|
|
|
dbHelper = action.NewDbHelper(dbType);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
action.LogError("获取数据连接失败...");
|
|
|
return false;
|
|
|
}
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
string strSql = string.Empty;
|
|
|
if (dbType == Basic.DataSourceFactory.MCDbType.Server)
|
|
|
{
|
|
|
strSql = "select count(plan_ID) from Ppt_Plan where Equip_code = @RecipeEquipCode and Convert(varchar,Plan_Date,112) = @PlanDate and Shift_ID = @ShiftID and Plan_ID = @PlanID";
|
|
|
}
|
|
|
else if (dbType == Basic.DataSourceFactory.MCDbType.Local)
|
|
|
{
|
|
|
strSql = "select count(plan_id) from ppt_plan where equip_code = @RecipeEquipCode and Convert(varchar,down_date,112) = @PlanDate and shift = @ShiftID and plan_id = @PlanID";
|
|
|
}
|
|
|
dbHelper.CommandText = strSql;
|
|
|
dbHelper.AddParameter("@RecipeEquipCode", equipCode);
|
|
|
dbHelper.AddParameter("@PlanDate", String.Format("{0:yyyyMMdd}", planDate));
|
|
|
dbHelper.AddParameter("@ShiftID", shiftID);
|
|
|
dbHelper.AddParameter("@PlanID", planID);
|
|
|
object result = dbHelper.ToScalar();
|
|
|
if (result != null && result != DBNull.Value && Convert.ToInt32(result) > 0)
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 获取本机台、日期、班次的计划数据
|
|
|
/// <summary>
|
|
|
/// 获取本机台、日期、班次的计划数据
|
|
|
/// </summary>
|
|
|
/// <param name="dbType">数据类型、网络、本地</param>
|
|
|
/// <param name="equipCode">机台号</param>
|
|
|
/// <param name="planDate">计划生产日期</param>
|
|
|
/// <param name="shiftID">班次</param>
|
|
|
/// <returns>返回符合条件的计划数据</returns>
|
|
|
public static DataTable GetPlanData(Mesnac.Basic.DataSourceFactory.MCDbType dbType, string equipCode, DateTime planDate, int shiftID)
|
|
|
{
|
|
|
DatabaseAction action = new DatabaseAction();
|
|
|
DbHelper dbHelper;
|
|
|
dbHelper = action.NewDbHelper(dbType);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
action.LogError("获取数据连接失败...");
|
|
|
return null;
|
|
|
}
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
string strSql = String.Empty;
|
|
|
if (dbType == Basic.DataSourceFactory.MCDbType.Server)
|
|
|
{
|
|
|
//strSql = "select * from PptPlan where RecipeEquipCode = @RecipeEquipCode and Convert(varchar,PlanDate,112) = @PlanDate and ShiftID = @ShiftID order by ActionOrder";
|
|
|
strSql = "select plan_id as PlanID,pri_level as PriLevel,mater_code as RecipeMaterialCode,shift_class as ClassID,equip_code as RecipeEquipCode,edt_code as RecipeVersionID,plan_num as PlanNum,real_num as RealNum,plan_state as PlanState,revise_sgn as ReviseSgn,Shift_id as ShiftID,Plan_date as PlanDate,recipe_code as RecipeMaterialName,plan_weight as PlanWeight,total_weight as TotalWeight,real_weight as RealWeight,Real_Endtime as RealEndtime,oper_code as OperCode,oper_datetime as OperDatetime,Serial_num as ActionOrder from ppt_plan where Equip_code = @RecipeEquipCode and left(Plan_id,6) = right(@PlanDate,6) and Shift_id = @ShiftID order by Serial_num";
|
|
|
}
|
|
|
else if (dbType == Basic.DataSourceFactory.MCDbType.Local)
|
|
|
{
|
|
|
//strSql = "select plan_id as PlanID,pri_level as PriLevel,mater_code as RecipeMaterialCode,shift_class as ClassID,equip_code as RecipeEquipCode,edt_code as RecipeVersionID,plan_num as PlanNum,real_num as RealNum,plan_state as PlanState,revise_sgn as ReviseSgn,shift as ShiftID,down_date as PlanDate,recipe_code as RecipeMaterialName,plan_weight as PlanWeight,total_weight as TotalWeight,real_weight as RealWeight,real_datetime as RealEndtime,oper_code as OperCode,oper_datetime as OperDatetime,ActionOrder from ppt_plan where equip_code = @RecipeEquipCode and Convert(varchar,down_date,112) = @PlanDate and shift = @ShiftID order by ActionOrder";
|
|
|
strSql = "select plan_id as PlanID,pri_level as PriLevel,mater_code as RecipeMaterialCode,shift_class as ClassID,equip_code as RecipeEquipCode,edt_code as RecipeVersionID,plan_num as PlanNum,real_num as RealNum,plan_state as PlanState,revise_sgn as ReviseSgn,shift as ShiftID,down_date as PlanDate,recipe_code as RecipeMaterialName,plan_weight as PlanWeight,total_weight as TotalWeight,real_weight as RealWeight,real_datetime as RealEndtime,oper_code as OperCode,oper_datetime as OperDatetime,ActionOrder from ppt_plan where equip_code = @RecipeEquipCode and left(plan_id,6) = right(@PlanDate,6) and shift = @ShiftID order by ActionOrder";
|
|
|
}
|
|
|
dbHelper.CommandText = strSql;
|
|
|
dbHelper.AddParameter("@RecipeEquipCode", equipCode);
|
|
|
dbHelper.AddParameter("@PlanDate", String.Format("{0:yyyyMMdd}", planDate));
|
|
|
dbHelper.AddParameter("@ShiftID", shiftID);
|
|
|
DataTable table = dbHelper.ToDataTable();
|
|
|
return table;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 获取对应计划日期,班次,班次的第一条未生产的计划
|
|
|
/// <summary>
|
|
|
/// 获取本机台、日期、班次的第一条未生产的计划ID
|
|
|
/// </summary>
|
|
|
/// <param name="dbType">数据类型、网络、本地</param>
|
|
|
/// <param name="equipCode">机台号</param>
|
|
|
/// <param name="planDate">计划生产日期</param>
|
|
|
/// <param name="shiftID">班次</param>
|
|
|
/// <returns>返回符合条件的计划ID,失败返回null或String.Empty</returns>
|
|
|
public static string GetFirstPlanID(Mesnac.Basic.DataSourceFactory.MCDbType dbType, string equipCode, DateTime planDate, int shiftID)
|
|
|
{
|
|
|
DatabaseAction action = new DatabaseAction();
|
|
|
DbHelper dbHelper;
|
|
|
dbHelper = action.NewDbHelper(dbType);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
action.LogError("获取数据连接失败...");
|
|
|
return null;
|
|
|
}
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
string strSql = String.Empty;
|
|
|
if (dbType == Basic.DataSourceFactory.MCDbType.Server)
|
|
|
{
|
|
|
//strSql = "select top 1 * from PptPlan where RecipeEquipCode = @RecipeEquipCode and Convert(varchar,PlanDate,112) = @PlanDate and ShiftID = @ShiftID and PlanState = 3 and RealNum = 0 order by ActionOrder";
|
|
|
strSql = "select top 1 plan_id as PlanID,pri_level as PriLevel,mater_code as RecipeMaterialCode,shift_class as ClassID,equip_code as RecipeEquipCode,edt_code as RecipeVersionID,plan_num as PlanNum,real_num as RealNum,plan_state as PlanState,revise_sgn as ReviseSgn,Shift_id as ShiftID,Plan_date as PlanDate,recipe_code as RecipeMaterialName,plan_weight as PlanWeight,total_weight as TotalWeight,real_weight as RealWeight,Real_Endtime as RealEndtime,oper_code as OperCode,oper_datetime as OperDatetime,Serial_num as ActionOrder from ppt_plan where equip_code = @RecipeEquipCode and left(plan_id,6) = right(@PlanDate,6) and Shift_id = @ShiftID and plan_state =3 and real_num = 0 order by Serial_num";
|
|
|
}
|
|
|
else if (dbType == Basic.DataSourceFactory.MCDbType.Local)
|
|
|
{
|
|
|
//strSql = "select top 1 plan_id as PlanID,pri_level as PriLevel,mater_code as RecipeMaterialCode,shift_class as ClassID,equip_code as RecipeEquipCode,edt_code as RecipeVersionID,plan_num as PlanNum,real_num as RealNum,plan_state as PlanState,revise_sgn as ReviseSgn,shift as ShiftID,down_date as PlanDate,recipe_code as RecipeMaterialName,plan_weight as PlanWeight,total_weight as TotalWeight,real_weight as RealWeight,real_datetime as RealEndtime,oper_code as OperCode,oper_datetime as OperDatetime,ActionOrder from ppt_plan where equip_code = @RecipeEquipCode and Convert(varchar,down_date,112) = @PlanDate and shift = @ShiftID and plan_state =3 and real_num = 0 order by ActionOrder";
|
|
|
strSql = "select top 1 plan_id as PlanID,pri_level as PriLevel,mater_code as RecipeMaterialCode,shift_class as ClassID,equip_code as RecipeEquipCode,edt_code as RecipeVersionID,plan_num as PlanNum,real_num as RealNum,plan_state as PlanState,revise_sgn as ReviseSgn,shift as ShiftID,down_date as PlanDate,recipe_code as RecipeMaterialName,plan_weight as PlanWeight,total_weight as TotalWeight,real_weight as RealWeight,real_datetime as RealEndtime,oper_code as OperCode,oper_datetime as OperDatetime,ActionOrder from ppt_plan where equip_code = @RecipeEquipCode and left(plan_id,6) = right(@PlanDate,6) and shift = @ShiftID and plan_state =3 and real_num = 0 order by ActionOrder";
|
|
|
}
|
|
|
dbHelper.CommandText = strSql;
|
|
|
dbHelper.AddParameter("@RecipeEquipCode", equipCode);
|
|
|
dbHelper.AddParameter("@PlanDate", String.Format("{0:yyyyMMdd}", planDate));
|
|
|
dbHelper.AddParameter("@ShiftID", shiftID);
|
|
|
DataTable table = dbHelper.ToDataTable();
|
|
|
if (table != null && table.Rows.Count > 0)
|
|
|
{
|
|
|
return table.Rows[0]["PlanID"] as string;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return String.Empty;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 获取本机台、日期、班次的计划数量
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取本机台、日期、班次的计划数量
|
|
|
/// </summary>
|
|
|
/// <param name="dbType">数据类型、网络、本地</param>
|
|
|
/// <param name="equipCode">机台号</param>
|
|
|
/// <param name="planDate">计划生产日期</param>
|
|
|
/// <param name="shiftID">班次</param>
|
|
|
/// <returns>返回符合条件的计划数据</returns>
|
|
|
public static int GetPlanCount(Mesnac.Basic.DataSourceFactory.MCDbType dbType, string equipCode, DateTime planDate, int shiftID)
|
|
|
{
|
|
|
DatabaseAction action = new DatabaseAction();
|
|
|
DbHelper dbHelper;
|
|
|
dbHelper = action.NewDbHelper(dbType);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
action.LogError("获取数据连接失败...");
|
|
|
return -1;
|
|
|
}
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
string strSql = String.Empty;
|
|
|
if (dbType == Basic.DataSourceFactory.MCDbType.Server)
|
|
|
{
|
|
|
//strSql = "select count(PlanID) from PptPlan where RecipeEquipCode = @RecipeEquipCode and Convert(varchar,PlanDate,112) = @PlanDate and ShiftID = @ShiftID";
|
|
|
strSql = "select count(plan_id) from ppt_plan where equip_code = @RecipeEquipCode and left(plan_id,6) = right(@PlanDate,6) and Shift_id = @ShiftID";
|
|
|
}
|
|
|
else if (dbType == Basic.DataSourceFactory.MCDbType.Local)
|
|
|
{
|
|
|
//strSql = "select count(plan_id) from ppt_plan where equip_code = @RecipeEquipCode and Convert(varchar,down_date,112) = @PlanDate and shift = @ShiftID";
|
|
|
strSql = "select count(plan_id) from ppt_plan where equip_code = @RecipeEquipCode and left(plan_id,6) = right(@PlanDate,6) and shift = @ShiftID";
|
|
|
}
|
|
|
dbHelper.CommandText = strSql;
|
|
|
dbHelper.AddParameter("@RecipeEquipCode", equipCode);
|
|
|
dbHelper.AddParameter("@PlanDate", String.Format("{0:yyyyMMdd}", planDate));
|
|
|
dbHelper.AddParameter("@ShiftID", shiftID);
|
|
|
object result = dbHelper.ToScalar();
|
|
|
if (result != null && result != System.DBNull.Value)
|
|
|
{
|
|
|
return Convert.ToInt32(result);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 获取本机台、日期、班次的当前计划索引。从1开始
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取当前计划索引。从1开始
|
|
|
/// </summary>
|
|
|
/// <param name="dbType">数据类型、网络、本地</param>
|
|
|
/// <param name="planID">计划号</param>
|
|
|
/// <returns>返回符合条件的计划数据</returns>
|
|
|
public static int GetCurrentPlanIndex(Mesnac.Basic.DataSourceFactory.MCDbType dbType, string planId)
|
|
|
{
|
|
|
DatabaseAction action = new DatabaseAction();
|
|
|
DbHelper dbHelper;
|
|
|
dbHelper = action.NewDbHelper(dbType);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
action.LogError("获取数据连接失败...");
|
|
|
return -1;
|
|
|
}
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
string strSql = String.Empty;
|
|
|
if (dbType == Basic.DataSourceFactory.MCDbType.Server)
|
|
|
{
|
|
|
//strSql = "select ActionOrder from PptPlan where PlanID = @PlanID order by ActionOrder";
|
|
|
strSql = "select Serial_num as ActionOrder from Ppt_Plan where Plan_id = @PlanID order by Serial_num";
|
|
|
}
|
|
|
else if (dbType == Basic.DataSourceFactory.MCDbType.Local)
|
|
|
{
|
|
|
strSql = "select ActionOrder from ppt_plan where plan_id = @PlanID order by ActionOrder";
|
|
|
}
|
|
|
dbHelper.CommandText = strSql;
|
|
|
dbHelper.AddParameter("@PlanID", planId);
|
|
|
object result = dbHelper.ToScalar();
|
|
|
if (result != null && result != System.DBNull.Value)
|
|
|
{
|
|
|
return Convert.ToInt32(result);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 根据计划号删除本地库的生产计划
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据计划号删除本地库的生产计划
|
|
|
/// </summary>
|
|
|
/// <param name="planId">要删除的计划号</param>
|
|
|
public static void DeleteByPlanID(string planId)
|
|
|
{
|
|
|
FeedingAction action = new FeedingAction();
|
|
|
DbHelper localHelper;
|
|
|
localHelper = action.NewDbHelper(Basic.DataSourceFactory.MCDbType.Local);
|
|
|
if (localHelper == null)
|
|
|
{
|
|
|
action.LogError("获取数据连接失败...");
|
|
|
}
|
|
|
localHelper.ClearParameter();
|
|
|
localHelper.CommandType = CommandType.Text;
|
|
|
string strSql = "delete from ppt_plan where plan_id = @PlanID";
|
|
|
localHelper.CommandText = strSql;
|
|
|
localHelper.AddParameter("@PlanID", planId);
|
|
|
localHelper.ExecuteNonQuery();
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 更新计划排序ActionOrder
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新本地计划排序ActionOrder
|
|
|
/// </summary>
|
|
|
/// <param name="planId">要更新的计划号</param>
|
|
|
/// <param name="actionOrder">排序值</param>
|
|
|
public static void UpdateActionOrder(string planId, int actionOrder)
|
|
|
{
|
|
|
FeedingAction action = new FeedingAction();
|
|
|
DbHelper localHelper = action.NewDbHelper(Basic.DataSourceFactory.MCDbType.Local);
|
|
|
if (localHelper == null)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("更新本机计划排序错误:获取本地数据连接失败!");
|
|
|
return;
|
|
|
}
|
|
|
localHelper.CommandType = CommandType.Text;
|
|
|
localHelper.ClearParameter();
|
|
|
string strSql = "update ppt_plan set ActionOrder = @ActionOrder where plan_id = @PlanID";
|
|
|
localHelper.CommandText = strSql;
|
|
|
localHelper.AddParameter("@ActionOrder", actionOrder);
|
|
|
localHelper.AddParameter("@PlanID", planId);
|
|
|
localHelper.ExecuteNonQuery();
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 向网络发送接收计划的数据
|
|
|
/// <summary>
|
|
|
/// 向网络发送接收计划的数据
|
|
|
/// </summary>
|
|
|
/// <param name="equipCode">机台号</param>
|
|
|
/// <param name="planDate">计划生产日期</param>
|
|
|
/// <param name="shiftID">班次</param>
|
|
|
public static void SendNetPlanMsg(string equipCode, DateTime planDate, int shiftID, int classID, string currentUser)
|
|
|
{
|
|
|
DataTable table = PlanCommon.GetPlanData(Mesnac.Basic.DataSourceFactory.MCDbType.Local, equipCode, planDate, shiftID);
|
|
|
StringBuilder sbNetMsg = new StringBuilder(); //保存要发送的网络消息
|
|
|
sbNetMsg.Append(Global.ProtocalHeader.ReceivePlanIpNumber);
|
|
|
sbNetMsg.Append(":");
|
|
|
sbNetMsg.Append(String.Format("{0:yyyy-MM-dd}", planDate));
|
|
|
sbNetMsg.Append("|");
|
|
|
sbNetMsg.Append(shiftID);
|
|
|
sbNetMsg.Append("|");
|
|
|
sbNetMsg.Append(classID);
|
|
|
sbNetMsg.Append("|");
|
|
|
sbNetMsg.Append(currentUser);
|
|
|
sbNetMsg.Append("|");
|
|
|
if (table != null && table.Rows.Count > 0)
|
|
|
{
|
|
|
foreach (DataRow row in table.Rows)
|
|
|
{
|
|
|
//sbNetMsg.Append(row["RecipeMaterialName"]);
|
|
|
//sbNetMsg.Append("+");
|
|
|
sbNetMsg.Append(row["RecipeMaterialCode"]);
|
|
|
sbNetMsg.Append("+");
|
|
|
sbNetMsg.Append(row["PlanNum"]);
|
|
|
sbNetMsg.Append("+");
|
|
|
sbNetMsg.Append(row["RealNum"]);
|
|
|
if (Mesnac.Basic.DataProcessor.RowValue(row, "PlanState", String.Empty) == "5")
|
|
|
{
|
|
|
sbNetMsg.Append("[终止]");
|
|
|
}
|
|
|
sbNetMsg.Append("+");
|
|
|
sbNetMsg.Append(row["PlanID"]);
|
|
|
sbNetMsg.Append("~");
|
|
|
}
|
|
|
}
|
|
|
sbNetMsg.Append("/");
|
|
|
Mesnac.Communication.TcpService.Instance.NetSendMsg(sbNetMsg.ToString()); //发送网络消息
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// socket通信
|
|
|
/// </summary>
|
|
|
/// <param name="equipCode"></param>
|
|
|
/// <param name="planDate"></param>
|
|
|
/// <param name="shiftID"></param>
|
|
|
/// <param name="classID"></param>
|
|
|
/// <param name="currentUser"></param>
|
|
|
public static void SendInit(string equipCode, DateTime planDate, int shiftID, int classID, string currentUser)
|
|
|
{
|
|
|
DataTable table = PlanCommon.GetPlanData(Mesnac.Basic.DataSourceFactory.MCDbType.Local, equipCode, planDate, shiftID);
|
|
|
//获取当前计划
|
|
|
DataRow dr = table.Select(string.Format("PlanID='{0}'", PlanCommon.PlanLog.LastPlanID)).FirstOrDefault();
|
|
|
StringBuilder sbNetMsg = new StringBuilder();
|
|
|
if (dr != null)
|
|
|
{
|
|
|
sbNetMsg.AppendFormat("{0}:{1}|{2}|{3}|{4}|{5:yyyy-MM-dd}|{6}|{7}/", Global.ProtocalHeader.ReceiveBaseStatu, Convert.ToInt32(dr["ActionOrder"]) - 1, dr["PlanNum"], dr["RealNum"], PlanCommon.PlanLog.LastSelectShiftID, PlanCommon.PlanLog.LastSelectDate, dr["RecipeMaterialCode"], currentUser);
|
|
|
}
|
|
|
sbNetMsg.AppendFormat("{0}:{1}", Global.ProtocalHeader.ReceivePlanIdIpNumber, PlanCommon.PlanLog.LastPlanID);
|
|
|
sbNetMsg.Append("/");
|
|
|
|
|
|
sbNetMsg.Append(Global.ProtocalHeader.ReceivePlanIpNumber);
|
|
|
sbNetMsg.Append(":");
|
|
|
sbNetMsg.Append(String.Format("{0:yyyy-MM-dd}", planDate));
|
|
|
sbNetMsg.Append("|");
|
|
|
sbNetMsg.Append(shiftID);
|
|
|
sbNetMsg.Append("|");
|
|
|
sbNetMsg.Append(classID);
|
|
|
sbNetMsg.Append("|");
|
|
|
sbNetMsg.Append(currentUser);
|
|
|
sbNetMsg.Append("|");
|
|
|
foreach (DataRow row in table.Rows)
|
|
|
{
|
|
|
sbNetMsg.Append(row["RecipeMaterialCode"]);
|
|
|
sbNetMsg.Append("+");
|
|
|
sbNetMsg.Append(row["PlanNum"]);
|
|
|
sbNetMsg.Append("+");
|
|
|
sbNetMsg.Append(row["RealNum"]);
|
|
|
if (Mesnac.Basic.DataProcessor.RowValue(row, "PlanState", String.Empty) == "5")
|
|
|
{
|
|
|
sbNetMsg.Append("[终止]");
|
|
|
}
|
|
|
sbNetMsg.Append("+");
|
|
|
sbNetMsg.Append(row["PlanID"]);
|
|
|
sbNetMsg.Append("~");
|
|
|
}
|
|
|
sbNetMsg.Append("/");
|
|
|
//称量参数
|
|
|
sbNetMsg.Append(RecipeWeighInfo());
|
|
|
|
|
|
Mesnac.Communication.TcpService.Instance.NetSendMsg(sbNetMsg.ToString());
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 获取配方胶料称量信息
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public static string RecipeWeighInfo()
|
|
|
{
|
|
|
if (RecipeWeighCache.Instance.CacheFlag)//下一个计划的称量配方已经下传
|
|
|
{
|
|
|
return RecipeWeighCache.Instance.RecipeWeighResolve();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return RecipeCache.Instance.RecipeWeighResolve();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 获取配方物料列表
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取网络版配方物料数据
|
|
|
/// </summary>
|
|
|
/// <param name="recipeEquipCode">机台号</param>
|
|
|
/// <param name="recipeState">配方状态</param>
|
|
|
/// <returns>返回符合条件的配方列表</returns>
|
|
|
public static List<SimplePmtRecipe> GetNetRecipeMaterialList(string recipeEquipCode, int recipeState)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
DatabaseAction action = new DatabaseAction();
|
|
|
DbHelper dbHelper;
|
|
|
dbHelper = action.NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Server);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
action.LogError("获取数据连接失败...");
|
|
|
return new List<SimplePmtRecipe>();
|
|
|
}
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
string strSql = @"SELECT '0' AS Mater_Code,' ---请选择---' AS ShowName,'0' as Edt_Code UNION ALL SELECT a.Mater_Code,rtrim(b.Mater_name)+'('+substring(rtrim(isnull(a.Recipe_Code,'')),7,2)+')'+'['+rtrim(a.Mater_Code)+']' AS ShowName,a.Edt_Code FROM Pmt_Recipe a
|
|
|
left join (select mater_code,mater_name from Pmt_material) b
|
|
|
on a.Mater_Code=b.Mater_code WHERE Recipe_State = @RecipeState and Equip_Code = @RecipeEquipCode and Audit_Flag= @AuditFlag order by Mater_Code";
|
|
|
dbHelper.CommandText = strSql;
|
|
|
dbHelper.AddParameter("@RecipeState", recipeState); //配方状态
|
|
|
dbHelper.AddParameter("@RecipeEquipCode", recipeEquipCode); //机台号
|
|
|
dbHelper.AddParameter("@AuditFlag", 1); //审批标志
|
|
|
DataTable table = dbHelper.ToDataTable();
|
|
|
List<SimplePmtRecipe> lst = new List<SimplePmtRecipe>();
|
|
|
SimplePmtRecipe recipe = null;
|
|
|
foreach (DataRow row in table.Rows)
|
|
|
{
|
|
|
recipe = new SimplePmtRecipe();
|
|
|
recipe.ObjID = row["Mater_Code"].ToString();
|
|
|
recipe.Content = row["ShowName"] as string;
|
|
|
recipe.RecipeVersionID = Convert.ToInt32(row["Edt_Code"]);
|
|
|
lst.Add(recipe);
|
|
|
}
|
|
|
return lst;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("获取网络版配方物料数据失败:" + ex.Message);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取本机版配方物料数据
|
|
|
/// </summary>
|
|
|
/// <param name="recipeEquipCode">机台号</param>
|
|
|
/// <param name="recipeState">配方状态</param>
|
|
|
/// <returns>返回符合条件的配方列表</returns>
|
|
|
public static List<SimplePmtRecipe> GetLocalRecipeMaterialList(string recipeEquipCode, int recipeState)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
DatabaseAction action = new DatabaseAction();
|
|
|
DbHelper dbHelper;
|
|
|
dbHelper = action.NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
action.LogError("获取数据连接失败...");
|
|
|
return new List<SimplePmtRecipe>();
|
|
|
}
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
string strSql = "SELECT '0' AS ObjID,'---请选择---' AS ShowName UNION ALL SELECT CONVERT(VARCHAR(100),ObjID) AS ObjID,rtrim(mater_name)+'('+substring(rtrim(isnull(recipe_code,'')),7,2)+')'+'['+rtrim(mater_code)+']' AS ShowName FROM pmt_recipe WHERE recipe_State=@RecipeState AND equip_code=@RecipeEquipCode order by ObjID";
|
|
|
dbHelper.CommandText = strSql;
|
|
|
dbHelper.AddParameter("@RecipeState", recipeState); //配方状态
|
|
|
dbHelper.AddParameter("@RecipeEquipCode", recipeEquipCode.Substring(3, 2)); //机台号
|
|
|
DataTable table = dbHelper.ToDataTable();
|
|
|
List<SimplePmtRecipe> lst = new List<SimplePmtRecipe>();
|
|
|
SimplePmtRecipe recipe = null;
|
|
|
foreach (DataRow row in table.Rows)
|
|
|
{
|
|
|
recipe = new SimplePmtRecipe();
|
|
|
recipe.ObjID = row["ObjID"].ToString();
|
|
|
recipe.Content = row["ShowName"] as string;
|
|
|
lst.Add(recipe);
|
|
|
}
|
|
|
return lst;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("获取本机版配方物料数据失败:" + ex.Message);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 定位一个配方的物料
|
|
|
/// </summary>
|
|
|
/// <param name="recipeEquipCode">机台号</param>
|
|
|
/// <param name="mater_code">物料代码</param>
|
|
|
/// <param name="edt_code">版本号</param>
|
|
|
/// <returns>返回配方物料</returns>
|
|
|
public static SimplePmtRecipe GetLocalRecipeMaterial(string recipeEquipCode, string mater_code, string edt_code)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
DatabaseAction action = new DatabaseAction();
|
|
|
DbHelper dbHelper;
|
|
|
dbHelper = action.NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
action.LogError("获取数据连接失败...");
|
|
|
return new SimplePmtRecipe();
|
|
|
}
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
string strSql = "SELECT CONVERT(VARCHAR(100),ObjID) AS ObjID,rtrim(mater_name)+'('+substring(rtrim(isnull(recipe_code,'')),7,2)+')'+'['+rtrim(mater_code)+']' AS ShowName FROM pmt_recipe WHERE equip_code=@RecipeEquipCode AND mater_code=@mater_code AND edt_code=@edt_code";
|
|
|
dbHelper.CommandText = strSql;
|
|
|
dbHelper.AddParameter("@RecipeEquipCode", recipeEquipCode.Substring(3, 2)); //机台号
|
|
|
dbHelper.AddParameter("@mater_code", mater_code); //物料编码
|
|
|
dbHelper.AddParameter("@edt_code", edt_code); //物料版本号
|
|
|
DataTable table = dbHelper.ToDataTable();
|
|
|
SimplePmtRecipe recipe = new SimplePmtRecipe();
|
|
|
foreach (DataRow row in table.Rows)
|
|
|
{
|
|
|
recipe.ObjID = row["ObjID"].ToString();
|
|
|
recipe.Content = row["ShowName"] as string;
|
|
|
break;
|
|
|
}
|
|
|
return recipe;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("定位一个配方的物料失败:" + ex.Message);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 拼音检索配方物料列表
|
|
|
|
|
|
/// <summary>
|
|
|
/// 拼音检索,获取网络版配方物料数据
|
|
|
/// </summary>
|
|
|
/// <param name="recipeEquipCode">机台号</param>
|
|
|
/// <param name="recipeState">配方状态</param>
|
|
|
/// <param name="materNamePY">拼音检索的物料名称</param>
|
|
|
/// <returns>返回符合条件的配方列表</returns>
|
|
|
public static List<SimplePmtRecipe> GetNetRecipeMaterialListPY(string recipeEquipCode, int recipeState, string materNamePY)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
DatabaseAction action = new DatabaseAction();
|
|
|
DbHelper dbHelper;
|
|
|
dbHelper = action.NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Server);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
action.LogError("获取数据连接失败...");
|
|
|
return new List<SimplePmtRecipe>();
|
|
|
}
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
string strSql = @"SELECT Mater_Code,rtrim(Mater_name)+'('+substring(rtrim(isnull(Recipe_Code,'')),7,2)+')'+'['+rtrim(Mater_Code)+']' AS ShowName,Edt_Code FROM Pmt_Recipe
|
|
|
WHERE Recipe_State = @RecipeState and Equip_Code = @RecipeEquipCode and Audit_Flag= @AuditFlag and dbo.fun_getPY(Mater_name) like @MaterName order by Mater_Code";
|
|
|
dbHelper.CommandText = strSql;
|
|
|
dbHelper.AddParameter("@RecipeState", recipeState); //配方状态
|
|
|
dbHelper.AddParameter("@RecipeEquipCode", recipeEquipCode); //机台号
|
|
|
dbHelper.AddParameter("@AuditFlag", 1); //审批标志
|
|
|
dbHelper.AddParameter("@MaterName", "%" + materNamePY + "%");
|
|
|
DataTable table = dbHelper.ToDataTable();
|
|
|
List<SimplePmtRecipe> lst = new List<SimplePmtRecipe>();
|
|
|
SimplePmtRecipe recipe = null;
|
|
|
foreach (DataRow row in table.Rows)
|
|
|
{
|
|
|
recipe = new SimplePmtRecipe();
|
|
|
recipe.ObjID = row["Mater_Code"].ToString();
|
|
|
recipe.Content = row["ShowName"] as string;
|
|
|
recipe.RecipeVersionID = Convert.ToInt32(row["Edt_Code"]);
|
|
|
lst.Add(recipe);
|
|
|
}
|
|
|
return lst;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("拼音检索,获取网络版配方物料数据失败:" + ex.Message);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取本机版配方物料数据
|
|
|
/// </summary>
|
|
|
/// <param name="recipeEquipCode">机台号</param>
|
|
|
/// <param name="recipeState">配方状态</param>
|
|
|
/// <param name="materNamePY">拼音检索的配方物料名称</param>
|
|
|
/// <returns>返回符合条件的配方列表</returns>
|
|
|
public static List<SimplePmtRecipe> GetLocalRecipeMaterialListPY(string recipeEquipCode, int recipeState, string materNamePY)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
DatabaseAction action = new DatabaseAction();
|
|
|
DbHelper dbHelper;
|
|
|
dbHelper = action.NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
action.LogError("获取数据连接失败...");
|
|
|
return new List<SimplePmtRecipe>();
|
|
|
}
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
string strSql = "SELECT CONVERT(VARCHAR(100),ObjID) AS ObjID,rtrim(mater_code) as Mater_Code,rtrim(mater_name)+'('+substring(rtrim(isnull(recipe_code,'')),7,2)+')'+'['+rtrim(mater_code)+']' AS ShowName,Edt_Code FROM pmt_recipe WHERE recipe_State=@RecipeState AND equip_code=@RecipeEquipCode and dbo.fun_getPY(mater_name) like @MaterName order by ObjID";
|
|
|
dbHelper.CommandText = strSql;
|
|
|
dbHelper.AddParameter("@RecipeState", recipeState); //配方状态
|
|
|
dbHelper.AddParameter("@RecipeEquipCode", recipeEquipCode.Substring(3, 2)); //机台号
|
|
|
dbHelper.AddParameter("@MaterName", "%" + materNamePY + "%");
|
|
|
DataTable table = dbHelper.ToDataTable();
|
|
|
List<SimplePmtRecipe> lst = new List<SimplePmtRecipe>();
|
|
|
SimplePmtRecipe recipe = null;
|
|
|
foreach (DataRow row in table.Rows)
|
|
|
{
|
|
|
recipe = new SimplePmtRecipe();
|
|
|
recipe.ObjID = row["ObjID"].ToString();
|
|
|
|
|
|
recipe.Content = row["ShowName"] as string;
|
|
|
lst.Add(recipe);
|
|
|
}
|
|
|
return lst;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("拼音检索,获取本机版配方物料数据失败:" + ex.Message);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 获取SysCode表中的项名称
|
|
|
/// <summary>
|
|
|
/// 获取SysCode表中的项名称
|
|
|
/// </summary>
|
|
|
/// <param name="dbType">数据类型,网络数据、本地数据</param>
|
|
|
/// <param name="typeID">类型ID</param>
|
|
|
/// <param name="itemCode">项序号</param>
|
|
|
/// <returns>返回项名称</returns>
|
|
|
public static string GetSysCodeItemName(Mesnac.Basic.DataSourceFactory.MCDbType dbType, string typeID, int itemCode)
|
|
|
{
|
|
|
DatabaseAction action = new DatabaseAction();
|
|
|
DbHelper dbHelper;
|
|
|
dbHelper = action.NewDbHelper(dbType);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
action.LogError("获取数据连接失败...");
|
|
|
return String.Empty;
|
|
|
}
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
string strSql = "select ItemName from SysCode where TypeID = @TypeID and ItemCode = @ItemCode";
|
|
|
dbHelper.CommandText = strSql;
|
|
|
dbHelper.AddParameter("@TypeID", typeID);
|
|
|
dbHelper.AddParameter("@ItemCode", itemCode);
|
|
|
object result = dbHelper.ToScalar();
|
|
|
if (result != null && result != System.DBNull.Value)
|
|
|
{
|
|
|
return result as string;
|
|
|
}
|
|
|
return String.Empty;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 获取网络库中胶料称锁定状态
|
|
|
/// <summary>
|
|
|
/// 获取网络库中胶料称锁定状态
|
|
|
/// </summary>
|
|
|
/// <param name="equipCode">机台号</param>
|
|
|
/// <returns>返回胶料称锁定状态实体</returns>
|
|
|
public static RubWeightSetting GetRubWeightSetting(string equipCode)
|
|
|
{
|
|
|
DatabaseAction action = new DatabaseAction();
|
|
|
DbHelper dbHelper;
|
|
|
dbHelper = action.NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Server);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
action.LogError("获取数据连接失败...");
|
|
|
return new RubWeightSetting();
|
|
|
}
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
//string strSql = "SELECT [ObjID],[EquipCode],[State],[EquipElectricCurrent],[WeightSettingCtrl],[DeleteFlag],[Remark] FROM [PmtRubWeightSetting] where [EquipCode] = @EquipCode";
|
|
|
string strSql = "SELECT 0 as [ObjID],Equip_Code as [EquipCode],[State],DianLiu as [EquipElectricCurrent],BarCtl as [WeightSettingCtrl],0 as [DeleteFlag],'' as [Remark] FROM ppt_EquipState where Equip_Code = @EquipCode";
|
|
|
dbHelper.CommandText = strSql;
|
|
|
dbHelper.AddParameter("@EquipCode", equipCode);
|
|
|
RubWeightSetting rws = null;
|
|
|
using (DbDataReader reader = dbHelper.ToDbDataReader())
|
|
|
{
|
|
|
if (reader.Read())
|
|
|
{
|
|
|
rws = new RubWeightSetting();
|
|
|
rws.ObjID = Convert.ToInt32(reader["ObjID"]);
|
|
|
rws.EquipCode = equipCode;
|
|
|
rws.State = reader["State"] as string;
|
|
|
rws.EquipElectricCurrent = Convert.ToInt32(reader["EquipElectricCurrent"]);
|
|
|
rws.WeightSettingCtrl = reader["WeightSettingCtrl"] as string; //大于等于1参与锁秤控制
|
|
|
rws.DeleteFlag = reader["DeleteFlag"] as string;
|
|
|
rws.Remark = reader["Remark"] as string;
|
|
|
reader.Close();
|
|
|
reader.Dispose();
|
|
|
}
|
|
|
}
|
|
|
return rws;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 获取班组
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取班组ID
|
|
|
/// </summary>
|
|
|
/// <param name="dbType">数据库类型,网络数据库、本地数据库</param>
|
|
|
/// <param name="procedureID">工序,密炼上辅机工序为1</param>
|
|
|
/// <param name="planDate">计划生产日期</param>
|
|
|
/// <param name="shiftID">班次</param>
|
|
|
/// <returns>返回对应的班组ID</returns>
|
|
|
public static int GetClassID(Mesnac.Basic.DataSourceFactory.MCDbType dbType, int procedureID, DateTime planDate, int shiftID)
|
|
|
{
|
|
|
DatabaseAction action = new DatabaseAction();
|
|
|
DbHelper dbHelper;
|
|
|
if (dbType == Basic.DataSourceFactory.MCDbType.Local)
|
|
|
{
|
|
|
action.LogError("本地库不支持此方法:PlanCommon.GetClassID!");
|
|
|
return -1;
|
|
|
}
|
|
|
dbHelper = action.NewDbHelper(dbType);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
action.LogError("获取数据连接失败...");
|
|
|
return -1;
|
|
|
}
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
string strSql = "select Shift_Class from Ppt_Shiftime where Dept_Code = @ProcedureID and Convert(varchar,Shift_DT,112) = @PlanDate and Shift_ID = @ShiftID";
|
|
|
dbHelper.CommandText = strSql;
|
|
|
dbHelper.AddParameter("@ProcedureID", procedureID);
|
|
|
dbHelper.AddParameter("@PlanDate", String.Format("{0:yyyyMMdd}", planDate));
|
|
|
dbHelper.AddParameter("@ShiftID", shiftID);
|
|
|
object result = dbHelper.ToScalar();
|
|
|
if (result == null || result == System.DBNull.Value)
|
|
|
{
|
|
|
return 0;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return Convert.ToInt32(result);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取班组名称
|
|
|
/// </summary>
|
|
|
/// <param name="dbType">数据库类型,网络数据库、本地数据库</param>
|
|
|
/// <param name="procedureID">工序,密炼上辅机工序为1</param>
|
|
|
/// <param name="planDate">计划生产日期</param>
|
|
|
/// <param name="shiftID">班次</param>
|
|
|
/// <returns>返回对应的班组名称</returns>
|
|
|
public static string GetClassName(Mesnac.Basic.DataSourceFactory.MCDbType dbType, int procedureID, DateTime planDate, int shiftID)
|
|
|
{
|
|
|
DatabaseAction action = new DatabaseAction();
|
|
|
DbHelper dbHelper;
|
|
|
if (dbType == Basic.DataSourceFactory.MCDbType.Local)
|
|
|
{
|
|
|
action.LogError("不支持此方法!");
|
|
|
return String.Empty;
|
|
|
}
|
|
|
dbHelper = action.NewDbHelper(dbType);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
action.LogError("获取数据连接失败...");
|
|
|
return String.Empty;
|
|
|
}
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
string strSql = "select ClassName from PptClass where ObjID=(select ShiftClassID from PptShiftTime where ProcedureID = @ProcedureID and Convert(varchar,ShiftDT,112) = @PlanDate and ShiftID = @ShiftID)";
|
|
|
if(dbType==Mesnac.Basic.DataSourceFactory.MCDbType.Server)//如果为网络库,则换清泉数据库
|
|
|
strSql = @"select shift_ClassName as ClassName from Ppt_ShiftClass
|
|
|
where shift_ClassId=(select shift_Class from Ppt_ShifTime where Dept_code = @ProcedureID
|
|
|
and Convert(varchar,cast(Shift_DT as datetime),112) = @PlanDate and Shift_ID = @ShiftID)";
|
|
|
|
|
|
dbHelper.CommandText = strSql;
|
|
|
dbHelper.AddParameter("@ProcedureID", procedureID);
|
|
|
dbHelper.AddParameter("@PlanDate", String.Format("{0:yyyyMMdd}", planDate));
|
|
|
dbHelper.AddParameter("@ShiftID", shiftID);
|
|
|
object result = dbHelper.ToScalar();
|
|
|
if (result == null || result == System.DBNull.Value)
|
|
|
{
|
|
|
return String.Empty;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return result.ToString().Trim();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 获取下一个可用的序号SerialNum 规则:同机台、同日期、同班次 计划号最后2位的最大值加1
|
|
|
/// <summary>
|
|
|
/// 获取下一个可用的序号
|
|
|
/// </summary>
|
|
|
/// <param name="dbType">数据库类型,网络数据库、本地数据库</param>
|
|
|
/// <param name="equipCode">5位机台号</param>
|
|
|
/// <param name="planDate">计划生产日期</param>
|
|
|
/// <param name="shiftID">班次</param>
|
|
|
/// <returns>返回可用的序号</returns>
|
|
|
public static int GetNextSerialNum(Mesnac.Basic.DataSourceFactory.MCDbType dbType, string equipCode, DateTime planDate, int shiftID)
|
|
|
{
|
|
|
DatabaseAction action = new DatabaseAction();
|
|
|
DbHelper dbHelper;
|
|
|
dbHelper = action.NewDbHelper(dbType);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
action.LogError("获取数据连接失败...");
|
|
|
return -1;
|
|
|
}
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
string strSql = String.Empty;
|
|
|
if (dbType == Basic.DataSourceFactory.MCDbType.Server)
|
|
|
{
|
|
|
//strSql = "select max(right(PlanID,2)) from PptPlan where RecipeEquipCode = @RecipeEquipCode and Convert(varchar,PlanDate,112) = @PlanDate and ShiftID = @ShiftID";
|
|
|
strSql = "select max(right(Plan_ID,2)) from Ppt_Plan where Equip_code = @RecipeEquipCode and left(Plan_ID,6) = right(@PlanDate,6) and Shift_ID = @ShiftID";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//strSql = "select max(right(plan_id,2)) from ppt_plan where equip_code = @RecipeEquipCode and Convert(varchar,down_date,112) = @PlanDate and shift = @ShiftID";
|
|
|
strSql = "select max(right(plan_id,2)) from ppt_plan where equip_code = @RecipeEquipCode and left(plan_id,6) = right(@PlanDate,6) and shift = @ShiftID";
|
|
|
}
|
|
|
dbHelper.CommandText = strSql;
|
|
|
dbHelper.AddParameter("@RecipeEquipCode", equipCode);
|
|
|
dbHelper.AddParameter("@PlanDate", String.Format("{0:yyyyMMdd}", planDate));
|
|
|
dbHelper.AddParameter("@ShiftID", shiftID);
|
|
|
object result = dbHelper.ToScalar();
|
|
|
if (result == null || result == System.DBNull.Value)
|
|
|
{
|
|
|
return 1;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return Convert.ToInt32(result) + 1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 添加生产计划
|
|
|
/// <summary>
|
|
|
/// 加生产计划
|
|
|
/// </summary>
|
|
|
/// <param name="dbType">数据库类型,网络数据库、本地数据库</param>
|
|
|
/// <param name="equipCode">5位机台号</param>
|
|
|
/// <param name="planDate">计划生产日期</param>
|
|
|
/// <param name="shiftID">班次</param>
|
|
|
/// <param name="classID">班组</param>
|
|
|
/// <param name="recipeObjID">配方ID</param>
|
|
|
/// <param name="planNum">计划数</param>
|
|
|
/// <param name="errorList">输出错误列表</param>
|
|
|
/// <returns>返回新加计划的计划号</returns>
|
|
|
public static string AddPlan(Mesnac.Basic.DataSourceFactory.MCDbType dbType, string equipCode, DateTime planDate, int shiftID, int classID, string recipeObjID,int edtCode, int planNum, out List<string> errorList)
|
|
|
{
|
|
|
errorList = new List<string>();
|
|
|
DatabaseAction action = new DatabaseAction();
|
|
|
DbHelper dbHelper;
|
|
|
dbHelper = action.NewDbHelper(dbType);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
action.LogError("获取数据连接失败...");
|
|
|
return String.Empty;
|
|
|
}
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
//查询配方数据的SQL语句
|
|
|
string strSql1 = String.Empty;
|
|
|
if (dbType == Basic.DataSourceFactory.MCDbType.Server)
|
|
|
{
|
|
|
strSql1 = "select Mater_code as RecipeMaterialCode,mater_name as RecipeMaterialName,edt_code as RecipeVersionID,Edt_code as RecipeUserVersion,recipe_code as RecipeName,1 as RecipeType,total_weight as LotTotalWeight from Pmt_Recipe where Equip_code = @Equipcode and Mater_code=@Matercode and Edt_code=@Edtcode";
|
|
|
dbHelper.CommandText = strSql1;
|
|
|
dbHelper.AddParameter("@Equipcode", equipCode);
|
|
|
dbHelper.AddParameter("@Matercode", recipeObjID);
|
|
|
dbHelper.AddParameter("@Edtcode", edtCode);
|
|
|
}
|
|
|
else if (dbType == Basic.DataSourceFactory.MCDbType.Local)
|
|
|
{
|
|
|
strSql1 = "select ObjID,mater_code as RecipeMaterialCode,mater_name as RecipeMaterialName,edt_code as RecipeVersionID,'' as RecipeUserVersion,recipe_code as RecipeName,1 as RecipeType,total_weight as LotTotalWeight from pmt_recipe where ObjID = @ObjID";
|
|
|
dbHelper.CommandText = strSql1;
|
|
|
dbHelper.AddParameter("@ObjID", recipeObjID);
|
|
|
}
|
|
|
DataTable recipeTable = dbHelper.ToDataTable();
|
|
|
if (recipeTable != null && recipeTable.Rows.Count == 1)
|
|
|
{
|
|
|
DataRow row = recipeTable.Rows[0];
|
|
|
|
|
|
object recipeMaterialCode = row["RecipeMaterialCode"]; //物料代码
|
|
|
object recipeMaterialName = row["RecipeMaterialName"]; //配方名称
|
|
|
object recipeVersionID = row["RecipeVersionID"]; //配方版本号
|
|
|
object recipeUserVersion = row["RecipeUserVersion"];
|
|
|
object recipeName = row["RecipeName"]; //配方名称
|
|
|
object recipeType = row["RecipeType"]; //配方类型
|
|
|
object totalWeight = row["LotTotalWeight"]; //每车重量
|
|
|
if (dbType == Basic.DataSourceFactory.MCDbType.Server)
|
|
|
{
|
|
|
if (classID < 1)
|
|
|
{
|
|
|
classID = GetClassID(dbType, 1, planDate, shiftID); //班组
|
|
|
}
|
|
|
}
|
|
|
int localSerialNum = 0;
|
|
|
string localPlanID = String.Empty;
|
|
|
|
|
|
int serialNum = GetNextSerialNum(dbType, equipCode, planDate, shiftID); //序号
|
|
|
string planID = GenerateNextPlanID(dbType, equipCode, planDate, shiftID); //计划号
|
|
|
|
|
|
if (dbType == Basic.DataSourceFactory.MCDbType.Server)
|
|
|
{
|
|
|
//如果是网络版则获取本地计划号和序号,用于跟网络版进行大小对比,防止,由单机切换网络版本时添加重复计划
|
|
|
localSerialNum = GetNextSerialNum(Basic.DataSourceFactory.MCDbType.Local, equipCode, planDate, shiftID); //通过本地库生成序号
|
|
|
localPlanID = GenerateNextPlanID(Basic.DataSourceFactory.MCDbType.Local, equipCode, planDate, shiftID); //通过本地库生成
|
|
|
|
|
|
//如果网络获取的计划号小于通过本地获取的计划号,则用本地获取的计划号
|
|
|
if (planID.Contains("L") && planID.CompareTo(localPlanID) < 0)
|
|
|
{
|
|
|
planID = localPlanID;
|
|
|
serialNum = localSerialNum;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
try
|
|
|
{
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
//添加计划的SQL语句
|
|
|
string strSql3 = String.Empty;
|
|
|
if (dbType == Mesnac.Basic.DataSourceFactory.MCDbType.Server)
|
|
|
{
|
|
|
strSql3 = "insert into Ppt_Plan(Plan_ID,Plan_Date,Equip_code,Mater_code,Mater_Name,Edt_code,User_Edtcode,Shift_id,Shift_class,";
|
|
|
strSql3 += "Serial_num,Pri_level,recipe_code,Recipe_Type,Run_Type,Print_Type,Plan_Source,Total_weight,Plan_num,Plan_weight,Real_num,Real_weight,";
|
|
|
strSql3 += "Urgency_state,Plan_state,Oper_datetime,Plan_EndTime,Real_StartTime,Real_Endtime,Oper_code,revise_sgn,XLcreate,Memo";
|
|
|
strSql3 += ")";
|
|
|
strSql3 += " values(@PlanID,@PlanDate,@RecipeEquipCode,@RecipeMaterialCode,@RecipeMaterialName,@RecipeVersionID,@RecipeUserVersion,@ShiftID,@ClassID,";
|
|
|
strSql3 += "@SerialNum,@PriLevel,@RecipeName,@RecipeType,@RunType,@PrintType,@PlanSource,@TotalWeight,@PlanNum,@PlanWeight,@RealNum,@RealWeight,";
|
|
|
strSql3 += "@UrgencyState,@PlanState,@OperDatetime,@PlanEndTime,@RealStartTime,@RealEndtime,@OperCode,@ReviseSgn,@SmallCreate,@Remark";
|
|
|
strSql3 += ")";
|
|
|
|
|
|
dbHelper.CommandText = strSql3;
|
|
|
|
|
|
dbHelper.AddParameter("@PlanID", planID);
|
|
|
dbHelper.AddParameter("@PlanDate", Convert.ToDateTime(planDate.ToShortDateString()).ToString("yyyy-MM-dd"));
|
|
|
dbHelper.AddParameter("@RecipeEquipCode", equipCode);
|
|
|
dbHelper.AddParameter("@RecipeMaterialCode", recipeMaterialCode);
|
|
|
dbHelper.AddParameter("@RecipeMaterialName", recipeMaterialName);
|
|
|
dbHelper.AddParameter("@RecipeVersionID", recipeVersionID);
|
|
|
dbHelper.AddParameter("@RecipeUserVersion", recipeUserVersion);
|
|
|
dbHelper.AddParameter("@ShiftID", shiftID);
|
|
|
dbHelper.AddParameter("@ClassID", classID);
|
|
|
dbHelper.AddParameter("@SerialNum", serialNum);
|
|
|
dbHelper.AddParameter("@PriLevel", serialNum);
|
|
|
dbHelper.AddParameter("@RecipeName", recipeName);
|
|
|
dbHelper.AddParameter("@RecipeType", recipeType);
|
|
|
dbHelper.AddParameter("@RunType", null);
|
|
|
dbHelper.AddParameter("@PrintType", null);
|
|
|
dbHelper.AddParameter("@PlanSource", "L");
|
|
|
dbHelper.AddParameter("@TotalWeight", totalWeight);
|
|
|
dbHelper.AddParameter("@PlanNum", planNum);
|
|
|
dbHelper.AddParameter("@PlanWeight", Convert.ToDecimal(totalWeight) * planNum);
|
|
|
dbHelper.AddParameter("@RealNum", 0);
|
|
|
dbHelper.AddParameter("@RealWeight", 0);
|
|
|
dbHelper.AddParameter("@UrgencyState", 2); //计划紧急状态
|
|
|
dbHelper.AddParameter("@PlanState", 2); //计划状态,初始为2-已下达
|
|
|
dbHelper.AddParameter("@OperDatetime", String.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now));
|
|
|
dbHelper.AddParameter("@PlanEndTime", null);
|
|
|
dbHelper.AddParameter("@RealStartTime", null);
|
|
|
dbHelper.AddParameter("@RealEndtime", null);
|
|
|
dbHelper.AddParameter("@OperCode", "JiTai");
|
|
|
dbHelper.AddParameter("@ReviseSgn", 1);
|
|
|
dbHelper.AddParameter("@SmallCreate", 0);
|
|
|
//dbHelper.AddParameter("@AvgTime", null);
|
|
|
dbHelper.AddParameter("@Remark", null);
|
|
|
}
|
|
|
else if (dbType == Mesnac.Basic.DataSourceFactory.MCDbType.Local)
|
|
|
{
|
|
|
strSql3 = "insert into ppt_plan([plan_id],[pri_level],[mater_code],[shift_class],[equip_code],[edt_code],[modi_code],[plan_num],[real_num],[plan_state],[revise_sgn],[revise_date],[shift],[down_date],[recipe_code],[plan_weight],[total_weight],[real_weight],[plan_datetime],[real_datetime],[oper_code],[oper_datetime],[ActionOrder])";
|
|
|
strSql3 += " values(@PlanID,@PriLevel,@RecipeMaterialCode,@ClassID,@RecipeEquipCode,@RecipeVersionID,@ModiCode,@PlanNum,@RealNum,@PlanState,@ReviseSgn,@revise_date,@ShiftID,@PlanDate,@RecipeMaterialName,@PlanWeight,@TotalWeight,@RealWeight,@plan_datetime,@RealEndtime,@OperCode,@OperDatetime,@ActionOrder)";
|
|
|
|
|
|
dbHelper.CommandText = strSql3;
|
|
|
|
|
|
dbHelper.AddParameter("@PlanID", planID);
|
|
|
dbHelper.AddParameter("@PriLevel", serialNum);
|
|
|
dbHelper.AddParameter("@RecipeMaterialCode", recipeMaterialCode);
|
|
|
dbHelper.AddParameter("@ClassID", classID);
|
|
|
dbHelper.AddParameter("@RecipeEquipCode", equipCode);
|
|
|
dbHelper.AddParameter("@RecipeVersionID", recipeVersionID);
|
|
|
dbHelper.AddParameter("@ModiCode", 0); //计划上传标志,0-未上传,1-已上传
|
|
|
dbHelper.AddParameter("@PlanNum", planNum);
|
|
|
dbHelper.AddParameter("@RealNum", 0);
|
|
|
dbHelper.AddParameter("@PlanState", 3); //接收网络计划时把PlanState设置为3-已接收,同时把网络计划的PlanState设置为3
|
|
|
dbHelper.AddParameter("@ReviseSgn", 1); //接收网络计划时把ReviseSgn设置为0,同时把网络计划的ReviseSgn设置为0
|
|
|
dbHelper.AddParameter("@revise_date", null); //接收网络计划的时间
|
|
|
dbHelper.AddParameter("@ShiftID", shiftID);
|
|
|
dbHelper.AddParameter("@PlanDate", Convert.ToDateTime(planDate.ToShortDateString()));
|
|
|
dbHelper.AddParameter("@RecipeMaterialName", recipeMaterialName);
|
|
|
dbHelper.AddParameter("@PlanWeight", Convert.ToDecimal(totalWeight) * planNum);
|
|
|
dbHelper.AddParameter("@TotalWeight", totalWeight);
|
|
|
dbHelper.AddParameter("@RealWeight", 0);
|
|
|
dbHelper.AddParameter("@plan_datetime", String.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now)); //计划制定时间
|
|
|
dbHelper.AddParameter("@RealEndtime", null);
|
|
|
dbHelper.AddParameter("@OperCode", "JiTai");
|
|
|
dbHelper.AddParameter("@OperDatetime", String.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now));
|
|
|
dbHelper.AddParameter("@ActionOrder", serialNum);
|
|
|
}
|
|
|
|
|
|
dbHelper.ExecuteNonQuery();
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("添加计划失败:" + ex.Message);
|
|
|
return String.Empty;
|
|
|
}
|
|
|
|
|
|
return planID;
|
|
|
}
|
|
|
return String.Empty;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 按计划号删除计划
|
|
|
/// <summary>
|
|
|
/// 按计划号删除计划
|
|
|
/// </summary>
|
|
|
/// <param name="dbType">数据库类型:网络库、本地库</param>
|
|
|
/// <param name="planId">要删除计划对应的计划号</param>
|
|
|
/// <returns>成功返回true,失败返回false</returns>
|
|
|
public static bool DeletePlan(Mesnac.Basic.DataSourceFactory.MCDbType dbType, string planId)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
FeedingAction action = new FeedingAction();
|
|
|
DbHelper dbHelper = action.NewDbHelper(dbType);
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
dbHelper.ClearParameter();
|
|
|
string strSql = String.Empty;
|
|
|
if (dbType == Basic.DataSourceFactory.MCDbType.Server)
|
|
|
{
|
|
|
strSql = "delete from Ppt_Plan where plan_id=@PlanID";
|
|
|
}
|
|
|
else if (dbType == Basic.DataSourceFactory.MCDbType.Local)
|
|
|
{
|
|
|
strSql = "delete from Ppt_Plan where plan_id=@PlanID";
|
|
|
}
|
|
|
dbHelper.CommandText = strSql;
|
|
|
dbHelper.AddParameter("@PlanID", planId);
|
|
|
dbHelper.ExecuteNonQuery();
|
|
|
return true;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("删除计划失败:" + ex.Message);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 接收计划核心业务
|
|
|
/// <summary>
|
|
|
/// 接收计划核心业务
|
|
|
/// </summary>
|
|
|
/// <param name="planID">计划号</param>
|
|
|
/// <param name="equipCode">机台号</param>
|
|
|
/// <param name="planDate">计划日期</param>
|
|
|
/// <param name="shiftID">班次</param>
|
|
|
/// <returns>如果有接到数据返回true,否则返回false</returns>
|
|
|
public static bool RecivePlan(string planID, string equipCode, DateTime planDate, int shiftID)
|
|
|
{
|
|
|
DatabaseAction action = new DatabaseAction();
|
|
|
DbHelper dbHelper1, dbHelper2;
|
|
|
dbHelper1 = action.NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Server);
|
|
|
if (dbHelper1 == null)
|
|
|
{
|
|
|
action.LogError("获取网络数据连接失败...");
|
|
|
return false;
|
|
|
}
|
|
|
dbHelper2 = action.NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
if (dbHelper2 == null)
|
|
|
{
|
|
|
action.LogError("获取本地数据连接失败...");
|
|
|
return false;
|
|
|
}
|
|
|
string strSql1 = @"select Plan_id PlanID, Plan_date PlanDate, Equip_code RecipeEquipCode, Mater_code RecipeMaterialCode, Mater_Name RecipeMaterialName, Edt_code RecipeVersionID, User_Edtcode RecipeUserVersion
|
|
|
, Shift_id ShiftID, Shift_class ClassID, Serial_num SerialNum, Pri_level PriLevel, recipe_code RecipeName, Recipe_Type RecipeType, Run_Type RunType, Print_Type PrintType
|
|
|
, Plan_Source PlanSource, Total_weight TotalWeight, Plan_num PlanNum, Plan_weight PlanWeight, Real_num RealNum, Real_weight RealWeight, Urgency_state UrgencyState
|
|
|
, Plan_state PlanState, Oper_datetime OperDatetime, Plan_EndTime PlanEndTime, Real_StartTime RealStartTime, Real_Endtime RealEndtime, Oper_code OperCode, revise_sgn ReviseSgn
|
|
|
, XLcreate SmallCreate, MonthSerial AvgTime, Memo Remark from Ppt_Plan where Plan_ID = @PlanID";
|
|
|
dbHelper1.CommandText = strSql1;
|
|
|
dbHelper1.AddParameter("@PlanID", planID);
|
|
|
DataTable fromTable = dbHelper1.ToDataTable();
|
|
|
bool flag = false;
|
|
|
if (fromTable != null && fromTable.Rows.Count == 1)
|
|
|
{
|
|
|
DataRow row = fromTable.Rows[0];
|
|
|
bool result = RecivePlan(dbHelper1, dbHelper2, row, equipCode, planDate, shiftID);
|
|
|
if (result == true)
|
|
|
{
|
|
|
flag = true;
|
|
|
}
|
|
|
}
|
|
|
return flag;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除本地库计划
|
|
|
/// </summary>
|
|
|
/// <param name="dbHelperLocal"></param>
|
|
|
/// <param name="equipCode"></param>
|
|
|
/// <param name="planDate"></param>
|
|
|
/// <param name="shiftID"></param>
|
|
|
/// <returns></returns>
|
|
|
public static bool DelCurrentPlan(string equipCode, DateTime planDate, int shiftID)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
DatabaseAction action = new DatabaseAction();
|
|
|
DbHelper dbHelperLocal;
|
|
|
dbHelperLocal = action.NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
if (dbHelperLocal == null)
|
|
|
{
|
|
|
action.LogError("获取本地数据连接失败...");
|
|
|
return false;
|
|
|
}
|
|
|
string sqlStr3 = "delete from ppt_plan where convert(varchar,down_date,112)=@PlanDate and shift=@ShiftID and equip_code=@RecipeEquipCode";
|
|
|
dbHelperLocal.AddParameter("@PlanDate", String.Format("{0:yyyyMMdd}", planDate));
|
|
|
dbHelperLocal.AddParameter("@ShiftID", shiftID);
|
|
|
dbHelperLocal.AddParameter("@RecipeEquipCode", equipCode);
|
|
|
dbHelperLocal.CommandText = sqlStr3;
|
|
|
dbHelperLocal.ExecuteNonQuery();
|
|
|
return true;
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 接收计划
|
|
|
/// </summary>
|
|
|
/// <param name="dbHelperServer">服务器数据辅助对象</param>
|
|
|
/// <param name="dbHelperLocal">本地数据辅助对象</param>
|
|
|
/// <param name="planRow">计划数据行</param>
|
|
|
/// <param name="equipCode">机台号</param>
|
|
|
/// <param name="planDate">计划生产日期</param>
|
|
|
/// <param name="shiftID">班次</param>
|
|
|
/// <returns>如果有接到数据返回true,否则返回false</returns>
|
|
|
public static bool RecivePlan(DbHelper dbHelperServer, DbHelper dbHelperLocal, DataRow planRow, string equipCode, DateTime planDate, int shiftID)
|
|
|
{
|
|
|
DataRow row = planRow;
|
|
|
dbHelperLocal.ClearParameter();
|
|
|
dbHelperLocal.CommandType = CommandType.Text;
|
|
|
//检测本地库中是否存在对应的计划
|
|
|
string sqlStr2 = "select count(plan_id) from ppt_plan where plan_id=@PlanID";
|
|
|
dbHelperLocal.AddParameter("@PlanID", row["PlanID"]);
|
|
|
dbHelperLocal.CommandText = sqlStr2;
|
|
|
object result = dbHelperLocal.ToScalar();
|
|
|
if (Convert.ToInt32(result) == 0)
|
|
|
{
|
|
|
//获取ActionOrder值
|
|
|
int nextActionOrder = PlanCommon.GetNewActionOrder(equipCode, planDate, shiftID);
|
|
|
|
|
|
dbHelperLocal.ClearParameter();
|
|
|
dbHelperLocal.CommandType = CommandType.Text;
|
|
|
|
|
|
//本地追加计划
|
|
|
//string sqlStr3 = "insert into PptPlan(PlanID,PlanDate,RecipeEquipCode,RecipeMaterialCode,RecipeMaterialName,RecipeVersionID,RecipeUserVersion,ShiftID,ClassID,SerialNum,PriLevel,RecipeName,RecipeType,RunType,PrintType,PlanSource,TotalWeight,PlanNum,PlanWeight,RealNum,RealWeight,UrgencyState,PlanState,OperDatetime,PlanEndTime,RealStartTime,RealEndtime,OperCode,ReviseSgn,SmallCreate,AvgTime,Remark,DeleteFlag,CreatePlanFlag,ActionOrder)";
|
|
|
//sqlStr3 += " values(@PlanID,@PlanDate,@RecipeEquipCode,@RecipeMaterialCode,@RecipeMaterialName,@RecipeVersionID,@RecipeUserVersion,@ShiftID,@ClassID,@SerialNum,@PriLevel,@RecipeName,@RecipeType,@RunType,@PrintType,@PlanSource,@TotalWeight,@PlanNum,@PlanWeight,@RealNum,@RealWeight,@UrgencyState,@PlanState,@OperDatetime,@PlanEndTime,@RealStartTime,@RealEndtime,@OperCode,@ReviseSgn,@SmallCreate,@AvgTime,@Remark,@DeleteFlag,@CreatePlanFlag,@ActionOrder)";
|
|
|
|
|
|
string sqlStr3 = "insert into ppt_plan([plan_id],[pri_level],[mater_code],[shift_class],[equip_code],[edt_code],[modi_code],[plan_num],[real_num],[plan_state],[revise_sgn],[revise_date],[shift],[down_date],[recipe_code],[plan_weight],[total_weight],[real_weight],[plan_datetime],[real_datetime],[oper_code],[oper_datetime],[ActionOrder])";
|
|
|
sqlStr3 += " values(@PlanID,@PriLevel,@RecipeMaterialCode,@ClassID,@RecipeEquipCode,@RecipeVersionID,@ModiCode,@PlanNum,@RealNum,@PlanState,@ReviseSgn,@revise_date,@ShiftID,@PlanDate,@RecipeMaterialName,@PlanWeight,@TotalWeight,@RealWeight,@plan_datetime,@RealEndtime,@OperCode,@OperDatetime,@ActionOrder)";
|
|
|
|
|
|
dbHelperLocal.AddParameter("@PlanID", row["PlanID"]);
|
|
|
dbHelperLocal.AddParameter("@PriLevel", row["PriLevel"]);
|
|
|
dbHelperLocal.AddParameter("@RecipeMaterialCode", row["RecipeMaterialCode"]);
|
|
|
dbHelperLocal.AddParameter("@ClassID", row["ClassID"]);
|
|
|
dbHelperLocal.AddParameter("@RecipeEquipCode", row["RecipeEquipCode"]);
|
|
|
dbHelperLocal.AddParameter("@RecipeVersionID", row["RecipeVersionID"]);
|
|
|
dbHelperLocal.AddParameter("@ModiCode", 1); //计划上传标志,0-未上传,1-已上传
|
|
|
dbHelperLocal.AddParameter("@PlanNum", row["PlanNum"]);
|
|
|
dbHelperLocal.AddParameter("@RealNum", row["RealNum"]);
|
|
|
dbHelperLocal.AddParameter("@PlanState", 3); //接收网络计划时把PlanState设置为3-已接收,同时把网络计划的PlanState设置为3
|
|
|
dbHelperLocal.AddParameter("@ReviseSgn", 0); //接收网络计划时把ReviseSgn设置为0,同时把网络计划的ReviseSgn设置为0
|
|
|
dbHelperLocal.AddParameter("@revise_date", String.Format("{0:yyyy-MM-dd}",DateTime.Now)); //接收网络计划的时间
|
|
|
dbHelperLocal.AddParameter("@ShiftID", row["ShiftID"]);
|
|
|
dbHelperLocal.AddParameter("@PlanDate", row["PlanDate"]);
|
|
|
dbHelperLocal.AddParameter("@RecipeMaterialName", row["RecipeMaterialName"]);
|
|
|
dbHelperLocal.AddParameter("@PlanWeight", row["PlanWeight"]);
|
|
|
dbHelperLocal.AddParameter("@TotalWeight", row["TotalWeight"]);
|
|
|
dbHelperLocal.AddParameter("@RealWeight", row["RealWeight"]);
|
|
|
dbHelperLocal.AddParameter("@plan_datetime", String.Format("{0:yyyy-MM-dd HH:mm:ss}",DateTime.Now)); //计划制定时间
|
|
|
//row["RealEndtime"]
|
|
|
dbHelperLocal.AddParameter("@RealEndtime", Mesnac.Basic.DataProcessor.RowValue(row, "RealEndtime", null));
|
|
|
dbHelperLocal.AddParameter("@OperCode", row["OperCode"]);
|
|
|
dbHelperLocal.AddParameter("@OperDatetime", row["OperDatetime"]);
|
|
|
dbHelperLocal.AddParameter("@ActionOrder", nextActionOrder);
|
|
|
|
|
|
|
|
|
//dbHelperLocal.AddParameter("@RecipeUserVersion", row["RecipeUserVersion"]);
|
|
|
//dbHelperLocal.AddParameter("@SerialNum", row["SerialNum"]);
|
|
|
//dbHelperLocal.AddParameter("@RecipeName", row["RecipeName"]);
|
|
|
//dbHelperLocal.AddParameter("@RecipeType", row["RecipeType"]);
|
|
|
//dbHelperLocal.AddParameter("@RunType", row["RunType"]);
|
|
|
//dbHelperLocal.AddParameter("@PrintType", row["PrintType"]);
|
|
|
//dbHelperLocal.AddParameter("@PlanSource", row["PlanSource"]);
|
|
|
//dbHelperLocal.AddParameter("@UrgencyState", row["UrgencyState"]);
|
|
|
//dbHelperLocal.AddParameter("@PlanEndTime", row["PlanEndTime"]);
|
|
|
//dbHelperLocal.AddParameter("@RealStartTime", row["RealStartTime"]);
|
|
|
//dbHelperLocal.AddParameter("@SmallCreate", row["SmallCreate"]);
|
|
|
//dbHelperLocal.AddParameter("@AvgTime", row["AvgTime"]);
|
|
|
//dbHelperLocal.AddParameter("@Remark", row["Remark"]);
|
|
|
//dbHelperLocal.AddParameter("@DeleteFlag", row["DeleteFlag"]);
|
|
|
//dbHelperLocal.AddParameter("@CreatePlanFlag", row["CreatePlanFlag"]);
|
|
|
|
|
|
dbHelperLocal.CommandText = sqlStr3;
|
|
|
dbHelperLocal.ExecuteNonQuery();
|
|
|
|
|
|
//把网络计划的PlanState设置为3-已接收,把网络计划的ReviseSgn设置为0
|
|
|
dbHelperServer.ClearParameter();
|
|
|
dbHelperServer.CommandType = CommandType.Text;
|
|
|
string strSql4 = "Update Ppt_Plan set Plan_State = 3, Revise_Sgn = 0 where Plan_ID = @PlanID";
|
|
|
dbHelperServer.AddParameter("@PlanID", row["PlanID"]);
|
|
|
dbHelperServer.CommandText = strSql4;
|
|
|
dbHelperServer.ExecuteNonQuery();
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 更新计划设定数UpdatePlanNum
|
|
|
/// <summary>
|
|
|
/// 更新计划设定数
|
|
|
/// </summary>
|
|
|
/// <param name="planID">计划号</param>
|
|
|
/// <param name="planNum">设定数</param>
|
|
|
public static void UpdatePlanNum(string planID, int planNum)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
DatabaseAction action = new DatabaseAction();
|
|
|
DbHelper dbHelper;
|
|
|
dbHelper = action.NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
action.LogError("获取本地数据连接失败...");
|
|
|
return;
|
|
|
}
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
string strSql = "update ppt_plan set plan_num = @PlanNum where plan_id = @PlanID";
|
|
|
dbHelper.CommandText = strSql;
|
|
|
dbHelper.AddParameter("@PlanNum", planNum);
|
|
|
dbHelper.AddParameter("@PlanID", planID);
|
|
|
dbHelper.ExecuteNonQuery();
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("更新本地计划数失败:" + ex.Message);
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 更新计划设定数
|
|
|
/// </summary>
|
|
|
/// <param name="dbType">数据类型,本地、网络</param>
|
|
|
/// <param name="planID">计划号</param>
|
|
|
/// <param name="planNum">设定数</param>
|
|
|
public static void UpdatePlanNum(Mesnac.Basic.DataSourceFactory.MCDbType dbType, string planID, int planNum)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
DatabaseAction action = new DatabaseAction();
|
|
|
DbHelper dbHelper;
|
|
|
dbHelper = action.NewDbHelper(dbType);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
action.LogError("获取数据连接失败...");
|
|
|
return;
|
|
|
}
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
string strSql = String.Empty;
|
|
|
if (dbType == Basic.DataSourceFactory.MCDbType.Server)
|
|
|
{
|
|
|
//strSql = "update PptPlan set PlanNum = @PlanNum where PlanID = @PlanID";
|
|
|
strSql = "update Ppt_Plan set Plan_num = @PlanNum where Plan_id = @PlanID";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strSql = "update ppt_plan set plan_num = @PlanNum where plan_id = @PlanID";
|
|
|
}
|
|
|
dbHelper.CommandText = strSql;
|
|
|
dbHelper.AddParameter("@PlanNum", planNum);
|
|
|
dbHelper.AddParameter("@PlanID", planID);
|
|
|
dbHelper.ExecuteNonQuery();
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("更新计划数失败:" + ex.Message);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 更新计划状态和计划执行时间
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新计划状态和计划执行时间
|
|
|
/// </summary>
|
|
|
/// <param name="dbType">数据库类型,网络库、本地库</param>
|
|
|
/// <param name="planID">计划号</param>
|
|
|
/// <param name="planState">计划状态</param>
|
|
|
/// <param name="realStartTime">实际计划开始时间</param>
|
|
|
public static void UpdatedPlanStateAndRealStartTime(Mesnac.Basic.DataSourceFactory.MCDbType dbType, string planID, int planState, DateTime realStartTime)
|
|
|
{
|
|
|
DatabaseAction action = new DatabaseAction();
|
|
|
DbHelper dbHelper;
|
|
|
dbHelper = action.NewDbHelper(dbType);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
action.LogError("获取数据连接失败...");
|
|
|
return;
|
|
|
}
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
string strSql = String.Empty;
|
|
|
if (dbType == Basic.DataSourceFactory.MCDbType.Server)
|
|
|
{
|
|
|
strSql = "update Ppt_Plan set Plan_State = @PlanState, Real_StartTime = @RealStartTime where Plan_ID = @PlanID";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strSql = "update ppt_plan set plan_state = @PlanState where plan_id = @PlanID";
|
|
|
}
|
|
|
dbHelper.CommandText = strSql;
|
|
|
dbHelper.AddParameter("@PlanState", planState);
|
|
|
if (dbType == Basic.DataSourceFactory.MCDbType.Server)
|
|
|
{
|
|
|
dbHelper.AddParameter("@RealStartTime", String.Format("{0:yyyy-MM-dd HH:mm:ss}", realStartTime));
|
|
|
}
|
|
|
dbHelper.AddParameter("@PlanID", planID);
|
|
|
dbHelper.ExecuteNonQuery();
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 更新计划状态和计划终止时间
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新计划状态和计划执行时间
|
|
|
/// </summary>
|
|
|
/// <param name="dbType">数据库类型,网络库、本地库</param>
|
|
|
/// <param name="planID">计划号</param>
|
|
|
/// <param name="planState">计划状态</param>
|
|
|
/// <param name="realStartTime">实际计划开始时间</param>
|
|
|
public static void UpdatedPlanStateAndRealEndTime(Mesnac.Basic.DataSourceFactory.MCDbType dbType, string planID, int planState, DateTime realEndTime)
|
|
|
{
|
|
|
DatabaseAction action = new DatabaseAction();
|
|
|
DbHelper dbHelper;
|
|
|
dbHelper = action.NewDbHelper(dbType);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
action.LogError("获取数据连接失败...");
|
|
|
return;
|
|
|
}
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
string strSql = String.Empty;
|
|
|
if (dbType == Basic.DataSourceFactory.MCDbType.Server)
|
|
|
{
|
|
|
strSql = "update Ppt_Plan set Plan_State = @PlanState, Real_Endtime = @RealEndTime where Plan_ID = @PlanID";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (action.NetType == BaseAction.NetTypes.Net)
|
|
|
{
|
|
|
strSql = "update ppt_plan set plan_state = @PlanState where plan_id = @PlanID";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//如果单机运行,则把计划上传标志modi_code设置为0
|
|
|
strSql = "update ppt_plan set plan_state = @PlanState,modi_code=0 where plan_id = @PlanID";
|
|
|
}
|
|
|
}
|
|
|
dbHelper.CommandText = strSql;
|
|
|
dbHelper.AddParameter("@PlanState", planState);
|
|
|
if (dbType == Basic.DataSourceFactory.MCDbType.Server)
|
|
|
{
|
|
|
dbHelper.AddParameter("@RealEndTime", String.Format("{0:yyyy-MM-dd HH:mm:ss}", realEndTime));
|
|
|
}
|
|
|
dbHelper.AddParameter("@PlanID", planID);
|
|
|
dbHelper.ExecuteNonQuery();
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 获取本地所有班次信息
|
|
|
/// <summary>
|
|
|
/// 获取本地所有班次信息
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public static DataTable GetAllLocalShiftData()
|
|
|
{
|
|
|
FeedingAction action = new FeedingAction();
|
|
|
DbHelper localHelper;
|
|
|
localHelper = action.NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
if (localHelper == null)
|
|
|
{
|
|
|
action.LogError("获取本地数据连接失败...");
|
|
|
return null;
|
|
|
}
|
|
|
try
|
|
|
{
|
|
|
localHelper.ClearParameter();
|
|
|
localHelper.CommandType = CommandType.Text;
|
|
|
string strSql = "select * from PptShift where UseFlag = 1 order by ObjID";
|
|
|
localHelper.CommandText = strSql;
|
|
|
DataTable shiftTable = localHelper.ToDataTable();
|
|
|
return shiftTable;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("获取本地班次数据失败:" + ex.Message, ex);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 日期班次验证
|
|
|
/// <summary>
|
|
|
/// 日期班次验证
|
|
|
/// </summary>
|
|
|
/// <param name="plandate">验证后输出的正确日期</param>
|
|
|
/// <param name="shiftitem">验证后输出的正确班次</param>
|
|
|
/// <param name="pickervalue">要验证的日期值</param>
|
|
|
/// <param name="comshiftitem">要验证的班次值</param>
|
|
|
/// <param name="Msg">消息提示</param>
|
|
|
/// <returns>验证通过返回true,否则返回false</returns>
|
|
|
public static bool PlanDateVerify(out DateTime plandate, out int shiftitem, string pickervalue, int comshiftitem, out string Msg)
|
|
|
{
|
|
|
#region 老版本验证,中策验证规则,早8:00换班
|
|
|
//string hhmm = DateTime.Now.ToString("HHmm");
|
|
|
//plandate = DateTime.Now;
|
|
|
//shiftitem = comshiftitem;
|
|
|
//Msg = string.Empty;
|
|
|
//if (((hhmm.CompareTo("0758") > 0) && (hhmm.CompareTo("1540") < 0)) || ((hhmm.CompareTo("1558") > 0) && (hhmm.CompareTo("2340") < 0)) || ((hhmm.CompareTo("2358") > 0) || (hhmm.CompareTo("0740") < 0)))
|
|
|
//{
|
|
|
// string dt2 = Convert.ToDateTime(pickervalue).ToString("yyyy-MM-dd");
|
|
|
// if ((hhmm.CompareTo("1558") == 1) && (hhmm.CompareTo("2340") == -1))
|
|
|
// {
|
|
|
// shiftitem = 2;
|
|
|
// }
|
|
|
// else if (hhmm.CompareTo("0740") == -1 || hhmm.CompareTo("0740") == 0)
|
|
|
// {
|
|
|
// plandate = DateTime.Now.Date.AddDays(-1);
|
|
|
// shiftitem = 3;
|
|
|
// }
|
|
|
// else if (hhmm.CompareTo("2358") == 1)
|
|
|
// {
|
|
|
// plandate = DateTime.Now;
|
|
|
// shiftitem = 2;
|
|
|
// }
|
|
|
// else if ((hhmm.CompareTo("1540") == -1) && (hhmm.CompareTo("0758") == 1)) { shiftitem = 1; }
|
|
|
// string dt1 = plandate.ToString("yyyy-MM-dd");
|
|
|
// if ((dt1 != dt2) || (comshiftitem != shiftitem))
|
|
|
// {
|
|
|
// comshiftitem = shiftitem - 1;
|
|
|
// Msg = "请将日期 班次调整正确:" + "\r\n"
|
|
|
// + "当前生产日期:" + plandate.ToString("yyyy-MM-dd") + "\r\n"
|
|
|
// + "当前生产班次:" + shiftitem.ToString();
|
|
|
// return false;
|
|
|
// }
|
|
|
// return true;
|
|
|
//}
|
|
|
//return true;
|
|
|
#endregion
|
|
|
|
|
|
#region 老版本验证,建德验证规则,早7:30换班
|
|
|
|
|
|
string firstBegin = "0758";
|
|
|
string firstEnd = "1540";
|
|
|
string secondBegin = "1558";
|
|
|
string secondEnd = "2340";
|
|
|
string thirdBegin = "2358";
|
|
|
string thirdEnd = "0740";
|
|
|
DateTime dt = DateTime.Now;
|
|
|
object shiftT = null;
|
|
|
|
|
|
#region 从数据库获取值
|
|
|
DataTable shiftTable = PlanCommon.GetAllLocalShiftData();
|
|
|
if (shiftTable != null && shiftTable.Rows.Count >= 3)
|
|
|
{
|
|
|
shiftT = shiftTable.Rows[0]["ShiftST"];
|
|
|
if (shiftT != null && shiftT != System.DBNull.Value)
|
|
|
{
|
|
|
if (DateTime.TryParse(shiftT.ToString(), out dt))
|
|
|
{
|
|
|
firstBegin = String.Format("{0:HHmm}", dt.AddMinutes(-2));
|
|
|
}
|
|
|
}
|
|
|
shiftT = shiftTable.Rows[0]["ShiftET"];
|
|
|
if (shiftT != null && shiftT != System.DBNull.Value)
|
|
|
{
|
|
|
if (DateTime.TryParse(shiftT.ToString(), out dt))
|
|
|
{
|
|
|
firstEnd = String.Format("{0:HHmm}", dt.AddMinutes(-19));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
shiftT = shiftTable.Rows[1]["ShiftST"];
|
|
|
if (shiftT != null && shiftT != System.DBNull.Value)
|
|
|
{
|
|
|
if (DateTime.TryParse(shiftT.ToString(), out dt))
|
|
|
{
|
|
|
secondBegin = String.Format("{0:HHmm}", dt.AddMinutes(-2));
|
|
|
}
|
|
|
}
|
|
|
shiftT = shiftTable.Rows[1]["ShiftET"];
|
|
|
if (shiftT != null && shiftT != System.DBNull.Value)
|
|
|
{
|
|
|
if (DateTime.TryParse(shiftT.ToString(), out dt))
|
|
|
{
|
|
|
secondEnd = String.Format("{0:HHmm}", dt.AddMinutes(-19));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
shiftT = shiftTable.Rows[2]["ShiftST"];
|
|
|
if (shiftT != null && shiftT != System.DBNull.Value)
|
|
|
{
|
|
|
if (DateTime.TryParse(shiftT.ToString(), out dt))
|
|
|
{
|
|
|
thirdBegin = String.Format("{0:HHmm}", dt.AddMinutes(-2));
|
|
|
}
|
|
|
}
|
|
|
shiftT = shiftTable.Rows[2]["ShiftET"];
|
|
|
if (shiftT != null && shiftT != System.DBNull.Value)
|
|
|
{
|
|
|
if (DateTime.TryParse(shiftT.ToString(), out dt))
|
|
|
{
|
|
|
thirdEnd = String.Format("{0:HHmm}", dt.AddMinutes(-19));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
string hhmm = DateTime.Now.ToString("HHmm");
|
|
|
plandate = DateTime.Now;
|
|
|
shiftitem = comshiftitem;
|
|
|
Msg = string.Empty;
|
|
|
if (((hhmm.CompareTo(firstBegin) > 0) && (hhmm.CompareTo(firstEnd) < 0)) || ((hhmm.CompareTo(secondBegin) > 0) && (hhmm.CompareTo(secondEnd) < 0)) || ((hhmm.CompareTo(thirdBegin) > 0) || (hhmm.CompareTo(thirdEnd) < 0)))
|
|
|
{
|
|
|
string dt2 = Convert.ToDateTime(pickervalue).ToString("yyyy-MM-dd");
|
|
|
if ((hhmm.CompareTo(secondBegin) == 1) && (hhmm.CompareTo(secondEnd) == -1))
|
|
|
{
|
|
|
shiftitem = 2;
|
|
|
}
|
|
|
else if (hhmm.CompareTo(thirdEnd) == -1 || hhmm.CompareTo(thirdEnd) == 0)
|
|
|
{
|
|
|
plandate = DateTime.Now.Date.AddDays(-1);
|
|
|
shiftitem = 3;
|
|
|
}
|
|
|
else if (hhmm.CompareTo(thirdBegin) == 1)
|
|
|
{
|
|
|
//plandate = DateTime.Now;
|
|
|
//shiftitem = 2;
|
|
|
plandate = DateTime.Now;
|
|
|
if (thirdBegin.CompareTo(thirdEnd) == -1)
|
|
|
{
|
|
|
plandate = DateTime.Now.Date.AddDays(-1);
|
|
|
}
|
|
|
shiftitem = 3;
|
|
|
}
|
|
|
else if ((hhmm.CompareTo(firstEnd) == -1) && (hhmm.CompareTo(firstBegin) == 1)) { shiftitem = 1; }
|
|
|
string dt1 = plandate.ToString("yyyy-MM-dd");
|
|
|
if ((dt1 != dt2) || (comshiftitem != shiftitem))
|
|
|
{
|
|
|
comshiftitem = shiftitem - 1;
|
|
|
Msg = "请将日期 班次调整正确:" + "\r\n"
|
|
|
+ "当前生产日期:" + plandate.ToString("yyyy-MM-dd") + "\r\n"
|
|
|
+ "当前生产班次:" + shiftitem.ToString();
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
return true;
|
|
|
#endregion
|
|
|
|
|
|
#region 玲珑验证规则
|
|
|
|
|
|
//string hhmm = DateTime.Now.ToString("HHmm");
|
|
|
//plandate = DateTime.Now;
|
|
|
//shiftitem = comshiftitem;
|
|
|
//Msg = string.Empty;
|
|
|
//if (((hhmm.CompareTo("0758") > 0) && (hhmm.CompareTo("1540") < 0)) || ((hhmm.CompareTo("1558") > 0) && (hhmm.CompareTo("2340") < 0)) || ((hhmm.CompareTo("2358") > 0) || (hhmm.CompareTo("0740") < 0)))
|
|
|
//{
|
|
|
// string dt2 = Convert.ToDateTime(pickervalue).ToString("yyyy-MM-dd");
|
|
|
// if ((hhmm.CompareTo("1558") == 1) && (hhmm.CompareTo("2340") == -1))
|
|
|
// {
|
|
|
// shiftitem = 1;
|
|
|
// plandate = DateTime.Now.Date.AddDays(1);
|
|
|
// }
|
|
|
// else if (hhmm.CompareTo("0740") == -1 || hhmm.CompareTo("0740") == 0)
|
|
|
// {
|
|
|
// shiftitem = 2;
|
|
|
// }
|
|
|
// else if (hhmm.CompareTo("2358") == 1)
|
|
|
// {
|
|
|
// plandate = DateTime.Now.Date.AddDays(1);
|
|
|
// shiftitem = 2;
|
|
|
// }
|
|
|
// else if ((hhmm.CompareTo("1540") == -1) && (hhmm.CompareTo("0758") == 1)) { shiftitem = 3; }
|
|
|
// string dt1 = plandate.ToString("yyyy-MM-dd");
|
|
|
// if ((dt1 != dt2) || (comshiftitem != shiftitem))
|
|
|
// {
|
|
|
// comshiftitem = shiftitem - 1;
|
|
|
// Msg = "请将日期 班次调整正确:" + "\r\n"
|
|
|
// + "当前生产日期:" + plandate.ToString("yyyy-MM-dd") + "\r\n"
|
|
|
// + "当前生产班次:" + shiftitem.ToString();
|
|
|
// return false;
|
|
|
// }
|
|
|
// return true;
|
|
|
//}
|
|
|
//return true;
|
|
|
|
|
|
#endregion
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 清除扫描条码数据
|
|
|
/// <summary>
|
|
|
/// 清除扫描条码数据,如果为网络版,则把网络库中对应本机台的条码数据删除,清空本地条码表(PptShelfBar)数据
|
|
|
/// </summary>
|
|
|
/// <param name="netType">系统类型,单机、网络</param>
|
|
|
/// <param name="equipCode">机台号</param>
|
|
|
public static void TruncatePptShelfBar(Mesnac.Action.Base.BaseAction.NetTypes netType, string equipCode)
|
|
|
{
|
|
|
DatabaseAction action = new DatabaseAction();
|
|
|
DbHelper dbHelper;
|
|
|
if (netType == BaseAction.NetTypes.Net)
|
|
|
{
|
|
|
//清除网络库中对应此机台的条码数据
|
|
|
dbHelper = action.NewDbHelper(Basic.DataSourceFactory.MCDbType.Server);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
action.LogError("获取网络数据连接失败...");
|
|
|
return;
|
|
|
}
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
string strSql = "delete from ppt_ShelfBar where Equip_Code = @EquipCode";
|
|
|
dbHelper.CommandText = strSql;
|
|
|
dbHelper.AddParameter("@EquipCode", equipCode);
|
|
|
dbHelper.ExecuteNonQuery();
|
|
|
}
|
|
|
dbHelper = action.NewDbHelper(Basic.DataSourceFactory.MCDbType.Local);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
action.LogError("获取本地数据连接失败...");
|
|
|
return;
|
|
|
}
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
string strSql1 = "if exists(select * from sysobjects where xtype='U' and name='pmt_shelfbar') truncate table pmt_shelfbar";
|
|
|
dbHelper.CommandText = strSql1;
|
|
|
dbHelper.ExecuteNonQuery();
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 为掺用配方增加下传计划标志
|
|
|
|
|
|
/// <summary>
|
|
|
/// 为掺用配方增加下传计划标志
|
|
|
/// </summary>
|
|
|
/// <param name="recipeMaterialCode">配方物料编码</param>
|
|
|
public static void SetExePlan(string recipeMaterialCode)
|
|
|
{
|
|
|
DatabaseAction action = new DatabaseAction();
|
|
|
DbHelper dbHelper;
|
|
|
dbHelper = action.NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
action.LogError("获取本地数据连接失败...");
|
|
|
}
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
string strSql = "truncate table pmt_ExecPlan;truncate table pmt_ChanYong;";
|
|
|
strSql += "insert into pmt_ExecPlan(Mater_code, Plan_Flag) values(@MaterCode,@PlanFlag)";
|
|
|
dbHelper.CommandText = strSql;
|
|
|
dbHelper.AddParameter("@MaterCode", recipeMaterialCode);
|
|
|
dbHelper.AddParameter("@PlanFlag", "1");
|
|
|
dbHelper.ExecuteNonQuery();
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 发送计划号
|
|
|
|
|
|
/// <summary>
|
|
|
/// 发送计划号
|
|
|
/// </summary>
|
|
|
/// <param name="netType">系统类型,网络、单机</param>
|
|
|
/// <param name="planID">计划号</param>
|
|
|
public static void SendPlanId(Mesnac.Action.Base.BaseAction.NetTypes netType, string planID)
|
|
|
{
|
|
|
//更新计划状态4-->5
|
|
|
if (PlanCommon.GetPlanState(planID) == PlanStates.Producting)
|
|
|
{
|
|
|
if (netType == BaseAction.NetTypes.Net)
|
|
|
{
|
|
|
PlanCommon.UpdatedPlanStateAndRealEndTime(Basic.DataSourceFactory.MCDbType.Server, planID, (int)PlanStates.Completed, DateTime.Now);
|
|
|
}
|
|
|
PlanCommon.UpdatedPlanStateAndRealEndTime(Basic.DataSourceFactory.MCDbType.Local, planID, (int)PlanStates.Completed, DateTime.Now);
|
|
|
|
|
|
|
|
|
//#region 更新日志
|
|
|
|
|
|
//PlanLog planLog =
|
|
|
//planLog.LastSelectDate = selectedDate;
|
|
|
//planLog.LastSelectShiftID = shiftID;
|
|
|
//planLog.LastPlanID = planID;
|
|
|
|
|
|
//base.LogDebug("序列化文件:" + PlanCommon.PlanLogFile);
|
|
|
//base.Serialize<PlanLog>(planLog, PlanCommon.PlanLogFile); //序列化至文件
|
|
|
|
|
|
//if (File.Exists(PlanCommon.PlanLogFile))
|
|
|
//{
|
|
|
// File.Delete(PlanCommon.PlanLogFile);
|
|
|
//}
|
|
|
|
|
|
//#endregion
|
|
|
}
|
|
|
string netMsg = "{0}:{1}:0:0:0:0/";
|
|
|
netMsg = String.Format(netMsg, Global.ProtocalHeader.ReceivePlanIdIpNumber, planID);
|
|
|
Mesnac.Communication.TcpService.Instance.NetSendMsg(netMsg);
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 刷新网络库架子信息
|
|
|
/// <summary>
|
|
|
/// 刷新网络库架子信息
|
|
|
/// </summary>
|
|
|
/// <param name="dbType">数据库类型,网络、本地</param>
|
|
|
/// <param name="firstLotBarCode">架子号</param>
|
|
|
/// <param name="firstLotSerialId">开始车号</param>
|
|
|
/// <param name="lastLotNum">结束车号</param>
|
|
|
public static void FlushShiftConfig(Basic.DataSourceFactory.MCDbType dbType, string firstLotBarCode, int firstLotSerialId, int lastLotNum)
|
|
|
{
|
|
|
if (dbType == Basic.DataSourceFactory.MCDbType.Local)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("本地库不支持刷新架子信息!");
|
|
|
return;
|
|
|
}
|
|
|
StringBuilder memnote = new StringBuilder();
|
|
|
for (int i = firstLotSerialId; i <= lastLotNum; i++)
|
|
|
{
|
|
|
if (String.IsNullOrEmpty(memnote.ToString()))
|
|
|
{
|
|
|
memnote.Append(i);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
memnote.Append(",");
|
|
|
memnote.Append(i);
|
|
|
}
|
|
|
}
|
|
|
FeedingAction action = new FeedingAction();
|
|
|
//action.DBLog("基本操作", "修改架子数", "条码" + firstLotBarCode);//记录日期LogData('基本操作','修改架子数','条码'+FirstLotBarCode);
|
|
|
DbHelper dbHelper;
|
|
|
dbHelper = action.NewDbHelper(dbType);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
action.LogError("获取数据连接失败...");
|
|
|
return;
|
|
|
}
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
string strSql = "Update Ppt_ShiftConfig set Barcode_End = @BarcodeEnd, Shelf_Num = @ShelfNum - Barcode_Start + 1, Mem_Note = @MemNote";
|
|
|
strSql += " where Barcode = @Barcode and Barcode_Start < @BarcodeStart";
|
|
|
dbHelper.CommandText = strSql;
|
|
|
dbHelper.AddParameter("@BarcodeEnd", lastLotNum);
|
|
|
dbHelper.AddParameter("@ShelfNum", lastLotNum);
|
|
|
dbHelper.AddParameter("@MemNote", memnote.ToString());
|
|
|
dbHelper.AddParameter("@Barcode", firstLotBarCode);
|
|
|
dbHelper.AddParameter("@BarcodeStart", lastLotNum);
|
|
|
dbHelper.ExecuteNonQuery();
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 停止掺用计划
|
|
|
/// <summary>
|
|
|
/// 停止掺用计划
|
|
|
/// </summary>
|
|
|
public static void StopChanYongPlan()
|
|
|
{
|
|
|
DatabaseAction action = new DatabaseAction();
|
|
|
DbHelper dbHelper;
|
|
|
dbHelper = action.NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
bool result = PlanCommon.StopChanYongPlan(dbHelper);
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 停止掺用计划
|
|
|
/// </summary>
|
|
|
/// <param name="dbHelper">数据访问对象</param>
|
|
|
/// <returns></returns>
|
|
|
public static bool StopChanYongPlan(DbHelper dbHelper)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Warn("停止掺用失败:获取数据连接失败...");
|
|
|
return false;
|
|
|
}
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
string strSql = "update Pmt_ExecPlan set Plan_Flag = '2'";
|
|
|
dbHelper.CommandText = strSql;
|
|
|
dbHelper.ExecuteNonQuery();
|
|
|
return true;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("停止掺用失败:" + ex.Message);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 在本地库中添加批报表数据
|
|
|
|
|
|
/// <summary>
|
|
|
/// 在本地库中添加批报表数据
|
|
|
/// </summary>
|
|
|
/// <param name="planId">对应的计划编号</param>
|
|
|
/// <returns>成功返回true,失败返回false</returns>
|
|
|
public static bool AddPptGroupLot(string planId)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
string strSql = String.Empty;
|
|
|
FeedingAction action = new FeedingAction();
|
|
|
DbHelper localHelper = action.NewDbHelper(Basic.DataSourceFactory.MCDbType.Local);
|
|
|
if (localHelper == null)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Debug("添加批报表失败:获取本地数据连接失败!");
|
|
|
return false;
|
|
|
}
|
|
|
localHelper.CommandType = CommandType.Text;
|
|
|
localHelper.ClearParameter();
|
|
|
strSql = "Update PptGroupLot set FinishTag = 1 where FinishTag = 0";
|
|
|
localHelper.CommandText = strSql;
|
|
|
localHelper.ExecuteNonQuery();
|
|
|
|
|
|
DataRow planRow = PlanCommon.GetPlanData(Basic.DataSourceFactory.MCDbType.Local, planId);
|
|
|
if (planRow != null)
|
|
|
{
|
|
|
localHelper.ClearParameter();
|
|
|
strSql = "insert into PptGroupLot(ShiftID,ShiftClass,RecipeCode,RecipeName,SetNumber,StartDatetime,FinishTag,FinishNum)";
|
|
|
strSql += " values(@ShiftID,@ShiftClass,@RecipeCode,@RecipeName,@SetNumber,@StartDatetime,@FinishTag,@FinishNum)";
|
|
|
localHelper.CommandText = strSql;
|
|
|
localHelper.AddParameter("@ShiftID", planRow["ShiftID"]);
|
|
|
localHelper.AddParameter("@ShiftClass", planRow["ClassID"]);
|
|
|
localHelper.AddParameter("@RecipeCode", planRow["RecipeMaterialCode"]);
|
|
|
localHelper.AddParameter("@RecipeName", planRow["RecipeMaterialName"]);
|
|
|
localHelper.AddParameter("@SetNumber", planRow["PlanNum"]);
|
|
|
localHelper.AddParameter("@StartDatetime", DateTime.Now);
|
|
|
localHelper.AddParameter("@FinishTag", 0);
|
|
|
localHelper.AddParameter("@FinishNum", 0);
|
|
|
localHelper.ExecuteNonQuery();
|
|
|
}
|
|
|
|
|
|
ICSharpCode.Core.LoggingService.Debug("添加批报表成功!");
|
|
|
return true;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("添加批报表失败:" + ex.Message, ex);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 在本地数据库,根据计划号获取对应的Recipe_Code
|
|
|
|
|
|
/// <summary>
|
|
|
/// 在本地数据库,根据计划号获取对应的Recipe_Code
|
|
|
/// </summary>
|
|
|
/// <param name="planID">计划号</param>
|
|
|
/// <returns>获取成功返回对应的值,失败返回String.Empty</returns>
|
|
|
public static string GetRecipeCodeByPlanID(string planID)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
FeedingAction action = new FeedingAction();
|
|
|
DbHelper localHelper = action.NewDbHelper(Basic.DataSourceFactory.MCDbType.Local);
|
|
|
localHelper.CommandType = CommandType.Text;
|
|
|
localHelper.ClearParameter();
|
|
|
// string strSql = @"select a.recipe_code from pmt_recipe as a
|
|
|
// inner join ppt_plan as b
|
|
|
// on a.equip_code = substring(b.equip_code,4,2) and a.mater_code = b.mater_code and a.edt_code = b.edt_code
|
|
|
// where b.plan_id = @PlanID";
|
|
|
string strSql = @"SELECT top 1 rtrim(a.mater_name)+'('+substring(rtrim(isnull(a.recipe_code,'')),7,2)+')'+'['+rtrim(A.mater_code)+']' AS ShowName
|
|
|
FROM pmt_recipe as a
|
|
|
inner join ppt_plan as b
|
|
|
on a.equip_code = substring(b.equip_code,4,2) and a.mater_code = b.mater_code and a.edt_code = b.edt_code
|
|
|
where b.plan_id = @PlanID";
|
|
|
localHelper.CommandText = strSql;
|
|
|
localHelper.AddParameter("@PlanID", planID);
|
|
|
object result = localHelper.ToScalar();
|
|
|
if (result != null && result != System.DBNull.Value)
|
|
|
{
|
|
|
return result.ToString();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return String.Empty;
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("获取Recipe_Code失败:" + ex.Message, ex);
|
|
|
return String.Empty;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 根据物料编码获取物料名称
|
|
|
/// <summary>
|
|
|
/// 根据物料编码获取物料名称
|
|
|
/// </summary>
|
|
|
/// <param name="dbType">数据连接类型,本地,网络</param>
|
|
|
/// <param name="materCode">物料编码</param>
|
|
|
/// <returns>返回对应的物料名称</returns>
|
|
|
public static string GetMaterName(Mesnac.Basic.DataSourceFactory.MCDbType dbType, string materCode)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
FeedingAction action = new FeedingAction();
|
|
|
DbHelper dbHelper = action.NewDbHelper(dbType);
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
dbHelper.ClearParameter();
|
|
|
string strSql = String.Empty;
|
|
|
if (dbType == Basic.DataSourceFactory.MCDbType.Local)
|
|
|
{
|
|
|
strSql = @"select top 1 mater_name from pmt_material where mater_code = @mater_code";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strSql = @"select top 1 Mater_name from Pmt_material where Mater_code = @mater_code";
|
|
|
}
|
|
|
dbHelper.CommandText = strSql;
|
|
|
dbHelper.AddParameter("@mater_code", materCode.Trim());
|
|
|
object result = dbHelper.ToScalar();
|
|
|
if (result != null && result != System.DBNull.Value)
|
|
|
{
|
|
|
return result.ToString();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return String.Empty;
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("获取Recipe_Code失败:" + ex.Message, ex);
|
|
|
return String.Empty;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 在本地数据库,判断某个物料编码是否存在
|
|
|
/// <summary>
|
|
|
/// 在本地数据库,判断某个物料编码是否存在
|
|
|
/// </summary>
|
|
|
/// <param name="materCode">要判断的物料编码</param>
|
|
|
/// <returns>物料编码存在返回true,否则返回false</returns>
|
|
|
public static bool IsExistsMaterCode(string materCode)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
FeedingAction action = new FeedingAction();
|
|
|
DbHelper localHelper = action.NewDbHelper(Basic.DataSourceFactory.MCDbType.Local);
|
|
|
localHelper.CommandType = CommandType.Text;
|
|
|
localHelper.ClearParameter();
|
|
|
string strSql = @"select COUNT(*) from pmt_material where mater_code=@materCode";
|
|
|
localHelper.CommandText = strSql;
|
|
|
localHelper.AddParameter("@materCode", materCode.Trim());
|
|
|
object result = localHelper.ToScalar();
|
|
|
if (result != null && result != System.DBNull.Value)
|
|
|
{
|
|
|
int intResult = 0;
|
|
|
if (int.TryParse(result.ToString(), out intResult))
|
|
|
{
|
|
|
if (intResult > 0)
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("获取mater_code失败:" + ex.Message, ex);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 在本地数据库,判断某个物料名称是否存在
|
|
|
|
|
|
/// <summary>
|
|
|
/// 在本地数据库,判断某个物料名称是否存在
|
|
|
/// </summary>
|
|
|
/// <param name="materName">要判断的物料名称</param>
|
|
|
/// <returns>物料名称存在返回true,否则返回false</returns>
|
|
|
public static bool IsExistsMaterName(string materName)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
FeedingAction action = new FeedingAction();
|
|
|
DbHelper localHelper = action.NewDbHelper(Basic.DataSourceFactory.MCDbType.Local);
|
|
|
localHelper.CommandType = CommandType.Text;
|
|
|
localHelper.ClearParameter();
|
|
|
string strSql = @"select COUNT(*) from pmt_material where mater_name=@materName";
|
|
|
localHelper.CommandText = strSql;
|
|
|
localHelper.AddParameter("@materName", materName.Trim());
|
|
|
object result = localHelper.ToScalar();
|
|
|
if (result != null && result != System.DBNull.Value)
|
|
|
{
|
|
|
int intResult = 0;
|
|
|
if (int.TryParse(result.ToString(), out intResult))
|
|
|
{
|
|
|
if (intResult > 0)
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("获取Recipe_Name失败:" + ex.Message, ex);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 在本地数据库,判断某个配方编码是否存在
|
|
|
|
|
|
/// <summary>
|
|
|
/// 在本地数据库,判断某个配方编码是否存在
|
|
|
/// </summary>
|
|
|
/// <param name="materCode">要判断的配方编码</param>
|
|
|
/// <returns>如果存在返回true,不存在返回false</returns>
|
|
|
public static bool IsExistsRecipeMaterCode(string materCode)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
FeedingAction action = new FeedingAction();
|
|
|
DbHelper localHelper = action.NewDbHelper(Basic.DataSourceFactory.MCDbType.Local);
|
|
|
localHelper.CommandType = CommandType.Text;
|
|
|
localHelper.ClearParameter();
|
|
|
string strSql = @"select COUNT(*) from pmt_recipe where mater_code=@materCode and equip_code=@equipCode";
|
|
|
localHelper.CommandText = strSql;
|
|
|
localHelper.AddParameter("@materCode", materCode);
|
|
|
localHelper.AddParameter("@equipCode", action.CurrEquipCode.Substring(3, 2));
|
|
|
object result = localHelper.ToScalar();
|
|
|
if (result != null && result != System.DBNull.Value)
|
|
|
{
|
|
|
int intResult = 0;
|
|
|
if (int.TryParse(result.ToString(), out intResult))
|
|
|
{
|
|
|
if (intResult > 0)
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("获取Recipe_Code失败:" + ex.Message, ex);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 在本地数据库,判断某个配方名称是否存在
|
|
|
|
|
|
/// <summary>
|
|
|
/// 在本地数据库,判断某个配方名称是否存在
|
|
|
/// </summary>
|
|
|
/// <param name="materName">要判断的配方名称</param>
|
|
|
/// <returns>如果存在返回true,不存在返回false</returns>
|
|
|
public static bool IsExistsRecipeMaterName(string materName)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
FeedingAction action = new FeedingAction();
|
|
|
DbHelper localHelper = action.NewDbHelper(Basic.DataSourceFactory.MCDbType.Local);
|
|
|
localHelper.CommandType = CommandType.Text;
|
|
|
localHelper.ClearParameter();
|
|
|
string strSql = @"select COUNT(*) from pmt_recipe where mater_name=@materName and equip_code=@equipCode";
|
|
|
localHelper.CommandText = strSql;
|
|
|
localHelper.AddParameter("@materName", materName);
|
|
|
localHelper.AddParameter("@equipCode", action.CurrEquipCode.Substring(3, 2));
|
|
|
object result = localHelper.ToScalar();
|
|
|
if (result != null && result != System.DBNull.Value)
|
|
|
{
|
|
|
int intResult = 0;
|
|
|
if (int.TryParse(result.ToString(), out intResult))
|
|
|
{
|
|
|
if (intResult > 0)
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("获取Recipe_Name失败:" + ex.Message, ex);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 在本地数据库,根据计划号获取对应的配方总重TotalWeight
|
|
|
|
|
|
/// <summary>
|
|
|
/// 在本地数据库,根据计划号获取对应的Recipe_Code
|
|
|
/// </summary>
|
|
|
/// <param name="planID">计划号</param>
|
|
|
/// <returns>获取成功返回对应的值,失败返回String.Empty</returns>
|
|
|
public static double GetTotalWeightByPlanID(string planID)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
FeedingAction action = new FeedingAction();
|
|
|
DbHelper localHelper = action.NewDbHelper(Basic.DataSourceFactory.MCDbType.Local);
|
|
|
localHelper.CommandType = CommandType.Text;
|
|
|
localHelper.ClearParameter();
|
|
|
string strSql = @"select a.total_weight from pmt_recipe as a
|
|
|
inner join ppt_plan as b
|
|
|
on a.equip_code = substring(b.equip_code,4,2) and a.mater_code = b.mater_code and a.edt_code = b.edt_code
|
|
|
where b.plan_id = @PlanID";
|
|
|
localHelper.CommandText = strSql;
|
|
|
localHelper.AddParameter("@PlanID", planID);
|
|
|
object result = localHelper.ToScalar();
|
|
|
if (result != null && result != System.DBNull.Value)
|
|
|
{
|
|
|
return Convert.ToDouble(result.ToString());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("获取Total_Weight失败:" + ex.Message, ex);
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 更新计划表中的单车总重
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新计划表中的单车总重
|
|
|
/// </summary>
|
|
|
/// <param name="planID">计划ID</param>
|
|
|
/// <param name="totalWeight">设定总重</param>
|
|
|
public static void UpdateTotalWeight(string planID, double totalWeight)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
FeedingAction action = new FeedingAction();
|
|
|
DbHelper localHelper = action.NewDbHelper(Basic.DataSourceFactory.MCDbType.Local);
|
|
|
localHelper.CommandType = CommandType.Text;
|
|
|
localHelper.ClearParameter();
|
|
|
string strSql = @"update ppt_plan set total_weight = @total_weight where plan_id = @PlanID";
|
|
|
localHelper.CommandText = strSql;
|
|
|
localHelper.AddParameter("@total_weight", totalWeight);
|
|
|
localHelper.AddParameter("@PlanID", planID);
|
|
|
localHelper.ExecuteNonQuery();
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("更新计划表Total_Weight失败:" + ex.Message, ex);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 判断本地库当前计划与上一个计划是否生产同一物料
|
|
|
|
|
|
/// <summary>
|
|
|
/// 判断本地库当前计划与上一个计划是否生产同一物料
|
|
|
/// </summary>
|
|
|
/// <param name="currPlanID">当前计划号</param>
|
|
|
/// <param name="equipCode">机台号</param>
|
|
|
/// <param name="planDate">计划日期</param>
|
|
|
/// <param name="shiftID">班次</param>
|
|
|
/// <returns>相同返回true,不同返回false</returns>
|
|
|
public static bool IsSameMaterCode(string currPlanID, string equipCode, DateTime planDate, int shiftID)
|
|
|
{
|
|
|
string prePlanID = PlanCommon.GetPrevPlanID(currPlanID, equipCode, planDate, shiftID);
|
|
|
if (String.IsNullOrEmpty(prePlanID))
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
DataRow prevRow = PlanCommon.GetPlanData(Basic.DataSourceFactory.MCDbType.Local, prePlanID);
|
|
|
DataRow currRow = PlanCommon.GetPlanData(Basic.DataSourceFactory.MCDbType.Local, prePlanID);
|
|
|
if (prevRow != null && currRow != null)
|
|
|
{
|
|
|
if (prevRow["RecipeMaterialCode"] != null && prevRow["RecipeMaterialCode"] != System.DBNull.Value && currRow["RecipeMaterialCode"] != null && currRow["RecipeMaterialCode"] != System.DBNull.Value)
|
|
|
{
|
|
|
if (prevRow["RecipeMaterialCode"].ToString() == currRow["RecipeMaterialCode"].ToString())
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 刷新胶料称量画面物料列
|
|
|
/// <summary>
|
|
|
/// 刷新胶料称量画面物料列
|
|
|
/// </summary>
|
|
|
public static void GetScanBarcode()
|
|
|
{
|
|
|
FeedingAction action = new FeedingAction();
|
|
|
if (action.NetType != Mesnac.Action.Base.BaseAction.NetTypes.Net)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
try
|
|
|
{
|
|
|
if (!PlanCommon.IsCanConnectServer())
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("扫描架子条码处理失败:获取网络数据库连接失败!");
|
|
|
return;
|
|
|
}
|
|
|
DbHelper serverHelper = action.NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Server);
|
|
|
if (serverHelper == null)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("扫描架子条码处理失败:获取网络数据库连接失败!");
|
|
|
return;
|
|
|
}
|
|
|
serverHelper.CommandType = CommandType.Text;
|
|
|
serverHelper.ClearParameter();
|
|
|
//MaterCode 条码对应物料 ,MaterCode2 配方中的物料
|
|
|
string strSql = @" SELECT Barcode,mater_Code2,Mater_name FROM Ppt_Shelfbar a
|
|
|
join Pmt_material b on a.mater_Code2=b.Mater_code
|
|
|
where Equip_code= @EquipCode
|
|
|
and Used_Flag<>'1'";
|
|
|
serverHelper.CommandText = strSql;
|
|
|
serverHelper.AddParameter("@EquipCode", action.CurrEquipCode);
|
|
|
DataTable table = serverHelper.ToDataTable();
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
if (table != null && table.Rows.Count > 0)
|
|
|
{
|
|
|
foreach (DataRow row in table.Rows)
|
|
|
{
|
|
|
if (String.IsNullOrEmpty(sb.ToString()))
|
|
|
{
|
|
|
sb.Append(row["MaterialName"] as string);
|
|
|
sb.Append("|");
|
|
|
sb.Append(row["Barcode"] as string);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
sb.Append("|");
|
|
|
sb.Append(row["MaterialName"] as string);
|
|
|
sb.Append("|");
|
|
|
sb.Append(row["Barcode"] as string);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
action.UpdateSysValue("JLCLHM_BarcodeMaterialList", sb.ToString()); //更新ssValue
|
|
|
action.RefreshCustomEquip(); //更新设备变量
|
|
|
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("扫描架子条码处理失败:" + ex.Message, ex);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 向一次法本地库追加一次法计划
|
|
|
|
|
|
/// <summary>
|
|
|
/// 向一次法本地库追加一次法计划
|
|
|
/// </summary>
|
|
|
/// <param name="planId">要追加的计划号</param>
|
|
|
/// <returns>成功返回true,失败返回false</returns>
|
|
|
public static bool AddPlanOne(string planId)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
DataRow planRowData = PlanCommon.GetPlanData(Basic.DataSourceFactory.MCDbType.Local, planId);
|
|
|
if (planRowData != null)
|
|
|
{
|
|
|
DateTime planDate = Mesnac.Basic.DataProcessor.RowValue(planRowData, "PlanDate", DateTime.Now);
|
|
|
int shiftId = Mesnac.Basic.DataProcessor.RowValue(planRowData, "ShiftID", 0);
|
|
|
string recipeCode = Mesnac.Basic.DataProcessor.RowValue(planRowData, "RecipeMaterialCode", String.Empty);
|
|
|
string recipeName = PlanCommon.GetMaterName(Basic.DataSourceFactory.MCDbType.Local, recipeCode);
|
|
|
int setNum = Mesnac.Basic.DataProcessor.RowValue(planRowData, "PlanNum", 0);
|
|
|
int realNum = Mesnac.Basic.DataProcessor.RowValue(planRowData, "RealNum", 0);
|
|
|
|
|
|
FeedingAction action = new FeedingAction();
|
|
|
DbHelper localOneHelper = action.NewDbHelper(Basic.DataSourceFactory.MCDbType.LocalOne);
|
|
|
if (localOneHelper == null)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Warn("向一次法本地库追加一次法计划失败:获取一次法本地库数据连接失败...");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
localOneHelper.CommandType = CommandType.Text;
|
|
|
localOneHelper.ClearParameter();
|
|
|
string strSql = "INSERT INTO Pmt_Plan_One(Plan_time, Plan_Shift, Recipe_code, Recipe_name, Set_num, Real_num, Plan_ID, [Status]) VALUES(@Plan_time,@Plan_Shift,@Recipe_code,@Recipe_name,@Set_num,@Real_num,@Plan_ID,@Status)";
|
|
|
localOneHelper.CommandText = strSql;
|
|
|
localOneHelper.AddParameter("@Plan_time", planDate);
|
|
|
localOneHelper.AddParameter("@Plan_Shift", shiftId);
|
|
|
localOneHelper.AddParameter("@Recipe_code", recipeCode);
|
|
|
localOneHelper.AddParameter("@Recipe_name", recipeName);
|
|
|
localOneHelper.AddParameter("@Set_num", setNum);
|
|
|
localOneHelper.AddParameter("@Real_num", realNum);
|
|
|
localOneHelper.AddParameter("@Plan_ID", planId);
|
|
|
localOneHelper.AddParameter("@Status", 0);
|
|
|
localOneHelper.ExecuteNonQuery();
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Warn("向一次法本地库追加一次法计划失败:没有获取到计划数据,PlanID = " + planId);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("向一次法本地库追加一次法计划失败:" + ex.Message, ex);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 修改一次法本地库计划表的设定数和状态
|
|
|
/// <summary>
|
|
|
/// 修改一次法本地库计划表的设定数和状态
|
|
|
/// </summary>
|
|
|
/// <param name="planId">要修改一次法计划的计划号</param>
|
|
|
/// <param name="setNum">新设定数</param>
|
|
|
/// <param name="status">新的状态:添加:0,修改数量:2,重传配方:3,终止为4</param>
|
|
|
/// <param name="isUpdateSetNum">是否更新设定数</param>
|
|
|
/// <returns>成功返回true,失败返回false</returns>
|
|
|
public static bool UpdatePlanOne(string planId, int setNum, int status, bool isUpdateSetNum)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
FeedingAction action = new FeedingAction();
|
|
|
DbHelper localOneHelper = action.NewDbHelper(Basic.DataSourceFactory.MCDbType.LocalOne);
|
|
|
if (localOneHelper == null)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Warn("向一次法本地库追加一次法计划失败:获取一次法本地库数据连接失败...");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
localOneHelper.CommandType = CommandType.Text;
|
|
|
localOneHelper.ClearParameter();
|
|
|
string strSql = String.Empty;
|
|
|
if (isUpdateSetNum)
|
|
|
{
|
|
|
strSql = "Update Pmt_Plan_One set Set_num = @Set_num,[Status] = @Status where Plan_ID = @Plan_ID";
|
|
|
localOneHelper.AddParameter("@Set_num", setNum);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strSql = "Update Pmt_Plan_One set [Status] = @Status where Plan_ID = @Plan_ID";
|
|
|
}
|
|
|
localOneHelper.CommandText = strSql;
|
|
|
localOneHelper.AddParameter("@Status", status);
|
|
|
localOneHelper.AddParameter("@Plan_ID", planId);
|
|
|
localOneHelper.ExecuteNonQuery();
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("修改一次法本地库计划表的设定数和状态失败:" + ex.Message, ex);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 获取一次法计划完成标志的值
|
|
|
/// <summary>
|
|
|
/// 获取一次法计划完成标志的值,完成标志(PlanFinishTag = 2)代表计划完成或终止
|
|
|
/// </summary>
|
|
|
/// <param name="planId">计划号</param>
|
|
|
/// <returns>返回对应计划的完成标志</returns>
|
|
|
public static int GetPlanOneFinishTag(string planId)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
FeedingAction action = new FeedingAction();
|
|
|
DbHelper dbHelper = action.NewDbHelper(Basic.DataSourceFactory.MCDbType.LocalOne);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Warn("获取一次发计划完成标志失败:获取一次法数据库连接失败!");
|
|
|
return -1;
|
|
|
}
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
string strSql = "select top 1 PlanFinishTag from pmt_PlanQueue_One where PlanNo = @PlanNo";
|
|
|
dbHelper.CommandText = strSql;
|
|
|
dbHelper.AddParameter("@PlanNo", planId);
|
|
|
object result = dbHelper.ToScalar();
|
|
|
if (result != null && result != System.DBNull.Value)
|
|
|
{
|
|
|
int intResult = -1;
|
|
|
if (int.TryParse(result.ToString(), out intResult))
|
|
|
{
|
|
|
return intResult;
|
|
|
}
|
|
|
}
|
|
|
return -1;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("获取一次法计划完成标志失败:" + ex.Message);
|
|
|
return -2;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 设置(网格控件)的表头、字体和行样式
|
|
|
/// <summary>
|
|
|
/// 设置(网格控件)的表头、字体和行样式
|
|
|
/// </summary>
|
|
|
/// <param name="grid"></param>
|
|
|
public static void SetDataGridViewStyle(DataGridView grid)
|
|
|
{
|
|
|
lock (String.Empty)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
if (grid == null)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Warn("设置计划背景色失败:网格控件为null");
|
|
|
return;
|
|
|
}
|
|
|
grid.RowTemplate.Height = 28;
|
|
|
grid.DefaultCellStyle.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
|
|
grid.ColumnHeadersHeight = 28;
|
|
|
grid.ColumnHeadersDefaultCellStyle.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
|
|
grid.RowHeadersVisible = false;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("【当班计划】设置(网格控件)的表头、字体和行样式SetDataGridViewStyle失败:" + ex.Message);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 设置(网格控件)的表头、字体和行样式
|
|
|
/// </summary>
|
|
|
/// <param name="grid"></param>
|
|
|
public static void SetDataGridViewStyle48(DataGridView grid)
|
|
|
{
|
|
|
lock (String.Empty)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
if (grid == null)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Warn("设置计划背景色失败:网格控件为null");
|
|
|
return;
|
|
|
}
|
|
|
grid.RowTemplate.Height = 60;
|
|
|
grid.DefaultCellStyle.Font = new System.Drawing.Font("宋体", 32F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
|
|
grid.ColumnHeadersHeight = 70;
|
|
|
grid.ColumnHeadersDefaultCellStyle.Font = new System.Drawing.Font("宋体", 48F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
|
|
grid.RowHeadersVisible = false;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("【当班计划】设置(网格控件)的表头、字体和行样式SetDataGridViewStyle48失败:" + ex.Message);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 设置(网格控件)计划状态背景色
|
|
|
/// <summary>
|
|
|
/// 设置计划状态背景色
|
|
|
/// </summary>
|
|
|
/// <param name="grid"></param>
|
|
|
public static void SetBackColor(DataGridView grid)
|
|
|
{
|
|
|
lock (String.Empty)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
if (grid == null)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Warn("设置计划背景色失败:网格控件为null");
|
|
|
return;
|
|
|
}
|
|
|
if (grid.Columns.Contains("PlanNum"))
|
|
|
{
|
|
|
grid.Columns["PlanNum"].Width = 50;
|
|
|
}
|
|
|
if (grid.Columns.Contains("RealNum"))
|
|
|
{
|
|
|
grid.Columns["RealNum"].Width = 50;
|
|
|
}
|
|
|
if (grid.Columns.Contains("PlanID"))
|
|
|
{
|
|
|
grid.Columns["PlanID"].Width = 130;
|
|
|
}
|
|
|
//grid.Refresh();
|
|
|
|
|
|
string lastPlanID = String.Empty;
|
|
|
PlanLog log = PlanCommon.PlanLog;
|
|
|
if (log != null)
|
|
|
{
|
|
|
lastPlanID = log.LastPlanID;
|
|
|
}
|
|
|
grid.ClearSelection(); //清空选中行
|
|
|
grid.ColumnHeadersHeight = 25;
|
|
|
grid.ColumnHeadersDefaultCellStyle.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
|
|
grid.RowHeadersVisible = false;
|
|
|
grid.RowTemplate.Height = 28;
|
|
|
grid.RowsDefaultCellStyle.Font = new System.Drawing.Font("宋体", 12, System.Drawing.FontStyle.Bold);
|
|
|
foreach (DataGridViewRow row in grid.Rows)
|
|
|
{
|
|
|
switch (Convert.ToInt32(row.Cells["PlanState"].Value))
|
|
|
{
|
|
|
case (int)PlanStates.Producting:
|
|
|
row.DefaultCellStyle.BackColor = System.Drawing.Color.GreenYellow; //绿色
|
|
|
break;
|
|
|
case (int)PlanStates.Completed:
|
|
|
if (Convert.ToInt32(row.Cells["RealNum"].Value) < Convert.ToInt32(row.Cells["PlanNum"].Value))
|
|
|
{
|
|
|
//停止计划
|
|
|
row.DefaultCellStyle.BackColor = System.Drawing.Color.FromArgb(220, 220, 120); //灰色
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//完成计划
|
|
|
row.DefaultCellStyle.BackColor = System.Drawing.Color.FromArgb(220, 220, 220); //灰色
|
|
|
}
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
//if (row.Cells["PlanId"].Value.ToString().Trim() == lastPlanID)
|
|
|
//{
|
|
|
// row.Selected = true;
|
|
|
//}
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("设置计划背景色失败:" + ex.Message);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 设置计划状态背景色
|
|
|
/// </summary>
|
|
|
/// <param name="grid"></param>
|
|
|
public static void SetBackColor48(DataGridView grid)
|
|
|
{
|
|
|
lock (String.Empty)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
if (grid == null)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Warn("设置计划背景色失败:网格控件为null");
|
|
|
return;
|
|
|
}
|
|
|
if (grid.Columns.Contains("PlanNum"))
|
|
|
{
|
|
|
grid.Columns["PlanNum"].Width = 200;
|
|
|
}
|
|
|
if (grid.Columns.Contains("RealNum"))
|
|
|
{
|
|
|
grid.Columns["RealNum"].Width = 200;
|
|
|
}
|
|
|
//grid.Refresh();
|
|
|
grid.ClearSelection(); //清空选中行
|
|
|
grid.ColumnHeadersHeight = 60;
|
|
|
grid.ColumnHeadersDefaultCellStyle.Font = new System.Drawing.Font("宋体", 32F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
|
|
grid.RowHeadersVisible = false;
|
|
|
grid.RowTemplate.Height = 70;
|
|
|
grid.RowsDefaultCellStyle.Font = new System.Drawing.Font("宋体", 48F, System.Drawing.FontStyle.Bold);
|
|
|
foreach (DataGridViewRow row in grid.Rows)
|
|
|
{
|
|
|
row.Selected = false;
|
|
|
switch (Convert.ToInt32(row.Cells["PlanState"].Value))
|
|
|
{
|
|
|
case (int)PlanStates.Producting:
|
|
|
row.DefaultCellStyle.BackColor = System.Drawing.Color.GreenYellow; //绿色
|
|
|
break;
|
|
|
case (int)PlanStates.Completed:
|
|
|
if (Convert.ToInt32(row.Cells["RealNum"].Value) < Convert.ToInt32(row.Cells["PlanNum"].Value))
|
|
|
{
|
|
|
//停止计划
|
|
|
row.DefaultCellStyle.BackColor = System.Drawing.Color.FromArgb(220, 220, 120); //灰色
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//完成计划
|
|
|
row.DefaultCellStyle.BackColor = System.Drawing.Color.FromArgb(220, 220, 220); //灰色
|
|
|
}
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("设置计划背景色失败:" + ex.Message);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 计划日志
|
|
|
/// <summary>
|
|
|
/// 计划日志对象
|
|
|
/// </summary>
|
|
|
[Serializable]
|
|
|
public class PlanLog
|
|
|
{
|
|
|
private DateTime _lastSelectDate = DateTime.Now;
|
|
|
private int _lastSelectShiftID = 1;
|
|
|
private int _lastClassID = 1;
|
|
|
private string _lastPlanID = String.Empty;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 最后一次执行计划时选择的日期
|
|
|
/// </summary>
|
|
|
public DateTime LastSelectDate { get { return this._lastSelectDate; } set { this._lastSelectDate = value; } }
|
|
|
/// <summary>
|
|
|
/// 最后一次执行计划是选择的班次ID
|
|
|
/// </summary>
|
|
|
public int LastSelectShiftID { get { return this._lastSelectShiftID; } set { this._lastSelectShiftID = value; } }
|
|
|
/// <summary>
|
|
|
/// 最后一次执行计划对应的班组
|
|
|
/// </summary>
|
|
|
public int LastClassID { get { return this._lastClassID; } set { this._lastClassID = value; } }
|
|
|
/// <summary>
|
|
|
/// 最后一次执行的计划号
|
|
|
/// </summary>
|
|
|
public string LastPlanID { get { return this._lastPlanID; } set { this._lastPlanID = value; } }
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 计划状态
|
|
|
/// <summary>
|
|
|
/// 计划状态
|
|
|
/// </summary>
|
|
|
public enum PlanStates
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 未知状态
|
|
|
/// </summary>
|
|
|
UnKnow = -1,
|
|
|
/// <summary>
|
|
|
/// 初始化
|
|
|
/// </summary>
|
|
|
Init = 0,
|
|
|
/// <summary>
|
|
|
/// 新增
|
|
|
/// </summary>
|
|
|
New = 1,
|
|
|
/// <summary>
|
|
|
/// 下达
|
|
|
/// </summary>
|
|
|
Issued = 2,
|
|
|
/// <summary>
|
|
|
/// 已接收
|
|
|
/// </summary>
|
|
|
Received = 3,
|
|
|
/// <summary>
|
|
|
/// 正在生产
|
|
|
/// </summary>
|
|
|
Producting = 4,
|
|
|
/// <summary>
|
|
|
/// 已完成
|
|
|
/// </summary>
|
|
|
Completed = 5
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 配方简单实体封装
|
|
|
|
|
|
/// <summary>
|
|
|
/// 配方简单实体封装
|
|
|
/// </summary>
|
|
|
[Serializable]
|
|
|
public class SimplePmtRecipe
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// ID
|
|
|
/// </summary>
|
|
|
public string ObjID { get; set; }
|
|
|
/// <summary>
|
|
|
/// 物料名称
|
|
|
/// </summary>
|
|
|
public string RecipeMaterialName { get; set; }
|
|
|
/// <summary>
|
|
|
/// 配方类型
|
|
|
/// </summary>
|
|
|
public string RecipeTypeName { get; set; }
|
|
|
/// <summary>
|
|
|
/// 版本号
|
|
|
/// </summary>
|
|
|
public int RecipeVersionID { get; set; }
|
|
|
|
|
|
private string _content = String.Empty;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 内容
|
|
|
/// </summary>
|
|
|
public string Content
|
|
|
{
|
|
|
get { return _content; }
|
|
|
set { _content = value; }
|
|
|
}
|
|
|
|
|
|
public override string ToString()
|
|
|
{
|
|
|
if (String.IsNullOrEmpty(this._content))
|
|
|
{
|
|
|
return String.Format("{0}[{1}]{2}", this.RecipeMaterialName, this.RecipeTypeName, this.RecipeVersionID);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return this._content;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 胶料称锁定设置
|
|
|
/// <summary>
|
|
|
/// 胶料称锁定设置,对应网络库的PmtRubWeightSetting表
|
|
|
/// </summary>
|
|
|
[Serializable]
|
|
|
public class RubWeightSetting
|
|
|
{
|
|
|
public int ObjID { get; set; }
|
|
|
/// <summary>
|
|
|
/// 机台号
|
|
|
/// </summary>
|
|
|
public string EquipCode { get; set; }
|
|
|
/// <summary>
|
|
|
/// 状态:0-停机,1-运转,2-空转
|
|
|
/// </summary>
|
|
|
public string State { get; set; }
|
|
|
/// <summary>
|
|
|
/// 电流值
|
|
|
/// </summary>
|
|
|
public int EquipElectricCurrent { get; set; }
|
|
|
/// <summary>
|
|
|
/// 锁定状态,0-不锁,1-部分锁定,2-全锁定
|
|
|
/// </summary>
|
|
|
public string WeightSettingCtrl { get; set; }
|
|
|
/// <summary>
|
|
|
/// 删除标志,0-不删除,1-已删除
|
|
|
/// </summary>
|
|
|
public string DeleteFlag { get; set; }
|
|
|
/// <summary>
|
|
|
/// 备注
|
|
|
/// </summary>
|
|
|
public string Remark { get; set; }
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 简单计划实体类封装
|
|
|
/// <summary>
|
|
|
/// 计划实体类
|
|
|
/// </summary>
|
|
|
[Serializable]
|
|
|
public class SimplePlan
|
|
|
{
|
|
|
#region 字段定义
|
|
|
|
|
|
private string _planID;
|
|
|
private DateTime _planDate;
|
|
|
private string _recipeEquipCode;
|
|
|
private string _recipeMaterialCode;
|
|
|
private string _recipeMaterialName;
|
|
|
private string _recipeVersionID;
|
|
|
private int _shiftID;
|
|
|
private int _classID;
|
|
|
private int _priLevel;
|
|
|
private string _recipeName;
|
|
|
private decimal _totalWeight;
|
|
|
private int _planNum;
|
|
|
private decimal _planWeight;
|
|
|
private int _realNum;
|
|
|
private decimal _realWeight;
|
|
|
private int _planState;
|
|
|
private string _userID;
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 属性定义
|
|
|
|
|
|
public string PlanID
|
|
|
{
|
|
|
get { return _planID; }
|
|
|
set { _planID = value; }
|
|
|
}
|
|
|
public DateTime PlanDate
|
|
|
{
|
|
|
get { return _planDate; }
|
|
|
set { _planDate = value; }
|
|
|
}
|
|
|
public string RecipeEquipCode
|
|
|
{
|
|
|
get { return _recipeEquipCode; }
|
|
|
set { _recipeEquipCode = value; }
|
|
|
}
|
|
|
public string RecipeMaterialCode
|
|
|
{
|
|
|
get { return _recipeMaterialCode; }
|
|
|
set { _recipeMaterialCode = value; }
|
|
|
}
|
|
|
public string RecipeMaterialName
|
|
|
{
|
|
|
get { return _recipeMaterialName; }
|
|
|
set { _recipeMaterialName = value; }
|
|
|
}
|
|
|
public string RecipeVersionID
|
|
|
{
|
|
|
get { return _recipeVersionID; }
|
|
|
set { _recipeVersionID = value; }
|
|
|
}
|
|
|
public int ShiftID
|
|
|
{
|
|
|
get { return _shiftID; }
|
|
|
set { _shiftID = value; }
|
|
|
}
|
|
|
public int ClassID
|
|
|
{
|
|
|
get { return _classID; }
|
|
|
set { _classID = value; }
|
|
|
}
|
|
|
public int PriLevel
|
|
|
{
|
|
|
get { return _priLevel; }
|
|
|
set { _priLevel = value; }
|
|
|
}
|
|
|
public string RecipeName
|
|
|
{
|
|
|
get { return _recipeName; }
|
|
|
set { _recipeName = value; }
|
|
|
}
|
|
|
public decimal TotalWeight
|
|
|
{
|
|
|
get { return _totalWeight; }
|
|
|
set { _totalWeight = value; }
|
|
|
}
|
|
|
public int PlanNum
|
|
|
{
|
|
|
get { return _planNum; }
|
|
|
set { _planNum = value; }
|
|
|
}
|
|
|
public decimal PlanWeight
|
|
|
{
|
|
|
get { return _planWeight; }
|
|
|
set { _planWeight = value; }
|
|
|
}
|
|
|
public int RealNum
|
|
|
{
|
|
|
get { return _realNum; }
|
|
|
set { _realNum = value; }
|
|
|
}
|
|
|
public decimal RealWeight
|
|
|
{
|
|
|
get { return _realWeight; }
|
|
|
set { _realWeight = value; }
|
|
|
}
|
|
|
public int PlanState
|
|
|
{
|
|
|
get { return _planState; }
|
|
|
set { _planState = value; }
|
|
|
}
|
|
|
|
|
|
public string UserID
|
|
|
{
|
|
|
get { return _userID; }
|
|
|
set { _userID = value; }
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#endregion
|
|
|
}
|