using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data; using ICSharpCode.Core; using Mesnac.Codd.Session; using Mesnac.Action.ChemicalWeighing.Entity; using Mesnac.Action.ChemicalWeighing.Technical.PmtRecipe.entity; using Mesnac.Action.ChemicalWeighing.Product.PptPlan.entity; namespace Mesnac.Action.ChemicalWeighing.Product.PptPlan { /// /// 计划业务辅助类 /// public class PlanHelper { #region 静态字段定义 private static bool _isInit = false; //当班计划是否已初始化 private static string _execDate; //执行日期 private static string _execShift; //执行班次 private static string _execClass; //执行班组 private static bool _isShift = false; //是否交接班标志 private static PlanLog _planLog = null; //计划日志 #endregion #region 静态属性定义 /// /// 是否正在初始化计划标志 /// 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_State"].Value.ToString()); switch (planState) { //case (int)PlanState.Issued: //已下传 // row.DefaultCellStyle.BackColor = System.Drawing.Color.FromArgb(255, 204, 204); // break; case (int)PlanState.Waiting: //未启动 row.DefaultCellStyle.BackColor = System.Drawing.Color.FromArgb(255, 255, 204); break; case (int)PlanState.Received: //正在运行 row.DefaultCellStyle.BackColor = System.Drawing.Color.GreenYellow; //绿色 break; case (int)PlanState.Terminated: //已终止 row.DefaultCellStyle.BackColor = System.Drawing.Color.FromArgb(220, 220, 120); //灰色 break; case (int)PlanState.Completed: //已完成 int realNum = 0; realNum = Convert.ToInt32(row.Cells["real_amount"].Value); if (realNum < Convert.ToInt32(row.Cells["plan_amount"].Value)) { //停止计划 row.DefaultCellStyle.BackColor = System.Drawing.Color.FromArgb(220, 220, 120); //灰色 } else { //完成计划 row.DefaultCellStyle.BackColor = System.Drawing.Color.FromArgb(220, 220, 220); //灰色 } break; default: break; } } } catch (Exception ex) { ICSharpCode.Core.LoggingService.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 Base_PlanInfo where Plan_Id = @PlanID"; dbHelper.CommandText = strSql; dbHelper.AddParameter("@PlanID", planID); object result = dbHelper.ToScalar(); if (result != null && result != DBNull.Value && Convert.ToInt32(result) > 0) { return true; } else { return false; } } #endregion #region 判断某个计划是否存在(RT_Plan) /// /// 判断某个计划是否存在 /// /// 计划号 /// 存在返回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 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 LR_plan WHERE LEFT(Plan_Id,8) = @PlanDate"; dbHelper.CommandText = strSql; dbHelper.AddParameter("@PlanDate", String.Format("{0:yyyyMMdd}", planDate)); object result = dbHelper.ToScalar(); if (result == null || result == System.DBNull.Value) { return 1; } else { return Convert.ToInt32(result) + 1; } } #endregion #region GenerateNextPlanID 获取下一个可用的计划号 (6位日期、2位机台、1位班次、1位网络/本机、2位流水) /// /// 获取下一个可用的计划号 (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 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 Entity.RT_Plan GetPlanDataEntity(string planID) { DataRow dr = GetPlanData(planID); if (dr != null) { Entity.RT_Plan plan = ConvertDataRowToPptPlan(dr); return plan; } else { return null; } } /// /// 获取某条生产计划(计划序号、日期) /// /// 计划序号 /// 计划日期 /// 返回对应计划实体对象 public static Entity.RT_Plan GetPlanDataEntity(int planSerial) { DataRow dr = GetPlanData(planSerial); if (dr != null) { Entity.RT_Plan plan = ConvertDataRowToPptPlan(dr); return plan; } else { return null; } } #endregion #region 实体类复制 ///         /// 将一个实体类复制到另一个实体类         ///         /// 源实体类         /// 复制到的实体类         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) { Entity.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) { Entity.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) { Entity.RT_Plan entity = null; foreach (DataRow dr in table.Rows) { entity = ConvertDataRowToPptPlan(dr); lst.Add(entity); } } return lst; } #endregion #region 获取当班某序号未执行的计划(下移使用) /// /// 获取当班某序号未执行的计划 /// /// 计划序号 /// 返回符合条件的计划列表 public static Entity.RT_Plan GetPlanBySerialDown(int planSerial) { Entity.RT_Plan reRtPlan = null; DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError); } string planDate = DateTime.Now.ToShortDateString(); //int shiftID = PlanHelper.PlanLog.LastShiftID; string msg = String.Empty; string strPlanDate = String.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now); //bool result = ProductHelper.PlanDateVerify(out planDate, out shiftID, strPlanDate, shiftID, out msg); dbHelper.CommandType = CommandType.Text; string strSql = "SELECT top 1 * FROM RT_Plan WHERE Plan_Date = @PlanDate AND Plan_State <= 5 AND Plan_State >3 AND Plan_Serial > @Plan_Serial ORDER BY Plan_Serial"; dbHelper.CommandText = strSql; dbHelper.ClearParameter(); dbHelper.AddParameter("@PlanDate", planDate); //dbHelper.AddParameter("@ShiftID", shiftID); dbHelper.AddParameter("@Plan_Serial", planSerial); DataTable table = dbHelper.ToDataTable(); if (table != null && table.Rows.Count > 0) { foreach (DataRow dr in table.Rows) { reRtPlan = ConvertDataRowToPptPlan(dr); break; } } return reRtPlan; } #endregion #region 获取当班某序号未执行的计划(上移使用) /// /// 获取当班某序号未执行的计划 /// /// 计划序号 /// 返回符合条件的计划列表 public static Entity.RT_Plan GetPlanBySerialUp(int planSerial) { Entity.RT_Plan reRtPlan = null; DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError); } string planDate = DateTime.Now.ToShortDateString(); //int shiftID = PlanHelper.PlanLog.LastShiftID; string msg = String.Empty; string strPlanDate = String.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now); //bool result = ProductHelper.PlanDateVerify(out planDate, out shiftID, strPlanDate, shiftID, out msg); dbHelper.CommandType = CommandType.Text; string strSql = "SELECT top 1 * FROM RT_Plan WHERE Plan_Date = @PlanDate AND Plan_State <= 5 AND Plan_State >3 AND Plan_Serial < @Plan_Serial ORDER BY Plan_Serial DESC"; dbHelper.CommandText = strSql; dbHelper.ClearParameter(); dbHelper.AddParameter("@PlanDate", planDate); //dbHelper.AddParameter("@ShiftID", shiftID); dbHelper.AddParameter("@Plan_Serial", planSerial); DataTable table = dbHelper.ToDataTable(); if (table != null && table.Rows.Count > 0) { foreach (DataRow dr in table.Rows) { reRtPlan = ConvertDataRowToPptPlan(dr); break; } } return reRtPlan; } #endregion #region 获取未执行的计划数(RT_Plan) /// /// 获取未执行的计划数 /// 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) { Entity.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) { Entity.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) { Entity.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) { 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) { Pmt_weigh entity = null; foreach (DataRow dr in table.Rows) { entity = ConvertDataRowToPmtweigh(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 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 Base_MaterialInfo"; dbHelper.CommandText = strSql; dbHelper.ClearParameter(); DataTable table = dbHelper.ToDataTable(); if (table != null && table.Rows.Count > 0) { Base_MaterialInfo entity = null; foreach (DataRow dr in table.Rows) { entity = ConvertDataRowToPmtMaterial(dr); materialList.Add(entity); } } return materialList; } public static List GetAllBaseCratParamInfo() { List 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 Base_CratParamInfo"; dbHelper.CommandText = strSql; dbHelper.ClearParameter(); DataTable table = dbHelper.ToDataTable(); if (table != null && table.Rows.Count > 0) { Base_CratParamInfo entity = null; foreach (DataRow dr in table.Rows) { entity = ConvertDataRowToBaseCratParamInfo(dr); materialList.Add(entity); } } return materialList; } #endregion #region 根据物料id获取Pmt_material /// /// 根据物料id获取Base_MaterialInfo /// /// 物料id /// 返回符合条件Pmt_Bin public static Base_MaterialInfo GetPmt_material(string materialID) { Base_MaterialInfo rePmt_material = null; DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError); } dbHelper.CommandType = CommandType.Text; string strSql = "SELECT * FROM Base_Material where material_Id = @Material_ID"; dbHelper.CommandText = strSql; dbHelper.ClearParameter(); dbHelper.AddParameter("@Material_ID", materialID); DataTable table = dbHelper.ToDataTable(); if (table != null && table.Rows.Count > 0) { Base_MaterialInfo entity = null; foreach (DataRow dr in table.Rows) { entity = ConvertDataRowToPmtMaterial(dr); rePmt_material = entity; break; } } return rePmt_material; } #endregion #region 根据物料名称获取物料的ID /// /// 根据物料名称获取物料的ID /// /// 物料名称 /// 返回符合条件materialID public static string GetPmt_materialID(string materialCode) { Base_MaterialInfo rePmt_material = null; DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError); } dbHelper.CommandType = CommandType.Text; string strSql = "SELECT * FROM Base_Material where material_Id = @Material_code"; dbHelper.CommandText = strSql; dbHelper.ClearParameter(); dbHelper.AddParameter("@Material_code", materialCode); DataTable table = dbHelper.ToDataTable(); if (table != null && table.Rows.Count > 0) { Base_MaterialInfo entity = null; foreach (DataRow dr in table.Rows) { entity = ConvertDataRowToPmtMaterial(dr); rePmt_material = entity; break; } } else { return null; } return rePmt_material.materialId; } #endregion #region 获取某条计划的状态 /// /// 获取某条计划的状态 /// /// 计划号 /// 返回计划状态 public static PlanState GetPlanState(string planID) { DataRow row = GetPlanData(planID); if (row != null) { int planState = Mesnac.Basic.DataProcessor.RowValue(row, "PlanState", 0); //获取计划状态 int planNum = Mesnac.Basic.DataProcessor.RowValue(row, "PlanNum", 0); //获取计划数 int realNum = Mesnac.Basic.DataProcessor.RowValue(row, "RealNum", 0); //获取完成数 if (realNum >= planNum) { return PlanState.Completed; } return (PlanState)planState; } else { return PlanState.Terminated; } } #endregion #region 获取某条计划的开炼状态 /// /// 获取某条计划的开炼状态 /// /// 计划号 /// 返回计划开炼状态 public static PlanState GetMillPlanState(string planID) { DataRow row = GetPlanData(planID); if (row != null) { int planState = Mesnac.Basic.DataProcessor.RowValue(row, "MillPlanState", 0); //获取计划状态 int planNum = Mesnac.Basic.DataProcessor.RowValue(row, "PlanNum", 0); //获取计划数 int realNum = Mesnac.Basic.DataProcessor.RowValue(row, "MillRealNum", 0); //获取完成数 if (realNum >= planNum) { return PlanState.Completed; } return (PlanState)planState; } else { return PlanState.Terminated; } } #endregion #region 根据计划号获取配方GUID /// /// 根据计划号获取配方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 GetPlanData(DateTime planDate, int shiftID) { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError); } dbHelper.ClearParameter(); dbHelper.CommandType = CommandType.Text; string strSql = "SELECT Plan_Serial,Recipe_Name,Equip_Code,Version,Plan_Id,Plan_Num,Real_Num,Plan_StateText,Start_Date,End_Date FROM RT_Plan WHERE LEFT(Plan_Id,8) = @PlanDate AND Shift_id = @ShiftID ORDER BY Plan_State,Plan_Serial"; dbHelper.CommandText = strSql; dbHelper.AddParameter("@PlanDate", String.Format("{0:yyyyMMdd}", planDate)); dbHelper.AddParameter("@ShiftID", shiftID); DataTable table = dbHelper.ToDataTable(); return table; } /// /// 获取本机台、日期的计划数据 /// /// 计划生产日期 /// 返回符合条件的计划数据 public static DataTable GetPlanData(DateTime planDate) { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError); } dbHelper.ClearParameter(); dbHelper.CommandType = CommandType.Text; string strSql = "SELECT Plan_Serial,Recipe_Name,Equip_Code,Version,Plan_Id,Plan_Num,Real_Num,Plan_StateText,Start_Date,End_Date FROM RT_Plan WHERE LEFT(Plan_Id,8) = @PlanDate ORDER BY Plan_State,Plan_Serial"; dbHelper.CommandText = strSql; dbHelper.AddParameter("@PlanDate", String.Format("{0:yyyyMMdd}", planDate)); DataTable table = dbHelper.ToDataTable(); return table; } /// /// 获取本机台全部的计划数据 /// /// 返回符合条件的计划数据表 public static DataTable GetPlanData() { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError); } dbHelper.ClearParameter(); dbHelper.CommandType = CommandType.Text; string strSql = @"select row_number() over (order by create_Time) as index_Id ,uid, plan_Id, recipe_Id, recipe_Name, t2.Shift_name as plan_Team, plan_Amount, real_Amount, case run_Type when '0' then '自动运行' else '手动运行' end as 'run_Type', case plan_State when '0' then '待执行' when '1' then '执行中' when '2' then '已完成' when '3' then '已终止' else '异常' end as 'plan_State', plan_beginTime, plan_endTime, create_By, create_Time, update_By, update_Time,plan_order from Base_PlanInfo t1 left join Pmt_Shiftime t2 on t1.plan_Team = t2.Shift_id order by plan_order asc"; dbHelper.CommandText = strSql; DataTable table = dbHelper.ToDataTable(); return table; } /// /// 获取本机台、日期的计划数据 /// /// 计划生产日期 /// 返回符合条件的计划对象列表 public static List GetPlanDataEntity(DateTime planDate) { List lst = new List(); DataTable dt = GetPlanData(planDate); Entity.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); Entity.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) { return AddPlan(equipCode, planDate, shiftID, recipeGUID, 0, planNum, String.Empty); } /// /// 添加生产计划 /// /// 5位机台号 /// 计划生产日期 /// 班次ID /// 班组ID /// 配方GUID /// 计划数 /// 备注 /// 返回新加计划的计划号 public static string AddPlan(string equipCode, DateTime planDate, int shiftID, string recipeGUID, int planNum, string remark) { return AddPlan(equipCode, planDate, shiftID, recipeGUID, 0, planNum, remark); } /// /// 添加生产计划 /// /// 5位机台号 /// 计划生产日期 /// 班次ID /// 班组ID /// 配方GUID /// 配方版本号 /// 计划数 /// 备注 /// 返回新加计划的计划号 public static string AddPlan(string equipCode, DateTime planDate, int shiftID, string recipeGUID, int recipeVersion, int planNum, string remark) { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError); } dbHelper.ClearParameter(); dbHelper.CommandType = CommandType.Text; //查询配方数据 Entity.Pmt_recipe recipe = null; if (recipeVersion ==0) { recipe = Technical.PmtRecipe.RecipeHelper.GetRecipeEntityByGUID(recipeGUID); } else { recipe = Technical.PmtRecipe.RecipeHelper.GetRecipeEntityByGUID(recipeGUID, recipeVersion.ToString()); } if (recipe != null) { string strRecipeVersion = recipe.Version; //配方版本号 string recipeCode = recipe.Recipe_Code; string recipeName = recipe.Recipe_Name; //配方名称 string recipeType = recipe.Recipe_type.ToString(); //配方类型 decimal? totalWeight = recipe.Total_Weight; //每车重量 #region 从两张表中获取最大的serialNum int serialNum = 0; int rtPlanSNum = GetNextSerialNum(); //RT_Plan序号 int lrPlanSNum = GetNextSerialNumFromLRPlan(planDate); //LR_Plan序号 if(rtPlanSNum >= lrPlanSNum) { serialNum = rtPlanSNum; } else { serialNum = lrPlanSNum; } #endregion #region 组合获取planID string planID = GenerateNextPlanIDNew(planDate, shiftID, serialNum); //计划号 #endregion //int serialNum = GetNextSerialNum(planDate); //string planID = GenerateNextPlanID(equipCode, planDate, shiftID); //计划号 dbHelper.ClearParameter(); dbHelper.CommandType = CommandType.Text; //添加计划的SQL语句 string strSql3 = @"INSERT INTO RT_Plan(Dosing_Id,Plan_Id,Equip_Code,Plan_Serial,Recipe_ID,Recipe_Code,Recipe_Name,Version,Mixer_Line,Recipe_Type,Shift_Id,Shift_Class,Plan_Num,Real_Num,Duration_Time,Start_Date,End_Date,Weight_Man,Stock_Man,Plan_Batch,Plan_State,Plan_StateText,Plan_Date,IF_FLAG) VALUES(@Dosing_Id,@Plan_Id,@Equip_Code,@Plan_Serial,@Recipe_ID,@Recipe_Code,@Recipe_Name,@Version,@Mixer_Line,@Recipe_Type,@Shift_Id,@Shift_Class,@Plan_Num,@Real_Num,@Duration_Time,@Start_Date,@End_Date,@Weight_Man,@Stock_Man,@Plan_Batch,@Plan_State,@Plan_StateText,@Plan_Date,@IF_FLAG)"; dbHelper.CommandText = strSql3; dbHelper.AddParameter("@Dosing_Id", 0); dbHelper.AddParameter("@Plan_Id", planID); //计划号 dbHelper.AddParameter("@Equip_Code", equipCode); //机台号 dbHelper.AddParameter("@Plan_Serial", serialNum); //排序字段(优先级,在此与ActionOrder相同) dbHelper.AddParameter("@Recipe_ID", recipeGUID); //配方GUID dbHelper.AddParameter("@Recipe_Code", recipeCode); //配方编码 dbHelper.AddParameter("@Recipe_Name", recipeName); //配方别名 dbHelper.AddParameter("@Version", strRecipeVersion); //配方版本号 dbHelper.AddParameter("@Mixer_Line", recipe.Mixer_line); //配方版本号 dbHelper.AddParameter("@Recipe_Type", recipeType); //配方类型 dbHelper.AddParameter("@Shift_Id", shiftID); //班次ID dbHelper.AddParameter("@Shift_Class", 0); //班组ID dbHelper.AddParameter("@Plan_Num", planNum); //计划数 dbHelper.AddParameter("@Real_Num", 0); //完成数量 dbHelper.AddParameter("@Duration_Time", 0); //持续时间 dbHelper.AddParameter("@Start_Date", String.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now));//开始时间 dbHelper.AddParameter("@End_Date", null); //结束时间 dbHelper.AddParameter("@Weight_Man", null); //称量工 dbHelper.AddParameter("@Stock_Man", null); //投料工 dbHelper.AddParameter("@Plan_Batch", null); //批次号,不同的现场有不同的命令规则。 dbHelper.AddParameter("@Plan_State", (int)PlanState.Waiting); //计划状态 dbHelper.AddParameter("@Plan_StateText", StateToShow((int)PlanState.Waiting)); //计划日期 dbHelper.AddParameter("@Plan_Date", String.Format("{0:yyyy-MM-dd}", DateTime.Now)); //计划日期 dbHelper.AddParameter("@IF_FLAG", 1); //MES计划变更标志位 dbHelper.ExecuteNonQuery(); return planID; } return String.Empty; } #endregion #region 添加生产计划(LR_plan) /// /// 添加生产计划 /// /// 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_Code,Recipe_Name,Version,Mixer_Line,Recipe_Type,Shift_Id,Shift_Class,Plan_Num,Real_Num,Duration_Time,Start_Date,End_Date,Weight_Man,Stock_Man,Plan_Batch,Plan_State,Plan_Date,IF_FLAG) VALUES(@Dosing_Id,@Plan_Id,@Equip_Code,@Plan_Serial,@Recipe_Code,@Recipe_Name,@Version,@Mixer_Line,@Recipe_Type,@Shift_Id,@Shift_Class,@Plan_Num,@Real_Num,@Duration_Time,@Start_Date,@End_Date,@Weight_Man,@Stock_Man,@Plan_Batch,@Plan_State,@Plan_Date,@IF_FLAG)"; dbHelper.CommandText = strSql3; dbHelper.AddParameter("@Dosing_Id", 0); dbHelper.AddParameter("@Plan_Id", lrPlan.Plan_Id); //计划号 dbHelper.AddParameter("@Equip_Code", lrPlan.Equip_Code); //机台号 dbHelper.AddParameter("@Plan_Serial", lrPlan.Plan_Serial); //排序字段(优先级,在此与ActionOrder相同) dbHelper.AddParameter("@Recipe_Code", lrPlan.Recipe_Code); //配方编码 dbHelper.AddParameter("@Recipe_Name", lrPlan.Recipe_Name); //配方别名 dbHelper.AddParameter("@Version", lrPlan.Version); //配方版本号 dbHelper.AddParameter("@Mixer_Line", lrPlan.Mixer_Line); //配方版本号 dbHelper.AddParameter("@Recipe_Type", lrPlan.Recipe_Type); //配方类型 dbHelper.AddParameter("@Shift_Id", lrPlan.Shift_Id); //班次ID dbHelper.AddParameter("@Shift_Class", 0); //班组ID dbHelper.AddParameter("@Plan_Num", lrPlan.Plan_Num); //计划数 dbHelper.AddParameter("@Real_Num", lrPlan.Real_Num); //完成数量 dbHelper.AddParameter("@Duration_Time", lrPlan.Duration_Time); //持续时间 dbHelper.AddParameter("@Start_Date", lrPlan.Start_Date); //开始时间 dbHelper.AddParameter("@End_Date", lrPlan.End_Date); //结束时间 dbHelper.AddParameter("@Weight_Man", lrPlan.Weight_Man); //称量工 dbHelper.AddParameter("@Stock_Man", lrPlan.Stock_Man); //投料工 dbHelper.AddParameter("@Plan_Batch", lrPlan.Plan_Batch); //批次号,不同的现场有不同的命令规则。 dbHelper.AddParameter("@Plan_State", lrPlan.Plan_State); //计划状态 dbHelper.AddParameter("@Plan_Date", lrPlan.Plan_Date); //计划日期 dbHelper.AddParameter("@IF_FLAG", lrPlan.IF_FLAG); //暂时无用 dbHelper.ExecuteNonQuery(); return lrPlan.Plan_Id; } #endregion #region 添加(LR_recipe) /// /// 添加(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) { try { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError); } dbHelper.ClearParameter(); dbHelper.CommandType = CommandType.Text; string strSql = "UPDATE RT_Plan SET RealNum = @RealNum, IsUpFlag = 0 WHERE PlanID = @PlanID"; dbHelper.CommandText = strSql; dbHelper.AddParameter("@RealNum", realNum); dbHelper.AddParameter("@PlanID", planID); dbHelper.ExecuteNonQuery(); } catch (Exception ex) { ICSharpCode.Core.LoggingService.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 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 bool DeletePlan(string planId) { try { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError); } dbHelper.CommandType = CommandType.Text; dbHelper.ClearParameter(); string strSql = "DELETE FROM Base_PlanInfo WHERE Plan_Id = @PlanID"; dbHelper.CommandText = strSql; dbHelper.AddParameter("@PlanID", planId); dbHelper.ExecuteNonQuery(); return true; } catch (Exception ex) { return false; } } #endregion #region 停止掺用计划 /// /// 停止掺用计划 /// /// 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 Entity.RT_Plan ConvertDataRowToPptPlan(DataRow dr) { if (dr != null) { Entity.RT_Plan plan = new Entity.RT_Plan(); plan.Dosing_Id = Mesnac.Basic.DataProcessor.RowValue(dr, "Dosing_Id", 0); plan.Plan_Id = Mesnac.Basic.DataProcessor.RowValue(dr, "Plan_Id", String.Empty); plan.Equip_Code = Mesnac.Basic.DataProcessor.RowValue(dr, "Equip_Code", String.Empty); plan.Plan_Serial = Mesnac.Basic.DataProcessor.RowValue(dr, "Plan_Serial", 0); plan.Recipe_ID = Mesnac.Basic.DataProcessor.RowValue(dr, "Recipe_ID", String.Empty); plan.Recipe_Code = Mesnac.Basic.DataProcessor.RowValue(dr, "Recipe_Code", String.Empty); plan.Recipe_Name = Mesnac.Basic.DataProcessor.RowValue(dr, "Recipe_Name", String.Empty); plan.Version = Mesnac.Basic.DataProcessor.RowValue(dr, "Version", String.Empty); plan.Mixer_Line = Mesnac.Basic.DataProcessor.RowValue(dr, "Mixer_Line", String.Empty); plan.Recipe_Type = Mesnac.Basic.DataProcessor.RowValue(dr, "Recipe_Type", 0); plan.Shift_Id = Mesnac.Basic.DataProcessor.RowValue(dr, "Shift_Id", String.Empty); plan.Shift_Class = Mesnac.Basic.DataProcessor.RowValue(dr, "Shift_Class", String.Empty); plan.Plan_Num = Mesnac.Basic.DataProcessor.RowValue(dr, "Plan_Num", 0); plan.Real_Num = Mesnac.Basic.DataProcessor.RowValue(dr, "Real_Num", 0); plan.Duration_Time = Mesnac.Basic.DataProcessor.RowValue(dr, "Plan_Id", 0); plan.Start_Date = Mesnac.Basic.DataProcessor.RowValue(dr, "Start_Date", String.Empty); plan.End_Date = Mesnac.Basic.DataProcessor.RowValue(dr, "End_Date", String.Empty); plan.Weight_Man = Mesnac.Basic.DataProcessor.RowValue(dr, "Weight_Man", String.Empty); plan.Stock_Man = Mesnac.Basic.DataProcessor.RowValue(dr, "Stock_Man", String.Empty); plan.Plan_Batch = Mesnac.Basic.DataProcessor.RowValue(dr, "Plan_Batch", String.Empty); plan.Plan_State = Mesnac.Basic.DataProcessor.RowValue(dr, "Plan_State", 0); plan.Plan_StateText = Mesnac.Basic.DataProcessor.RowValue(dr, "Plan_StateText", String.Empty); plan.Plan_Date = Mesnac.Basic.DataProcessor.RowValue(dr, "Plan_Date", String.Empty); plan.IF_FLAG = Mesnac.Basic.DataProcessor.RowValue(dr, "IF_FLAG", 0); return plan; } else { return null; } } /// /// 把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 = Mesnac.Basic.DataProcessor.RowValue(dr, "Set_Weight", 0.0); plan.Set_Error = Mesnac.Basic.DataProcessor.RowValue(dr, "Set_Error", 0.0); plan.Cpk_Error = Mesnac.Basic.DataProcessor.RowValue(dr, "Cpk_Error", 0.0); return plan; } else { return null; } } /// /// 把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数据行转换为Base_MaterialInfo实体对象 /// /// 要转换的数据行 /// 返回转换后的计划实体对象 public static Base_MaterialInfo ConvertDataRowToPmtMaterial(DataRow dr) { if (dr != null) { Base_MaterialInfo materialInfo = new Base_MaterialInfo(); materialInfo.materialId = Mesnac.Basic.DataProcessor.RowValue(dr, "material_Id", String.Empty); materialInfo.materialName = Mesnac.Basic.DataProcessor.RowValue(dr, "material_Name", String.Empty); materialInfo.materialWeight = Convert.ToDecimal(String.IsNullOrEmpty(Mesnac.Basic.DataProcessor.RowValue(dr, "material_Weight", String.Empty)) ? "0" : Mesnac.Basic.DataProcessor.RowValue(dr, "material_Weight", String.Empty)); materialInfo.putTime = Convert.ToInt32(String.IsNullOrEmpty(Mesnac.Basic.DataProcessor.RowValue(dr, "put_Time", String.Empty)) ? "0" : Mesnac.Basic.DataProcessor.RowValue(dr, "put_Time", String.Empty)); return materialInfo; } else { return null; } } public static Base_CratParamInfo ConvertDataRowToBaseCratParamInfo(DataRow dr) { if (dr != null) { Base_CratParamInfo paramInfo = new Base_CratParamInfo(); paramInfo.paramId = Mesnac.Basic.DataProcessor.RowValue(dr, "param_Id", String.Empty); paramInfo.paramName = Mesnac.Basic.DataProcessor.RowValue(dr, "param_Name", String.Empty); return paramInfo; } else { return null; } } #endregion #region 更新计划日志数据至SysKeyValue数据库 /// /// 更新计划日志数据至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 == 0) { reStr = "待执行"; } else if (stateNum == 1) { reStr = "执行中"; } else if (stateNum == 2) { reStr = "已终止"; } else if (stateNum == 3) { reStr = "已完成"; } return reStr; } #endregion #region 将计划运行状态文字转换为代码 /// /// 将计划运行状态文字转换为代码 /// /// 计划状态代码 /// 显示的文字信息 public static Int32 StateToValue(string stateInfo) { Int32 reStateNum = 0; if (stateInfo == "待执行") { reStateNum = 0; } else if (stateInfo == "执行中") { reStateNum = 1; } else if (stateInfo == "已完成") { reStateNum = 2; } else if (stateInfo == "已终止") { reStateNum = 3; } return reStateNum; } #endregion /// /// 添加生产计划 /// /// 5位机台号 /// 计划生产日期 /// 班次ID /// 班组ID /// 配方GUID /// 配方版本号 /// 计划数 /// 备注 /// 返回新加计划的计划号 public static string SaveBasePlanInfo(Base_PlanInfo base_PlanInfo) { try { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError); } dbHelper.ClearParameter(); dbHelper.CommandType = CommandType.Text; //添加计划的SQL语句 string strSql3 = @"insert into Base_PlanInfo (uid, plan_Id, recipe_Id, recipe_Name, plan_Team, plan_Amount, real_Amount, run_Type, plan_State, grid_Amount,line_Amount,car_Amount,create_By, create_Time,plan_order) VALUES (@uid, @plan_Id, @recipe_Id, @recipe_Name, @plan_Team, @plan_Amount,@real_Amount ,@run_Type, @plan_State, @grid_Amount,@line_Amount,@car_Amount,@create_By, @create_Time,@plan_order)"; dbHelper.CommandText = strSql3; dbHelper.AddParameter("@uid", base_PlanInfo.uid); dbHelper.AddParameter("@plan_Id", base_PlanInfo.plan_Id); dbHelper.AddParameter("@recipe_Id", base_PlanInfo.recipe_Id); dbHelper.AddParameter("@recipe_Name", base_PlanInfo.recipe_Name); dbHelper.AddParameter("@plan_Team", base_PlanInfo.plan_Team); dbHelper.AddParameter("@plan_Amount", base_PlanInfo.plan_Amount); dbHelper.AddParameter("@real_Amount", 0); dbHelper.AddParameter("@run_Type", base_PlanInfo.run_Type); dbHelper.AddParameter("@plan_State", 0); //dbHelper.AddParameter("@plan_beginTime", base_PlanInfo.plan_beginTime); dbHelper.AddParameter("@car_Amount", base_PlanInfo.car_Amount); dbHelper.AddParameter("@grid_Amount", base_PlanInfo.grid_Amount); dbHelper.AddParameter("@line_Amount", base_PlanInfo.line_Amount); dbHelper.AddParameter("@create_By", base_PlanInfo.create_By); dbHelper.AddParameter("@create_Time", base_PlanInfo.create_Time); dbHelper.AddParameter("@plan_order", base_PlanInfo.plan_order); dbHelper.ExecuteNonQuery(); }catch(Exception e) { ICSharpCode.Core.LoggingService.Error("当班计划—添加计划失败"+e.Message); } return base_PlanInfo.plan_Id; } /// /// 根据计划编号获取计划信息 /// /// 计划号 /// 存在返回true,否则返回false public static Base_PlanInfo getPlanInfoByPlanId(string plan_Id) { Base_PlanInfo planInfo = new Base_PlanInfo(); DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError); } dbHelper.CommandType = CommandType.Text; string strSql = "SELECT top 1 * FROM Base_PlanInfo WHERE plan_Id = @plan_Id"; dbHelper.CommandText = strSql; dbHelper.AddParameter("@plan_Id", plan_Id); DataTable table = dbHelper.ToDataTable(); if (table != null && table.Rows.Count > 0) { foreach (DataRow dr in table.Rows) { planInfo = ConvertDataRowToBasePlanInfo(dr); break; } } return planInfo; } public static Base_PlanInfo getNextPlanInfoByOrder(int plan_order) { Base_PlanInfo planInfo = new Base_PlanInfo(); DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError); } dbHelper.CommandType = CommandType.Text; string strSql = "SELECT top 1 * FROM Base_PlanInfo WHERE plan_order > @plan_order"; dbHelper.CommandText = strSql; dbHelper.AddParameter("@plan_order", plan_order); DataTable table = dbHelper.ToDataTable(); if (table != null && table.Rows.Count > 0) { foreach (DataRow dr in table.Rows) { planInfo = ConvertDataRowToBasePlanInfo(dr); break; } } return planInfo; } /// /// 修改计划数据 /// /// /// public static string UpdateBasePlanInfo(Base_PlanInfo base_PlanInfo) { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError); } dbHelper.CommandType = CommandType.Text; string sqlstr = @"update Base_PlanInfo set recipe_Id = @recipe_Id, recipe_Name = @recipe_Name, plan_Amount = @plan_Amount, real_Amount = @real_Amount, run_Type = @run_Type, plan_State = @plan_State,car_Amount = @car_Amount,grid_Amount = @grid_Amount,line_Amount = @line_Amount where uid = @uid"; dbHelper.ClearParameter(); dbHelper.CommandText = sqlstr; dbHelper.AddParameter("@uid", base_PlanInfo.uid); dbHelper.AddParameter("@recipe_Id", base_PlanInfo.recipe_Id); dbHelper.AddParameter("@recipe_Name", base_PlanInfo.recipe_Name); dbHelper.AddParameter("@plan_Amount", base_PlanInfo.plan_Amount); dbHelper.AddParameter("@real_Amount", base_PlanInfo.real_Amount); dbHelper.AddParameter("@run_Type", base_PlanInfo.run_Type); dbHelper.AddParameter("@car_Amount", base_PlanInfo.car_Amount); dbHelper.AddParameter("@grid_Amount", base_PlanInfo.grid_Amount); dbHelper.AddParameter("@line_Amount", base_PlanInfo.line_Amount); dbHelper.AddParameter("@plan_State", base_PlanInfo.plan_State); //dbHelper.AddParameter("@plan_beginTime", base_PlanInfo.plan_beginTime); dbHelper.ExecuteNonQuery(); return base_PlanInfo.plan_Id; } public static string UpdatePlanOrderByPlanId(Base_PlanInfo base_PlanInfo) { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError); } dbHelper.CommandType = CommandType.Text; string sqlstr = @"update Base_PlanInfo set plan_order = @plan_order where plan_Id = @plan_Id"; dbHelper.ClearParameter(); dbHelper.CommandText = sqlstr; dbHelper.AddParameter("@plan_Id", base_PlanInfo.plan_Id); dbHelper.AddParameter("@plan_Order", base_PlanInfo.plan_order); dbHelper.ExecuteNonQuery(); return base_PlanInfo.plan_Id; } /// /// Datatable转为Base_RepiceInfo /// /// /// public static Base_PlanInfo ConvertDataRowToBasePlanInfo(DataRow dr) { if (dr != null) { Base_PlanInfo plan = new Base_PlanInfo(); plan.uid = Mesnac.Basic.DataProcessor.RowValue(dr, "uid", String.Empty); plan.plan_Id = Mesnac.Basic.DataProcessor.RowValue(dr, "plan_Id", String.Empty); plan.recipe_Id = Mesnac.Basic.DataProcessor.RowValue(dr, "recipe_Id", String.Empty); plan.recipe_Name = Mesnac.Basic.DataProcessor.RowValue(dr, "recipe_Name", String.Empty); plan.plan_Amount = Convert.ToInt32(Mesnac.Basic.DataProcessor.RowValue(dr, "plan_Amount", String.Empty)); plan.real_Amount = String.IsNullOrEmpty(Mesnac.Basic.DataProcessor.RowValue(dr, "real_Amount", String.Empty)) ? 0 : Convert.ToInt32(Mesnac.Basic.DataProcessor.RowValue(dr, "real_Amount", String.Empty)); plan.run_Type = Convert.ToInt32(Mesnac.Basic.DataProcessor.RowValue(dr, "run_Type", String.Empty)); plan.plan_State = Convert.ToInt32(Mesnac.Basic.DataProcessor.RowValue(dr, "plan_State", String.Empty)); plan.plan_beginTime = Mesnac.Basic.DataProcessor.RowValue(dr, "plan_beginTime", String.Empty); plan.plan_endTime = Mesnac.Basic.DataProcessor.RowValue(dr, "plan_endTime", String.Empty); plan.car_Amount = Convert.ToInt32(Mesnac.Basic.DataProcessor.RowValue(dr, "car_Amount", String.Empty)); plan.grid_Amount = Convert.ToInt32(Mesnac.Basic.DataProcessor.RowValue(dr, "grid_Amount", String.Empty)); plan.line_Amount = Convert.ToInt32(Mesnac.Basic.DataProcessor.RowValue(dr, "line_Amount", String.Empty)); //plan.create_By = Mesnac.Basic.DataProcessor.RowValue(dr, "create_By", String.Empty); //plan.create_Time = Mesnac.Basic.DataProcessor.RowValue(dr, "create_Time", String.Empty); plan.plan_order = Convert.ToInt32(Mesnac.Basic.DataProcessor.RowValue(dr, "plan_order", String.Empty)); return plan; } else { return null; } } public static Base_PlanInfo getLastPlanInfoByPlanOrder(int plan_order) { Base_PlanInfo planInfo = new Base_PlanInfo(); DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError); } dbHelper.CommandType = CommandType.Text; string strSql = "SELECT top 1 * FROM Base_PlanInfo where plan_order < @plan_order order by plan_order desc"; dbHelper.CommandText = strSql; dbHelper.AddParameter("@plan_order", plan_order); DataTable table = dbHelper.ToDataTable(); if (table != null && table.Rows.Count > 0) { foreach (DataRow dr in table.Rows) { planInfo = ConvertDataRowToBasePlanInfo(dr); break; } } return planInfo; } public static Base_PlanInfo getNextPlanInfoByPlanOrder(int plan_order) { Base_PlanInfo planInfo = new Base_PlanInfo(); DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError); } dbHelper.CommandType = CommandType.Text; string strSql = "SELECT top 1 * FROM Base_PlanInfo where plan_order > @plan_order order by plan_order asc"; dbHelper.CommandText = strSql; dbHelper.AddParameter("@plan_order", plan_order); DataTable table = dbHelper.ToDataTable(); if (table != null && table.Rows.Count > 0) { foreach (DataRow dr in table.Rows) { planInfo = ConvertDataRowToBasePlanInfo(dr); break; } } return planInfo; } public static string getPlanIDByPlanInfo() { string PlanID = ""; string starttime = DateTime.Now.ToString("yyyy-MM-dd")+" 00:00:00"; string endtime = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") + " 00:00:00"; DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError); } dbHelper.CommandType = CommandType.Text; string strSql = "SELECT top 1 plan_Id FROM Base_PlanInfo where create_Time > @starttime and create_Time < @endtime order by create_Time desc"; dbHelper.CommandText = strSql; dbHelper.ClearParameter(); dbHelper.AddParameter("@starttime", starttime); dbHelper.AddParameter("@endtime", endtime); DataTable table = dbHelper.ToDataTable(); if (table != null && table.Rows.Count > 0) { Base_MaterialInfo entity = null; foreach (DataRow dr in table.Rows) { PlanID = Mesnac.Basic.DataProcessor.RowValue(dr, "plan_Id", String.Empty); } } return PlanID; } #region 冠合数据库计划信息表操作 public static bool UpdateBasePlanStateInfo(Base_PlanInfo base_PlanInfo) { bool iFlag = false; string sqlstr = ""; try { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError); } dbHelper.CommandType = CommandType.Text; sqlstr = @"update Base_PlanInfo set plan_State = @plan_State, plan_beginTime = @plan_beginTime, plan_endTime = @plan_endTime where uid = @uid and plan_Id = @plan_Id "; dbHelper.ClearParameter(); dbHelper.CommandText = sqlstr; dbHelper.AddParameter("@uid", base_PlanInfo.uid); dbHelper.AddParameter("@plan_Id", base_PlanInfo.plan_Id); dbHelper.AddParameter("@plan_State", base_PlanInfo.plan_State); dbHelper.AddParameter("@plan_beginTime", base_PlanInfo.plan_beginTime); dbHelper.AddParameter("@plan_endTime", base_PlanInfo.plan_endTime); dbHelper.ExecuteNonQuery(); iFlag = true; return iFlag; } catch (Exception ex) { return iFlag; } } public static bool UpdatePlanInfo(Base_PlanInfo base_PlanInfo) { bool iFlag = false; string sqlstr = ""; try { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError); } dbHelper.CommandType = CommandType.Text; sqlstr = @"update Base_PlanInfo set recipe_Id = @recipe_Id,recipe_Name = @recipe_Name,plan_Team = @plan_Team,plan_Amount = @plan_Amount,real_Amount = @real_Amount,run_Type = @run_Type,plan_State = @plan_State, plan_beginTime = @plan_beginTime, plan_endTime = @plan_endTime where uid = @uid and plan_Id = @plan_Id "; dbHelper.ClearParameter(); dbHelper.CommandText = sqlstr; dbHelper.AddParameter("@uid", base_PlanInfo.uid); dbHelper.AddParameter("@recipe_Id", base_PlanInfo.recipe_Id); dbHelper.AddParameter("@recipe_Name", base_PlanInfo.recipe_Name); dbHelper.AddParameter("@plan_Team", base_PlanInfo.plan_Team); dbHelper.AddParameter("@plan_Amount", base_PlanInfo.plan_Amount); dbHelper.AddParameter("@real_Amount", base_PlanInfo.real_Amount); dbHelper.AddParameter("@run_Type", base_PlanInfo.run_Type); dbHelper.AddParameter("@plan_State", base_PlanInfo.plan_State); dbHelper.AddParameter("@plan_beginTime", base_PlanInfo.plan_beginTime); dbHelper.AddParameter("@plan_endTime", base_PlanInfo.plan_endTime); dbHelper.AddParameter("@plan_Id", base_PlanInfo.plan_Id); dbHelper.ExecuteNonQuery(); iFlag = true; return iFlag; } catch (Exception ex) { return iFlag; } } #endregion } }