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.

582 lines
24 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 Mesnac.Action.ChemicalWeighing.Entity;
using Mesnac.Action.ChemicalWeighing.Entity.material;
using Mesnac.Action.ChemicalWeighing.Entity.station;
using Mesnac.Codd.Session;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mesnac.Action.ChemicalWeighing.Station
{
public class StationHelper
{
#region 根据工位id获取工位详情信息列表
/// <summary>
/// 根据工位id获取物料信息列表
/// </summary>
/// <param name="Id">ID</param>
/// <returns></returns>
public static DataTable GetStationSubDataTable(string Id)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.CommandType = CommandType.Text;
string strSql = "SELECT * FROM xl_station_sub where MainId = @MainId order by Id";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
dbHelper.AddParameter("@MainId", Id);
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
return table;
}
return null;
}
#endregion
#region 根据工位id获取工位详情信息列表
/// <summary>
/// 根据工位id获取物料信息列表
/// </summary>
/// <param name="Id">ID</param>
/// <returns></returns>
public static List<xl_station_sub> GetStationSubList()
{
List<xl_station_sub> lst = new List<xl_station_sub>();
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.CommandType = CommandType.Text;
string strSql = "SELECT * FROM xl_station_sub order by StationSubName";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
xl_station_sub entity = null;
foreach (DataRow dr in table.Rows)
{
entity = ConvertDataRowToStation(dr);
lst.Add(entity);
}
}
return lst;
}
#endregion
#region 根据工位id获取工位详情信息列表
/// <summary>
/// 根据工位id获取物料信息列表
/// </summary>
/// <param name="Id">ID</param>
/// <returns></returns>
public static List<xl_station_sub> GetStationSubList(string Id)
{
List<xl_station_sub> lst = new List<xl_station_sub>();
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.CommandType = CommandType.Text;
string strSql = "SELECT * FROM xl_station_sub where MainId=@MainId order by StationSubName";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
dbHelper.AddParameter("@MainId", Id);
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
xl_station_sub entity = null;
foreach (DataRow dr in table.Rows)
{
entity = ConvertDataRowToStation(dr);
lst.Add(entity);
}
}
return lst;
}
#endregion
/// <summary>
/// 把DataRow数据行转换为xl_weigh实体对象
/// </summary>
/// <param name="dr">要转换的数据行</param>
/// <returns>返回转换后的计划实体对象</returns>
public static xl_station_sub ConvertDataRowToStation(DataRow dr)
{
if (dr != null)
{
xl_station_sub station = new xl_station_sub();
station.ID = Mesnac.Basic.DataProcessor.RowValue(dr, "ID", String.Empty);
station.MainId = Mesnac.Basic.DataProcessor.RowValue(dr, "MainId", String.Empty);
station.StationSubName = Mesnac.Basic.DataProcessor.RowValue(dr, "StationSubName", String.Empty);
station.Station_Weight_Medium = Mesnac.Basic.DataProcessor.RowValue(dr, "Station_Weight_Medium", 0.0);
station.Station_Weight_Low = Mesnac.Basic.DataProcessor.RowValue(dr, "Station_Weight_Low", 0.0);
station.Station_Weight_Advance = Mesnac.Basic.DataProcessor.RowValue(dr, "Station_Weight_Advance", 0.0);
station.Station_Speed_Hight = Mesnac.Basic.DataProcessor.RowValue(dr, "Station_Speed_Hight", 0.0);
station.Station_Speed_Medium = Mesnac.Basic.DataProcessor.RowValue(dr, "Station_Speed_Medium", 0.0);
station.Station_Speed_Low = Mesnac.Basic.DataProcessor.RowValue(dr, "Station_Speed_Low", 0.0);
return station;
}
else
{
return null;
}
}
/// <summary>
/// 把DataRow数据行转换为Station实体对象
/// </summary>
/// <param name="dr">要转换的数据行</param>
/// <returns>返回转换后的计划实体对象</returns>
public static xl_station_sub ConvertDataRowToXlStation(DataRow dr)
{
if (dr != null)
{
xl_station_sub station = new xl_station_sub();
station.ID = Mesnac.Basic.DataProcessor.RowValue(dr, "ID", String.Empty);
station.StationSubName = Mesnac.Basic.DataProcessor.RowValue(dr, "StationSubName", String.Empty);
station.Station_Weight_Medium = Mesnac.Basic.DataProcessor.RowValue(dr, "Station_Weight_Medium", 0.0);
station.Station_Weight_Low = Mesnac.Basic.DataProcessor.RowValue(dr, "Station_Weight_Low", 0.0);
station.Station_Weight_Advance = Mesnac.Basic.DataProcessor.RowValue(dr, "Station_Weight_Advance", 0.0);
station.Station_Speed_Hight = Mesnac.Basic.DataProcessor.RowValue(dr, "Station_Speed_Hight", 0.0);
station.Station_Speed_Medium = Mesnac.Basic.DataProcessor.RowValue(dr, "Station_Speed_Medium", 0.0);
station.Station_Speed_Low = Mesnac.Basic.DataProcessor.RowValue(dr, "Station_Speed_Low", 0.0);
return station;
}
else
{
return null;
}
}
#region 获取某种配方的版本列表
/// <summary>
/// 获取某种配方的版本列表
/// </summary>
/// <param name="recipeMaterialGUID">ID</param>
/// <returns>返回对应的版本列表</returns>
public static List<Material> GetMaterialList(string ID)
{
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 Material_ID,Material_name from xl_weigh w left join xl_material m on w.Material_ID=m.ID where w.Recipe_ID=@Recipe_ID";
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@Recipe_ID", ID);
DataTable table = dbHelper.ToDataTable();
List<Material> lst = new List<Material>();
foreach (DataRow row in table.Rows)
{
Material recipe = new Material();
recipe.Material_ID = Mesnac.Basic.DataProcessor.RowValue(row, "Material_ID", String.Empty);
recipe.Material_name = Mesnac.Basic.DataProcessor.RowValue(row, "Material_name", String.Empty);
lst.Add(recipe);
}
return lst;
}
#endregion
/// <summary>
/// 保存工位主信息
/// </summary>
/// <param name="recipe">配方主信息对象</param>
/// <returns>返回当前配方的GUID</returns>
public static string InsertStation(Entity.xl_station station)
{
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(station.ID))
{
//添加新配方
sqlstr = @"INSERT INTO xl_station(ID,StationName,End_datetime)VALUES(@ID,@StationName,@End_datetime)";
}
else
{
//更新原有配方
sqlstr = @"UPDATE xl_station set StationName = @StationName,End_datetime =@End_datetime where ID = @ID";
}
dbHelper.ClearParameter();
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@ID", station.ID);
dbHelper.AddParameter("@StationName", station.StationName);
dbHelper.AddParameter("@End_datetime", station.End_datetime);
dbHelper.ExecuteNonQuery();
return station.ID;
}
/// <summary>
/// 判断某个工位是否存在(根据ID)
/// </summary>
/// <param name="recipeID">配方ID</param>
/// <returns>存在返回true不存在返回false</returns>
public static bool IsExists(string ID)
{
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_station where ID = @ID";
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@ID", ID);
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 InsertStationSub(Entity.xl_station_sub xlstationsub)
{
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_station_sub(ID,MainId,StationSubName,Station_Weight_Medium,Station_Weight_Low,Station_Weight_Advance,Station_Speed_Hight,Station_Speed_Medium,Station_Speed_Low,CreateDateTime)VALUES
(@ID,@MainId,@StationSubName,@Station_Weight_Medium,@Station_Weight_Low,@Station_Weight_Advance,@Station_Speed_Hight,@Station_Speed_Medium,@Station_Speed_Low,@CreateDateTime)";
dbHelper.ClearParameter();
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@ID", Guid.NewGuid().ToString());
dbHelper.AddParameter("@MainId", xlstationsub.MainId);
dbHelper.AddParameter("@StationSubName", xlstationsub.StationSubName);
dbHelper.AddParameter("@Station_Weight_Medium", xlstationsub.Station_Weight_Medium);
dbHelper.AddParameter("@Station_Weight_Low", xlstationsub.Station_Weight_Low);
dbHelper.AddParameter("@Station_Weight_Advance", xlstationsub.Station_Weight_Advance);
dbHelper.AddParameter("@Station_Speed_Hight", xlstationsub.Station_Speed_Hight);
dbHelper.AddParameter("@Station_Speed_Medium", xlstationsub.Station_Speed_Medium);
dbHelper.AddParameter("@Station_Speed_Low", xlstationsub.Station_Speed_Low);
dbHelper.AddParameter("@CreateDateTime", DateTime.Now);
dbHelper.ExecuteNonQuery();
}
public static bool PlanExistsRecipeID(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 strSql = "select count(Plan_Id) from xl_plan where Recipe_ID = @Recipe_ID";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@Recipe_ID", recipeID);
object result = dbHelper.ToScalar();
if (result != null && result != DBNull.Value && Convert.ToInt32(result) > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 获取工位信息
/// </summary>
/// <param name="recipeName">配方名称</param>
/// <returns>返回符合条件的配方</returns>
public static DataTable GetStationList()
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.CommandType = CommandType.Text;
string strSql = "SELECT * FROM xl_station";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
return table;
}
return null;
}
/// <summary>
/// 根据ID 获取工位信息
/// </summary>
/// <param name="recipeName">配方名称</param>
/// <returns>返回符合条件的配方</returns>
public static Entity.xl_station GetStation(string ID)
{
Entity.xl_station station = new Entity.xl_station();
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_station WHERE ID = @ID";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
dbHelper.AddParameter("@ID", ID);
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
foreach (DataRow dr in table.Rows)
{
station = ConvertDataRowToStationEntity(dr);
break;
}
}
return station;
}
/// <summary>
/// 把DataRow的数据封装至配方实体
/// </summary>
/// <param name="dr">配方数据行</param>
/// <returns>返回封装号的配方实体对象</returns>
public static Entity.xl_station ConvertDataRowToStationEntity(DataRow dr)
{
if (dr != null)
{
Entity.xl_station station = new Entity.xl_station();
station.ID = Mesnac.Basic.DataProcessor.RowValue(dr, "ID", String.Empty);
station.StationName = Mesnac.Basic.DataProcessor.RowValue(dr, "StationName", String.Empty);
station.End_datetime = Mesnac.Basic.DataProcessor.RowValue(dr, "End_datetime", DateTime.Now);
return station;
}
else
{
return null;
}
}
public static string UpdateStationData(Entity.xl_station station)
{
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(station.ID))
{
//添加新配方
sqlstr = @"INSERT INTO xl_station(ID,StationName,End_datetime)VALUES(@ID,@StationName,@End_datetime)";
}
else
{
//更新原有配方
sqlstr = @"UPDATE xl_station set StationName = @StationName,End_datetime =@End_datetime where ID = @ID";
}
dbHelper.ClearParameter();
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@ID", station.ID);
dbHelper.AddParameter("@StationName", station.StationName);
dbHelper.AddParameter("@End_datetime", DateTime.Now);
dbHelper.ExecuteNonQuery();
return station.ID;
}
public static void UpdateStationSubData(List<Entity.xl_station_sub> sub)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
try
{
dbHelper.CommandType = CommandType.Text;
string sqlstr = String.Empty;
foreach (Entity.xl_station_sub item in sub)
{
//更新原有配方
sqlstr = @"UPDATE xl_station_sub set StationSubName = @StationSubName,Station_Weight_Medium=@Station_Weight_Medium,Station_Weight_Low=@Station_Weight_Low,Station_Weight_Advance=@Station_Weight_Advance,
Station_Speed_Hight=@Station_Speed_Hight,Station_Speed_Medium=@Station_Speed_Medium,Station_Speed_Low=@Station_Speed_Low where ID = @ID";
dbHelper.ClearParameter();
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@ID", item.ID);
dbHelper.AddParameter("@StationSubName", item.StationSubName);
dbHelper.AddParameter("@Station_Weight_Medium", item.Station_Weight_Medium);
dbHelper.AddParameter("@Station_Weight_Low", item.Station_Weight_Low);
dbHelper.AddParameter("@Station_Weight_Advance", item.Station_Weight_Advance);
dbHelper.AddParameter("@Station_Speed_Hight", item.Station_Speed_Hight);
dbHelper.AddParameter("@Station_Speed_Medium", item.Station_Speed_Medium);
dbHelper.AddParameter("@Station_Speed_Low", item.Station_Speed_Low);
dbHelper.ExecuteNonQuery();
}
}
catch (Exception ex)
{
throw ex;
}
}
public static void DelStationSubData(string sub)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
try
{
dbHelper.CommandType = CommandType.Text;
string sqlstr = String.Empty;
//更新原有配方
sqlstr = @"Delete from xl_station_sub where MainId = @ID";
dbHelper.ClearParameter();
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@ID", sub);
dbHelper.ExecuteNonQuery();
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 判断某个计划是否存在
/// </summary>
/// <param name="recipeName">工位名称</param>
/// <returns>存在返回true否则返回false</returns>
public static bool PlanExistsStation(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 strSql = "select count(Plan_Id) from xl_plan where Recipe_ID = @ID";
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@ID", recipeID);
object result = dbHelper.ToScalar();
if (result != null && result != DBNull.Value && Convert.ToInt32(result) > 0)
{
return true;
}
else
{
return false;
}
}
#region 删除工位信息
/// <summary>
/// 删除工位信息
/// </summary>
/// <param name="recipeID">工位ID</param>
public static void DeleteStation(string ID)
{
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_station where ID = @ID";
dbHelper.ClearParameter();
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@ID", ID);
dbHelper.ExecuteNonQuery();
}
#endregion
#region 删除工位信息
/// <summary>
/// 删除工位信息
/// </summary>
/// <param name="recipeID">工位ID</param>
public static void DeleteStationSub(string ID)
{
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_station_sub where MainId = @MainId";
dbHelper.ClearParameter();
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@MainId", ID);
dbHelper.ExecuteNonQuery();
}
#endregion
}
}