You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3398 lines
154 KiB
C#

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;
using ICSharpCode.Core;
using Mesnac.Codd.Session;
using Mesnac.Action.ChemicalWeighing.Entity;
using Mesnac.Action.ChemicalWeighing.Entity.PptPlan;
using Mesnac.Action.ChemicalWeighing.Report;
using DevExpress.XtraRichEdit.Fields.Expression;
using Mesnac.Action.ChemicalWeighing.DBHelper;
namespace Mesnac.Action.ChemicalWeighing.Product.PptPlan
{
/// <summary>
/// 计划业务辅助类
/// </summary>
public class PlanHelper
{
#region 拼音检索配方物料列表
/// <summary>
/// 拼音检索配方物料列表
/// </summary>
/// <returns>返回配方列表</returns>
public static List<SimplePmtRecipe> GetRecipeMaterialListPY()
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string sqlstr = "select ROW_NUMBER() OVER(Order by GETDATE()) ID, recipe_Name from(select distinct recipe_Name from Pmt_recipe where Recipe_Verify=1) t ";
dbHelper.CommandText = sqlstr;
DataTable table = dbHelper.ToDataTable();
List<SimplePmtRecipe> lst = new List<SimplePmtRecipe>();
SimplePmtRecipe recipe = null;
foreach (DataRow row in table.Rows)
{
recipe = new SimplePmtRecipe();
recipe.ID = Mesnac.Basic.DataProcessor.RowValue(row, "ID", String.Empty);
//recipe.Recipe_Code = Mesnac.Basic.DataProcessor.RowValue(row, "recipe_Id", String.Empty);
recipe.Recipe_Name = Mesnac.Basic.DataProcessor.RowValue(row, "recipe_Name", String.Empty);
//recipe.Recipe_type = Mesnac.Basic.DataProcessor.RowValue(row, "recipe_Type", String.Empty);
lst.Add(recipe);
}
return lst;
}
#endregion
#region 静态字段定义
private static bool _isInit = false; //当班计划是否已初始化
private static string _execDate; //执行日期
private static string _execShift; //执行班次
private static string _execClass; //执行班组
private static bool _isShift = false; //是否交接班标志
private static PlanLog _planLog = null; //计划日志
#endregion
#region 静态属性定义
/// <summary>
/// 是否正在初始化计划标志
/// </summary>
public static bool IsInit
{
get { return _isInit; }
set { lock (String.Empty) { _isInit = value; } }
}
/// <summary>
/// 执行日期
/// </summary>
public static string ExecDate
{
get { return _execDate; }
set { lock (String.Empty) { _execDate = value; } }
}
/// <summary>
/// 执行班次
/// </summary>
public static string ExecShift
{
get { return _execShift; }
set { lock (String.Empty) { _execShift = value; } }
}
/// <summary>
/// 执行班组
/// </summary>
public static string ExecClass
{
get { return _execClass; }
set { lock (String.Empty) { _execClass = value; } }
}
/// <summary>
/// 是否交接班标记
/// </summary>
public static bool IsShift
{
get { return _isShift; }
set { lock (String.Empty) { _isShift = value; } }
}
/// <summary>
/// 计划日志对象
/// </summary>
public static PlanLog PlanLog
{
get
{
if (_planLog == null)
{
try
{
_planLog = new PlanLog();
string currentPlanDate = BaseDataHelper.GetSysValue("PlanLog.CurrentPlanDate"); //获取当前计划日期
string currentPlanId = BaseDataHelper.GetSysValue("PlanLog.CurrentPlanID"); //获取当前计划号
string currentShiftID = BaseDataHelper.GetSysValue("PlanLog.CurrentShiftID"); //获取当前班次
string currentShiftName = BaseDataHelper.GetSysValue("PlanLog.CurrentShiftName"); //获取当前班次名称
string currentClassID = BaseDataHelper.GetSysValue("PlanLog.CurrentClassID"); //获取当前班组
string currentClassName = BaseDataHelper.GetSysValue("PlanLog.CurrentClassName"); //获取当前班组名称
if (!String.IsNullOrEmpty(currentPlanDate))
{
_planLog.LastDate = Convert.ToDateTime(currentPlanDate);
}
if (!String.IsNullOrEmpty(currentShiftID))
{
_planLog.LastShiftID = Convert.ToInt32(currentShiftID);
}
if (!String.IsNullOrEmpty(currentClassID))
{
_planLog.LastClassID = Convert.ToInt32(currentClassID);
}
if (!String.IsNullOrEmpty(currentPlanId))
{
_planLog.LastPlanID = currentPlanId.Trim();
}
_planLog.LastShiftName = currentShiftName;
_planLog.LastClassName = currentClassName;
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<PlanHelper>.Error("从SysKeyValue中获取计划日志失败" + ex.Message, ex);
}
}
return _planLog;
}
set
{
_planLog = value;
try
{
if (_planLog != null)
{
BaseDataHelper.UpdateSysValue("PlanLog.CurrentPlanDate", String.Format("{0:yyyy-MM-dd}", _planLog.LastDate));
BaseDataHelper.UpdateSysValue("PlanLog.CurrentPlanID", _planLog.LastPlanID);
BaseDataHelper.UpdateSysValue("PlanLog.CurrentShiftID", _planLog.LastShiftID.ToString());
BaseDataHelper.UpdateSysValue("PlanLog.CurrentShiftName", _planLog.LastShiftName);
BaseDataHelper.UpdateSysValue("PlanLog.CurrentClassID", _planLog.LastClassID.ToString());
BaseDataHelper.UpdateSysValue("PlanLog.CurrentClassName", _planLog.LastClassName);
}
else
{
BaseDataHelper.UpdateSysValue("PlanLog.CurrentPlanDate", String.Format("{0:yyyy-MM-dd}", DateTime.Now));
BaseDataHelper.UpdateSysValue("PlanLog.CurrentPlanID", String.Empty);
BaseDataHelper.UpdateSysValue("PlanLog.CurrentShiftID", String.Empty);
BaseDataHelper.UpdateSysValue("PlanLog.CurrentShiftName", String.Empty);
BaseDataHelper.UpdateSysValue("PlanLog.CurrentClassID", String.Empty);
BaseDataHelper.UpdateSysValue("PlanLog.CurrentClassName", String.Empty);
}
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<PlanHelper>.Error("保存计划日志到SysKeyValue表中失败" + ex.Message, ex);
}
}
}
#endregion
#region 静态方法定义
#region 计划网格控件样式设置方法
#region 设置(网格控件)的表头、字体和行样式
/// <summary>
/// 设置(网格控件)的表头、字体和行样式
/// </summary>
/// <param name="grid"></param>
public static void SetDataGridViewStyle(DataGridView grid)
{
lock (String.Empty)
{
try
{
if (grid == null)
{
ICSharpCode.Core.LoggingService<PlanHelper>.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<PlanHelper>.Error("【当班计划】设置网格控件的表头、字体和行样式SetDataGridViewStyle失败" + ex.Message);
}
}
}
#endregion
#region 设置(网格控件)的表头、字体和行样式
/// <summary>
/// 设置(网格控件)的表头、字体和行样式
/// </summary>
/// <param name="grid"></param>
public static void SetDataGridViewStyle48(DataGridView grid)
{
lock (String.Empty)
{
try
{
if (grid == null)
{
ICSharpCode.Core.LoggingService<PlanHelper>.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;
grid.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; //列头居中
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<PlanHelper>.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 || grid.Visible == false)
{
ICSharpCode.Core.LoggingService.Warn("设置计划背景色失败网格控件为null或不可见");
return;
}
string lastPlanID = String.Empty;
PlanLog log = 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)
{
int planState = 0;
planState = StateToValue(row.Cells["Plan_StateText"].Value.ToString());
switch (planState)
{
case (int)PlanState.Download: //已下传
row.DefaultCellStyle.BackColor = System.Drawing.Color.FromArgb(255, 204, 204);
break;
case (int)PlanState.UnStart: //未启动
row.DefaultCellStyle.BackColor = System.Drawing.Color.FromArgb(255, 255, 204);
break;
case (int)PlanState.Producting: //正在运行
row.DefaultCellStyle.BackColor = System.Drawing.Color.GreenYellow; //绿色
break;
case (int)PlanState.Terminated: //已终止
row.DefaultCellStyle.BackColor = System.Drawing.Color.FromArgb(220, 220, 120); //灰色
break;
case (int)PlanState.Completed: //已完成
int realNum = 0;
realNum = Convert.ToInt32(row.Cells["Real_Num"].Value);
if (realNum < Convert.ToInt32(row.Cells["Plan_Num"].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<PlanHelper>.Error("设置计划背景色失败:" + ex.Message);
}
}
}
#endregion
#endregion
#region 判断某个计划是否存在(LR_Plan)
/// <summary>
/// 判断某个计划是否存在
/// </summary>
/// <param name="planID">计划号</param>
/// <returns>存在返回true否则返回false</returns>
public static bool LRPlanExists(string planID)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "select count(Plan_Id) from LR_plan where Plan_Id = @PlanID";
dbHelper.CommandText = strSql;
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 判断某个计划是否存在(RT_plan)
/// <summary>
/// 判断某个计划是否存在
/// </summary>
/// <param name="planID">计划号</param>
/// <returns>存在返回true否则返回false</returns>
public static bool PlanExists(string planID)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "select count(Plan_Id) from RT_plan where Plan_Id = @PlanID";
dbHelper.CommandText = strSql;
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="recipeName">配方名称</param>
/// <returns>存在返回true否则返回false</returns>
public static bool PlanExistsRecipeName(string recipeName)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "select count(Plan_Id) from RT_plan where Recipe_Name = @Recipe_Name";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@Recipe_Name", recipeName);
object result = dbHelper.ToScalar();
if (result != null && result != DBNull.Value && Convert.ToInt32(result) > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 判断某个计划是否存在
/// </summary>
/// <param name="recipeName">配方名称</param>
/// <returns>存在返回true否则返回false</returns>
public static bool PlanExistsRecipe(string recipeName)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "select count(Plan_Id) from RT_plan where Recipe_Name = @Recipe_Name ";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@Recipe_Name", recipeName);
object result = dbHelper.ToScalar();
if (result != null && result != DBNull.Value && Convert.ToInt32(result) > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 判断某个计划是否存在
/// </summary>
/// <param name="planDate">计划日期</param>
/// <param name="shiftID">班次</param>
/// <param name="planID">计划号</param>
/// <returns>存在返回true不存在返回false</returns>
public static bool PlanExists(DateTime planDate, int shiftID, string planID)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "select count(Plan_Id) from RT_plan where Convert(varchar,Plan_Date,112) = @PlanDate and Shift_Id = @ShiftID and Plan_Id = @PlanID";
dbHelper.CommandText = strSql;
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 GetNextSerialNum 获取下一个可用的序号SerialNum 规则:同机台、同日期、同班次 计划号最后2位的最大值加1
/// <summary>
/// 获取下一个可用的序号
/// </summary>
/// <param name="planDate">计划生产日期</param>
/// <returns>返回可用的序号</returns>
public static int GetNextSerialNum()
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "SELECT MAX(Plan_Serial) FROM RT_plan";
dbHelper.CommandText = strSql;
object result = dbHelper.ToScalar();
if (result == null || result == System.DBNull.Value)
{
return 1;
}
else
{
return Convert.ToInt32(result) + 1;
}
}
#endregion
#region GetNextSerialNumFromLRPlan 获取下一个可用的序号SerialNum 规则:同机台、同日期、同班次 计划号最后2位的最大值加1(RT_plan)
/// <summary>
/// 获取下一个可用的序号
/// </summary>
/// <param name="planDate">计划生产日期</param>
/// <returns>返回可用的序号</returns>
public static int GetNextSerialNumFromLRPlan(DateTime planDate)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "SELECT MAX(RIGHT(Plan_Id,2)) FROM Hw_plan WHERE LEFT(Plan_Id,8) = @PlanDate";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@PlanDate", String.Format("{0:yyyyMMdd}", planDate));
object result = dbHelper.ToScalar();
if (result == null || result == System.DBNull.Value)
{
return 1;
}
else
{
return Convert.ToInt32(result) + 1;
}
}
#endregion
#region GenerateNextPlanID 获取下一个可用的计划号 (6位日期、2位机台、1位班次、1位网络/本机、2位流水)
/// <summary>
/// 获取下一个可用的计划号 (6位日期、2位机台、1位班次、1位网络/本机、2位流水)
/// </summary>
/// <param name="equipCode">机台号</param>
/// <param name="planDate">计划生产日期</param>
/// <param name="shiftID">班次</param>
/// <returns>返回生成的12位计划号</returns>
public static string GenerateNextPlanID(string equipCode, DateTime planDate, int shiftID)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "SELECT Max(Plan_Id) FROM RT_plan WHERE LEFT(Plan_Id,8) = @PlanDate";
dbHelper.AddParameter("@PlanDate", String.Format("{0:yyyyMMdd}", planDate));
dbHelper.CommandText = strSql;
object result = dbHelper.ToScalar();
if (result == null || result == System.DBNull.Value)
{
//string code = equipCode.Substring(3, 2); //获取机台后2位
string code = "01";
return String.Format("{0:yyyyMMdd}{1}{2}01", planDate, code, shiftID);
}
string lastTwo = result.ToString().Substring(11, 2); //截取最后2位
int newValue = Convert.ToInt32(lastTwo) + 1;
string nextPlanID = result.ToString().Substring(0, 11) + Mesnac.Basic.DataProcessor.FillZero(newValue.ToString(), 2);
return nextPlanID;
}
#endregion
#region GenerateNextPlanIDNew 获取下一个可用的计划号 (6位日期、2位机台、1位班次、1位网络/本机、2位流水)
/// <summary>
/// 获取下一个可用的计划号 (6位日期、2位机台、1位班次、1位网络/本机、2位流水)
/// </summary>
/// <param name="equipCode">机台号</param>
/// <param name="planDate">计划生产日期</param>
/// <param name="shiftID">班次</param>
/// <returns>返回生成的12位计划号</returns>
public static string GenerateNextPlanIDNew(DateTime planDate, int shiftID,int sNum)
{
string code = "01";
return String.Format("{0:yyyyMMdd}{1}{2}", planDate, code, shiftID) + Mesnac.Basic.DataProcessor.FillZero(sNum.ToString(), 2);
}
#endregion
#region 获取某条生产计划(计划号)
/// <summary>
/// 获取某条生产计划(计划号)
/// </summary>
/// <param name="planID">计划号</param>
/// <returns>返回对应计划的DataRow</returns>
public static DataTable GetPlanData(DateTime planDate, int shiftID)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "SELECT * FROM RT_plan WHERE Plan_Date = @Plan_Date and Shift_Id=@Shift_Id";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@Plan_Date", planDate);
dbHelper.AddParameter("@Shift_Id", shiftID);
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count == 1)
{
return table;
}
return null;
}
/// <summary>
/// 获取某条生产计划(计划号)
/// </summary>
/// <param name="planID">计划号</param>
/// <returns>返回对应计划的DataRow</returns>
public static DataRow GetPlanData(string planID)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "SELECT * FROM RT_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;
}
/// <summary>
/// 获取某条生产计划(计划序号、日期)
/// </summary>
/// <param name="planID">计划号</param>
/// <returns>返回对应计划的DataRow</returns>
public static DataRow GetPlanData(int planSerial)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "SELECT * FROM RT_plan WHERE Plan_Serial = @Plan_Serial";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@Plan_Serial", planSerial);
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count == 1)
{
return table.Rows[0];
}
return null;
}
/// <summary>
/// 获取某条生产计划(计划号)
/// </summary>
/// <param name="planID">计划号</param>
/// <returns>返回对应计划实体对象</returns>
public static RT_plan GetPlanDataEntity(string planID)
{
DataRow dr = GetPlanData(planID);
if (dr != null)
{
RT_plan plan = ConvertDataRowToPptPlan(dr);
return plan;
}
else
{
return null;
}
}
/// <summary>
/// 获取某条生产计划(计划序号、日期)
/// </summary>
/// <param name="planSerial">计划序号</param>
/// <param name="planDate">计划日期</param>
/// <returns>返回对应计划实体对象</returns>
public static RT_plan GetPlanDataEntity(int planSerial)
{
DataRow dr = GetPlanData(planSerial);
if (dr != null)
{
RT_plan plan = ConvertDataRowToPptPlan(dr);
return plan;
}
else
{
return null;
}
}
#endregion
#region 实体类复制
/// <summary>
        /// 将一个实体类复制到另一个实体类
        /// </summary>
        /// <param name="objectsrc">源实体类</param>
        /// <param name="objectdest">复制到的实体类</param>
        public static void EntityToEntity(object objectsrc, object objectdest)
        {
            var sourceType = objectsrc.GetType();
            var destType = objectdest.GetType();
            foreach (var source in sourceType.GetProperties())
            {
                foreach (var dest in destType.GetProperties())
                {
                    if (dest.Name == source.Name)
                    {
                        dest.SetValue(objectdest, source.GetValue(objectsrc));
                    }
                }
            }
        }
