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