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.
lj_plc/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Product/PptPlan/PlanHelper.cs

3056 lines
136 KiB
C#

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.Technical.PmtRecipe.entity;
using Mesnac.Action.ChemicalWeighing.Product.PptPlan.entity;
namespace Mesnac.Action.ChemicalWeighing.Product.PptPlan
{
/// <summary>
/// 计划业务辅助类
/// </summary>
public class PlanHelper
{
#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_State"].Value.ToString());
switch (planState)
{
//case (int)PlanState.Issued: //已下传
// row.DefaultCellStyle.BackColor = System.Drawing.Color.FromArgb(255, 204, 204);
// break;
case (int)PlanState.Waiting: //未启动
row.DefaultCellStyle.BackColor = System.Drawing.Color.FromArgb(255, 255, 204);
break;
case (int)PlanState.Received: //正在运行
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_amount"].Value);
if (realNum < Convert.ToInt32(row.Cells["plan_amount"].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 Base_PlanInfo 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="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 LR_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 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 Entity.RT_Plan GetPlanDataEntity(string planID)
{
DataRow dr = GetPlanData(planID);
if (dr != null)
{
Entity.RT_Plan plan = ConvertDataRowToPptPlan(dr);
return plan;
}
else
{
return null;
}
}
/// <summary>
/// 获取某条生产计划(计划序号、日期)
/// </summary>
/// <param name="planSerial">计划序号</param>
/// <param name="planDate">计划日期</param>
/// <returns>返回对应计划实体对象</returns>
public static Entity.RT_Plan GetPlanDataEntity(int planSerial)
{
DataRow dr = GetPlanData(planSerial);
if (dr != null)
{
Entity.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<Entity.RT_Plan> GetUnExePlanEntityList(int limit)
{
List<Entity.RT_Plan> lst = new List<Entity.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)
{
Entity.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<Entity.RT_Plan> GetPlanEntityListByNum(int limit)
{
List<Entity.RT_Plan> lst = new List<Entity.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)
{
Entity.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<Entity.RT_Plan> GetPlanListAfterPlanSerial(int planSerial)
{
List<Entity.RT_Plan> lst = new List<Entity.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)
{
Entity.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 Entity.RT_Plan GetPlanBySerialDown(int planSerial)
{
Entity.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 Entity.RT_Plan GetPlanBySerialUp(int planSerial)
{
Entity.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<Entity.RT_Plan> lst = new List<Entity.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)
{
Entity.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<Entity.RT_Plan> lst = new List<Entity.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)
{
Entity.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<Entity.RT_Plan> lst = new List<Entity.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)
{
Entity.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)
{
List<Pmt_weigh> lst = new List<Pmt_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)
{
Pmt_weigh entity = null;
foreach (DataRow dr in table.Rows)
{
entity = ConvertDataRowToPmtweigh(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<Base_MaterialInfo> GetAllPmt_material()
{
List<Base_MaterialInfo> materialList = new List<Base_MaterialInfo>();
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 Base_MaterialInfo";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
Base_MaterialInfo entity = null;
foreach (DataRow dr in table.Rows)
{
entity = ConvertDataRowToPmtMaterial(dr);
materialList.Add(entity);
}
}
return materialList;
}
public static List<Base_CratParamInfo> GetAllBaseCratParamInfo()
{
List<Base_CratParamInfo> materialList = new List<Base_CratParamInfo>();
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 Base_CratParamInfo";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
Base_CratParamInfo entity = null;
foreach (DataRow dr in table.Rows)
{
entity = ConvertDataRowToBaseCratParamInfo(dr);
materialList.Add(entity);
}
}
return materialList;
}
#endregion
#region 根据物料id获取Pmt_material
/// <summary>
/// 根据物料id获取Base_MaterialInfo
/// </summary>
/// <param name="recipeId">物料id</param>
/// <returns>返回符合条件Pmt_Bin</returns>
public static Base_MaterialInfo GetPmt_material(string materialID)
{
Base_MaterialInfo 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 Base_Material 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)
{
Base_MaterialInfo 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)
{
Base_MaterialInfo 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 Base_Material where material_Id = @Material_code";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
dbHelper.AddParameter("@Material_code", materialCode);
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
Base_MaterialInfo entity = null;
foreach (DataRow dr in table.Rows)
{
entity = ConvertDataRowToPmtMaterial(dr);
rePmt_material = entity;
break;
}
}
else
{
return null;
}
return rePmt_material.materialId;
}
#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.Terminated;
}
}
#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.Terminated;
}
}
#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 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 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_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 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 row_number() over (order by create_Time) as index_Id ,uid, plan_Id, recipe_Id, recipe_Name, t2.Shift_name as plan_Team, plan_Amount, real_Amount,
case run_Type when '0' then '' else '' end as 'run_Type',
case plan_State when '0' then '' when '1' then '' when '2' then '' when '3' then '' else '' end as 'plan_State',
plan_beginTime, plan_endTime, create_By, create_Time, update_By, update_Time,plan_order from Base_PlanInfo t1 left join Pmt_Shiftime t2 on t1.plan_Team = t2.Shift_id order by plan_order asc";
dbHelper.CommandText = strSql;
DataTable table = dbHelper.ToDataTable();
return table;
}
/// <summary>
/// 获取本机台、日期的计划数据
/// </summary>
/// <param name="planDate">计划生产日期</param>
/// <returns>返回符合条件的计划对象列表</returns>
public static List<Entity.RT_Plan> GetPlanDataEntity(DateTime planDate)
{
List<Entity.RT_Plan> lst = new List<Entity.RT_Plan>();
DataTable dt = GetPlanData(planDate);
Entity.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<Entity.RT_Plan> GetPlanDataEntity(DateTime planDate, int shiftID)
{
List<Entity.RT_Plan> lst = new List<Entity.RT_Plan>();
DataTable dt = GetPlanData(planDate, shiftID);
Entity.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)
{
return AddPlan(equipCode, planDate, shiftID, recipeGUID, 0, planNum, String.Empty);
}
/// <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)
{
return AddPlan(equipCode, planDate, shiftID, recipeGUID, 0, planNum, remark);
}
/// <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)
{
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,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,Start_Date,End_Date,Weight_Man,Stock_Man,Plan_Batch,Plan_State,Plan_StateText,Plan_Date,IF_FLAG)
VALUES(@Dosing_Id,@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,@Start_Date,@End_Date,@Weight_Man,@Stock_Man,@Plan_Batch,@Plan_State,@Plan_StateText,@Plan_Date,@IF_FLAG)";
dbHelper.CommandText = strSql3;
dbHelper.AddParameter("@Dosing_Id", 0);
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.Waiting); //计划状态
dbHelper.AddParameter("@Plan_StateText", StateToShow((int)PlanState.Waiting)); //计划日期
dbHelper.AddParameter("@Plan_Date", String.Format("{0:yyyy-MM-dd}", DateTime.Now)); //计划日期
dbHelper.AddParameter("@IF_FLAG", 1); //MES计划变更标志位
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_Code,Recipe_Name,Version,Mixer_Line,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,IF_FLAG)
VALUES(@Dosing_Id,@Plan_Id,@Equip_Code,@Plan_Serial,@Recipe_Code,@Recipe_Name,@Version,@Mixer_Line,@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,@IF_FLAG)";
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_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.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)
{
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 RealNum = @RealNum, IsUpFlag = 0 WHERE PlanID = @PlanID";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@RealNum", realNum);
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="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 bool DeletePlan(string planId)
{
try
{
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 Base_PlanInfo WHERE Plan_Id = @PlanID";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@PlanID", planId);
dbHelper.ExecuteNonQuery();
return true;
}
catch (Exception ex)
{
return false;
}
}
#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 Entity.RT_Plan ConvertDataRowToPptPlan(DataRow dr)
{
if (dr != null)
{
Entity.RT_Plan plan = new Entity.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 = Mesnac.Basic.DataProcessor.RowValue(dr, "Set_Weight", 0.0);
plan.Set_Error = Mesnac.Basic.DataProcessor.RowValue(dr, "Set_Error", 0.0);
plan.Cpk_Error = Mesnac.Basic.DataProcessor.RowValue(dr, "Cpk_Error", 0.0);
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数据行转换为Base_MaterialInfo实体对象
/// </summary>
/// <param name="dr">要转换的数据行</param>
/// <returns>返回转换后的计划实体对象</returns>
public static Base_MaterialInfo ConvertDataRowToPmtMaterial(DataRow dr)
{
if (dr != null)
{
Base_MaterialInfo materialInfo = new Base_MaterialInfo();
materialInfo.materialId = Mesnac.Basic.DataProcessor.RowValue(dr, "material_Id", String.Empty);
materialInfo.materialName = Mesnac.Basic.DataProcessor.RowValue(dr, "material_Name", String.Empty);
materialInfo.materialWeight = Convert.ToDecimal(String.IsNullOrEmpty(Mesnac.Basic.DataProcessor.RowValue(dr, "material_Weight", String.Empty)) ? "0" : Mesnac.Basic.DataProcessor.RowValue(dr, "material_Weight", String.Empty));
materialInfo.putTime = Convert.ToInt32(String.IsNullOrEmpty(Mesnac.Basic.DataProcessor.RowValue(dr, "put_Time", String.Empty)) ? "0" : Mesnac.Basic.DataProcessor.RowValue(dr, "put_Time", String.Empty));
return materialInfo;
}
else
{
return null;
}
}
public static Base_CratParamInfo ConvertDataRowToBaseCratParamInfo(DataRow dr)
{
if (dr != null)
{
Base_CratParamInfo paramInfo = new Base_CratParamInfo();
paramInfo.paramId = Mesnac.Basic.DataProcessor.RowValue(dr, "param_Id", String.Empty);
paramInfo.paramName = Mesnac.Basic.DataProcessor.RowValue(dr, "param_Name", String.Empty);
return paramInfo;
}
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 == 0)
{
reStr = "待执行";
}
else if (stateNum == 1)
{
reStr = "执行中";
}
else if (stateNum == 2)
{
reStr = "已终止";
}
else if (stateNum == 3)
{
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 = 0;
}
else if (stateInfo == "执行中")
{
reStateNum = 1;
}
else if (stateInfo == "已完成")
{
reStateNum = 2;
}
else if (stateInfo == "已终止")
{
reStateNum = 3;
}
return reStateNum;
}
#endregion
/// <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 SaveBasePlanInfo(Base_PlanInfo base_PlanInfo)
{
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 Base_PlanInfo (uid, plan_Id, recipe_Id, recipe_Name, plan_Team, plan_Amount, real_Amount, run_Type, plan_State,
grid_Amount,line_Amount,car_Amount,create_By, create_Time,plan_order) VALUES (@uid, @plan_Id, @recipe_Id, @recipe_Name, @plan_Team,
@plan_Amount,@real_Amount ,@run_Type, @plan_State, @grid_Amount,@line_Amount,@car_Amount,@create_By, @create_Time,@plan_order)";
dbHelper.CommandText = strSql3;
dbHelper.AddParameter("@uid", base_PlanInfo.uid);
dbHelper.AddParameter("@plan_Id", base_PlanInfo.plan_Id);
dbHelper.AddParameter("@recipe_Id", base_PlanInfo.recipe_Id);
dbHelper.AddParameter("@recipe_Name", base_PlanInfo.recipe_Name);
dbHelper.AddParameter("@plan_Team", base_PlanInfo.plan_Team);
dbHelper.AddParameter("@plan_Amount", base_PlanInfo.plan_Amount);
dbHelper.AddParameter("@real_Amount", 0);
dbHelper.AddParameter("@run_Type", base_PlanInfo.run_Type);
dbHelper.AddParameter("@plan_State", 0);
//dbHelper.AddParameter("@plan_beginTime", base_PlanInfo.plan_beginTime);
dbHelper.AddParameter("@car_Amount", base_PlanInfo.car_Amount);
dbHelper.AddParameter("@grid_Amount", base_PlanInfo.grid_Amount);
dbHelper.AddParameter("@line_Amount", base_PlanInfo.line_Amount);
dbHelper.AddParameter("@create_By", base_PlanInfo.create_By);
dbHelper.AddParameter("@create_Time", base_PlanInfo.create_Time);
dbHelper.AddParameter("@plan_order", base_PlanInfo.plan_order);
dbHelper.ExecuteNonQuery();
}catch(Exception e)
{
ICSharpCode.Core.LoggingService<InsertAction>.Error("当班计划—添加计划失败"+e.Message);
}
return base_PlanInfo.plan_Id;
}
/// <summary>
/// 根据计划编号获取计划信息
/// </summary>
/// <param name="planID">计划号</param>
/// <returns>存在返回true否则返回false</returns>
public static Base_PlanInfo getPlanInfoByPlanId(string plan_Id)
{
Base_PlanInfo planInfo = new Base_PlanInfo();
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 Base_PlanInfo WHERE plan_Id = @plan_Id";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@plan_Id", plan_Id);
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
foreach (DataRow dr in table.Rows)
{
planInfo = ConvertDataRowToBasePlanInfo(dr);
break;
}
}
return planInfo;
}
public static Base_PlanInfo getNextPlanInfoByOrder(int plan_order)
{
Base_PlanInfo planInfo = new Base_PlanInfo();
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 Base_PlanInfo WHERE plan_order > @plan_order";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@plan_order", plan_order);
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
foreach (DataRow dr in table.Rows)
{
planInfo = ConvertDataRowToBasePlanInfo(dr);
break;
}
}
return planInfo;
}
/// <summary>
/// 修改计划数据
/// </summary>
/// <param name="base_PlanInfo"></param>
/// <returns></returns>
public static string UpdateBasePlanInfo(Base_PlanInfo base_PlanInfo)
{
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 sqlstr = @"update Base_PlanInfo set recipe_Id = @recipe_Id, recipe_Name = @recipe_Name, plan_Amount = @plan_Amount, real_Amount = @real_Amount,
run_Type = @run_Type, plan_State = @plan_State,car_Amount = @car_Amount,grid_Amount = @grid_Amount,line_Amount = @line_Amount where uid = @uid";
dbHelper.ClearParameter();
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@uid", base_PlanInfo.uid);
dbHelper.AddParameter("@recipe_Id", base_PlanInfo.recipe_Id);
dbHelper.AddParameter("@recipe_Name", base_PlanInfo.recipe_Name);
dbHelper.AddParameter("@plan_Amount", base_PlanInfo.plan_Amount);
dbHelper.AddParameter("@real_Amount", base_PlanInfo.real_Amount);
dbHelper.AddParameter("@run_Type", base_PlanInfo.run_Type);
dbHelper.AddParameter("@car_Amount", base_PlanInfo.car_Amount);
dbHelper.AddParameter("@grid_Amount", base_PlanInfo.grid_Amount);
dbHelper.AddParameter("@line_Amount", base_PlanInfo.line_Amount);
dbHelper.AddParameter("@plan_State", base_PlanInfo.plan_State);
//dbHelper.AddParameter("@plan_beginTime", base_PlanInfo.plan_beginTime);
dbHelper.ExecuteNonQuery();
return base_PlanInfo.plan_Id;
}
public static string UpdatePlanOrderByPlanId(Base_PlanInfo base_PlanInfo)
{
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 sqlstr = @"update Base_PlanInfo set plan_order = @plan_order where plan_Id = @plan_Id";
dbHelper.ClearParameter();
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@plan_Id", base_PlanInfo.plan_Id);
dbHelper.AddParameter("@plan_Order", base_PlanInfo.plan_order);
dbHelper.ExecuteNonQuery();
return base_PlanInfo.plan_Id;
}
/// <summary>
/// Datatable转为Base_RepiceInfo
/// </summary>
/// <param name="dr"></param>
/// <returns></returns>
public static Base_PlanInfo ConvertDataRowToBasePlanInfo(DataRow dr)
{
if (dr != null)
{
Base_PlanInfo plan = new Base_PlanInfo();
plan.uid = Mesnac.Basic.DataProcessor.RowValue(dr, "uid", String.Empty);
plan.plan_Id = Mesnac.Basic.DataProcessor.RowValue(dr, "plan_Id", String.Empty);
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.plan_Team = Mesnac.Basic.DataProcessor.RowValue(dr, "plan_Team", String.Empty);
plan.plan_Amount = Convert.ToInt32(Mesnac.Basic.DataProcessor.RowValue(dr, "plan_Amount", String.Empty));
plan.real_Amount = String.IsNullOrEmpty(Mesnac.Basic.DataProcessor.RowValue(dr, "real_Amount", String.Empty)) ? 0 : Convert.ToInt32(Mesnac.Basic.DataProcessor.RowValue(dr, "real_Amount", String.Empty));
plan.run_Type = Convert.ToInt32(Mesnac.Basic.DataProcessor.RowValue(dr, "run_Type", String.Empty));
plan.plan_State = Convert.ToInt32(Mesnac.Basic.DataProcessor.RowValue(dr, "plan_State", String.Empty));
plan.plan_beginTime = Mesnac.Basic.DataProcessor.RowValue(dr, "plan_beginTime", String.Empty);
plan.plan_endTime = Mesnac.Basic.DataProcessor.RowValue(dr, "plan_endTime", String.Empty);
plan.car_Amount = Convert.ToInt32(Mesnac.Basic.DataProcessor.RowValue(dr, "car_Amount", String.Empty));
plan.grid_Amount = Convert.ToInt32(Mesnac.Basic.DataProcessor.RowValue(dr, "grid_Amount", String.Empty));
plan.line_Amount = Convert.ToInt32(Mesnac.Basic.DataProcessor.RowValue(dr, "line_Amount", String.Empty));
//plan.create_By = Mesnac.Basic.DataProcessor.RowValue(dr, "create_By", String.Empty);
//plan.create_Time = Mesnac.Basic.DataProcessor.RowValue(dr, "create_Time", String.Empty);
plan.plan_order = Convert.ToInt32(Mesnac.Basic.DataProcessor.RowValue(dr, "plan_order", String.Empty));
return plan;
}
else
{
return null;
}
}
public static Base_PlanInfo getLastPlanInfoByPlanOrder(int plan_order)
{
Base_PlanInfo planInfo = new Base_PlanInfo();
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 Base_PlanInfo where plan_order < @plan_order order by plan_order desc";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@plan_order", plan_order);
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
foreach (DataRow dr in table.Rows)
{
planInfo = ConvertDataRowToBasePlanInfo(dr);
break;
}
}
return planInfo;
}
public static Base_PlanInfo getNextPlanInfoByPlanOrder(int plan_order)
{
Base_PlanInfo planInfo = new Base_PlanInfo();
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 Base_PlanInfo where plan_order > @plan_order order by plan_order asc";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@plan_order", plan_order);
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
foreach (DataRow dr in table.Rows)
{
planInfo = ConvertDataRowToBasePlanInfo(dr);
break;
}
}
return planInfo;
}
public static string getPlanIDByPlanInfo()
{
string PlanID = "";
string starttime = DateTime.Now.ToString("yyyy-MM-dd")+" 00:00:00";
string endtime = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") + " 00:00:00";
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 plan_Id FROM Base_PlanInfo where create_Time > @starttime and create_Time < @endtime order by create_Time desc";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
dbHelper.AddParameter("@starttime", starttime);
dbHelper.AddParameter("@endtime", endtime);
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
Base_MaterialInfo entity = null;
foreach (DataRow dr in table.Rows)
{
PlanID = Mesnac.Basic.DataProcessor.RowValue(dr, "plan_Id", String.Empty);
}
}
return PlanID;
}
#region 冠合数据库计划信息表操作
public static bool UpdateBasePlanStateInfo(Base_PlanInfo base_PlanInfo)
{
bool iFlag = false;
string sqlstr = "";
try
{
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;
sqlstr = @"update Base_PlanInfo set plan_State = @plan_State, BeginTime = @plan_beginTime, plan_endTime = @plan_endTime where uid = @uid and plan_Id = @plan_Id ";
dbHelper.ClearParameter();
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@uid", base_PlanInfo.uid);
dbHelper.AddParameter("@plan_Id", base_PlanInfo.plan_Id);
dbHelper.AddParameter("@plan_State", base_PlanInfo.plan_State);
dbHelper.AddParameter("@plan_beginTime", base_PlanInfo.plan_beginTime);
dbHelper.AddParameter("@plan_endTime", base_PlanInfo.plan_endTime);
dbHelper.ExecuteNonQuery();
iFlag = true;
return iFlag;
}
catch (Exception ex)
{
return iFlag;
}
}
public static bool UpdatePlanInfo(Base_PlanInfo base_PlanInfo)
{
bool iFlag = false;
string sqlstr = "";
try
{
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;
sqlstr = @"update Base_PlanInfo set recipe_Id = @recipe_Id,recipe_Name = @recipe_Name,plan_Team = @plan_Team,plan_Amount = @plan_Amount,real_Amount = @real_Amount,run_Type = @run_Type,plan_State = @plan_State, plan_beginTime = @plan_beginTime, plan_endTime = @plan_endTime where uid = @uid and plan_Id = @plan_Id ";
dbHelper.ClearParameter();
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@uid", base_PlanInfo.uid);
dbHelper.AddParameter("@recipe_Id", base_PlanInfo.recipe_Id);
dbHelper.AddParameter("@recipe_Name", base_PlanInfo.recipe_Name);
dbHelper.AddParameter("@plan_Team", base_PlanInfo.plan_Team);
dbHelper.AddParameter("@plan_Amount", base_PlanInfo.plan_Amount);
dbHelper.AddParameter("@real_Amount", base_PlanInfo.real_Amount);
dbHelper.AddParameter("@run_Type", base_PlanInfo.run_Type);
dbHelper.AddParameter("@plan_State", base_PlanInfo.plan_State);
dbHelper.AddParameter("@plan_beginTime", base_PlanInfo.plan_beginTime);
dbHelper.AddParameter("@plan_endTime", base_PlanInfo.plan_endTime);
dbHelper.AddParameter("@plan_Id", base_PlanInfo.plan_Id);
dbHelper.ExecuteNonQuery();
iFlag = true;
return iFlag;
}
catch (Exception ex)
{
return iFlag;
}
}
#endregion
}
}