You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lj_plc/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Technical/PmtRecipe/RecipeHelper.cs

1920 lines
82 KiB
C#

This file contains ambiguous Unicode characters!

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

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Windows.Forms;
using ICSharpCode.Core;
using Mesnac.Codd.Session;
using Mesnac.Action.Base;
using System.Reflection;
using System.Configuration;
using Mesnac.Action.ChemicalWeighing.Technical.PmtRecipe.entity;
namespace Mesnac.Action.ChemicalWeighing.Technical.PmtRecipe
{
/// <summary>
/// 工艺配方辅助类
/// </summary>
public class RecipeHelper
{
#region 静态属性定义
#region 配方码表业务
#region 配方主信息 - 获取配方类型列表
/// <summary>
/// 配方主信息 - 配方类型列表
/// </summary>
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 配方主信息 - 获取配方状态列表
/// <summary>
/// 配方主信息 - 配方状态列表
/// </summary>
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 获取控件所属设备单元编号
/// <summary>
/// 获取控件所属设备单元编号
/// </summary>
/// <param name="c">控件参数</param>
/// <returns>返回控件所属设备单元</returns>
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 获取控件自身设备单元编号
/// <summary>
/// 获取控件自身设备单元编号
/// </summary>
/// <param name="c">控件参数</param>
/// <returns>返回控件自身设备单元</returns>
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
/// <summary>
/// 如果为0则转换为null
/// </summary>
/// <param name="dgv"></param>
/// <param name="rowInx"></param>
/// <param name="colInx"></param>
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 网格头辅助方法-初始化网格控件事件
/// <summary>
/// 初始化网格控件事件
/// </summary>
/// <param name="grid"></param>
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控件是否为只读判断当前配方是否处于编辑状态
/// <summary>
/// 根据GridView控件是否为只读判断当前配方是否处于编辑状态
/// </summary>
public static bool IsEditMode(Mesnac.Action.Base.BaseAction baseAction)
{
bool flag = true;
List<Mesnac.Controls.Default.MCDataGridView> gridList = baseAction.GetTControls<Mesnac.Controls.Default.MCDataGridView>();
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 禁用、启用界面控件
/// <summary>
/// 禁用、启用界面控件
/// </summary>
/// <param name="baseAction">Action对象</param>
/// <param name="flag">true为启用false为禁用</param>
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<Mesnac.Controls.Default.MCDataGridView> gridList = baseAction.GetTControls<Mesnac.Controls.Default.MCDataGridView>();
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 重置选中的配方
/// <summary>
/// 重置选中的配方
/// </summary>
/// <param name="action">当前action对象</param>
/// <param name="defaultRecipe">要选中的配方</param>
//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<SelectRecipeTypeComboBoxAction>.Warn("配方管理-选择配方-缺少配方物料列表组合框控件!");
// return;
// }
// if (cmbRecipeVersion == null || !(cmbRecipeVersion is ComboBox))
// {
// ICSharpCode.Core.LoggingService<SelectRecipeTypeComboBoxAction>.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<Entity.SimplePmtRecipe> 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 设置(网格控件)的表头、字体和行样式
/// <summary>
/// 设置(网格控件)的表头、字体和行样式
/// </summary>
/// <param name="grid"></param>
public static void SetDataGridViewStyle(DataGridView grid)
{
lock (String.Empty)
{
try
{
if (grid == null)
{
ICSharpCode.Core.LoggingService<RecipeHelper>.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<RecipeHelper>.Error("【配方管理】设置网格控件的表头、字体和行样式SetDataGridViewStyle失败" + ex.Message);
}
}
}
#endregion
#endregion
#region 配方数据业务
#region 配方业务
#region 查询业务
#region GenerateNextRecipeCode 获取下一个可用的配方编码 (1位物料大类、2位物料细类、10位流水)
/// <summary>
/// 获取下一个可用的配方编码 (13位物料编码、10位版本号)
/// </summary>
/// <param name="recipeMaterialCode">配方物料编码</param>
/// <param name="recipeVersion">配方版本</param>
/// <returns>返回配方编码</returns>
public static string GenerateNextRecipeCode(string recipeMaterialCode, string recipeVersion)
{
string result = String.Format("{0}{1}", recipeMaterialCode, recipeVersion);
return result;
}
#endregion
#region GenerateNextRecipeVersion 根据配方物料GUID获取下一个可用的配方版本号
/// <summary>
/// 根据配方物料GUID获取下一个可用的配方版本号
/// </summary>
/// <param name="recipeMaterialGUID">配方物料GUID</param>
/// <returns>返回下一个可用的配方版本号</returns>
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 判断某个配方是否存在
/// <summary>
/// 判断某个配方是否存在(根据ID)
/// </summary>
/// <param name="recipeID">配方ID</param>
/// <returns>存在返回true不存在返回false</returns>
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(recipe_Id) from Base_RecipeInfo where recipe_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;
}
/// <summary>
/// 判断某个配方是否存在
/// </summary>
/// <param name="recipeName">配方名称</param>
/// <returns></returns>
public static bool IsExistsName(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.CommandType = CommandType.Text;
dbHelper.ClearParameter();
string sqlstr = "select count(recipe_Name) from Base_RecipeInfo where recipe_Name = @recipe_Name";
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@recipe_Name", recipeName);
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 根据配方类型和配方状态获取配方列表
/// <summary>
/// 根据配方类型和配方状态获取配方列表
/// </summary>
/// <param name="recipeType">配方类型</param>
/// <param name="recipeState">配方状态</param>
/// <returns>返回符合条件的配方列表</returns>
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
/// <summary>
/// 根据配方物料GUID和配方版本查询配方GUID
/// </summary>
/// <param name="recipeMaterialGUID">配方物料GUID</param>
/// <param name="recipeVersion">配方版本</param>
/// <returns>返回对应的配方GUID</returns>
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 判断是否存在某种物料的配方
/// <summary>
/// 判断是否存在某种物料的配方
/// </summary>
/// <param name="recipeMaterialGUID">配方物料GUID</param>
/// <returns>存在返回true不存在返回false</returns>
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 查询配方主信息
/// <summary>
/// 获取所有配方列表
/// </summary>
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 Pmt_recipe order by End_datetime desc";
dbHelper.CommandText = sqlstr;
DataTable dt = dbHelper.ToDataTable();
return dt;
}
/// <summary>
/// 根据配方名称获取配方信息
/// </summary>
/// <param name="recipeName">配方名称</param>
/// <returns>返回符合条件的配方</returns>
public static Base_RecipeInfo GetRecipeByName(string recipeName)
{
Base_RecipeInfo pmtRecipe = new Base_RecipeInfo();
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_RecipeInfo WHERE recipe_Name = @Recipe_Name";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
dbHelper.AddParameter("@Recipe_Name", recipeName);
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
foreach (DataRow dr in table.Rows)
{
pmtRecipe = ConvertDataRowToBaseRepiceInfo(dr);
break;
}
}
return pmtRecipe;
}
/// <summary>
/// 根据配方ID获取Base_RecipeInfo
/// </summary>
/// <param name="recipeId"></param>
/// <returns></returns>
public static Base_RecipeInfo GetRecipeById(string recipeId)
{
Base_RecipeInfo pmtRecipe = new Base_RecipeInfo();
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_RecipeInfo WHERE recipe_Id = @recipeId";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
dbHelper.AddParameter("@recipeId", recipeId);
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
foreach (DataRow dr in table.Rows)
{
pmtRecipe = ConvertDataRowToBaseRepiceInfo(dr);
break;
}
}
return pmtRecipe;
}
/// <summary>
/// 获取配方主信息
/// </summary>
/// <param name="recipeGUID">配方GUID</param>
/// <returns>返回配方主信息DataRow</returns>
public static DataRow GetRecipeByGUID(string recipeGUID)
{
return BaseDataHelper.GetDataRowByTableAndGUID("Pmt_recipe", recipeGUID);
}
/// <summary>
/// 获取配方主信息
/// </summary>
/// <param name="recipeGUID">配方GUID</param>
/// <param name="recipeVersion">配方版本</param>
/// <returns>返回配方主信息DataRow</returns>
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;
}
}
/// <summary>
/// 获取配方主信息
/// </summary>
/// <param name="recipeMaterialName">配方物料名称</param>
/// <param name="recipeVersion">配方版本</param>
/// <returns>返回配方主信息DataRow</returns>
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;
}
}
/// <summary>
/// 获取配方主信息实体对象
/// </summary>
/// <param name="recipeGUID">配方GUID</param>
/// <returns>返回配方主信息实体对象</returns>
public static Entity.Pmt_recipe GetRecipeEntityByGUID(string recipeGUID)
{
DataRow dr = GetRecipeByGUID(recipeGUID);
Entity.Pmt_recipe recipe = ConvertDataRowToRecipeEntity(dr);
return recipe;
}
/// <summary>
/// 获取配方主信息实体对象
/// </summary>
/// <param name="recipeGUID">配方GUID</param>
/// <param name="recipeVersion">配方版本</param>
/// <returns>返回配方主信息实体对象</returns>
public static Entity.Pmt_recipe GetRecipeEntityByGUID(string recipeGUID, string recipeVersion)
{
DataRow dr = GetRecipeByGUID(recipeGUID, recipeVersion);
Entity.Pmt_recipe recipe = ConvertDataRowToRecipeEntity(dr);
return recipe;
}
/// <summary>
/// 获取配方主信息实体对象
/// </summary>
/// <param name="recipeMaterialName">配方物料名称</param>
/// <param name="recipeVersion">配方版本</param>
/// <returns>返回配方主信息实体对象</returns>
public static Entity.Pmt_recipe GetRecipeEntityByRecipeMaterialName(string recipeMaterialName, string recipeVersion)
{
DataRow dr = GetRecipeByRecipeMaterialName(recipeMaterialName, recipeVersion);
Entity.Pmt_recipe recipe = ConvertDataRowToRecipeEntity(dr);
return recipe;
}
/// <summary>
/// 把DataRow的数据封装至配方实体
/// </summary>
/// <param name="dr">配方数据行</param>
/// <returns>返回封装号的配方实体对象</returns>
public static Entity.Pmt_recipe ConvertDataRowToRecipeEntity(DataRow dr)
{
if (dr != null)
{
Entity.Pmt_recipe recipe = new Entity.Pmt_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
/// <summary>
/// 查询配方物料GUID
/// </summary>
/// <param name="recipeMaterialName">配方物料名称</param>
/// <param name="recipeVersion">配方版本</param>
/// <returns>返回对应的配方物料GUID</returns>
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 保存配方主信息
/// <summary>
/// 保存配方主信息
/// </summary>
/// <param name="recipe">配方主信息对象</param>
/// <returns>返回当前配方的GUID</returns>
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.ExecuteNonQuery();
return recipe.ID;
}
#endregion
/// <summary>
/// 保存配方的物料信息
/// </summary>
/// <param name="pmt_Weigh">保存配方的物料信息</param>
public static void InsertWeigh(Base_RecipeMaterial 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;
if (!IsExistsRecipeMaterial(pmt_Weigh.recipeId, pmt_Weigh.materialName))
{
//添加新配方
sqlstr = @"insert into Base_RecipeMaterial (recipe_Id, material_Id, material_Nme, material_Weight, put_Time, edit_User)
VALUES (@recipe_Id, @material_Id, @material_Nme, @material_Weight, @put_Time, @edit_User)";
dbHelper.ClearParameter();
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@recipe_Id", pmt_Weigh.recipeId);
dbHelper.AddParameter("@material_Id", pmt_Weigh.materialId);
dbHelper.AddParameter("@material_Nme", pmt_Weigh.materialName);
dbHelper.AddParameter("@material_Weight", pmt_Weigh.materialWeight);
dbHelper.AddParameter("@put_Time", pmt_Weigh.putTime);
dbHelper.AddParameter("@edit_User", pmt_Weigh.editUser);
}
else
{
sqlstr = @"update Base_RecipeMaterial set material_Weight=@material_Weight where recipe_Id = @recipe_Id and material_Nme = @material_Nme ";
dbHelper.ClearParameter();
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@recipe_Id", pmt_Weigh.recipeId);
dbHelper.AddParameter("@material_Nme", pmt_Weigh.materialName);
dbHelper.AddParameter("@material_Weight", pmt_Weigh.materialWeight);
}
dbHelper.ExecuteNonQuery();
}
/// <summary>
/// 删除配方的物料信息
/// </summary>
/// <param name="recipeID">配方ID</param>
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 Base_RecipeMaterial where recipe_Id = @Recipe_ID";
dbHelper.ClearParameter();
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@Recipe_ID", recipeID);
dbHelper.ExecuteNonQuery();
}
public static void DelCratParamByRecipeId(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 Base_RecipeCratParam where recipe_Id = @Recipe_ID";
dbHelper.ClearParameter();
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@Recipe_ID", recipeId);
dbHelper.ExecuteNonQuery();
}
#endregion
#region 删除业务
#region 删除配方信息
/// <summary>
/// 删除配方信息
/// </summary>
/// <param name="recipeID">配方ID</param>
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 Base_RecipeInfo where recipe_Id = @ID";
dbHelper.ClearParameter();
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@ID", recipeID);
dbHelper.ExecuteNonQuery();
}
#endregion
#endregion
#region 配方导入、导出
#region 配方导入
#region 导入配方主表
/// <summary>
/// 导入配方主表
/// </summary>
/// <param name="fileName">要导入的文件名</param>
/// <param name="isClearOriginal">是否要清空原有数据</param>
/// <returns>成功返回true失败返回false</returns>
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<RecipeHelper>.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<DataTable>(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<RecipeHelper>.Debug("导入配方主表完毕,导入记录数:" + count + ",导入文件名:" + fileName);
return true;
}
catch(Exception ex)
{
ICSharpCode.Core.LoggingService<RecipeHelper>.Error("导入配方主表异常:" + ex.Message, ex);
return false;
}
}
#endregion
#region 导入下辅机称量物料数据
/// <summary>
/// 导入下辅机称量物料数据
/// </summary>
/// <param name="fileName">要导入的文件名</param>
/// <param name="isClearOriginal">是否清除原有数据</param>
/// <returns>成功返回true失败返回false</returns>
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<RecipeHelper>.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<DataTable>(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<RecipeHelper>.Debug("导入下辅机称量物料数据完毕,导入记录数:" + count + ",导入文件名:" + fileName);
return true;
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<RecipeHelper>.Error("导入下辅机称量物料数据异常:" + ex.Message, ex);
return false;
}
}
#endregion
#endregion
#region 配方导出
#region 导出配方主表
/// <summary>
/// 导出配方主表
/// </summary>
/// <param name="fileName">要导出的文件名</param>
/// <returns>成功返回true失败返回false</returns>
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<DataTable>(dt, fileName);
ICSharpCode.Core.LoggingService<RecipeHelper>.Debug("导出配方主表完毕,文件名:" + fileName);
return true;
}
catch(Exception ex)
{
ICSharpCode.Core.LoggingService<RecipeHelper>.Error("导出配方主表异常:" + ex.Message, ex);
return false;
}
}
#endregion
#region 导出下辅机称量物料数据
/// <summary>
/// 导出下辅机称量物料数据
/// </summary>
/// <param name="fileName">要导出的文件名</param>
/// <returns>成功返回true失败返回false</returns>
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<DataTable>(dt, fileName);
ICSharpCode.Core.LoggingService<RecipeHelper>.Debug("导出下辅机称量物料数据完毕,文件名:" + fileName);
return true;
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<RecipeHelper>.Error("导出下辅机称量物料数据异常:" + ex.Message, ex);
return false;
}
}
#endregion
#endregion
#endregion
#endregion
#endregion
#endregion
#region 配方打印(报表)
#region 获取配方基本信息 PmtRecipe
/// <summary>
/// 通过配方GUID获取配方基本信息
/// </summary>
/// <param name="recipeGUID"></param>
/// <returns>返回配方基本信息</returns>
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
/// <summary>
/// 获取配方信息
/// </summary>
/// <returns></returns>
public static DataTable GetBaseRecipeInfo(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.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string sqlstr = "select row_number() over (order by edit_Time) as index_Id,recipe_Id,recipe_Name,recipe_Type,recipe_Weight,edit_User,edit_Time,remark, case recipe_State when '1' then '是' else '否' end as 'recipe_State'";
sqlstr += "from Base_RecipeInfo where 1=1";
if (recipeId != "")
{
sqlstr += "and recipe_Id = @recipeId";
dbHelper.AddParameter("@recipeId", recipeId);
}
dbHelper.CommandText = sqlstr;
DataTable dt = dbHelper.ToDataTable();
return dt;
}
/// <summary>
/// 获取配方物料信息
/// </summary>
/// <returns></returns>
public static DataTable GetRecipeMaterialInfo(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.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string sqlstr = "select row_number() over (order by edit_Time) as index_Id,* from Base_RecipeMaterial where 1=1 ";
if(recipeId != "")
{
sqlstr += "and recipe_Id = @recipeId";
dbHelper.AddParameter("@recipeId", recipeId);
}
dbHelper.CommandText = sqlstr;
DataTable dt = dbHelper.ToDataTable();
return dt;
}
/// <summary>
/// 获取配方物料信息
/// </summary>
/// <returns></returns>
public static List<Base_RecipeMaterial> GetRecipeMaterialInfoByRecipeId(string recipeId)
{
List<Base_RecipeMaterial> recipeMaterials = new List<Base_RecipeMaterial>();
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string sqlstr = "select row_number() over (order by material_Id) as index_Id,* from Base_RecipeMaterial where 1=1 ";
if (recipeId != "")
{
sqlstr += "and recipe_Id = @recipeId";
dbHelper.AddParameter("@recipeId", recipeId);
}
dbHelper.CommandText = sqlstr;
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
foreach (DataRow dr in table.Rows)
{
Base_RecipeMaterial recipeMaterial = new Base_RecipeMaterial();
recipeMaterial = ConvertDataRowToBaseRepiceMaterial(dr);
recipeMaterials.Add(recipeMaterial);
}
}
return recipeMaterials;
}
/// <summary>
/// 根据配方信息、物料信息获取工艺参数
/// </summary>
/// <param name="recipeId"></param>
/// <param name="materialId"></param>
/// <returns></returns>
public static DataTable GerCratParamByRecipeAndMaterial(string recipeId,string materialId)
{
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 sqlstr = "select row_number() over (order by edit_Time) as index_Id,* from Base_RecipeCratParam where 1=1";
if (recipeId != "")
{
sqlstr += " and recipe_Id = @recipeId";
dbHelper.AddParameter("@recipeId", recipeId);
}
if (materialId != "")
{
sqlstr += " and material_Id = @materialId";
dbHelper.AddParameter("@materialId", materialId);
}
dbHelper.CommandText = sqlstr;
DataTable dt = dbHelper.ToDataTable();
return dt;
}catch(Exception ex)
{
return null;
}
}
public static List<Base_RecipeCratParam> GerCratParamListByRecipeAndMaterial(string recipeId, string materialId)
{
try
{
List<Base_RecipeCratParam> recipeCratParams = new List<Base_RecipeCratParam>();
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string sqlstr = "select row_number() over (order by edit_Time) as index_Id,* from Base_RecipeCratParam where 1=1";
if (recipeId != "")
{
sqlstr += " and recipe_Id = @recipeId";
dbHelper.AddParameter("@recipeId", recipeId);
}
if (materialId != "")
{
sqlstr += " and material_Id = @materialId";
dbHelper.AddParameter("@materialId", materialId);
}
dbHelper.CommandText = sqlstr;
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
foreach (DataRow dr in table.Rows)
{
Base_RecipeCratParam recipeCratParam = new Base_RecipeCratParam();
recipeCratParam = ConvertDataRowToBaseRepiceCratParam(dr);
recipeCratParams.Add(recipeCratParam);
}
}
return recipeCratParams;
}
catch (Exception ex)
{
return null;
}
}
/// <summary>
/// 保持配方信息
/// </summary>
/// <param name="recipe"></param>
/// <returns></returns>
public static string InsertRecipe(Base_RecipeInfo base_RepiceInfo)
{
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(base_RepiceInfo.recipeId))
{
//添加新配方
sqlstr = @"insert into Base_RecipeInfo(recipe_Id, recipe_Name, recipe_Type, recipe_Weight, recipe_State, edit_User, edit_Time, remark) values (@recipe_Id, @recipe_Name, @recipe_Type, @recipe_Weight, @recipe_State, @edit_User, @edit_Time, @remark)";
}
else
{
//更新原有配方
sqlstr = @"update Base_RecipeInfo set recipe_Id=@recipe_Id, recipe_Name=@recipe_Name, recipe_Type=@recipe_Type, recipe_Weight=@recipe_Weight, recipe_State=@recipe_State, edit_User=@edit_User,
edit_Time=@edit_Time, remark=@remark where recipe_Id = @recipe_Id";
}
dbHelper.ClearParameter();
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@recipe_Id", base_RepiceInfo.recipeId);
dbHelper.AddParameter("@recipe_Name", base_RepiceInfo.recipeName);
dbHelper.AddParameter("@recipe_Type", base_RepiceInfo.recipeType);
dbHelper.AddParameter("@recipe_Weight", base_RepiceInfo.recipeWeight);
dbHelper.AddParameter("@recipe_State", base_RepiceInfo.recipeState);
dbHelper.AddParameter("@edit_User", base_RepiceInfo.editUser);
dbHelper.AddParameter("@edit_Time", base_RepiceInfo.editTime);
dbHelper.AddParameter("@remark", base_RepiceInfo.remark);
dbHelper.ExecuteNonQuery();
return base_RepiceInfo.recipeId;
}
/// <summary>
/// Datatable转为Base_RepiceInfo
/// </summary>
/// <param name="dr"></param>
/// <returns></returns>
public static Base_RecipeInfo ConvertDataRowToBaseRepiceInfo(DataRow dr)
{
if (dr != null)
{
Base_RecipeInfo recipe = new Base_RecipeInfo();
recipe.recipeId = Mesnac.Basic.DataProcessor.RowValue(dr, "recipe_Id", String.Empty);
recipe.recipeName = Mesnac.Basic.DataProcessor.RowValue(dr, "recipe_Name", String.Empty);
recipe.recipeState = Convert.ToInt32(Mesnac.Basic.DataProcessor.RowValue(dr, "recipe_State", String.Empty));
recipe.recipeType = Mesnac.Basic.DataProcessor.RowValue(dr, "recipe_Type", String.Empty);
recipe.recipeWeight = Convert.ToDecimal(Mesnac.Basic.DataProcessor.RowValue(dr, "recipe_Weight", String.Empty));
recipe.editUser = Mesnac.Basic.DataProcessor.RowValue(dr, "edit_User", String.Empty);
recipe.remark = Mesnac.Basic.DataProcessor.RowValue(dr, "remark", String.Empty);
return recipe;
}
else
{
return null;
}
}
public static Base_RecipeMaterial ConvertDataRowToBaseRepiceMaterial(DataRow dr)
{
if (dr != null)
{
Base_RecipeMaterial recipe = new Base_RecipeMaterial();
recipe.materialId = Mesnac.Basic.DataProcessor.RowValue(dr, "material_Id", String.Empty);
recipe.materialName = Mesnac.Basic.DataProcessor.RowValue(dr, "material_Nme", String.Empty);
recipe.recipeId = Mesnac.Basic.DataProcessor.RowValue(dr, "recipe_Id", String.Empty);
recipe.materialWeight = Convert.ToDecimal(Mesnac.Basic.DataProcessor.RowValue(dr, "material_Weight", String.Empty));
recipe.putTime = Convert.ToInt32(Mesnac.Basic.DataProcessor.RowValue(dr, "put_Time", String.Empty));
return recipe;
}
else
{
return null;
}
}
public static Base_RecipeCratParam ConvertDataRowToBaseRepiceCratParam(DataRow dr)
{
if (dr != null)
{
Base_RecipeCratParam recipe = new Base_RecipeCratParam();
recipe.paramId = Mesnac.Basic.DataProcessor.RowValue(dr, "param_Id", String.Empty);
recipe.paramName = Mesnac.Basic.DataProcessor.RowValue(dr, "param_Name", String.Empty);
recipe.paramValue = Mesnac.Basic.DataProcessor.RowValue(dr, "param_Value", String.Empty);
recipe.recipeId = Mesnac.Basic.DataProcessor.RowValue(dr, "recipe_Id", String.Empty);
recipe.materialId = Mesnac.Basic.DataProcessor.RowValue(dr, "material_Id", String.Empty);
return recipe;
}
else
{
return null;
}
}
/// <summary>
/// 获取配方物料关联的工艺参数
/// </summary>
/// <param name="recipeId"></param>
/// <param name="material"></param>
/// <returns></returns>
public static DataTable GetCratParamByRecipeAndMaterial(string recipeId, string material)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string sqlstr = "select row_number() over (order by edit_Time) as index_Id ,* from Base_RecipeCratParam where 1=1";
if (recipeId != "")
{
sqlstr += " and recipe_Id = @recipeId";
dbHelper.AddParameter("@recipeId", recipeId);
}
if (material != "")
{
sqlstr += " and material_Id = @material";
dbHelper.AddParameter("@material", material);
}
dbHelper.CommandText = sqlstr;
DataTable dt = dbHelper.ToDataTable();
return dt;
}
/// <summary>
/// 删除配方物料关联的工艺参数
/// </summary>
/// <param name="recipeID"></param>
public static void DeleteCratParam(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 Base_RecipeCratParam where recipe_Id = @recipeID ";
dbHelper.ClearParameter();
dbHelper.AddParameter("@recipeID", recipeID);
dbHelper.CommandText = sqlstr;
dbHelper.ExecuteNonQuery();
}
/// <summary>
/// 判断某个配方参数是否存在(根据配方编号及参数名称)
/// </summary>
/// <param name="recipeID"></param>
/// <returns></returns>
public static bool IsExistsCratParam(string recipeID,string param_Name)
{
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(recipe_Id) from Base_RecipeCratParam where recipe_Id = @RecipeID and param_Name = @param_Name";
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@RecipeID", recipeID);
dbHelper.AddParameter("@param_Name", param_Name);
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;
}
/// <summary>
/// 判断某个配方物料是否存在
/// </summary>
/// <param name="recipeID"></param>
/// <param name="param_Name"></param>
/// <returns></returns>
public static bool IsExistsRecipeMaterial(string recipeID, string material_Nme)
{
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(recipe_Id) from Base_RecipeMaterial where recipe_Id = @RecipeID and material_Nme = @material_Nme";
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@RecipeID", recipeID);
dbHelper.AddParameter("@material_Nme", material_Nme);
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;
}
/// <summary>
/// 添加工艺参数
/// </summary>
/// <param name="pmt_Weigh"></param>
public static void InsertCratParam(Base_RecipeCratParam cratParam)
{
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 (!IsExistsCratParam(cratParam.recipeId, cratParam.paramName))
{
//添加新配方参数
sqlstr = @"insert into Base_RecipeCratParam (param_Id, param_Name, recipe_Id, material_Id, param_Value, edit_User)
values (@param_Id, @param_Name, @recipe_Id, @material_Id,@param_Value, @edit_User)";
dbHelper.ClearParameter();
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@param_Id", String.IsNullOrEmpty(cratParam.paramId) ? System.Guid.NewGuid().ToString("N") : cratParam.paramId);
dbHelper.AddParameter("@param_Name", cratParam.paramName);
dbHelper.AddParameter("@recipe_Id", cratParam.recipeId);
dbHelper.AddParameter("@material_Id", cratParam.materialId);
dbHelper.AddParameter("@param_Value", cratParam.paramValue);
dbHelper.AddParameter("@edit_User", cratParam.editUser);
}
else
{
//更新新配方参数
sqlstr = @"update Base_RecipeCratParam set param_Value=@param_Value where recipe_Id = @recipe_Id and param_Name = @param_Name ";
dbHelper.ClearParameter();
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@param_Name", cratParam.paramName);
dbHelper.AddParameter("@recipe_Id", cratParam.recipeId);
dbHelper.AddParameter("@param_Value", cratParam.paramValue);
}
dbHelper.ExecuteNonQuery();
}
#region 冠合数据库操作
/// <summary>
/// 获取配方物料信息
/// </summary>
/// <returns></returns>
public static List<Base_RecipeInfo> GetBaseRecipeInfo()
{
List<Base_RecipeInfo> recipeMaterials = new List<Base_RecipeInfo>();
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string sqlstr = "select row_number() over (order by recipe_Name) as index_Id,* from Base_RecipeInfo where 1=1 ";
dbHelper.CommandText = sqlstr;
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
foreach (DataRow dr in table.Rows)
{
Base_RecipeInfo recipeMaterial = new Base_RecipeInfo();
recipeMaterial = ConvertDataRowToBaseRecipeInfo(dr);
recipeMaterials.Add(recipeMaterial);
}
}
return recipeMaterials;
}
public static Base_RecipeInfo ConvertDataRowToBaseRecipeInfo(DataRow dr)
{
if (dr != null)
{
Base_RecipeInfo recipe = new Base_RecipeInfo();
recipe.recipeId = Mesnac.Basic.DataProcessor.RowValue(dr, "recipe_Id", String.Empty);
recipe.recipeName = Mesnac.Basic.DataProcessor.RowValue(dr, "recipe_Name", String.Empty);
recipe.recipeType = Mesnac.Basic.DataProcessor.RowValue(dr, "recipe_Type", String.Empty);
return recipe;
}
else
{
return null;
}
}
#endregion
}
}