#endregion
#region 获取当班未执行计划列表
/// <summary>
/// 获取当班未执行计划列表
/// </summary>
/// <param name="limit">限定返回结果的行数</param>
/// <returns>返回符合条件的计划列表</returns>
public static List<RT_plan> GetUnExePlanEntityList(int limit)
{
List<RT_plan> lst = new List<RT_plan>();
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "SELECT top {0} * FROM RT_plan WHERE Plan_State = 5 ORDER BY Plan_Date,Plan_Serial";
strSql = String.Format(strSql, limit);
dbHelper.CommandText = strSql;
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
RT_plan entity = null;
foreach(DataRow dr in table.Rows)
{
entity = ConvertDataRowToPptPlan(dr);
lst.Add(entity);
}
}
return lst;
}
#endregion
#region 获取当班正在执行及未执行的计划列表
/// <summary>
/// 获取当班正在执行及未执行的计划列表
/// </summary>
/// <param name="planDate">计划日期</param>
/// <param name="shiftID">班次</param>
/// <param name="limit">限定返回结果的行数</param>
/// <returns>返回符合条件的计划列表</returns>
public static List<RT_plan> GetPlanEntityListByNum(int limit)
{
List<RT_plan> lst = new List<RT_plan>();
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
DateTime planDate = PlanHelper.PlanLog.LastDate;
int shiftID = PlanHelper.PlanLog.LastShiftID;
string msg = String.Empty;
string strPlanDate = String.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now);
//bool result = ProductHelper.PlanDateVerify(out planDate, out shiftID, strPlanDate, shiftID, out msg);
dbHelper.CommandType = CommandType.Text;
string strSql = "SELECT top {0} * FROM RT_plan WHERE LEFT(Plan_Id,8) = @PlanDate AND Plan_State <= 5 ORDER BY Plan_Serial";
strSql = String.Format(strSql, limit);
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
dbHelper.AddParameter("@PlanDate", String.Format("{0:yyyyMMdd}", planDate));
//dbHelper.AddParameter("@ShiftID", shiftID);
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
RT_plan entity = null;
foreach (DataRow dr in table.Rows)
{
entity = ConvertDataRowToPptPlan(dr);
lst.Add(entity);
}
}
return lst;
}
#endregion
#region 获取当班大于某序号的正在执行及未执行的计划列表
/// <summary>
/// 获取当班大于某序号的正在执行及未执行的计划列表
/// </summary>
/// <param name="planSerial">计划序号</param>
/// <returns>返回符合条件的计划列表</returns>
public static List<RT_plan> GetPlanListAfterPlanSerial(int planSerial)
{
List<RT_plan> lst = new List<RT_plan>();
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
DateTime planDate = PlanHelper.PlanLog.LastDate;
int shiftID = PlanHelper.PlanLog.LastShiftID;
string msg = String.Empty;
string strPlanDate = String.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now);
//bool result = ProductHelper.PlanDateVerify(out planDate, out shiftID, strPlanDate, shiftID, out msg);
dbHelper.CommandType = CommandType.Text;
string strSql = "SELECT * FROM RT_plan WHERE LEFT(Plan_Id,8) = @PlanDate AND Shift_Id = @ShiftID AND Plan_State <= 5 AND Plan_Serial > @Plan_Serial ORDER BY Plan_Serial";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
dbHelper.AddParameter("@PlanDate", String.Format("{0:yyyyMMdd}", planDate));
dbHelper.AddParameter("@ShiftID", shiftID);
dbHelper.AddParameter("@Plan_Serial", planSerial);
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
RT_plan entity = null;
foreach (DataRow dr in table.Rows)
{
entity = ConvertDataRowToPptPlan(dr);
lst.Add(entity);
}
}
return lst;
}
#endregion
#region 获取当班某序号未执行的计划(下移使用)
/// <summary>
/// 获取当班某序号未执行的计划
/// </summary>
/// <param name="planSerial">计划序号</param>
/// <returns>返回符合条件的计划列表</returns>
public static RT_plan GetPlanBySerialDown(int planSerial)
{
RT_plan reRtPlan = null;
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
string planDate = DateTime.Now.ToShortDateString();
//int shiftID = PlanHelper.PlanLog.LastShiftID;
string msg = String.Empty;
string strPlanDate = String.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now);
//bool result = ProductHelper.PlanDateVerify(out planDate, out shiftID, strPlanDate, shiftID, out msg);
dbHelper.CommandType = CommandType.Text;
string strSql = "SELECT top 1 * FROM RT_plan WHERE Plan_Date = @PlanDate AND Plan_State <= 5 AND Plan_State >3 AND Plan_Serial > @Plan_Serial ORDER BY Plan_Serial";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
dbHelper.AddParameter("@PlanDate", planDate);
//dbHelper.AddParameter("@ShiftID", shiftID);
dbHelper.AddParameter("@Plan_Serial", planSerial);
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
foreach (DataRow dr in table.Rows)
{
reRtPlan = ConvertDataRowToPptPlan(dr);
break;
}
}
return reRtPlan;
}
#endregion
#region 获取当班某序号未执行的计划(上移使用)
/// <summary>
/// 获取当班某序号未执行的计划
/// </summary>
/// <param name="planSerial">计划序号</param>
/// <returns>返回符合条件的计划列表</returns>
public static RT_plan GetPlanBySerialUp(int planSerial)
{
RT_plan reRtPlan = null;
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
string planDate = DateTime.Now.ToShortDateString();
//int shiftID = PlanHelper.PlanLog.LastShiftID;
string msg = String.Empty;
string strPlanDate = String.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now);
//bool result = ProductHelper.PlanDateVerify(out planDate, out shiftID, strPlanDate, shiftID, out msg);
dbHelper.CommandType = CommandType.Text;
string strSql = "SELECT top 1 * FROM RT_plan WHERE Plan_Date = @PlanDate AND Plan_State <= 5 AND Plan_State >3 AND Plan_Serial < @Plan_Serial ORDER BY Plan_Serial DESC";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
dbHelper.AddParameter("@PlanDate", planDate);
//dbHelper.AddParameter("@ShiftID", shiftID);
dbHelper.AddParameter("@Plan_Serial", planSerial);
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
foreach (DataRow dr in table.Rows)
{
reRtPlan = ConvertDataRowToPptPlan(dr);
break;
}
}
return reRtPlan;
}
#endregion
#region 获取未执行的计划数(RT_plan)
/// <summary>
/// 获取未执行的计划数
/// </summary>
public static int GetUnExePlanNum()
{
List<RT_plan> lst = new List<RT_plan>();
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.CommandType = CommandType.Text;
string strSql = "SELECT * FROM RT_plan WHERE Plan_State = 5";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
RT_plan entity = null;
foreach (DataRow dr in table.Rows)
{
entity = ConvertDataRowToPptPlan(dr);
lst.Add(entity);
}
}
return lst.Count;
}
#endregion
#region 获取正在执行的计划数(RT_plan)
/// <summary>
/// 获取正在执行的计划数
/// </summary>
public static int GetRunningPlanNum()
{
List<RT_plan> lst = new List<RT_plan>();
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.CommandType = CommandType.Text;
string strSql = "SELECT * FROM RT_plan WHERE Plan_State = 3";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
RT_plan entity = null;
foreach (DataRow dr in table.Rows)
{
entity = ConvertDataRowToPptPlan(dr);
lst.Add(entity);
}
}
return lst.Count;
}
#endregion
#region 获取已经下传的计划数(RT_plan)
/// <summary>
/// 获取已经下传的计划数
/// </summary>
public static int GetDownPlanNum()
{
List<RT_plan> lst = new List<RT_plan>();
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.CommandType = CommandType.Text;
string strSql = "SELECT * FROM RT_plan WHERE Plan_State = 4";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
RT_plan entity = null;
foreach (DataRow dr in table.Rows)
{
entity = ConvertDataRowToPptPlan(dr);
lst.Add(entity);
}
}
return lst.Count;
}
#endregion
#region 清空计划列表(RT_plan)
/// <summary>
/// 清空计划列表
/// </summary>
public static void ClearRT_Plan()
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "Delete FROM RT_plan WHERE Plan_State <> 3 And Plan_State <> 5";
dbHelper.CommandText = strSql;
dbHelper.ExecuteNonQuery();
}
#endregion
#region 根据配方id获取物料信息列表
/// <summary>
/// 根据配方id获取物料信息列表
/// </summary>
/// <param name="recipeId">配方ID</param>
/// <returns>返回符合条件的计划列表</returns>
public static List<Pmt_weigh> GetPmt_weighList(string recipeId)
{
IFreeSql _freeSql = FreeHelper.Instance;
string strSql = $"SELECT * FROM Pmt_weigh where Recipe_ID ='{recipeId}'";
var obj = _freeSql.Select<Pmt_weigh>().WithSql(strSql).OrderBy(d=>d.Weight_Id).ToList();
return obj;
}
#endregion
#region 根据配方id获取物料信息列表----2023-06-21
/// <summary>
/// 根据配方id获取物料信息列表
/// </summary>
/// <param name="recipeId">配方ID</param>
/// <returns>返回符合条件的计划列表</returns>
public static List<xl_weigh> Getxl_weighList(string recipeId)
{
List<xl_weigh> lst = new List<xl_weigh>();
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.CommandType = CommandType.Text;
string strSql = "SELECT * FROM Pmt_weigh where Recipe_ID = @Recipe_ID order by Weight_Id";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
dbHelper.AddParameter("@Recipe_ID", recipeId);
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
xl_weigh entity = null;
foreach (DataRow dr in table.Rows)
{
entity = ConvertDataRowToXlweigh(dr);
lst.Add(entity);
}
}
return lst;
}
#endregion
#region 获取下一条生产计划
/// <summary>
/// 获取下一条生产计划
/// </summary>
/// <param name="planDate">计划日期</param>
/// <param name="shiftID">班次</param>
/// <returns>返回符合条件的计划</returns>
public static RT_plan GetNextPlan(int planSerial)
{
RT_plan reRtPLan = new RT_plan();
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.CommandType = CommandType.Text;
string strSql = "SELECT top 1 * FROM RT_plan WHERE Plan_State = 5 AND Plan_Serial > @Plan_Serial ORDER BY Plan_Date,Plan_Serial";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
dbHelper.AddParameter("@Plan_Serial", planSerial);
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
foreach (DataRow dr in table.Rows)
{
reRtPLan = ConvertDataRowToPptPlan(dr);
break;
}
}
return reRtPLan;
}
#endregion
#region 根据物料id获取Pmt_Bin
/// <summary>
/// 根据物料id获取Pmt_Bin
/// </summary>
/// <param name="recipeId">物料id</param>
/// <returns>返回符合条件Pmt_Bin</returns>
public static Pmt_Bin GetPmt_Bin(string materialID)
{
Pmt_Bin rePmt_Bin = new Pmt_Bin();
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.CommandType = CommandType.Text;
string strSql = "SELECT * FROM Pmt_Bin where Material_ID = @Material_ID";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
dbHelper.AddParameter("@Material_ID", materialID);
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
Pmt_Bin entity = null;
foreach (DataRow dr in table.Rows)
{
entity = ConvertDataRowToPmtBin(dr);
rePmt_Bin = entity;
break;
}
}
return rePmt_Bin;
}
#endregion
#region 获取所有Pmt_Bin
/// <summary>
/// 获取所有Pmt_Bin
/// </summary>
public static List<Pmt_Bin> GetAllPmt_Bin()
{
List<Pmt_Bin> rePmt_BinList = new List<Pmt_Bin>();
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.CommandType = CommandType.Text;
string strSql = "SELECT * FROM Pmt_Bin";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
Pmt_Bin entity = null;
foreach (DataRow dr in table.Rows)
{
entity = ConvertDataRowToPmtBin(dr);
rePmt_BinList.Add(entity);
}
}
return rePmt_BinList;
}
#endregion
#region 根据物料id获取料仓号
/// <summary>
/// 根据物料id获取料仓号
/// </summary>
/// <param name="recipeId">物料id</param>
/// <returns>返回符合条件Pmt_Bin</returns>
public static int GetPmt_BinSerial(string materialID)
{
Pmt_Bin rePmt_Bin = new Pmt_Bin();
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.CommandType = CommandType.Text;
string strSql = "SELECT * FROM Pmt_Bin where Material_ID = @Material_ID";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
dbHelper.AddParameter("@Material_ID", materialID);
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
Pmt_Bin entity = null;
foreach (DataRow dr in table.Rows)
{
entity = ConvertDataRowToPmtBin(dr);
rePmt_Bin = entity;
break;
}
}
else
{
return 0;
}
return (int)rePmt_Bin.Bin_Serial;
}
#endregion
#region 获取所有Pmt_material
/// <summary>
/// 获取所有Pmt_material
/// </summary>
public static List<Pmt_material> GetAllPmt_material()
{
List<Pmt_material> rePmt_materialList = new List<Pmt_material>();
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.CommandType = CommandType.Text;
string strSql = "SELECT * FROM Pmt_material where IsEnable='是'";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
Pmt_material entity = null;
foreach (DataRow dr in table.Rows)
{
entity = ConvertDataRowToPmtMaterial(dr);
rePmt_materialList.Add(entity);
}
}
return rePmt_materialList;
}
#endregion
#region 根据物料id获取Pmt_material
/// <summary>
/// 根据物料id获取Pmt_material
/// </summary>
/// <param name="recipeId">物料id</param>
/// <returns>返回符合条件Pmt_Bin</returns>
public static Pmt_material GetPmt_material(string materialID)
{
Pmt_material rePmt_material = null;
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.CommandType = CommandType.Text;
string strSql = "SELECT * FROM Pmt_material where ID = @Material_ID";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
dbHelper.AddParameter("@Material_ID", materialID);
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
Pmt_material entity = null;
foreach (DataRow dr in table.Rows)
{
entity = ConvertDataRowToPmtMaterial(dr);
rePmt_material = entity;
break;
}
}
return rePmt_material;
}
#endregion
#region 根据物料名称获取物料的ID
/// <summary>
/// 根据物料名称获取物料的ID
/// </summary>
/// <param name="materialCode">物料名称</param>
/// <returns>返回符合条件materialID</returns>
public static string GetPmt_materialID(string materialCode)
{
Pmt_material rePmt_material = null;
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.CommandType = CommandType.Text;
string strSql = "SELECT * FROM Pmt_material where Material_code = @Material_code";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
dbHelper.AddParameter("@Material_code", materialCode);
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
Pmt_material entity = null;
foreach (DataRow dr in table.Rows)
{
entity = ConvertDataRowToPmtMaterial(dr);
rePmt_material = entity;
break;
}
}
else
{
return null;
}
return rePmt_material.ID;
}
#endregion
#region 获取某条计划的状态
/// <summary>
/// 获取某条计划的状态
/// </summary>
/// <param name="planID">计划号</param>
/// <returns>返回计划状态</returns>
public static PlanState GetPlanState(string planID)
{
DataRow row = GetPlanData(planID);
if (row != null)
{
int planState = Mesnac.Basic.DataProcessor.RowValue(row, "PlanState", 0); //获取计划状态
int planNum = Mesnac.Basic.DataProcessor.RowValue(row, "PlanNum", 0); //获取计划数
int realNum = Mesnac.Basic.DataProcessor.RowValue(row, "RealNum", 0); //获取完成数
if (realNum >= planNum)
{
return PlanState.Completed;
}
return (PlanState)planState;
}
else
{
return PlanState.UnKnow;
}
}
#endregion
#region 获取某条计划的开炼状态
/// <summary>
/// 获取某条计划的开炼状态
/// </summary>
/// <param name="planID">计划号</param>
/// <returns>返回计划开炼状态</returns>
public static PlanState GetMillPlanState(string planID)
{
DataRow row = GetPlanData(planID);
if (row != null)
{
int planState = Mesnac.Basic.DataProcessor.RowValue(row, "MillPlanState", 0); //获取计划状态
int planNum = Mesnac.Basic.DataProcessor.RowValue(row, "PlanNum", 0); //获取计划数
int realNum = Mesnac.Basic.DataProcessor.RowValue(row, "MillRealNum", 0); //获取完成数
if (realNum >= planNum)
{
return PlanState.Completed;
}
return (PlanState)planState;
}
else
{
return PlanState.UnKnow;
}
}
#endregion
#region 根据计划号获取配方GUID
/// <summary>
/// 根据计划号获取配方GUID
/// </summary>
/// <param name="planID">计划号</param>
/// <returns>成功返回配方GUID失败返回String.Empty</returns>
public static string GetRecipeGUID(string planID)
{
DataRow row = GetPlanData(planID);
if (row != null)
{
string recipeGUID = Mesnac.Basic.DataProcessor.RowValue(row, "RecipeGUID", String.Empty);
return recipeGUID;
}
else
{
return String.Empty;
}
}
#endregion
#region 获取本机台、日期、班次的计划数据
/// <summary>
/// 获取本机台、日期、班次的计划数据
/// </summary>
/// <param name="planDate">计划生产日期</param>
/// <param name="shiftID">班次</param>
/// <returns>返回符合条件的计划数据</returns>
public static DataTable GetDownPlanData(DateTime planDate, int shiftID)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "SELECT Plan_Serial,Recipe_Name,Equip_Code,Version,Plan_Id,Plan_Num,Real_Num,Plan_StateText,Start_Date,End_Date FROM RT_plan WHERE LEFT(Plan_Id,8) = @PlanDate AND Shift_id = @ShiftID ORDER BY Plan_State,Plan_Serial";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@PlanDate", String.Format("{0:yyyyMMdd}", planDate));
dbHelper.AddParameter("@ShiftID", shiftID);
DataTable table = dbHelper.ToDataTable();
return table;
}
/// <summary>
/// 获取本机台、日期的计划数据
/// </summary>
/// <param name="planDate">计划生产日期</param>
/// <returns>返回符合条件的计划数据</returns>
public static DataTable GetPlanData(DateTime planDate)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "SELECT Plan_Serial,Recipe_ID,Recipe_Name,Equip_Code,Version,Plan_Id,Plan_Num,Real_Num,Plan_State,Plan_StateText,Start_Date,End_Date,Plan_Date FROM RT_plan WHERE LEFT(Plan_Id,8) = @PlanDate ORDER BY Plan_State,Plan_Serial";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@PlanDate", String.Format("{0:yyyyMMdd}", planDate));
DataTable table = dbHelper.ToDataTable();
return table;
}
/// <summary>
/// 获取本机台全部的计划数据
/// </summary>
/// <returns>返回符合条件的计划数据表</returns>
public static DataTable GetPlanData()
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "SELECT Batch,ProductName,Plan_Serial,Recipe_ID,Recipe_Name,Equip_Code,Version,Plan_Id,Plan_Num,Real_Num,Plan_State,Plan_StateText,Start_Date,End_Date,Plan_Date,CylinderName,PumpName,WeighbridgeId,Weighbridge FROM RT_plan ORDER BY Plan_State,left(Plan_Id,8),Plan_Serial";
dbHelper.CommandText = strSql;
DataTable table = dbHelper.ToDataTable();
return table;
}
/// <summary>
/// 获取本机台、日期的计划数据
/// </summary>
/// <param name="planDate">计划生产日期</param>
/// <returns>返回符合条件的计划对象列表</returns>
public static List<RT_plan> GetPlanDataEntity(DateTime planDate)
{
List<RT_plan> lst = new List<RT_plan>();
DataTable dt = GetPlanData(planDate);
RT_plan entity = null;
foreach (DataRow dr in dt.Rows)
{
entity = ConvertDataRowToPptPlan(dr);
lst.Add(entity);
}
return lst;
}
/// <summary>
/// 获取本机台、日期、班次的计划数据
/// </summary>
/// <param name="planDate">计划生产日期</param>
/// <param name="shiftID">班次</param>
/// <returns>返回符合条件的计划对象列表</returns>
public static List<RT_plan> GetPlanDataEntity(DateTime planDate, int shiftID)
{
List<RT_plan> lst = new List<RT_plan>();
DataTable dt = GetPlanData(planDate, shiftID);
RT_plan entity = null;
foreach(DataRow dr in dt.Rows)
{
entity = ConvertDataRowToPptPlan(dr);
lst.Add(entity);
}
return lst;
}
#endregion
#region GetFirstPlanID 获取对应计划日期,班次的第一条未生产的计划
/// <summary>
/// 获取对应计划日期,班次的第一条未生产的计划
/// </summary>
/// <param name="planDate">计划生产日期</param>
/// <param name="shiftID">班次</param>
/// <returns>返回符合条件的计划ID失败返回null或String.Empty</returns>
public static string GetFirstPlanID(DateTime planDate, int shiftID)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "select top 1 PlanID from RT_plan where left(PlanID,6) = right(@PlanDate,6) and ShiftID = @ShiftID and PlanState = '3' and RealNum = 0 order by ActionOrder";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@PlanDate", String.Format("{0:yyyyMMdd}", planDate));
dbHelper.AddParameter("@ShiftID", shiftID);
object result = dbHelper.ToScalar();
if (result != null && result != System.DBNull.Value)
{
return result as string;
}
return String.Empty;
}
#endregion
#region GetFirstMillPlanID 获取对应计划日期,班次的第一条开炼未生产的计划
/// <summary>
/// 获取对应计划日期,班次的第一条开炼未生产的计划
/// </summary>
/// <param name="planDate">计划生产日期</param>
/// <param name="shiftID">班次</param>
/// <returns>返回符合条件的计划ID失败返回null或String.Empty</returns>
public static string GetFirstMillPlanID(DateTime planDate, int shiftID)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "select top 1 PlanID from RT_plan where left(PlanID,6) = right(@PlanDate,6) and ShiftID = @ShiftID and MillPlanState = '3' and MillRealNum = 0 order by ActionOrder";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@PlanDate", String.Format("{0:yyyyMMdd}", planDate));
dbHelper.AddParameter("@ShiftID", shiftID);
object result = dbHelper.ToScalar();
if (result != null && result != System.DBNull.Value)
{
return result as string;
}
return String.Empty;
}
#endregion
#region GetFirstUnAllExecPlanID 获取对应计划日期,班次的第一条未完全生产(密炼未执行或开炼未执行)的计划
/// <summary>
/// 获取对应计划日期,班次的第一条未完全生产(密炼未执行或开炼未执行)的计划
/// </summary>
/// <param name="planDate">计划生产日期</param>
/// <param name="shiftID">班次ID</param>
/// <returns>返回符合条件的计划ID失败返回null或String.Empty</returns>
public static string GetFirstUnAllExecPlanID(DateTime planDate, int shiftID)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "select top 1 PlanID from RT_plan where left(PlanID,6) = right(@PlanDate,6) and ShiftID = @ShiftID and (PlanState = '3' or MillPlanState='3') and RealNum = 0 and MillRealNum = 0 order by ActionOrder";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@PlanDate", String.Format("{0:yyyyMMdd}", planDate));
dbHelper.AddParameter("@ShiftID", shiftID);
object result = dbHelper.ToScalar();
if (result != null && result != System.DBNull.Value)
{
return result as string;
}
return String.Empty;
}
#endregion
#region GetPrevPlanID 获取当前计划的前一个计划号,用户计划排序
/// <summary>
/// 获取当前计划的前一个计划号,用户计划排序
/// </summary>
/// <param name="currPlanID">当前计划号</param>
/// <param name="planDate">计划生产日期</param>
/// <param name="shiftID">班次</param>
/// <returns>返回当前计划的前一个计划号</returns>
public static string GetPrevPlanID(string currPlanID, DateTime planDate, int shiftID)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "select top 1 PlanID from RT_plan where ActionOrder < (select ActionOrder from RT_plan where PlanID = @PlanID) and left(PlanID,6) = right(@PlanDate,6) and ShiftID = @ShiftID order by ActionOrder desc";
dbHelper.AddParameter("@PlanDate", String.Format("{0:yyyyMMdd}", planDate));
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 GetNextPlanID 获取当前计划的下一个计划号,用于计划排序
/// <summary>
/// 获取当前计划的下一个计划号,用于计划排序
/// </summary>
/// <param name="currPlanID">当前计划号</param>
/// <param name="planDate">计划生产日期</param>
/// <param name="shiftID">班次</param>
/// <returns></returns>
public static string GetNextPlanID(string currPlanID, DateTime planDate, int shiftID)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string sqlStr = "select top 1 PlanID from RT_plan where ActionOrder > (select ActionOrder from RT_plan where PlanID = @PlanID) and left(PlanID,6) = right(@PlanDate,6) and ShiftID = @ShiftID order by ActionOrder asc";
dbHelper.AddParameter("@PlanID", currPlanID);
dbHelper.AddParameter("@PlanDate", String.Format("{0:yyyyMMdd}", planDate));
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 根据计划号获取对应的配方总重TotalWeight
/// <summary>
/// 根据计划号获取对应的配方总重TotalWeight
/// </summary>
/// <param name="planID">计划号</param>
/// <returns>获取成功返回对应的值失败返回0</returns>
public static double GetTotalWeightByPlanID(string planID)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
dbHelper.ClearParameter();
string strSql = @"select LotTotalWeight from PmtRecipe where GUID = (select RecipeGUID from RT_plan where PlanID = @PlanID)";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@PlanID", planID);
object result = dbHelper.ToScalar();
if (result != null && result != System.DBNull.Value)
{
return Convert.ToDouble(result.ToString());
}
else
{
return 0;
}
}
#endregion
#region 添加生产计划(RT_plan)
/// <summary>
/// 添加生产计划
/// </summary>
/// <param name="equipCode">5位机台号</param>
/// <param name="planDate">计划生产日期</param>
/// <param name="shiftID">班次ID</param>
/// <param name="classID">班组ID</param>
/// <param name="recipeGUID">配方GUID</param>
/// <param name="planNum">计划数</param>
/// <returns>返回新加计划的计划号</returns>
public static string AddPlan(string equipCode, DateTime planDate, int shiftID, string recipeGUID, int planNum, string CylinderName, string CylinderBarCode, string PumpName, string PumpBarCode,string Weighbridge,string batch,string productNames)
{
return AddPlan(equipCode, planDate, shiftID, recipeGUID, 0, planNum, String.Empty, CylinderName, CylinderBarCode, PumpName, PumpBarCode, Weighbridge, batch, productNames);
}
/// <summary>
/// 添加生产计划
/// </summary>
/// <param name="equipCode">5位机台号</param>
/// <param name="planDate">计划生产日期</param>
/// <param name="shiftID">班次ID</param>
/// <param name="classID">班组ID</param>
/// <param name="recipeGUID">配方GUID</param>
/// <param name="planNum">计划数</param>
/// <param name="remark">备注</param>
/// <returns>返回新加计划的计划号</returns>
public static string AddPlan(string equipCode, DateTime planDate, int shiftID, string recipeGUID, int planNum, string remark, string CylinderName, string CylinderBarCode, string PumpName, string PumpBarCode, string Weighbridge, string batch, string productNames)
{
return AddPlan(equipCode, planDate, shiftID, recipeGUID, 0, planNum, remark, CylinderName, CylinderBarCode, PumpName, PumpBarCode, Weighbridge, batch, productNames);
}
/// <summary>
/// 添加生产计划
/// </summary>
/// <param name="equipCode">5位机台号</param>
/// <param name="planDate">计划生产日期</param>
/// <param name="shiftID">班次ID</param>
/// <param name="classID">班组ID</param>
/// <param name="recipeGUID">配方GUID</param>
/// <param name="recipeVersion">配方版本号</param>
/// <param name="planNum">计划数</param>
/// <param name="remark">备注</param>
/// <returns>返回新加计划的计划号</returns>
public static string AddPlan(string equipCode, DateTime planDate, int shiftID, string recipeGUID, int recipeVersion, int planNum, string remark,string CylinderName,string CylinderBarCode,string PumpName,string PumpBarCode,string Weighbridge, string batch, string productNames)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
//查询配方数据
Entity.Pmt_recipe recipe = null;
if (recipeVersion ==0)
{
recipe = Technical.PmtRecipe.RecipeHelper.GetRecipeEntityByGUID(recipeGUID);
}
else
{
recipe = Technical.PmtRecipe.RecipeHelper.GetRecipeEntityByGUID(recipeGUID, recipeVersion.ToString());
}
if (recipe != null)
{
string strRecipeVersion = recipe.Version; //配方版本号
string recipeCode = recipe.Recipe_Code;
string recipeName = recipe.Recipe_Name; //配方名称
string recipeType = recipe.Recipe_type.ToString(); //配方类型
decimal? totalWeight = recipe.Total_Weight; //每车重量
#region 从两张表中获取最大的serialNum
int serialNum = 0;
int rtPlanSNum = GetNextSerialNum(); //RT_plan序号
int lrPlanSNum = GetNextSerialNumFromLRPlan(planDate); //LR_Plan序号
if(rtPlanSNum >= lrPlanSNum)
{
serialNum = rtPlanSNum;
}
else
{
serialNum = lrPlanSNum;
}
#endregion
#region 组合获取planID
string planID = GenerateNextPlanIDNew(planDate, shiftID, serialNum); //计划号
#endregion
//int serialNum = GetNextSerialNum(planDate);
//string planID = GenerateNextPlanID(equipCode, planDate, shiftID); //计划号
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
//添加计划的SQL语句
string strSql3 = @"INSERT INTO RT_plan(Dosing_Id,Batch,ProductName,Plan_Id,Equip_Code,Plan_Serial,Recipe_ID,Recipe_Code,Recipe_Name,Version,Mixer_Line,Recipe_Type,Shift_Id,Shift_Class,Plan_Num,Real_Num,Duration_Time,End_Date,Weight_Man,Stock_Man,Plan_Batch,Plan_State,Plan_StateText,Plan_Date,IF_FLAG,CylinderName,CylinderBarCode,PumpName,PumpBarCode,Weighbridge)
VALUES(@Dosing_Id,@Batch,@ProductName,@Plan_Id,@Equip_Code,@Plan_Serial,@Recipe_ID,@Recipe_Code,@Recipe_Name,@Version,@Mixer_Line,@Recipe_Type,@Shift_Id,@Shift_Class,@Plan_Num,@Real_Num,@Duration_Time,@End_Date,@Weight_Man,@Stock_Man,@Plan_Batch,@Plan_State,@Plan_StateText,@Plan_Date,@IF_FLAG,@CylinderName,@CylinderBarCode,@PumpName,@PumpBarCode,@Weighbridge)";
dbHelper.CommandText = strSql3;
dbHelper.AddParameter("@Dosing_Id", 0);
dbHelper.AddParameter("@Batch", batch); //计划生产批次
dbHelper.AddParameter("@ProductName", productNames); //生产名称
dbHelper.AddParameter("@Plan_Id", planID); //计划号
dbHelper.AddParameter("@Equip_Code", equipCode); //机台号
dbHelper.AddParameter("@Plan_Serial", serialNum); //排序字段优先级在此与ActionOrder相同
dbHelper.AddParameter("@Recipe_ID", recipeGUID); //配方GUID
dbHelper.AddParameter("@Recipe_Code", recipeCode); //配方编码
dbHelper.AddParameter("@Recipe_Name", recipeName); //配方别名
dbHelper.AddParameter("@Version", strRecipeVersion); //配方版本号
dbHelper.AddParameter("@Mixer_Line", recipe.Mixer_line); //配方版本号
dbHelper.AddParameter("@Recipe_Type", recipeType); //配方类型
dbHelper.AddParameter("@Shift_Id", shiftID); //班次ID
dbHelper.AddParameter("@Shift_Class", 0); //班组ID
dbHelper.AddParameter("@Plan_Num", planNum); //计划数
dbHelper.AddParameter("@Real_Num", 0); //完成数量
dbHelper.AddParameter("@Duration_Time", 0); //持续时间
// dbHelper.AddParameter("@Start_Date", String.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now));//开始时间
dbHelper.AddParameter("@End_Date", null); //结束时间
dbHelper.AddParameter("@Weight_Man", null); //称量工
dbHelper.AddParameter("@Stock_Man", null); //投料工
dbHelper.AddParameter("@Plan_Batch", null); //批次号,不同的现场有不同的命令规则。
dbHelper.AddParameter("@Plan_State", (int)PlanState.UnStart); //计划状态
dbHelper.AddParameter("@Plan_StateText", StateToShow((int)PlanState.UnStart)); //计划日期
dbHelper.AddParameter("@Plan_Date", String.Format("{0:yyyy-MM-dd}", DateTime.Now)); //计划日期
dbHelper.AddParameter("@IF_FLAG", 1); //MES计划变更标志位
dbHelper.AddParameter("@CylinderName", CylinderName);
dbHelper.AddParameter("@CylinderBarCode", CylinderBarCode);
dbHelper.AddParameter("@PumpName", PumpName);
dbHelper.AddParameter("@PumpBarCode", PumpBarCode);
dbHelper.AddParameter("@Weighbridge", Weighbridge);
dbHelper.ExecuteNonQuery();
return planID;
}
return String.Empty;
}
#endregion
#region 添加生产计划LR_plan
/// <summary>
/// 添加生产计划
/// </summary>
/// <param name="lrPlan">LR_plan实体类</param>
/// <returns>返回新加计划的计划号</returns>
public static string LRAddPlan(LR_plan lrPlan)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
//添加计划的SQL语句
string strSql3 = @"INSERT INTO LR_plan(Dosing_Id,Plan_Id,Equip_Code,Plan_Serial,Recipe_ID,Recipe_Code,Recipe_Name,Version,Recipe_Type,Shift_Id,Shift_Class,Plan_Num,Real_Num,Duration_Time,Start_Date,End_Date,Weight_Man,Stock_Man,Plan_Batch,Plan_State,Plan_Date,Total_Weight,Total_Error,IF_FLAG,IsRetransmission)
VALUES(@Dosing_Id,@Plan_Id,@Equip_Code,@Plan_Serial,@Recipe_ID@Recipe_Code,@Recipe_Name,@Version,@Recipe_Type,@Shift_Id,@Shift_Class,@Plan_Num,@Real_Num,@Duration_Time,@Start_Date,@End_Date,@Weight_Man,@Stock_Man,@Plan_Batch,@Plan_State,@Plan_Date,@Total_Weight,@Total_Error,@IF_FLAG,@IsRetransmission)";
dbHelper.CommandText = strSql3;
dbHelper.AddParameter("@Dosing_Id", 0);
dbHelper.AddParameter("@Plan_Id", lrPlan.Plan_Id); //计划号
dbHelper.AddParameter("@Equip_Code", lrPlan.Equip_Code); //机台号
dbHelper.AddParameter("@Plan_Serial", lrPlan.Plan_Serial); //排序字段优先级在此与ActionOrder相同
dbHelper.AddParameter("@Recipe_ID", lrPlan.Recipe_ID);
dbHelper.AddParameter("@Recipe_Code", lrPlan.Recipe_Code); //配方编码
dbHelper.AddParameter("@Recipe_Name", lrPlan.Recipe_Name); //配方别名
dbHelper.AddParameter("@Version", lrPlan.Version); //配方版本号
//dbHelper.AddParameter("@Mixer_Line", lrPlan.Mixer_Line); //配方版本号
dbHelper.AddParameter("@Recipe_Type", lrPlan.Recipe_Type); //配方类型
dbHelper.AddParameter("@Shift_Id", lrPlan.Shift_Id); //班次ID
dbHelper.AddParameter("@Shift_Class", 0); //班组ID
dbHelper.AddParameter("@Plan_Num", lrPlan.Plan_Num); //计划数
dbHelper.AddParameter("@Real_Num", lrPlan.Real_Num); //完成数量
dbHelper.AddParameter("@Duration_Time", lrPlan.Duration_Time); //持续时间
dbHelper.AddParameter("@Start_Date", lrPlan.Start_Date); //开始时间
dbHelper.AddParameter("@End_Date", lrPlan.End_Date); //结束时间
dbHelper.AddParameter("@Weight_Man", lrPlan.Weight_Man); //称量工
dbHelper.AddParameter("@Stock_Man", lrPlan.Stock_Man); //投料工
dbHelper.AddParameter("@Plan_Batch", lrPlan.Plan_Batch); //批次号,不同的现场有不同的命令规则。
dbHelper.AddParameter("@Plan_State", lrPlan.Plan_State); //计划状态
dbHelper.AddParameter("@Plan_Date", lrPlan.Plan_Date); //计划日期
dbHelper.AddParameter("@IF_FLAG", lrPlan.IF_FLAG); //暂时无用
dbHelper.AddParameter("@Total_Weight", lrPlan.Total_Weight);
dbHelper.AddParameter("@Total_Error", lrPlan.Total_Error);
dbHelper.AddParameter("@IsRetransmission", lrPlan.IsRetransmission);
dbHelper.ExecuteNonQuery();
return lrPlan.Plan_Id;
}
#endregion
#region 添加LR_recipe
/// <summary>
/// 添加LR_recipe
/// </summary>
/// <param name="lrPlan">LR_recipe实体类</param>
/// <returns>返回新加计划的计划号</returns>
public static string AddLR_recipe(LR_recipe lrRecipe)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
//添加计划的SQL语句
string strSql3 = @"INSERT INTO LR_recipe(Plan_id,Equip_code,Weight_ID,Material_Code,Material_Name,Set_Weight,Set_Error,CPK_Error,Batch_number,remark)
VALUES(@Plan_id,@Equip_code,@Weight_ID,@Material_Code,@Material_Name,@Set_Weight,@Set_Error,@CPK_Error,@Batch_number,@remark)";
dbHelper.CommandText = strSql3;
dbHelper.AddParameter("@Plan_id", lrRecipe.Plan_id);
dbHelper.AddParameter("@Equip_code", lrRecipe.Equip_Code);
dbHelper.AddParameter("@Weight_ID", lrRecipe.Weight_ID);
dbHelper.AddParameter("@Material_Code", lrRecipe.Material_Code);
dbHelper.AddParameter("@Material_Name", lrRecipe.Material_Name);
dbHelper.AddParameter("@Set_Weight", lrRecipe.Set_Weight);
dbHelper.AddParameter("@Set_Error", lrRecipe.Set_Error);
dbHelper.AddParameter("@CPK_Error", lrRecipe.CPK_Error);
dbHelper.AddParameter("@Batch_number", lrRecipe.Batch_number);
dbHelper.AddParameter("@remark", lrRecipe.remark);
dbHelper.ExecuteNonQuery();
return lrRecipe.Plan_id;
}
#endregion
#region 更新计划的序号
/// <summary>
/// 更新计划的序号
/// </summary>
/// <param name="rtPlanList">要更新的计划列表</param>
public static void UpdatePlanSerial(RT_plan rtPlan)
{
try
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "UPDATE RT_plan SET Plan_Serial = @Plan_Serial WHERE Plan_Id = @PlanID";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@Plan_Serial", rtPlan.Plan_Serial);
dbHelper.AddParameter("@PlanID", rtPlan.Plan_Id);
dbHelper.ExecuteNonQuery();
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<PlanHelper>.Error("更新计划设定数异常:" + ex.Message, ex);
}
}
#endregion
#region 更新计划设定数
/// <summary>
/// 更新计划设定数
/// </summary>
/// <param name="planID">计划号</param>
/// <param name="planNum">设定数</param>
public static void UpdatePlanNum(string planID, int planNum)
{
try
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "UPDATE RT_plan SET Plan_Num = @PlanNum, IF_FLAG = @IfFlag WHERE Plan_Id = @PlanID";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@PlanNum", planNum);
dbHelper.AddParameter("@IfFlag", 1);
dbHelper.AddParameter("@PlanID", planID);
dbHelper.ExecuteNonQuery();
}
catch(Exception ex)
{
ICSharpCode.Core.LoggingService<PlanHelper>.Error("更新计划设定数异常:" + ex.Message, ex);
}
}
#endregion
#region 更新计划完成数
/// <summary>
/// 更新计划完成数UpdateRealNum
/// </summary>
/// <param name="planID">计划编号</param>
/// <param name="realNum">完成数</param>
public static void UpdateRealNum(string planID, int realNum, decimal totalWeight, decimal totalError)
{
try
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "UPDATE RT_plan SET Real_Num = @RealNum,Plan_TotalWeight=@Plan_TotalWeight,Plan_TotalError=@Plan_TotalError,Exec_Num=@Exec_Num WHERE Plan_Id = @PlanID";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@RealNum", realNum);
dbHelper.AddParameter("@Plan_TotalWeight", totalWeight);
dbHelper.AddParameter("@Plan_TotalError", totalError);
dbHelper.AddParameter("@Exec_Num", 1);
dbHelper.AddParameter("@PlanID", planID);
dbHelper.ExecuteNonQuery();
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<PlanHelper>.Error("更新计划完成数异常:" + ex.Message, ex);
}
}
#endregion
#region 更新计划状态(RT_plan)
/// <summary>
/// 更新计划状态(RT_plan)
/// </summary>
/// <param name="planID">要更新的计划号</param>
/// <param name="planState">新的计划状态</param>
public static void UpdatePlanState(string planID, int planState)
{
try
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "update RT_plan set Plan_State = @PlanState, Plan_StateText = @Plan_StateText, IF_FLAG = @IfFlag where Plan_Id = @PlanID";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@PlanState", planState);
dbHelper.AddParameter("@Plan_StateText", StateToShow(planState));
dbHelper.AddParameter("@IfFlag", 1);
dbHelper.AddParameter("@PlanID", planID);
dbHelper.ExecuteNonQuery();
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<PlanHelper>.Error("更新计划状态异常:" + ex.Message, ex);
}
}
/// <summary>
/// 更新计划状态(RT_plan)
/// </summary>
/// <param name="planID">要更新的计划号</param>
/// <param name="planState">新的计划状态</param>
public static void UpdatePlanState1(string planID, int planState)
{
try
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "update RT_plan set Plan_State = @PlanState, Plan_StateText = @Plan_StateText,Start_Date=@Start_Date, IF_FLAG = @IfFlag,Exec_Num=1 where Plan_Id = @PlanID";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@PlanState", planState);
dbHelper.AddParameter("@Plan_StateText", StateToShow(planState));
dbHelper.AddParameter("@Start_Date", String.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now));
dbHelper.AddParameter("@IfFlag", 1);
dbHelper.AddParameter("@PlanID", planID);
dbHelper.ExecuteNonQuery();
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<PlanHelper>.Error("更新计划状态异常:" + ex.Message, ex);
}
}
/// <summary>
/// 更新计划状态(RT_plan)
/// </summary>
/// <param name="planSerial">查询条件:要更新的计划的序号</param>
/// <param name="planDate">查询条件:要更新的计划的日期</param>
/// <param name="planState">新的计划状态</param>
/// <param name="planNum">新的计划数</param>
/// <param name="planComNum">更新完成数量</param>
public static void UpdatePlanInfo(int planSerial, int planState, int planNum, int planComNum)
{
try
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "update RT_plan set Plan_State = @PlanState, Plan_StateText = @Plan_StateText, Plan_Num = @planNum, Real_Num = @planComNum, IF_FLAG = @IfFlag where Plan_Serial = @planSerial";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@PlanState", planState);
dbHelper.AddParameter("@Plan_StateText", StateToShow(planState));
dbHelper.AddParameter("@planNum", planNum);
dbHelper.AddParameter("@planComNum", planComNum);
dbHelper.AddParameter("@IfFlag", 1);
dbHelper.AddParameter("@planSerial", planSerial);
dbHelper.ExecuteNonQuery();
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<PlanHelper>.Error("更新计划状态异常:" + ex.Message, ex);
}
}
/// <summary>
/// 更新计划状态(RT_plan)
/// </summary>
/// <param name="planSerial">查询条件:要更新的计划的序号</param>
/// <param name="planDate">查询条件:要更新的计划的日期</param>
/// <param name="planState">新的计划状态</param>
/// <param name="planNum">新的计划数</param>
/// <param name="planComNum">更新完成数量</param>
public static void UpdatePlanInfo(int planSerial, int planState, int planNum, int planComNum, string endDateTime)
{
try
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "update RT_plan set Plan_State = @PlanState, Plan_StateText = @Plan_StateText, Plan_Num = @planNum, Real_Num = @planComNum,End_Date = @endDateTime, IF_FLAG = @IfFlag where Plan_Serial = @planSerial";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@PlanState", planState);
dbHelper.AddParameter("@Plan_StateText", StateToShow(planState));
dbHelper.AddParameter("@planNum", planNum);
dbHelper.AddParameter("@planComNum", planComNum);
dbHelper.AddParameter("@endDateTime", endDateTime);
dbHelper.AddParameter("@IfFlag", 1);
dbHelper.AddParameter("@planSerial", planSerial);
dbHelper.ExecuteNonQuery();
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<PlanHelper>.Error("更新计划状态异常:" + ex.Message, ex);
}
}
#endregion
#region 更新计划状态(LR_Plan)
/// <summary>
/// 更新计划状态(LR_Plan)
/// </summary>
/// <param name="planID">要更新的计划号</param>
/// <param name="planState">新的计划状态</param>
public static void LRUpdatePlanState(string planID, int planState)
{
try
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "update LR_plan set Plan_State = @PlanState where Plan_Id = @PlanID";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@PlanState", planState);
dbHelper.AddParameter("@PlanID", planID);
dbHelper.ExecuteNonQuery();
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<PlanHelper>.Error("更新计划状态异常:" + ex.Message, ex);
}
}
/// <summary>
/// 更新计划状态(LR_Plan)
/// </summary>
/// <param name="planSerial">查询条件:要更新的计划的序号</param>
/// <param name="planDate">查询条件:要更新的计划的日期</param>
/// <param name="planState">新的计划状态</param>
/// <param name="planNum">新的计划数</param>
/// <param name="planComNum">更新完成数量</param>
public static void LRUpdatePlanInfo(string planID, int planState, int planNum, int planComNum)
{
try
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "update LR_plan set Plan_State = @PlanState, Plan_Num = @planNum, Real_Num = @planComNum where Plan_Id = @Plan_Id";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@PlanState", planState);
dbHelper.AddParameter("@planNum", planNum);
dbHelper.AddParameter("@planComNum", planComNum);
dbHelper.AddParameter("@Plan_Id", planID);
dbHelper.ExecuteNonQuery();
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<PlanHelper>.Error("更新计划状态异常:" + ex.Message, ex);
}
}
/// <summary>
/// 更新计划状态(LR_Plan)
/// </summary>
/// <param name="planSerial">查询条件:要更新的计划的序号</param>
/// <param name="planDate">查询条件:要更新的计划的日期</param>
/// <param name="planState">新的计划状态</param>
/// <param name="planNum">新的计划数</param>
/// <param name="planComNum">更新完成数量</param>
public static void LRUpdatePlanInfo(string planID, int planState, int planNum, int planComNum, string endDateTime)
{
try
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "update LR_plan set Plan_State = @PlanState, Plan_Num = @planNum, Real_Num = @planComNum,End_Date = @endDateTime where Plan_Id = @Plan_Id";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@PlanState", planState);
dbHelper.AddParameter("@planNum", planNum);
dbHelper.AddParameter("@planComNum", planComNum);
dbHelper.AddParameter("@endDateTime", endDateTime);
dbHelper.AddParameter("@Plan_Id", planID);
dbHelper.ExecuteNonQuery();
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<PlanHelper>.Error("更新计划状态异常:" + ex.Message, ex);
}
}
#endregion
#region 更新计划状态和计划终止时间
/// <summary>
/// 更新计划状态和计划执行时间
/// </summary>
/// <param name="dbType">数据库类型,网络库、本地库</param>
/// <param name="planID">计划号</param>
/// <param name="planState">计划状态</param>
/// <param name="realStartTime">实际计划开始时间</param>
public static void UpdatedPlanStateAndRealEndTime(string planID, int planState, DateTime realEndTime)
{
try
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "update RT_plan set PlanState = @PlanState, IsUpFlag=0 where PlanID = @PlanID"; //如果单机运行则把计划上传标志IsUpFlag设置为0
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@PlanState", planState);
dbHelper.AddParameter("@PlanID", planID);
dbHelper.ExecuteNonQuery();
}
catch(Exception ex)
{
ICSharpCode.Core.LoggingService<PlanHelper>.Error("更新计划状态和计划终止时间异常:" + ex.Message, ex);
}
}
#endregion
#region 更新计划状态、密炼完成数、计划结束时间
/// <summary>
/// 更新计划状态、密炼完成数、计划结束时间
/// </summary>
/// <param name="planID">计划编号</param>
/// <param name="planState">计划状态</param>
/// <param name="realNum">密炼完成数</param>
/// <param name="realEndTime">计划结束时间</param>
public static void UpdatePlanStateRealNumRealEndTime(string planID, int planState, int realNum, DateTime realEndTime)
{
try
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "update RT_plan set PlanState = @PlanState, RealNum = @RealNum, IsUpFlag=0 where PlanID = @PlanID"; //如果单机运行则把计划上传标志IsUpFlag设置为0
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@PlanState", planState);
dbHelper.AddParameter("@RealNum", realNum);
dbHelper.AddParameter("@PlanID", planID);
dbHelper.ExecuteNonQuery();
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<PlanHelper>.Error("更新计划状态、密炼完成数、计划终止时间异常:" + ex.Message, ex);
}
}
#endregion
#region 更新计划开炼状态、开炼完成数、计划结束时间
/// <summary>
/// 更新计划开炼状态、密炼完成数、计划结束时间
/// </summary>
/// <param name="planID">计划编号</param>
/// <param name="millPlanState">计划开炼状态</param>
/// <param name="millRealNum">开炼完成数</param>
/// <param name="realEndTime">计划结束时间</param>
public static void UpdateMillPlanStateMillRealNumRealEndTime(string planID, int millPlanState, int millRealNum, DateTime realEndTime)
{
try
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "update RT_plan set MillPlanState = @MillPlanState, MillRealNum = @MillRealNum, IsUpFlag=0 where PlanID = @PlanID"; //如果单机运行则把计划上传标志IsUpFlag设置为0
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@MillPlanState", millPlanState);
dbHelper.AddParameter("@MillRealNum", millRealNum);
dbHelper.AddParameter("@PlanID", planID);
dbHelper.ExecuteNonQuery();
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<PlanHelper>.Error("更新计划开炼状态、开炼完成数、计划终止时间异常:" + ex.Message, ex);
}
}
#endregion
#region 更新计划表中的单车总重
/// <summary>
/// 更新计划表中的单车总重
/// </summary>
/// <param name="planID">计划ID</param>
/// <param name="totalWeight">设定总重</param>
public static void UpdateTotalWeight(string planID, double totalWeight)
{
try
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
string strSql = @"update RT_plan set TotalWeight = @TotalWeight, IsUpFlag = 0 where PlanID = @PlanID";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@TotalWeight", totalWeight);
dbHelper.AddParameter("@PlanID", planID);
dbHelper.ExecuteNonQuery();
}
catch(Exception ex)
{
ICSharpCode.Core.LoggingService<PlanHelper>.Error("更新计划表中的单车总重异常:" + ex.Message, ex);
}
}
#endregion
#region 按计划号删除计划
/// <summary>
/// 按计划号删除计划
/// </summary>
/// <param name="planId">要删除计划对应的计划号</param>
/// <returns>成功返回true失败返回false</returns>
public static void DeletePlan(string planId)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.CommandType = CommandType.Text;
dbHelper.ClearParameter();
string strSql = "DELETE FROM RT_plan WHERE Plan_Id = @PlanID";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@PlanID", planId);
dbHelper.ExecuteNonQuery();
}
#endregion
#region 停止掺用计划
/// <summary>
/// 停止掺用计划
/// </summary>
/// <returns></returns>
public static bool StopChanYongPlan()
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "update PmtExecPlan set PlanFlag = '2'";
dbHelper.CommandText = strSql;
dbHelper.ExecuteNonQuery();
return true;
}
#endregion
#region 下传计划列表至PLC(带班次)
/// <summary>
/// 下传计划列表至PLC未生成的前10条计划
/// </summary>
/// <param name="planDatestr">传入的计划日期</param>
/// <param name="shiftID">传入的班次ID</param>
/// <param name="msg">输出错误信息</param>
/// <returns>成功返回true失败返回false</returns>
public static bool DownloadPlanInfo(string planDatestr, int shiftID, out string msg)
{
#region 检查日期班次是否设置正确,不正确则给出提示
//DateTime plandate = DateTime.Now;
//int shiftitem = 0;
//if (!ProductHelper.PlanDateVerify(out plandate, out shiftitem, planDatestr, shiftID, out msg))
//{
// ICSharpCode.Core.LoggingService<RefreshAction>.Debug(String.Format("刷新计划-下传计划列表PLC操作取消因为界面选择的日期、班次不是当班班次:选择计划日期:{0},选择班次:{1},当班日期:{2:yyyy-MM-dd},当班班次:{3}", planDatestr, shiftID, plandate, shiftitem));
// return false;
//}
#endregion
List<string> msgList = new List<string>();
bool result = ChemicalWeighingPlc.PlcPlanHelper.DownloadPlanData(msgList);
if (!result)
{
msg = Mesnac.Basic.DataProcessor.CombineMsgList(msgList);
ICSharpCode.Core.LoggingService<RefreshAction>.Error("计划列表下传失败:" + msg);
}
else
{
msg = "计划列表下传成功";
}
return result;
}
#endregion
#region 计划辅助方法
/// <summary>
/// 把DataRow数据行转换为计划实体对象
/// </summary>
/// <param name="dr">要转换的数据行</param>
/// <returns>返回转换后的计划实体对象</returns>
public static RT_plan ConvertDataRowToPptPlan(DataRow dr)
{
if (dr != null)
{
RT_plan plan = new RT_plan();
plan.Dosing_Id = Mesnac.Basic.DataProcessor.RowValue(dr, "Dosing_Id", 0);
plan.Plan_Id = Mesnac.Basic.DataProcessor.RowValue(dr, "Plan_Id", String.Empty);
plan.Equip_Code = Mesnac.Basic.DataProcessor.RowValue(dr, "Equip_Code", String.Empty);
plan.Plan_Serial = Mesnac.Basic.DataProcessor.RowValue(dr, "Plan_Serial", 0);
plan.Recipe_ID = Mesnac.Basic.DataProcessor.RowValue(dr, "Recipe_ID", String.Empty);
plan.Recipe_Code = Mesnac.Basic.DataProcessor.RowValue(dr, "Recipe_Code", String.Empty);
plan.Recipe_Name = Mesnac.Basic.DataProcessor.RowValue(dr, "Recipe_Name", String.Empty);
plan.Version = Mesnac.Basic.DataProcessor.RowValue(dr, "Version", String.Empty);
plan.Mixer_Line = Mesnac.Basic.DataProcessor.RowValue(dr, "Mixer_Line", String.Empty);
plan.Recipe_Type = Mesnac.Basic.DataProcessor.RowValue(dr, "Recipe_Type", 0);
plan.Shift_Id = Mesnac.Basic.DataProcessor.RowValue(dr, "Shift_Id", String.Empty);
plan.Shift_Class = Mesnac.Basic.DataProcessor.RowValue(dr, "Shift_Class", String.Empty);
plan.Plan_Num = Mesnac.Basic.DataProcessor.RowValue(dr, "Plan_Num", 0);
plan.Real_Num = Mesnac.Basic.DataProcessor.RowValue(dr, "Real_Num", 0);
plan.Duration_Time = Mesnac.Basic.DataProcessor.RowValue(dr, "Plan_Id", 0);
plan.Start_Date = Mesnac.Basic.DataProcessor.RowValue(dr, "Start_Date", String.Empty);
plan.End_Date = Mesnac.Basic.DataProcessor.RowValue(dr, "End_Date", String.Empty);
plan.Weight_Man = Mesnac.Basic.DataProcessor.RowValue(dr, "Weight_Man", String.Empty);
plan.Stock_Man = Mesnac.Basic.DataProcessor.RowValue(dr, "Stock_Man", String.Empty);
plan.Plan_Batch = Mesnac.Basic.DataProcessor.RowValue(dr, "Plan_Batch", String.Empty);
plan.Plan_State = Mesnac.Basic.DataProcessor.RowValue(dr, "Plan_State", 0);
plan.Plan_StateText = Mesnac.Basic.DataProcessor.RowValue(dr, "Plan_StateText", String.Empty);
plan.Plan_Date = Mesnac.Basic.DataProcessor.RowValue(dr, "Plan_Date", String.Empty);
plan.IF_FLAG = Mesnac.Basic.DataProcessor.RowValue(dr, "IF_FLAG", 0);
return plan;
}
else
{
return null;
}
}
/// <summary>
/// 把DataRow数据行转换为Pmt_weigh实体对象
/// </summary>
/// <param name="dr">要转换的数据行</param>
/// <returns>返回转换后的计划实体对象</returns>
public static Pmt_weigh ConvertDataRowToPmtweigh(DataRow dr)
{
if (dr != null)
{
Pmt_weigh plan = new Pmt_weigh();
plan.ID = Mesnac.Basic.DataProcessor.RowValue(dr, "ID", String.Empty);
plan.Equip_Code = Mesnac.Basic.DataProcessor.RowValue(dr, "Equip_Code", String.Empty);
plan.Recipe_ID = Mesnac.Basic.DataProcessor.RowValue(dr, "Recipe_ID", String.Empty);
plan.Weight_Id = Mesnac.Basic.DataProcessor.RowValue(dr, "Weight_Id", 0);
plan.Material_ID = Mesnac.Basic.DataProcessor.RowValue(dr, "Material_ID", String.Empty);
plan.Set_Weight = Convert.ToDecimal(Mesnac.Basic.DataProcessor.RowValue(dr, "Set_Weight", String.Empty));
plan.Set_Error = Convert.ToDecimal(Mesnac.Basic.DataProcessor.RowValue(dr, "Set_Error", String.Empty));
plan.Cpk_Error = Convert.ToDecimal(Mesnac.Basic.DataProcessor.RowValue(dr, "Cpk_Error", String.Empty));
plan.IsRate =Convert.ToBoolean(Mesnac.Basic.DataProcessor.RowValue(dr, "IsRate", String.Empty));
plan.TheoryRate = Convert.ToDecimal(Mesnac.Basic.DataProcessor.RowValue(dr, "TheoryRate", String.Empty));
return plan;
}
else
{
return null;
}
}
/// <summary>
/// 把DataRow数据行转换为Pmt_weigh实体对象
/// </summary>
/// <param name="dr">要转换的数据行</param>
/// <returns>返回转换后的计划实体对象</returns>
public static xl_weigh ConvertDataRowToXlweigh(DataRow dr)
{
if (dr != null)
{
xl_weigh plan = new xl_weigh();
plan.ID = Mesnac.Basic.DataProcessor.RowValue(dr, "ID", 0);
plan.Equip_Code = Mesnac.Basic.DataProcessor.RowValue(dr, "Equip_Code", String.Empty);
plan.Recipe_ID = Mesnac.Basic.DataProcessor.RowValue(dr, "Recipe_ID", String.Empty);
plan.Weight_Id = Mesnac.Basic.DataProcessor.RowValue(dr, "Weight_Id", 0);
plan.Material_ID = Mesnac.Basic.DataProcessor.RowValue(dr, "Material_ID", String.Empty);
plan.Set_Weight =Convert.ToDecimal(Mesnac.Basic.DataProcessor.RowValue(dr, "Set_Weight", String.Empty));
plan.Set_Error = Convert.ToDecimal(Mesnac.Basic.DataProcessor.RowValue(dr, "Set_Error", String.Empty));
plan.Cpk_Error = Convert.ToDecimal(Mesnac.Basic.DataProcessor.RowValue(dr, "Cpk_Error", String.Empty));
return plan;
}
else
{
return null;
}
}
/// <summary>
/// 把DataRow数据行转换为Pmt_Bin实体对象
/// </summary>
/// <param name="dr">要转换的数据行</param>
/// <returns>返回转换后的计划实体对象</returns>
public static Pmt_Bin ConvertDataRowToPmtBin(DataRow dr)
{
if (dr != null)
{
Pmt_Bin pmtBin = new Pmt_Bin();
pmtBin.Equip_Code = Mesnac.Basic.DataProcessor.RowValue(dr, "Equip_Code", String.Empty);
pmtBin.Bin_Serial = Mesnac.Basic.DataProcessor.RowValue(dr, "Bin_Serial", 0);
pmtBin.Dosing_ID = Mesnac.Basic.DataProcessor.RowValue(dr, "Dosing_ID", 0);
pmtBin.Material_ID = Mesnac.Basic.DataProcessor.RowValue(dr, "Material_ID", String.Empty);
pmtBin.Bin_Capacity = Mesnac.Basic.DataProcessor.RowValue(dr, "Bin_Capacity", 0);
pmtBin.Bin_Baseline = Mesnac.Basic.DataProcessor.RowValue(dr, "Bin_Baseline", 0);
pmtBin.Bin_Residua = Mesnac.Basic.DataProcessor.RowValue(dr, "Bin_Residua", 0);
pmtBin.Bin_UseFlag = Mesnac.Basic.DataProcessor.RowValue(dr, "Bin_UseFlag", 0);
pmtBin.IF_FLAG = Mesnac.Basic.DataProcessor.RowValue(dr, "IF_FLAG", 0);
return pmtBin;
}
else
{
return null;
}
}
/// <summary>
/// 把DataRow数据行转换为Pmt_material实体对象
/// </summary>
/// <param name="dr">要转换的数据行</param>
/// <returns>返回转换后的计划实体对象</returns>
public static Pmt_material ConvertDataRowToPmtMaterial(DataRow dr)
{
if (dr != null)
{
Pmt_material pmtMaterial = new Pmt_material();
pmtMaterial.ID = Mesnac.Basic.DataProcessor.RowValue(dr, "ID", String.Empty);
pmtMaterial.Material_code = Mesnac.Basic.DataProcessor.RowValue(dr, "Material_code", String.Empty);
pmtMaterial.Material_name = Mesnac.Basic.DataProcessor.RowValue(dr, "Material_name", String.Empty);
pmtMaterial.Remark = Mesnac.Basic.DataProcessor.RowValue(dr, "Remark", String.Empty);
pmtMaterial.Batch_number = Mesnac.Basic.DataProcessor.RowValue(dr, "Batch_number", String.Empty);
pmtMaterial.Barcode1 = Mesnac.Basic.DataProcessor.RowValue(dr, "Barcode1", String.Empty);
pmtMaterial.Barcode2 = Mesnac.Basic.DataProcessor.RowValue(dr, "Barcode2", String.Empty);
pmtMaterial.Barcode3 = Mesnac.Basic.DataProcessor.RowValue(dr, "Barcode3", String.Empty);
pmtMaterial.IsEnable = Mesnac.Basic.DataProcessor.RowValue(dr, "IsEnable", String.Empty);
return pmtMaterial;
}
else
{
return null;
}
}
#endregion
#region 更新计划日志数据至SysKeyValue数据库
/// <summary>
/// 更新计划日志数据至SysKeyValue数据库
/// </summary>
public static void UpdatePlanLogToDb()
{
try
{
if (_planLog != null)
{
BaseDataHelper.UpdateSysValue("PlanLog.CurrentPlanDate", String.Format("{0:yyyy-MM-dd}", _planLog.LastDate));
BaseDataHelper.UpdateSysValue("PlanLog.CurrentPlanID", _planLog.LastPlanID);
BaseDataHelper.UpdateSysValue("PlanLog.CurrentShiftID", _planLog.LastShiftID.ToString());
BaseDataHelper.UpdateSysValue("PlanLog.CurrentShiftName", _planLog.LastShiftName);
BaseDataHelper.UpdateSysValue("PlanLog.CurrentClassID", _planLog.LastClassID.ToString());
BaseDataHelper.UpdateSysValue("PlanLog.CurrentClassName", _planLog.LastClassName);
}
else
{
BaseDataHelper.UpdateSysValue("PlanLog.CurrentPlanDate", String.Format("{0:yyyy-MM-dd}", DateTime.Now));
BaseDataHelper.UpdateSysValue("PlanLog.CurrentPlanID", String.Empty);
BaseDataHelper.UpdateSysValue("PlanLog.CurrentShiftID", String.Empty);
BaseDataHelper.UpdateSysValue("PlanLog.CurrentShiftName", String.Empty);
BaseDataHelper.UpdateSysValue("PlanLog.CurrentClassID", String.Empty);
BaseDataHelper.UpdateSysValue("PlanLog.CurrentClassName", String.Empty);
}
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<PlanHelper>.Error("保存计划日志到SysKeyValue表中失败" + ex.Message, ex);
}
}
#endregion
#endregion
#region 将计划运行状态转换为文字进行显示
/// <summary>
/// 将计划运行状态转换为文字进行显示
/// </summary>
/// <param name="stateNum">计划状态代码</param>
/// <returns>显示的文字信息</returns>
public static string StateToShow(int stateNum)
{
string reStr = null;
if (stateNum == 3)
{
reStr = "正在运行";
}
else if (stateNum == 4)
{
reStr = "已下传";
}
else if (stateNum == 5)
{
reStr = "未启动";
}
else if (stateNum == 7)
{
reStr = "已终止";
}
else if (stateNum == 8)
{
reStr = "已完成";
}
return reStr;
}
#endregion
#region 将计划运行状态文字转换为代码
/// <summary>
/// 将计划运行状态文字转换为代码
/// </summary>
/// <param name="stateInfo">计划状态代码</param>
/// <returns>显示的文字信息</returns>
public static Int32 StateToValue(string stateInfo)
{
Int32 reStateNum = 0;
if (stateInfo == "正在运行")
{
reStateNum = 3;
}
else if (stateInfo == "已下传")
{
reStateNum = 4;
}
else if (stateInfo == "未启动")
{
reStateNum = 5;
}
else if (stateInfo == "已终止")
{
reStateNum = 7;
}
else if (stateInfo == "已完成")
{
reStateNum = 8;
}
return reStateNum;
}
#endregion
#region 根据计划号获取下发计划任务
/// <summary>
/// 根据计划号获取下发计划任务
/// </summary>
/// <param name="planId"></param>
/// <param name="recipeId"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public static List<MetagePlan> GetPlan(string planId)
{
//IFreeSql _fsql = DBHelper.FreeHelper.Instance;
//string strSql = @"select w.Weight_Id MID,p.Plan_Id,p.Plan_Num,p.Real_Num,p.Plan_Serial,p.Plan_State,p.Plan_Date,p.Plan_StateText,r.ID as RecipeID,r.Recipe_Serial,r.Recipe_Name,r.Version,r.Recipe_Verify,r.Total_Weight,r.Total_Error,
// m.ID as MaterialID,m.Material_name,w.Set_Weight,w.Set_Error,w.IsRate,w.TheoryRate
// from RT_plan p left join Pmt_recipe r on p.Recipe_ID=r.ID left join Pmt_weigh w on r.ID=w.Recipe_ID
//left join Pmt_material m on w.Material_ID=m.ID
//where p.Plan_State=5 and p.Plan_Id=@Plan_Id ORDER BY w.Weight_Id";
//var list = _fsql.Select<MetagePlan>(strSql).ToList();
//return list;
List<MetagePlan> lst = new List<MetagePlan>();
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.CommandType = CommandType.Text;
string strSql = @"select w.Weight_Id MID,p.Plan_Id,p.Plan_Num,p.Real_Num,p.Plan_Serial,p.Plan_State,p.Plan_Date,p.Plan_StateText,r.ID as RecipeID,r.Recipe_Serial,r.Recipe_Name,r.Version,r.Recipe_Verify,r.Total_Weight,r.Total_Error,
m.ID as MaterialID,m.Material_name,w.Set_Weight,w.Set_Error,w.IsRate,w.TheoryRate
from RT_plan p left join Pmt_recipe r on p.Recipe_ID=r.ID left join Pmt_weigh w on r.ID=w.Recipe_ID
left join Pmt_material m on w.Material_ID=m.ID
where p.Plan_State=5 and p.Plan_Id=@Plan_Id ORDER BY w.Weight_Id";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
dbHelper.AddParameter("@Plan_Id", planId);
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
MetagePlan entity = null;
foreach (DataRow dr in table.Rows)
{
entity = ConvertDataRowToPlan(dr);
lst.Add(entity);
}
}
return lst;
}
#endregion
#region 根据计划号获取下发计划任务——地磅
/// <summary>
/// 根据计划号获取下发计划任务
/// </summary>
/// <param name="planId"></param>
/// <param name="recipeId"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public static List<MetagePlan> GetPlan()
{
List<MetagePlan> lst = new List<MetagePlan>();
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.CommandType = CommandType.Text;
string strSql = @"select w.Weight_Id MID, p.Dosing_Id,p.Plan_Id,p.Plan_Serial,p.Recipe_ID,p.Recipe_Name,p.Version,p.Plan_Num,p.Real_Num,p.Shift_Id,p.Shift_Class,p.Plan_State,p.Plan_StateText,p.Plan_TotalWeight,p.Plan_TotalError,
r.Total_Weight,r.Total_Error,m.ID as MaterialID,m.Material_name,b.Bin_Serial as Station,b.Bin_Name as StationName,w.Set_Weight,w.Set_Error,p.IsRetransmission,p.Retransmission_Num
from (select * from RT_plan where Start_Date=(select MAX(Start_Date) from RT_plan)) p left join Pmt_recipe r on p.Recipe_ID=r.ID left join Pmt_weigh w on r.ID=w.Recipe_ID left join Pmt_material m on w.Material_ID=m.ID left join Pmt_Bin b on m.ID=b.Material_ID
where p.Weighbridge='1号地磅' and p.Plan_State=3 ORDER BY w.Weight_Id";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
MetagePlan entity = null;
foreach (DataRow dr in table.Rows)
{
entity = ConvertDataRowToPlan(dr);
lst.Add(entity);
}
}
return lst;
}
#endregion
#region 根据计划号获取下发计划任务——2号地磅
/// <summary>
/// 根据计划号获取下发计划任务
/// </summary>
/// <param name="planId"></param>
/// <param name="recipeId"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public static List<MetagePlan> GetPlan2()
{
List<MetagePlan> lst = new List<MetagePlan>();
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.CommandType = CommandType.Text;
string strSql = @"select w.Weight_Id MID, p.Dosing_Id,p.Plan_Id,p.Plan_Serial,p.Recipe_ID,p.Recipe_Name,p.Version,p.Plan_Num,p.Real_Num,p.Shift_Id,p.Shift_Class,p.Plan_State,p.Plan_StateText,p.Plan_TotalWeight,p.Plan_TotalError,
r.Total_Weight,r.Total_Error,m.ID as MaterialID,m.Material_name,b.Bin_Serial as Station,b.Bin_Name as StationName,w.Set_Weight,w.Set_Error,p.IsRetransmission,p.Retransmission_Num
from (select * from RT_plan where Start_Date=(select MAX(Start_Date) from RT_plan)) p left join Pmt_recipe r on p.Recipe_ID=r.ID left join Pmt_weigh w on r.ID=w.Recipe_ID left join Pmt_material m on w.Material_ID=m.ID left join Pmt_Bin b on m.ID=b.Material_ID
where p.Weighbridge='2号地磅' ORDER BY w.Weight_Id";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
MetagePlan entity = null;
foreach (DataRow dr in table.Rows)
{
entity = ConvertDataRowToPlan(dr);
lst.Add(entity);
}
}
return lst;
}
#endregion
#region 根据计划号 查看计划是否完成
/// <summary>
/// 根据计划号 查看计划是否完成
/// </summary>
/// <param name="planId">计划号</param>
/// <param name="realNum">处理次数</param>
/// <returns>true:已完成;false:还未完成</returns>
/// <exception cref="Exception"></exception>
public static bool GetRtPlanState(string plan_Id)
{
List<xl_plan> lst = new List<xl_plan>();
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.CommandType = CommandType.Text;
string strSql = @"select top 1 * from RT_plan where Plan_State=3 and Plan_Id=@Plan_Id";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
dbHelper.AddParameter("@Plan_Id", plan_Id);
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
return false;
}
return true;
}
#endregion
#region 获取当前正在执行的计划任务
/// <summary>
/// 根据计划号获取当前正在执行的计划任务
/// </summary>
/// <param name="planId"></param>
/// <param name="recipeId"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public static List<MetagePlan> GetExecPlan()
{
List<MetagePlan> lst = new List<MetagePlan>();
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.CommandType = CommandType.Text;
string strSql = @"select w.Weight_Id MID,p.Plan_Id,p.Plan_Num,p.Real_Num,p.Plan_Serial,p.Plan_State,p.Plan_Date,p.Plan_StateText,r.ID as RecipeID,r.Recipe_Serial,r.Recipe_Name,r.Version,r.Recipe_Verify,r.Total_Weight,r.Total_Error,
m.ID as MaterialID,m.Material_name,w.Set_Weight,w.Set_Error
from RT_plan p left join Pmt_recipe r on p.Recipe_ID=r.ID left join Pmt_weigh w on r.ID=w.Recipe_ID
left join Pmt_material m on w.Material_ID=m.ID
where p.Plan_State=3 ORDER BY w.Weight_Id";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
MetagePlan entity = null;
foreach (DataRow dr in table.Rows)
{
entity = ConvertDataRowToPlan(dr);
lst.Add(entity);
}
}
return lst;
}
public static DataTable GetProPlan()
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.CommandType = CommandType.Text;
string strSql = @"select w.Weight_Id MID,p.Plan_Id,p.Plan_Num,p.Real_Num,p.Plan_Serial,p.Plan_State,p.Plan_Date,p.Plan_StateText,r.ID as RecipeID,r.Recipe_Serial,r.Recipe_Name,r.Version,r.Recipe_Verify,r.Total_Weight,r.Total_Error,
m.ID as MaterialID,m.Material_name,w.Set_Weight,w.Set_Error,p.Exec_Num
from (select * from RT_plan where Start_Date=(select Max(Start_Date) from RT_plan)) p left join Pmt_recipe r on p.Recipe_ID=r.ID left join Pmt_weigh w on r.ID=w.Recipe_ID
left join Pmt_material m on w.Material_ID=m.ID where p.Weighbridge='1号地磅'
ORDER BY w.Weight_Id";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
return table;
}
return null;
}
/// <summary>
/// 2号地磅
/// </summary>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public static DataTable GetProWeighbridge2Plan()
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.CommandType = CommandType.Text;
string strSql = @"select w.Weight_Id MID,p.Plan_Id,p.Plan_Num,p.Real_Num,p.Plan_Serial,p.Plan_State,p.Plan_Date,p.Plan_StateText,r.ID as RecipeID,r.Recipe_Serial,r.Recipe_Name,r.Version,r.Recipe_Verify,r.Total_Weight,r.Total_Error,
m.ID as MaterialID,m.Material_name,w.Set_Weight,w.Set_Error,p.Exec_Num
from (select * from RT_plan where Start_Date=(select Max(Start_Date) from RT_plan)) p left join Pmt_recipe r on p.Recipe_ID=r.ID left join Pmt_weigh w on r.ID=w.Recipe_ID
left join Pmt_material m on w.Material_ID=m.ID where p.Weighbridge='2号地磅'
ORDER BY w.Weight_Id";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
return table;
}
return null;
}
public static List<MetagePlan> DataTableToList(DataTable table)
{
List<MetagePlan> list=new List<MetagePlan>();
MetagePlan entity = null;
foreach (DataRow dr in table.Rows)
{
entity = ConvertDataRowToPlan(dr);
list.Add(entity);
}
return list;
}
#endregion
#region 获取当前正在执行的计划任务
/// <summary>
/// 根据计划号获取当前正在执行的计划任务
/// </summary>
/// <param name="planId"></param>
/// <param name="recipeId"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public static DataTable GetDataTablePlan()
{
List<MetagePlan> lst = new List<MetagePlan>();
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.CommandType = CommandType.Text;
string strSql = @"select p.Plan_Id,p.Plan_Num,p.Real_Num,p.Plan_Serial,p.Plan_State,p.Plan_Date,p.Plan_StateText,r.ID as RecipeID,r.Recipe_Serial,r.Recipe_Name,r.Version,r.Recipe_Verify,r.Total_Weight,r.Total_Error,
ROW_NUMBER() OVER(ORDER BY Plan_Serial ) as MID, m.ID as MaterialID,m.Material_name,w.Set_Weight,w.Set_Error
from RT_plan p left join Pmt_recipe r on p.Recipe_ID=r.ID left join Pmt_weigh w on r.ID=w.Recipe_ID
left join Pmt_material m on w.Material_ID=m.ID
where p.Plan_State=3 ORDER BY Plan_Serial";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
return table;
}
return null;
}
#endregion
#region 获取当前正在执行的计划任务
/// <summary>
/// 根据计划号获取当前正在执行的计划任务
/// </summary>
/// <param name="planId"></param>
/// <param name="recipeId"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public static List<MetagePlan> GetExecPlan(string planId)
{
List<MetagePlan> lst = new List<MetagePlan>();
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.CommandType = CommandType.Text;
string strSql = @"select w.Weight_Id MID,p.Plan_Id,p.Plan_Num,p.Real_Num,p.Plan_Serial,p.Plan_State,p.Plan_Date,p.Plan_StateText,r.ID as RecipeID,r.Recipe_Serial,r.Recipe_Name,r.Version,r.Recipe_Verify,r.Total_Weight,r.Total_Error,
m.ID as MaterialID,m.Material_name,w.Set_Weight,w.Set_Error
from RT_plan p left join Pmt_recipe r on p.Recipe_ID=r.ID left join Pmt_weigh w on r.ID=w.Recipe_ID
left join Pmt_material m on w.Material_ID=m.ID
where p.Plan_State=3 and Plan_Id=@Plan_Id ORDER BY w.Weight_Id";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
dbHelper.AddParameter("@Plan_Id", planId);
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
MetagePlan entity = null;
foreach (DataRow dr in table.Rows)
{
entity = ConvertDataRowToPlan(dr);
lst.Add(entity);
}
}
return lst;
}
#endregion
#region 更新计划完成数
/// <summary>
/// 更新计划完成数UpdateRealNum
/// </summary>
/// <param name="planID">计划编号</param>
/// <param name="realNum">完成数</param>
public static void UpdatePlan(string planID, int realNum,int state,decimal totalWeight, decimal totalError)
{
try
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "UPDATE RT_plan SET Real_Num = @RealNum,Plan_State=@Plan_State,Plan_StateText=@Plan_StateText,End_Date=@End_Date,Plan_TotalWeight=@Plan_TotalWeight,Plan_TotalError=@Plan_TotalError,Exec_Num=@Exec_Num WHERE Plan_Id = @PlanID";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@RealNum", realNum);
dbHelper.AddParameter("@PlanID", planID);
dbHelper.AddParameter("@Plan_State", state);
dbHelper.AddParameter("@Plan_StateText", StateToShow(state));
dbHelper.AddParameter("@End_Date", String.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now));
dbHelper.AddParameter("@Plan_TotalWeight", totalWeight);
dbHelper.AddParameter("@Plan_TotalError", totalError);
dbHelper.AddParameter("@Exec_Num", 0);
dbHelper.ExecuteNonQuery();
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<PlanHelper>.Error("更新计划完成数异常:" + ex.Message, ex);
}
}
#endregion
#region 保存计划执行记录
/// <summary>
/// 保存计划执行记录
/// </summary>
/// <param name="record"></param>
public static void SavePlanRecord(Pmt_WeighRecord record)
{
try
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
//添加计划的SQL语句
string strSql3 = @"INSERT INTO Pmt_WeighRecord(Plan_Id,Plan_Num,Real_Num,Plan_Serial,Version,Recipe_Serial,RecipeID,Recipe_Name,Total_Weight,Total_Error,MaterialID,Material_name,Set_Weight,Set_Error,RActTol,RMatCode,RActWeight,CreateDateTime)
VALUES(Plan_Id=@Plan_Id,Plan_Num=@Plan_Num,Real_Num=@Real_Num,Plan_Serial=@Plan_Serial,Version=@Version,Recipe_Serial=@Recipe_Serial,RecipeID=@RecipeID,Recipe_Name=@Recipe_Name,Total_Weight=@Total_Weight,Total_Error=@Total_Error,MaterialID=@MaterialID,Material_name=@Material_name,Set_Weight=@Set_Weight,Set_Error=@Set_Error,RActTol=@RActTol,RMatCode=@RMatCode,RActWeight=@RActWeight,CreateDateTime=@CreateDateTime)";
dbHelper.CommandText = strSql3;
dbHelper.AddParameter("@Plan_Id", record.Plan_Id);
dbHelper.AddParameter("@Plan_Num", record.Plan_Num);
dbHelper.AddParameter("@Real_Num", record.Real_Num);
dbHelper.AddParameter("@Plan_Serial", record.Plan_Serial);
dbHelper.AddParameter("@Version", record.Version);
dbHelper.AddParameter("@Recipe_Serial", record.Recipe_Serial);
dbHelper.AddParameter("@RecipeID", record.RecipeID);
dbHelper.AddParameter("@Recipe_Name", record.Recipe_Name);
dbHelper.AddParameter("@Total_Weight", record.Total_Weight);
dbHelper.AddParameter("@Total_Error", record.Total_Error);
dbHelper.AddParameter("@MaterialID", record.MaterialID);
dbHelper.AddParameter("@Material_name", record.Material_name);
dbHelper.AddParameter("@Set_Weight", record.Set_Weight);
dbHelper.AddParameter("@Set_Error", record.Set_Error);
dbHelper.AddParameter("@RActTol", record.RActTol);
dbHelper.AddParameter("@RMatCode", record.RMatCode);
dbHelper.AddParameter("@RActWeight", record.RActWeight);
dbHelper.AddParameter("@CreateDateTime", DateTime.Now);
dbHelper.ExecuteNonQuery();
}
catch (Exception)
{
throw;
}
}
#endregion
#region 把DataRow数据行转换为xl_weigh实体对象
/// <summary>
/// 把DataRow数据行转换为xl_weigh实体对象
/// </summary>
/// <param name="dr">要转换的数据行</param>
/// <returns>返回转换后的计划实体对象</returns>
public static MetagePlan ConvertDataRowToPlan(DataRow dr)
{
if (dr != null)
{
MetagePlan plan = new MetagePlan();
plan.MID = Mesnac.Basic.DataProcessor.RowValue(dr, "MID", 0);
plan.Dosing_Id = Mesnac.Basic.DataProcessor.RowValue(dr, "Dosing_Id", String.Empty);
plan.Plan_Id = Mesnac.Basic.DataProcessor.RowValue(dr, "Plan_Id", String.Empty);
plan.Plan_Serial = Mesnac.Basic.DataProcessor.RowValue(dr, "Plan_Serial", 0);
plan.Recipe_ID = Mesnac.Basic.DataProcessor.RowValue(dr, "Recipe_ID", String.Empty);
plan.Recipe_Name = Mesnac.Basic.DataProcessor.RowValue(dr, "Recipe_Name", String.Empty);
plan.Version = Mesnac.Basic.DataProcessor.RowValue(dr, "Version", 0);
plan.Plan_Num = Mesnac.Basic.DataProcessor.RowValue(dr, "Plan_Num", 0);
plan.Real_Num = Mesnac.Basic.DataProcessor.RowValue(dr, "Real_Num", 0);
plan.Shift_Id = Mesnac.Basic.DataProcessor.RowValue(dr, "Shift_Id", 0);
plan.Shift_Class = Mesnac.Basic.DataProcessor.RowValue(dr, "Shift_Class", String.Empty);
plan.Plan_State = Mesnac.Basic.DataProcessor.RowValue(dr, "Plan_State", 0);
plan.Plan_StateText = Mesnac.Basic.DataProcessor.RowValue(dr, "Plan_StateText", String.Empty);
plan.Plan_TotalWeight = Convert.ToDecimal(Mesnac.Basic.DataProcessor.RowValue(dr, "Plan_TotalWeight", 0.000));
plan.Plan_TotalError = Convert.ToDecimal(Mesnac.Basic.DataProcessor.RowValue(dr, "Plan_TotalError", 0.000));
plan.Total_Weight = Convert.ToDecimal(Mesnac.Basic.DataProcessor.RowValue(dr, "Total_Weight", 0.000));
plan.Total_Error = Convert.ToDecimal(Mesnac.Basic.DataProcessor.RowValue(dr, "Total_Error", 0.000));
plan.MaterialID = Mesnac.Basic.DataProcessor.RowValue(dr, "MaterialID", String.Empty);
plan.Material_name = Mesnac.Basic.DataProcessor.RowValue(dr, "Material_name", String.Empty);
plan.Station = Mesnac.Basic.DataProcessor.RowValue(dr, "Station", 0);
plan.StationName = Mesnac.Basic.DataProcessor.RowValue(dr, "StationName", String.Empty);
plan.Set_Weight = Convert.ToDecimal(Mesnac.Basic.DataProcessor.RowValue(dr, "Set_Weight", 0.000));
plan.Set_Error = Convert.ToDecimal(Mesnac.Basic.DataProcessor.RowValue(dr, "Set_Error", 0.000));
var t= Mesnac.Basic.DataProcessor.RowValue(dr, "IsRate", String.Empty);
plan.IsRate = t== "True" ?1:0;
plan.TheoryRate = Convert.ToDecimal(Mesnac.Basic.DataProcessor.RowValue(dr, "TheoryRate", 0.00));
plan.IsRetransmission = Mesnac.Basic.DataProcessor.RowValue(dr, "IsRetransmission", 0);
plan.Retransmission_Num = Mesnac.Basic.DataProcessor.RowValue(dr, "Retransmission_Num", 0);
plan.Exec_Num = Mesnac.Basic.DataProcessor.RowValue(dr, "Exec_Num", 0);
return plan;
}
else
{
return null;
}
}
#endregion
#region 获取List
/// <summary>
///
/// </summary>
/// <param name="Plan_Id">计划号</param>
/// <param name="Dosing_Id">批次</param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public static DataTable GetLRWeighDataTable(string plan_Id, string real_Num)
{
//List<LR_weigh> lR_Weighs = new List<LR_weigh>();
//DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
//if (dbHelper == null)
//{
// throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
//}
//dbHelper.CommandType = CommandType.Text;
//string strSql = "SELECT * FROM Hw_weigh where Plan_Id=@Plan_Id and Dosing_Id = @Dosing_Id order by ID";
//dbHelper.CommandText = strSql;
//dbHelper.ClearParameter();
//dbHelper.AddParameter("@Plan_Id", plan_Id);
//dbHelper.AddParameter("@Dosing_Id", real_Num);
//DataTable table = dbHelper.ToDataTable();
//if (table != null && table.Rows.Count > 0)
//{
// return table;
//}
IFreeSql fsql = FreeHelper.Instance;
var table= fsql.Select<LR_weigh>().Where(a => a.Plan_ID == plan_Id && a.Dosing_ID== real_Num).ToDataTable("*");
return table;
}
#endregion
#region 获取List
/// <summary>
///
/// </summary>
/// <param name="Plan_Id">计划号</param>
/// <param name="Dosing_Id">批次</param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public static DataTable GetHwWeighDataTable(string plan_Id, string real_Num)
{
//List<LR_weigh> lR_Weighs = new List<LR_weigh>();
//DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
//if (dbHelper == null)
//{
// throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
//}
//dbHelper.CommandType = CommandType.Text;
//string strSql = "SELECT * FROM Hw_weigh where Plan_Id=@Plan_Id and Dosing_Id = @Dosing_Id order by ID";
//dbHelper.CommandText = strSql;
//dbHelper.ClearParameter();
//dbHelper.AddParameter("@Plan_Id", plan_Id);
//dbHelper.AddParameter("@Dosing_Id", real_Num);
//DataTable table = dbHelper.ToDataTable();
//if (table != null && table.Rows.Count > 0)
//{
// return table;
//}
IFreeSql fsql = FreeHelper.Instance;
var table = fsql.Select<Hw_weigh>().Where(a => a.Plan_ID == plan_Id && a.Dosing_ID == real_Num).ToDataTable("*");
return table;
}
#endregion
}
}