using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using System.Windows.Forms; using ICSharpCode.Core; using Mesnac.Codd.Session; using Mesnac.Action.Base; using System.Reflection; using System.Configuration; namespace Mesnac.Action.ChemicalWeighing.Technical.XlRecipe { /// /// 工艺配方辅助类 /// public class RecipeHelper { #region 静态属性定义 #region 配方码表业务 #region 配方主信息 - 获取配方类型列表 /// /// 配方主信息 - 配方类型列表 /// public static DataTable RecipeTypeList { get { if (BaseDataHelper.SysCode.ContainsKey("PmtType")) { DataTable dt = BaseDataHelper.SysCode["PmtType"]; DataTable table = BaseDataHelper.CloneDataTable(dt); return table; } else { return null; } } } #endregion #region 配方主信息 - 获取配方状态列表 /// /// 配方主信息 - 配方状态列表 /// public static DataTable RecipeStateList { get { if (BaseDataHelper.SysCode.ContainsKey("PmtState")) { DataTable dt = BaseDataHelper.SysCode["PmtState"]; DataTable table = BaseDataHelper.CloneDataTable(dt); return table; } else { return null; } } } #endregion #endregion #endregion #region 静态方法定义 #region 界面处理业务 #region 获取控件所属设备单元编号 /// /// 获取控件所属设备单元编号 /// /// 控件参数 /// 返回控件所属设备单元 public static string GetUnitNumByControl(Control c) { if (c == null) { return String.Empty; } if (c.Parent == null) { return String.Empty; } else { if (c.Parent.Tag == null) { return GetUnitNumByControl(c.Parent); } else { return c.Parent.Tag as string; } } } #endregion #region 获取控件自身设备单元编号 /// /// 获取控件自身设备单元编号 /// /// 控件参数 /// 返回控件自身设备单元 public static string GetItselfUnitNumByControl(Control c) { if (c == null) { return String.Empty; } else { if (c.Tag == null) { return String.Empty; } else { return c.Tag as string; } } } #endregion #region 网格头辅助方法-如果为0则转换为null /// /// 如果为0则转换为null /// /// /// /// public static void Is0ToNull(DataGridView dgv, int rowInx, int colInx) { if (rowInx >= 0 && colInx >= 0 && (dgv.Columns[colInx] is DataGridViewTextBoxColumn) && ( ((DataGridViewTextBoxColumn)dgv.Columns[colInx]).ValueType == typeof(double) || ((DataGridViewTextBoxColumn)dgv.Columns[colInx]).ValueType == typeof(decimal) || ((DataGridViewTextBoxColumn)dgv.Columns[colInx]).ValueType == typeof(int))) { if (dgv.Rows[rowInx].Cells[colInx].Value != null && dgv.Rows[rowInx].Cells[colInx].Value != DBNull.Value) { double d = 0.0; if (!double.TryParse(dgv.Rows[rowInx].Cells[colInx].Value.ToString(), out d)) { dgv.CancelEdit(); } else if (d == 0) { dgv.Rows[rowInx].Cells[colInx].Value = DBNull.Value; } } } } #endregion #region 网格头辅助方法-初始化网格控件事件 /// /// 初始化网格控件事件 /// /// public static void InitDataGridEvent(DataGridView grid) { grid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None; grid.DataError -= grid_DataError; grid.DataError += grid_DataError; //grid.CellValueChanged -= grid_CellValueChanged; //grid.CellValueChanged += grid_CellValueChanged; grid.CellValidating -= grid_CellValidating; grid.CellValidating += grid_CellValidating; grid.CellMouseDown -= grid_CellMouseDown; grid.CellMouseDown += grid_CellMouseDown; grid.SortCompare -= grid_SortCompare; grid.SortCompare += grid_SortCompare; grid.AllowUserToAddRows = false; grid.ReadOnly = false; grid.AutoGenerateColumns = false; grid.AllowUserToResizeRows = false; grid.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnEnter; } #region 事件处理方法 private static void grid_DataError(object sender, DataGridViewDataErrorEventArgs e) { DataGridView dgv = (DataGridView)sender; dgv.CancelEdit(); e.Cancel = true; } private static void grid_CellValueChanged(object sender, DataGridViewCellEventArgs e) { DataGridView dgv = (DataGridView)sender; if (dgv.Columns[e.ColumnIndex].DataPropertyName == "MaterialName") { dgv.Rows[e.RowIndex].Cells[e.ColumnIndex + 1].Value = dgv.Rows[e.RowIndex].Cells[e.ColumnIndex].Value; } Is0ToNull(dgv, e.RowIndex, e.ColumnIndex); } private static void grid_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { if (string.IsNullOrWhiteSpace(e.FormattedValue.ToString())) { return; } DataGridView dgv = (DataGridView)sender; Is0ToNull(dgv, e.RowIndex, e.ColumnIndex); } private static void grid_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e) { if (e.Button == MouseButtons.Right) { if (e.RowIndex >= 0) { DataGridView dgv = (DataGridView)sender; dgv.ClearSelection(); dgv.Rows[e.RowIndex].Selected = true; dgv.CurrentCell = dgv.Rows[e.RowIndex].Cells[e.ColumnIndex]; } } } private static void grid_SortCompare(object sender, DataGridViewSortCompareEventArgs e) { DataGridView dgv = (DataGridView)sender; e.SortResult = Convert.ToInt32(dgv.Rows[e.RowIndex1].Cells[0].Value.ToString()) - Convert.ToInt32(dgv.Rows[e.RowIndex2].Cells[0].Value.ToString()); e.Handled = true; } #endregion #endregion #region 根据GridView控件是否为只读,判断当前配方是否处于编辑状态 /// /// 根据GridView控件是否为只读,判断当前配方是否处于编辑状态 /// public static bool IsEditMode(Mesnac.Action.Base.BaseAction baseAction) { bool flag = true; List gridList = baseAction.GetTControls(); foreach (Mesnac.Controls.Default.MCDataGridView grid in gridList) { string unitNum = RecipeHelper.GetUnitNumByControl(grid); if (Basic.BasicHelper.BasEquip.StrUnitList.Contains(unitNum) && grid.ReadOnly == true) { flag = false; break; } } return flag; } #endregion #region 禁用、启用界面控件 /// /// 禁用、启用界面控件 /// /// Action对象 /// true为启用,false为禁用 public static void SetRecipeUIEnabled(Mesnac.Action.Base.BaseAction baseAction, bool flag) { foreach (Mesnac.Controls.Base.IBaseControl control in baseAction.GetAllMCControls()) { if (baseAction.DbOptionTypesIsModify(control) && !control.MCKey.Contains("[PmtRecipe].[GUID]") && !control.MCKey.Contains("[PmtRecipe].[RecipeType].Query")) { string unitNum = GetUnitNumByControl(control as Control); if (!String.IsNullOrEmpty(unitNum)) { if (Basic.BasicHelper.BasEquip.StrUnitList.Contains(unitNum.Trim())) { control.MCEnabled = flag; } } else { control.MCEnabled = flag; } } } List gridList = baseAction.GetTControls(); foreach (Mesnac.Controls.Default.MCDataGridView grid in gridList) { string unitNum = GetUnitNumByControl(grid as Control); if (Basic.BasicHelper.BasEquip.StrUnitList.Contains(unitNum.Trim())) { grid.ReadOnly = !flag; if (grid.ContextMenuStrip != null) { grid.ContextMenuStrip.Enabled = flag; } if (grid.MCKey != null && (grid.MCKey.Contains("[PmtMixWeight]") || grid.MCKey.Contains("[PmtMillWeight]"))) { if (grid.Columns.Contains("WeightID")) { grid.Columns["WeightID"].ReadOnly = true; } if (grid.Columns.Contains("MaterialCode")) { grid.Columns["MaterialCode"].ReadOnly = true; } if (grid.Columns.Contains("MaterialIKindName")) { grid.Columns["MaterialIKindName"].ReadOnly = true; } } if (grid.MCKey != null && (grid.MCKey.Contains("[PmtMixStep]") || grid.MCKey.Contains("[PmtMillStep]") || grid.MCKey.Contains("[PmtMixTempCurve]"))) { if (grid.Columns.Contains("MixStep")) { grid.Columns["MixStep"].ReadOnly = true; } if (grid.Columns.Contains("MillStep")) { grid.Columns["MillStep"].ReadOnly = true; } if (grid.Columns.Contains("SeqIndex")) { grid.Columns["SeqIndex"].ReadOnly = true; } } } } } #endregion #region 重置选中的配方 /// /// 重置选中的配方 /// /// 当前action对象 /// 要选中的配方 //public static void ResetSelectRecipe(BaseAction action, Entity.Pmt_recipe defaultRecipe) //{ // Control cmbRecipeMaterialGUID = action.GetControlById("cbMaterialGUID"); // Control cmbRecipeVersion = action.GetControlById("cbRecipeVersion"); // if (cmbRecipeMaterialGUID == null || !(cmbRecipeMaterialGUID is ComboBox)) // { // ICSharpCode.Core.LoggingService.Warn("配方管理-选择配方-缺少配方物料列表组合框控件!"); // return; // } // if (cmbRecipeVersion == null || !(cmbRecipeVersion is ComboBox)) // { // ICSharpCode.Core.LoggingService.Warn("配方管理-选择配方-缺少配方版本列表组合框控件!"); // return; // } // ComboBox cbRecipeMaterialGUID = cmbRecipeMaterialGUID as ComboBox; // ComboBox cbRecipeVersion = cmbRecipeVersion as ComboBox; // Entity.SimplePmtRecipe originalSelectRecipe = cbRecipeMaterialGUID.SelectedItem as Entity.SimplePmtRecipe; // string originalRecipeVersion = cbRecipeVersion.SelectedItem as string; // int recipeType = BaseDataHelper.GetSysValue("Recipe.LastRecipeType", 0); // int recipeState = BaseDataHelper.GetSysValue("Recipe.LastRecipeState", 1); // cbRecipeMaterialGUID.Text = String.Empty; // List lst = TechnicalHelper.GetRecipeMaterialListPY(recipeType, recipeState, String.Empty); // (cmbRecipeMaterialGUID as Mesnac.Controls.Base.IBaseControl).IsEventValid = false; // (cmbRecipeVersion as Mesnac.Controls.Base.IBaseControl).IsEventValid = false; // cbRecipeMaterialGUID.DataSource = null; // cbRecipeVersion.DataSource = null; // (cmbRecipeMaterialGUID as Mesnac.Controls.Base.IBaseControl).IsEventValid = true; // (cmbRecipeVersion as Mesnac.Controls.Base.IBaseControl).IsEventValid = true; // cbRecipeMaterialGUID.Items.Clear(); // cbRecipeVersion.Items.Clear(); // foreach (Entity.SimplePmtRecipe r in lst) // { // cbRecipeMaterialGUID.Items.Add(r); // } // if (defaultRecipe != null && !String.IsNullOrEmpty(defaultRecipe.MaterialGUID)) // { // foreach (object item in cbRecipeMaterialGUID.Items) // { // if ((item as Entity.SimplePmtRecipe).MaterialGUID == defaultRecipe.MaterialGUID) // { // cbRecipeMaterialGUID.SelectedItem = item; // break; // } // } // } // else // { // bool flag = false; // if (originalSelectRecipe != null) // { // foreach (object item in cbRecipeMaterialGUID.Items) // { // if ((item as Entity.SimplePmtRecipe).MaterialGUID.Equals(originalSelectRecipe.MaterialGUID, StringComparison.CurrentCultureIgnoreCase)) // { // cbRecipeMaterialGUID.SelectedItem = item; // flag = true; // break; // } // } // } // if (!flag) // { // //如果未设置默认选中的项,则默认选中第一项 // foreach (object item in cbRecipeMaterialGUID.Items) // { // cbRecipeMaterialGUID.SelectedItem = item; // break; // } // } // } // if (defaultRecipe != null) // { // cbRecipeVersion.SelectedItem = defaultRecipe.RecipeVersion; // } // else // { // if (!String.IsNullOrEmpty(originalRecipeVersion)) // { // cbRecipeVersion.SelectedItem = originalRecipeVersion; // } // } //} #endregion #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 #endregion #region 配方数据业务 #region 配方业务 #region 查询业务 #region GenerateNextRecipeCode 获取下一个可用的配方编码 (1位物料大类、2位物料细类、10位流水) /// /// 获取下一个可用的配方编码 (13位物料编码、10位版本号) /// /// 配方物料编码 /// 配方版本 /// 返回配方编码 public static string GenerateNextRecipeCode(string recipeMaterialCode, string recipeVersion) { string result = String.Format("{0}{1}", recipeMaterialCode, recipeVersion); return result; } #endregion #region GenerateNextRecipeVersion 根据配方物料GUID获取下一个可用的配方版本号 /// /// 根据配方物料GUID获取下一个可用的配方版本号 /// /// 配方物料GUID /// 返回下一个可用的配方版本号 public static string GenerateNextRecipeVersion(string recipeMaterialGUID) { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError); } string sqlstr = "select MAX(RecipeVersion) from PmtRecipe where MaterialGUID = @MaterialGUID"; dbHelper.CommandType = CommandType.Text; dbHelper.ClearParameter(); dbHelper.CommandText = sqlstr; dbHelper.AddParameter("@MaterialGUID", recipeMaterialGUID); object result = dbHelper.ToScalar(); if (Mesnac.Basic.DataProcessor.IsNullOrEmpty(result)) { return String.Format("{0:yyyyMMdd}01", DateTime.Now); } else { string recipeVersion = result.ToString(); if (String.Format("{0:yyyyMMdd}", DateTime.Now) == recipeVersion.Substring(0,8)) { int serialNum = Convert.ToInt32(recipeVersion.Substring(8, 2)); serialNum++; return String.Format("{0:yyyyMMdd}", DateTime.Now) + Mesnac.Basic.DataProcessor.FillZero(serialNum.ToString(), 2); } else { return String.Format("{0:yyyyMMdd}01", DateTime.Now); } } } #endregion #region 判断某个配方是否存在 /// /// 判断某个配方是否存在(根据ID) /// /// 配方ID /// 存在返回true,不存在返回false public static bool IsExists(string recipeID) { 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 sqlstr = "select count(ID) from xl_recipe where ID = @RecipeID"; dbHelper.CommandText = sqlstr; dbHelper.AddParameter("@RecipeID", recipeID); object result = dbHelper.ToScalar(); if (result != null && result != System.DBNull.Value) { int intResult = 0; int.TryParse(result.ToString(), out intResult); if (intResult > 0) { return true; } } return false; } /// /// 判断某个配方是否存在(根据ID) /// /// 配方ID /// 存在返回true,不存在返回false public static bool IsExists(string recipeName, string Version) { 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 sqlstr = "select count(ID) from xl_recipe where Recipe_Name = @Recipe_Name and Version=@Version"; dbHelper.CommandText = sqlstr; dbHelper.AddParameter("@Recipe_Name", recipeName); dbHelper.AddParameter("@Version", Version); object result = dbHelper.ToScalar(); if (result != null && result != System.DBNull.Value) { int intResult = 0; int.TryParse(result.ToString(), out intResult); if (intResult > 0) { return true; } } return false; } /// /// 判断某个配方是否存在(根据ID) /// /// 配方ID /// 存在返回true,不存在返回false public static bool IsExistsName(string recipeName,string Version) { 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 sqlstr = "select count(ID) from xl_recipe where Recipe_Name = @Recipe_Name and Version=@Version"; dbHelper.CommandText = sqlstr; dbHelper.AddParameter("@Recipe_Name", recipeName); dbHelper.AddParameter("@Version", Version); object result = dbHelper.ToScalar(); if (result != null && result != System.DBNull.Value) { int intResult = 0; int.TryParse(result.ToString(), out intResult); if (intResult > 0) { return true; } } return false; } #endregion #region 根据配方类型和配方状态获取配方列表 /// /// 根据配方类型和配方状态获取配方列表 /// /// 配方类型 /// 配方状态 /// 返回符合条件的配方列表 public static DataTable GetRecipeListForSelect(int recipeType, string recipeState) { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError); } string sqlstr = String.Empty; if (String.IsNullOrEmpty(recipeState)) { sqlstr = @"select * from ( select '' as GUID,'{0}' as ShowName, GETDATE() as LastModifyTime union ALL select TA.GUID,rtrim(TA.RecipeMaterialName)+'('+rtrim(isnull(TB.ItemName,''))+')'+'['+rtrim(TA.RecipeVersion)+']' as ShowName, TA.LastModifyTime from PmtRecipe TA left join SysCode TB on TA.RecipeType = TB.ItemCode where TA.DeleteFlag='0' and TA.RecipeType = @RecipeType and TB.TypeID='PmtType' ) as temp order by LastModifyTime desc"; } else { sqlstr = @"select * from ( select '' as GUID,'{0}' as ShowName, GETDATE() as LastModifyTime union ALL select TA.GUID,rtrim(TA.RecipeMaterialName)+'('+rtrim(isnull(TB.ItemName,''))+')'+'['+rtrim(TA.RecipeVersion)+']' as ShowName, TA.LastModifyTime from PmtRecipe TA left join SysCode TB on TA.RecipeType = TB.ItemCode where TA.DeleteFlag='0' and TA.RecipeType = @RecipeType and TA.RecipeState = @RecipeState and TB.TypeID='PmtType' ) as temp order by LastModifyTime desc"; } sqlstr = String.Format(sqlstr, Mesnac.Basic.LanguageHelper.PleaseSelect); dbHelper.CommandType = CommandType.Text; dbHelper.ClearParameter(); dbHelper.CommandText = sqlstr; dbHelper.AddParameter("@RecipeType", recipeType); if (!String.IsNullOrEmpty(recipeState)) { dbHelper.AddParameter("@RecipeState", recipeState); } DataTable dt = dbHelper.ToDataTable(); return dt; } #endregion #region 根据配方物料GUID和配方版本查询配方GUID /// /// 根据配方物料GUID和配方版本查询配方GUID /// /// 配方物料GUID /// 配方版本 /// 返回对应的配方GUID public static string GetRecipeGUID(string recipeMaterialGUID, string recipeVersion) { 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 = "select GUID from PmtRecipe where MaterialGUID = @MaterialGUID and RecipeVersion = @RecipeVersion"; dbHelper.CommandText = sqlstr; dbHelper.ClearParameter(); dbHelper.AddParameter("@MaterialGUID", recipeMaterialGUID); dbHelper.AddParameter("@RecipeVersion", recipeVersion); object result = dbHelper.ToScalar(); if (!Mesnac.Basic.DataProcessor.IsNullOrEmpty(result)) { return result as string; } return String.Empty; } #endregion #region 判断是否存在某种物料的配方 /// /// 判断是否存在某种物料的配方 /// /// 配方物料GUID /// 存在返回true,不存在返回false public static bool ExistsRecipeMaterialGUID(string recipeMaterialGUID) { 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 = "select count(GUID) from PmtRecipe where DeleteFlag = '0' and MaterialGUID = @MaterialGUID"; dbHelper.CommandText = sqlstr; dbHelper.ClearParameter(); dbHelper.AddParameter("@MaterialGUID", recipeMaterialGUID); object result = dbHelper.ToScalar(); if (!Mesnac.Basic.DataProcessor.IsNullOrEmpty(result)) { int intResult = 0; int.TryParse(result.ToString(), out intResult); if (intResult > 0) { return true; } } return false; } #endregion #region 查询配方主信息 /// /// 获取所有配方列表 /// public static DataTable GetAllRecipeDT() { 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 *, case Recipe_Verify when '1' then '是' else '否' end as 'RecipeVerify' from xl_recipe order by End_datetime desc"; dbHelper.CommandText = sqlstr; DataTable dt = dbHelper.ToDataTable(); return dt; } /// /// 根据配方名称获取配方信息 /// /// 配方名称 /// 返回符合条件的配方 public static Entity.xl_recipe GetRecipeByName(string recipeID) { Entity.xl_recipe pmtRecipe = new Entity.xl_recipe(); 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 xl_recipe WHERE ID = @ID"; dbHelper.CommandText = strSql; dbHelper.ClearParameter(); dbHelper.AddParameter("@ID", recipeID); DataTable table = dbHelper.ToDataTable(); if (table != null && table.Rows.Count > 0) { foreach (DataRow dr in table.Rows) { pmtRecipe = ConvertDataRowToRecipeEntity(dr); break; } } return pmtRecipe; } /// /// 获取配方主信息 /// /// 配方GUID /// 返回配方主信息DataRow public static DataRow GetRecipeByGUID(string recipeGUID) { return BaseDataHelper.GetDataRowByTableAndGUID("xl_recipe", recipeGUID); } /// /// 获取配方主信息 /// /// 配方GUID /// 配方版本 /// 返回配方主信息DataRow public static DataRow GetRecipeByGUID(string recipeGUID, string recipeVersion) { 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 * from PmtRecipe where GUID = @RecipeGUID and RecipeVersion = @RecipeVersion"; dbHelper.CommandText = sqlstr; dbHelper.AddParameter("@RecipeGUID", recipeGUID); dbHelper.AddParameter("@RecipeVersion", recipeVersion); DataTable dt = dbHelper.ToDataTable(); if (dt != null && dt.Rows.Count > 0) { return dt.Rows[0]; } else { return null; } } /// /// 获取配方主信息 /// /// 配方物料名称 /// 配方版本 /// 返回配方主信息DataRow public static DataRow GetRecipeByRecipeMaterialName(string recipeMaterialName, string recipeVersion) { 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 * from PmtRecipe where RecipeMaterialName = @RecipeMaterialName and RecipeVersion = @RecipeVersion"; dbHelper.CommandText = sqlstr; dbHelper.AddParameter("@RecipeMaterialName", recipeMaterialName); dbHelper.AddParameter("@RecipeVersion", recipeVersion); DataTable dt = dbHelper.ToDataTable(); if (dt != null && dt.Rows.Count > 0) { return dt.Rows[0]; } else { return null; } } /// /// 获取配方主信息实体对象 /// /// 配方GUID /// 返回配方主信息实体对象 public static Entity.xl_recipe GetRecipeEntityByGUID(string recipeGUID) { DataRow dr = GetRecipeByGUID(recipeGUID); Entity.xl_recipe recipe = ConvertDataRowToRecipeEntity(dr); return recipe; } /// /// 获取配方主信息实体对象 /// /// 配方GUID /// 配方版本 /// 返回配方主信息实体对象 public static Entity.xl_recipe GetRecipeEntityByGUID(string recipeGUID, string recipeVersion) { DataRow dr = GetRecipeByGUID(recipeGUID, recipeVersion); Entity.xl_recipe recipe = ConvertDataRowToRecipeEntity(dr); return recipe; } /// /// 获取配方主信息实体对象 /// /// 配方物料名称 /// 配方版本 /// 返回配方主信息实体对象 public static Entity.xl_recipe GetRecipeEntityByRecipeMaterialName(string recipeMaterialName, string recipeVersion) { DataRow dr = GetRecipeByRecipeMaterialName(recipeMaterialName, recipeVersion); Entity.xl_recipe recipe = ConvertDataRowToRecipeEntity(dr); return recipe; } /// /// 把DataRow的数据封装至配方实体 /// /// 配方数据行 /// 返回封装号的配方实体对象 public static Entity.xl_recipe ConvertDataRowToRecipeEntity(DataRow dr) { if (dr != null) { Entity.xl_recipe recipe = new Entity.xl_recipe(); recipe.ID = Mesnac.Basic.DataProcessor.RowValue(dr, "ID", String.Empty); recipe.Equip_Code = Mesnac.Basic.DataProcessor.RowValue(dr, "Equip_Code", String.Empty); recipe.Recipe_Code = Mesnac.Basic.DataProcessor.RowValue(dr, "Recipe_Code", String.Empty); recipe.Version = Mesnac.Basic.DataProcessor.RowValue(dr, "Version", String.Empty); recipe.Recipe_Name = Mesnac.Basic.DataProcessor.RowValue(dr, "Recipe_Name", String.Empty); recipe.Mixer_line = Mesnac.Basic.DataProcessor.RowValue(dr, "Mixer_line", String.Empty); recipe.Recipe_type = Mesnac.Basic.DataProcessor.RowValue(dr, "Recipe_type", 0); recipe.Recipe_Used = Mesnac.Basic.DataProcessor.RowValue(dr, "Recipe_Used", 0); recipe.Recipe_Verify = Mesnac.Basic.DataProcessor.RowValue(dr, "Recipe_Verify", 0); recipe.Total_Weight = Mesnac.Basic.DataProcessor.RowValue(dr, "Total_Weight", 0.0M); recipe.Total_Error = Mesnac.Basic.DataProcessor.RowValue(dr, "Total_Error", 0.0M); recipe.End_datetime = Mesnac.Basic.DataProcessor.RowValue(dr, "End_datetime", String.Empty); recipe.Remark = Mesnac.Basic.DataProcessor.RowValue(dr, "Remark", String.Empty); recipe.Attach_User = Mesnac.Basic.DataProcessor.RowValue(dr, "Attach_User", 0); recipe.GroupBags = Mesnac.Basic.DataProcessor.RowValue(dr, "GroupBags", 0); recipe.IF_FLAG = Mesnac.Basic.DataProcessor.RowValue(dr, "IF_FLAG", 0); recipe.Validity = Mesnac.Basic.DataProcessor.RowValue(dr, "Validity", 0); return recipe; } else { return null; } } #endregion #region 查询配方物料GUID /// /// 查询配方物料GUID /// /// 配方物料名称 /// 配方版本 /// 返回对应的配方物料GUID public static string GetRecipeMaterialGUID(string recipeMaterialName, string recipeVersion) { 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 = "select top 1 MaterialGUID from PmtRecipe where RecipeMaterialName = @RecipeMaterialName and RecipeVersion = @RecipeVersion"; dbHelper.CommandText = sqlstr; dbHelper.ClearParameter(); dbHelper.AddParameter("@RecipeMaterialName", recipeMaterialName); dbHelper.AddParameter("@RecipeVersion", recipeVersion); object result = dbHelper.ToScalar(); if (result != null && result != System.DBNull.Value) { return result.ToString(); } else { return String.Empty; } } #endregion #endregion #region 保存业务 #region 保存配方主信息 /// /// 保存配方主信息 /// /// 配方主信息对象 /// 返回当前配方的GUID public static string SaveRecipe(Entity.Pmt_recipe recipe) { #region 每次保存都生成一个新的配方版本 recipe.ID = String.Empty; recipe.Version = RecipeHelper.GenerateNextRecipeVersion(recipe.ID); //每次生成一个新版本 recipe.Recipe_Code = RecipeHelper.GenerateNextRecipeCode(recipe.Recipe_Code, recipe.Version); //设置配方编码为配方物料编码+配方版本号 #endregion 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 = String.Empty; if (string.IsNullOrEmpty(recipe.ID) || !IsExists(recipe.ID)) { //添加新配方 sqlstr = @"insert into PmtRecipe(GUID, MaterialGUID, RecipeMaterialCode, RecipeMaterialName, RecipeCode, RecipeName, RecipeDesc, RecipeVersion, RecipeType, RecipeState, ShelfLotCount, LotTotalWeight, CreateTime, CreateActor, LastModifyTime, LastModifyActor, DataSource, DeleteFlag) values(@GUID, @MaterialGUID, @RecipeMaterialCode, @RecipeMaterialName, @RecipeCode, @RecipeName, @RecipeDesc, @RecipeVersion, @RecipeType, @RecipeState, @ShelfLotCount, @LotTotalWeight, @CreateTime, @CreateActor, @LastModifyTime, @LastModifyActor, @DataSource, @DeleteFlag)"; recipe.ID = Guid.NewGuid().ToString().ToUpper(); } else { //更新原有配方 sqlstr = @"update PmtRecipe set MaterialGUID=@MaterialGUID, RecipeMaterialCode=@RecipeMaterialCode, RecipeMaterialName=@RecipeMaterialName, RecipeCode=@RecipeCode, RecipeName=@RecipeName, RecipeDesc=@RecipeDesc, RecipeVersion=@RecipeVersion, RecipeType=@RecipeType, RecipeState=@RecipeState, ShelfLotCount=@ShelfLotCount, LotTotalWeight=@LotTotalWeight, CreateTime=@CreateTime, CreateActor=@CreateActor, LastModifyTime=@LastModifyTime, LastModifyActor=@LastModifyActor, DataSource=@DataSource, DeleteFlag=@DeleteFlag where GUID = @GUID"; } dbHelper.ClearParameter(); dbHelper.CommandText = sqlstr; //dbHelper.AddParameter("@GUID", recipe.GUID); //dbHelper.AddParameter("@MaterialGUID", recipe.MaterialGUID); //dbHelper.AddParameter("@RecipeMaterialCode", recipe.RecipeMaterialCode); //dbHelper.AddParameter("@RecipeMaterialName", recipe.RecipeMaterialName); //dbHelper.AddParameter("@RecipeCode", recipe.RecipeCode); //dbHelper.AddParameter("@RecipeName", recipe.RecipeName); //dbHelper.AddParameter("@RecipeDesc", recipe.RecipeDesc); //dbHelper.AddParameter("@RecipeVersion", recipe.RecipeVersion); //dbHelper.AddParameter("@RecipeType", recipe.RecipeType); //dbHelper.AddParameter("@RecipeState", recipe.RecipeState); //dbHelper.AddParameter("@ShelfLotCount", recipe.ShelfLotCount); //dbHelper.AddParameter("@LotTotalWeight", recipe.LotTotalWeight); //dbHelper.AddParameter("@CreateTime", recipe.CreateTime); //dbHelper.AddParameter("@CreateActor", recipe.CreateActor); //dbHelper.AddParameter("@LastModifyTime", DateTime.Now); //dbHelper.AddParameter("@LastModifyActor", Mesnac.Basic.UserInfo.Instance.UserName); //dbHelper.AddParameter("@DataSource", recipe.DataSource); //dbHelper.AddParameter("@DeleteFlag", recipe.DeleteFlag); dbHelper.ExecuteNonQuery(); return recipe.ID; } /// /// 保存配方主信息 /// /// 配方主信息对象 /// 返回当前配方的GUID public static string InsertRecipe(Entity.xl_recipe recipe) { 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 = String.Empty; if (!IsExists(recipe.ID)) { //添加新配方 sqlstr = @"insert into xl_recipe(ID, Equip_Code, Recipe_Code, Version, Recipe_Name, Mixer_line, Recipe_type, Recipe_Used, Recipe_Verify, Total_Weight, Total_Error, End_datetime, Remark, Attach_User, GroupBags, IF_FLAG, Validity, ValidDays,CreatorID,Creator,CreateDateTime) values(@ID, @Equip_Code, @Recipe_Code, @Version, @Recipe_Name, @Mixer_line, @Recipe_type, @Recipe_Used, @Recipe_Verify, @Total_Weight, @Total_Error, @End_datetime, @Remark, @Attach_User, @GroupBags, @IF_FLAG, @Validity, @ValidDays,@CreatorID,@Creator,@CreateDateTime)"; } else { //更新原有配方 sqlstr = @"update xl_recipe set Equip_Code=@Equip_Code, Recipe_Code=@Recipe_Code, Version=@Version, Recipe_Name=@Recipe_Name, Mixer_line=@Mixer_line, Recipe_type=@Recipe_type, Recipe_Used=@Recipe_Used, Recipe_Verify=@Recipe_Verify, Total_Weight=@Total_Weight, Total_Error=@Total_Error, End_datetime=@End_datetime, Remark=@Remark, Attach_User=@Attach_User, GroupBags=@GroupBags, IF_FLAG=@IF_FLAG, Validity=@Validity, ValidDays=@ValidDays where ID = @ID"; } dbHelper.ClearParameter(); dbHelper.CommandText = sqlstr; dbHelper.AddParameter("@ID", recipe.ID); dbHelper.AddParameter("@Equip_Code", ConfigurationManager.AppSettings["EquipCode"]); dbHelper.AddParameter("@Recipe_Code", recipe.Recipe_Code); dbHelper.AddParameter("@Version", recipe.Version); dbHelper.AddParameter("@Recipe_Name", recipe.Recipe_Name); dbHelper.AddParameter("@Mixer_line", recipe.Mixer_line); dbHelper.AddParameter("@Recipe_type", null); dbHelper.AddParameter("@Recipe_Used", null); dbHelper.AddParameter("@Recipe_Verify", recipe.Recipe_Verify); dbHelper.AddParameter("@Total_Weight", recipe.Total_Weight); dbHelper.AddParameter("@Total_Error", recipe.Total_Error); dbHelper.AddParameter("@End_datetime", recipe.End_datetime); dbHelper.AddParameter("@Remark", recipe.Remark); dbHelper.AddParameter("@Attach_User", null); dbHelper.AddParameter("@GroupBags", recipe.GroupBags); dbHelper.AddParameter("@IF_FLAG", null); dbHelper.AddParameter("@Validity", null); dbHelper.AddParameter("@ValidDays", null); if (!IsExists(recipe.ID)) { dbHelper.AddParameter("@CreatorID", null); dbHelper.AddParameter("@Creator", null); dbHelper.AddParameter("@CreateDateTime", DateTime.Now); } dbHelper.ExecuteNonQuery(); return recipe.ID; } #endregion /// /// 保存配方的物料信息 /// /// 保存配方的物料信息 public static void InsertWeigh(Entity.xl_weigh pmt_Weigh) { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError); } dbHelper.CommandType = CommandType.Text; string sqlstr = String.Empty; //添加新配方 sqlstr = @"insert into xl_weigh(Equip_Code, Recipe_ID, Weight_Id, Material_ID,Station, Set_Weight, Set_Error, Cpk_Error) values(@Equip_Code, @Recipe_ID, @Weight_Id, @Material_ID,@Station, @Set_Weight, @Set_Error, @Cpk_Error)"; dbHelper.ClearParameter(); dbHelper.CommandText = sqlstr; dbHelper.AddParameter("@Equip_Code", pmt_Weigh.Equip_Code); dbHelper.AddParameter("@Recipe_ID", pmt_Weigh.Recipe_ID); dbHelper.AddParameter("@Weight_Id", pmt_Weigh.Weight_Id); dbHelper.AddParameter("@Material_ID", pmt_Weigh.Material_ID); dbHelper.AddParameter("@Station", pmt_Weigh.Station); dbHelper.AddParameter("@Set_Weight", pmt_Weigh.Set_Weight); dbHelper.AddParameter("@Set_Error", pmt_Weigh.Set_Error); dbHelper.AddParameter("@Cpk_Error", null); dbHelper.ExecuteNonQuery(); } /// /// 删除配方的物料信息 /// /// 配方ID public static void DelWeighByRecipeID(string recipeID) { 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 = String.Empty; //添加新配方 sqlstr = @"delete from xl_weigh where Recipe_ID = @Recipe_ID"; dbHelper.ClearParameter(); dbHelper.CommandText = sqlstr; dbHelper.AddParameter("@Recipe_ID", recipeID); dbHelper.ExecuteNonQuery(); } #endregion #region 删除业务 #region 删除配方信息 /// /// 删除配方信息 /// /// 配方ID public static void DeleteRecipe(string recipeID) { 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 = "delete from xl_recipe where ID = @ID"; dbHelper.ClearParameter(); dbHelper.CommandText = sqlstr; dbHelper.AddParameter("@ID", recipeID); dbHelper.ExecuteNonQuery(); } #endregion #endregion #region 配方导入、导出 #region 配方导入 #region 导入配方主表 /// /// 导入配方主表 /// /// 要导入的文件名 /// 是否要清空原有数据 /// 成功返回true,失败返回false public static bool ImportPmtRecipe(string fileName, bool isClearOriginal) { try { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError); } #region 清空原有数据 if (isClearOriginal) { dbHelper.CommandType = CommandType.Text; string sqlstr = "truncate table PmtRecipe"; dbHelper.ClearParameter(); dbHelper.CommandText = sqlstr; dbHelper.ExecuteNonQuery(); ICSharpCode.Core.LoggingService.Debug("在导入配方主表时,清空了原有配方主表数据!"); } #endregion #region 导入数据 int count = 0; string insertSql = @"delete from PmtRecipe where GUID=@GUID; insert into PmtRecipe(GUID, MaterialGUID, RecipeMaterialCode, RecipeMaterialName, RecipeCode, RecipeName, RecipeDesc, RecipeVersion, RecipeType, RecipeUserVersion, RecipeState, LotDoneTime, ShelfLotCount, LotTotalWeight, AuditFlag, AuditUser, AuditDateTime, StartDatetime, EndDatetime, CreateTime, CreateActor, LastModifyTime, LastModifyActor, DataSource, DeleteFlag, Remark) values(@GUID, @MaterialGUID, @RecipeMaterialCode, @RecipeMaterialName, @RecipeCode, @RecipeName, @RecipeDesc, @RecipeVersion, @RecipeType, @RecipeUserVersion, @RecipeState, @LotDoneTime, @ShelfLotCount, @LotTotalWeight, @AuditFlag, @AuditUser, @AuditDateTime, @StartDatetime, @EndDatetime, @CreateTime, @CreateActor, @LastModifyTime, @LastModifyActor, @DataSource, @DeleteFlag, @Remark)"; DataTable dt = Mesnac.Basic.SerializeHandler.Deserialize(fileName); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { dbHelper.ClearParameter(); dbHelper.CommandText = insertSql; dbHelper.AddParameter("@GUID", dr["GUID"]); dbHelper.AddParameter("@MaterialGUID", dr["MaterialGUID"]); dbHelper.AddParameter("@RecipeMaterialCode", dr["RecipeMaterialCode"]); dbHelper.AddParameter("@RecipeMaterialName", dr["RecipeMaterialName"]); dbHelper.AddParameter("@RecipeCode", dr["RecipeCode"]); dbHelper.AddParameter("@RecipeName", dr["RecipeName"]); dbHelper.AddParameter("@RecipeDesc", dr["RecipeDesc"]); dbHelper.AddParameter("@RecipeVersion", dr["RecipeVersion"]); dbHelper.AddParameter("@RecipeType", dr["RecipeType"]); dbHelper.AddParameter("@RecipeUserVersion", dr["RecipeUserVersion"]); dbHelper.AddParameter("@RecipeState", dr["RecipeState"]); dbHelper.AddParameter("@LotDoneTime", dr["LotDoneTime"]); dbHelper.AddParameter("@ShelfLotCount", dr["ShelfLotCount"]); dbHelper.AddParameter("@LotTotalWeight", dr["LotTotalWeight"]); dbHelper.AddParameter("@AuditFlag", dr["AuditFlag"]); dbHelper.AddParameter("@AuditUser", dr["AuditUser"]); dbHelper.AddParameter("@AuditDateTime", dr["AuditDateTime"]); dbHelper.AddParameter("@StartDatetime", dr["StartDatetime"]); dbHelper.AddParameter("@EndDatetime", dr["EndDatetime"]); dbHelper.AddParameter("@CreateTime", dr["CreateTime"]); dbHelper.AddParameter("@CreateActor", dr["CreateActor"]); dbHelper.AddParameter("@LastModifyTime", dr["LastModifyTime"]); dbHelper.AddParameter("@LastModifyActor", dr["LastModifyActor"]); dbHelper.AddParameter("@DataSource", dr["DataSource"]); dbHelper.AddParameter("@DeleteFlag", dr["DeleteFlag"]); dbHelper.AddParameter("@Remark", dr["Remark"]); dbHelper.ExecuteNonQuery(); count++; System.Threading.Thread.Sleep(2); //中间休眠2毫秒 } } #endregion ICSharpCode.Core.LoggingService.Debug("导入配方主表完毕,导入记录数:" + count + ",导入文件名:" + fileName); return true; } catch(Exception ex) { ICSharpCode.Core.LoggingService.Error("导入配方主表异常:" + ex.Message, ex); return false; } } #endregion #region 导入下辅机称量物料数据 /// /// 导入下辅机称量物料数据 /// /// 要导入的文件名 /// 是否清除原有数据 /// 成功返回true,失败返回false public static bool ImportPmtMillWeight(string fileName, bool isClearOriginal) { try { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError); } #region 清空原有数据 if (isClearOriginal) { dbHelper.CommandType = CommandType.Text; string sqlstr = "truncate table PmtMillWeight"; dbHelper.ClearParameter(); dbHelper.CommandText = sqlstr; dbHelper.ExecuteNonQuery(); ICSharpCode.Core.LoggingService.Debug("在导入下辅机称量物料数据时,清空了原有下辅机称量物料数据!"); } #endregion #region 导入数据 int count = 0; string insertSql = @"delete from PmtMillWeight where GUID=@GUID or (MillWeightHeadGUID=@MillWeightHeadGUID and WeightID=@WeightID); insert into PmtMillWeight(GUID, MillWeightHeadGUID, WeightID, ActCode, MaterialGUID, MaterialCode, MaterialName, SetWeight, SetUpTolerance, SetLowTolerance, MaterialType, NeedMaterialCode, ChanYongFlag, AutoPloy, Remark) values(@GUID, @MillWeightHeadGUID, @WeightID, @ActCode, @MaterialGUID, @MaterialCode, @MaterialName, @SetWeight, @SetUpTolerance, @SetLowTolerance, @MaterialType, @NeedMaterialCode, @ChanYongFlag, @AutoPloy, @Remark)"; DataTable dt = Mesnac.Basic.SerializeHandler.Deserialize(fileName); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { dbHelper.ClearParameter(); dbHelper.CommandText = insertSql; dbHelper.AddParameter("@GUID", dr["GUID"]); dbHelper.AddParameter("@MillWeightHeadGUID", dr["MillWeightHeadGUID"]); dbHelper.AddParameter("@WeightID", dr["WeightID"]); dbHelper.AddParameter("@ActCode", dr["ActCode"]); dbHelper.AddParameter("@MaterialGUID", dr["MaterialGUID"]); dbHelper.AddParameter("@MaterialCode", dr["MaterialCode"]); dbHelper.AddParameter("@MaterialName", dr["MaterialName"]); dbHelper.AddParameter("@SetWeight", dr["SetWeight"]); dbHelper.AddParameter("@SetUpTolerance", dr["SetUpTolerance"]); dbHelper.AddParameter("@SetLowTolerance", dr["SetLowTolerance"]); dbHelper.AddParameter("@MaterialType", dr["MaterialType"]); dbHelper.AddParameter("@NeedMaterialCode", dr["NeedMaterialCode"]); dbHelper.AddParameter("@ChanYongFlag", dr["ChanYongFlag"]); dbHelper.AddParameter("@AutoPloy", dr["AutoPloy"]); dbHelper.AddParameter("@Remark", dr["Remark"]); dbHelper.ExecuteNonQuery(); count++; System.Threading.Thread.Sleep(2); //中间休眠2毫秒 } } #endregion ICSharpCode.Core.LoggingService.Debug("导入下辅机称量物料数据完毕,导入记录数:" + count + ",导入文件名:" + fileName); return true; } catch (Exception ex) { ICSharpCode.Core.LoggingService.Error("导入下辅机称量物料数据异常:" + ex.Message, ex); return false; } } #endregion #endregion #region 配方导出 #region 导出配方主表 /// /// 导出配方主表 /// /// 要导出的文件名 /// 成功返回true,失败返回false public static bool ExportPmtRecipe(string fileName) { 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; string sqlstr = "select * from PmtRecipe"; DataTable dt = dbHelper.GetDataTableBySql(sqlstr); Mesnac.Basic.SerializeHandler.Serialize(dt, fileName); ICSharpCode.Core.LoggingService.Debug("导出配方主表完毕,文件名:" + fileName); return true; } catch(Exception ex) { ICSharpCode.Core.LoggingService.Error("导出配方主表异常:" + ex.Message, ex); return false; } } #endregion #region 导出下辅机称量物料数据 /// /// 导出下辅机称量物料数据 /// /// 要导出的文件名 /// 成功返回true,失败返回false public static bool ExportPmtMillWeight(string fileName) { 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; string sqlstr = "select * from PmtMillWeight"; DataTable dt = dbHelper.GetDataTableBySql(sqlstr); Mesnac.Basic.SerializeHandler.Serialize(dt, fileName); ICSharpCode.Core.LoggingService.Debug("导出下辅机称量物料数据完毕,文件名:" + fileName); return true; } catch (Exception ex) { ICSharpCode.Core.LoggingService.Error("导出下辅机称量物料数据异常:" + ex.Message, ex); return false; } } #endregion #endregion #endregion #endregion #endregion #endregion #region 配方打印(报表) #region 获取配方基本信息 PmtRecipe /// /// 通过配方GUID获取配方基本信息 /// /// /// 返回配方基本信息 public static DataTable GetPmtRecipe(string recipeGUID) { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { return new DataTable(); } string sqlStr = @"SELECT TA.*,TB.ItemName AS RecipeTypeName,TC.ItemName AS RecipeStateName FROM PmtRecipe TA LEFT JOIN SysCode TB ON TA.RecipeType=TB.ItemCode AND TB.TypeID='PmtType' LEFT JOIN SysCode TC ON TA.RecipeState=TC.ItemCode AND TC.TypeID='PmtState' WHERE TA.GUID = '" + recipeGUID + "' "; dbHelper.ClearParameter(); dbHelper.CommandType = CommandType.Text; dbHelper.CommandText = sqlStr; DataTable dt = dbHelper.ToDataTable(); return dt; } #endregion #endregion } }