|
|
using ICSSoft.Common;using ICSSoft.Entity;using Newtonsoft.Json;using System;using System.Collections.Generic;using System.Data;using System.Data.SqlClient;using System.Linq;using System.Text;using System.Threading.Tasks;
namespace ICSSoft.DataProject{ /// <summary>
/// 管控方式
/// </summary>
public class ICSControlModeService { private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static string connString = System.Configuration.ConfigurationManager.AppSettings["ConnStr"]; private static string ERPDB = System.Configuration.ConfigurationManager.AppSettings["ERPDB"]; DataTable table = null; SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString); string sql = string.Empty; string sqlInfo = string.Empty; VerificationMethod verification = new VerificationMethod();
/// <summary>
/// 获取当前启用的管控方式
/// </summary>
/// <param name="cmd"></param>
/// <param name="language"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public static ControlMode GetControlMode() { using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString)) { conn.Open(); SqlCommand cmd = new SqlCommand(); SqlTransaction sqlTran = conn.BeginTransaction(); cmd.Transaction = sqlTran; cmd.Connection = conn; try { string sql = @"SELECT TOP 1 F_ItemCode as itemCode,F_ItemName as itemName,F_EnabledMark as enableMark
FROM [dbo].[Sys_SRM_ItemsDetail] WHERE F_ItemId='14361ce1-c5e3-4e85-a253-51aa3cdde3e6'AND F_EnabledMark='1' ORDER BY F_ItemCode";
DataTable table = DBHelper.SQlReturnData(sql, cmd); string json = JsonConvert.SerializeObject(table); List<ControlMode> model = JsonConvert.DeserializeObject<List<ControlMode>>(json); cmd.Transaction.Commit(); return model[0]; } catch (Exception ex) { if (cmd.Transaction != null) cmd.Transaction.Rollback(); log.Error(ex.Message); throw new Exception(ex.Message); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } conn.Dispose(); } } }
/// <summary>
/// 获取建议库位方式
/// </summary>
/// <param name="cmd"></param>
/// <param name="language"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public static ControlMode GetSuLocation() { using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString)) { conn.Open(); SqlCommand cmd = new SqlCommand(); ControlMode contro = new ControlMode(); SqlTransaction sqlTran = conn.BeginTransaction(); cmd.Transaction = sqlTran; cmd.Connection = conn; try { string sql = @"SELECT Top 1 a.F_ItemCode as itemCode,a.F_ItemName as itemName,a.F_EnabledMark as enableMark
FROM [dbo].[Sys_SRM_ItemsDetail] a LEFT JOIN [dbo].[Sys_SRM_Items] b ON a.F_ItemId=b.F_Id AND b.F_EnabledMark='1' WHERE F_ItemId='c8767643-1429-48b1-ad31-c6b19a1dfcb9'AND a.F_EnabledMark='1' ORDER BY a.F_ItemCode";
DataTable table = DBHelper.SQlReturnData(sql, cmd); if (table == null || table.Rows.Count <= 0) { return null; } else { string json = JsonConvert.SerializeObject(table); List<ControlMode> model = JsonConvert.DeserializeObject<List<ControlMode>>(json); cmd.Transaction.Commit(); return model[0]; } } catch (Exception ex) { if (cmd.Transaction != null) cmd.Transaction.Rollback(); log.Error(ex.Message); throw new Exception(ex.Message); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } conn.Dispose(); } } }
/// <summary>
/// 获取拣配
/// </summary>
/// <param name="cmd"></param>
/// <param name="language"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public static DataTable GetZL() { using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString)) { conn.Open(); SqlCommand cmd = new SqlCommand(); ControlMode contro = new ControlMode(); SqlTransaction sqlTran = conn.BeginTransaction(); cmd.Transaction = sqlTran; cmd.Connection = conn; try { string sql = @"select b.F_ItemCode as Code ,b.F_Define2 as Name,b.F_EnabledMark AS Enable,b.F_Define1 AS BusinessCode
from Sys_SRM_Items a left join Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId where a.F_EnCode='PL00001' order by cast(b.F_SortCode as int) asc";
DataTable table = DBHelper.SQlReturnData(sql, cmd); if (table == null || table.Rows.Count <= 0) { return null; } else { return table; //string json = JsonConvert.SerializeObject(table);
//List<ControlMode> model = JsonConvert.DeserializeObject<List<ControlMode>>(json);
//cmd.Transaction.Commit();
//return model[0];
}
} catch (Exception ex) { if (cmd.Transaction != null) cmd.Transaction.Rollback(); log.Error(ex.Message); throw new Exception(ex.Message); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } conn.Dispose(); } } }
/// <summary>
/// 获取晶华立库仓库
/// </summary>
/// <param name="cmd"></param>
/// <param name="language"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public static DataTable GetJHWHCode() { using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString)) { conn.Open(); SqlCommand cmd = new SqlCommand(); ControlMode contro = new ControlMode(); SqlTransaction sqlTran = conn.BeginTransaction(); cmd.Transaction = sqlTran; cmd.Connection = conn; try { string sql = @"SELECT DISTINCT
b.F_ItemCode FROM Sys_SRM_Items a LEFT JOIN Sys_SRM_ItemsDetail b ON a.F_Id = b.F_ItemId WHERE a.F_EnCode = 'JinHuaLiKu'";
DataTable table = DBHelper.SQlReturnData(sql, cmd); if (table == null || table.Rows.Count <= 0) { return null; } else { return table; //string json = JsonConvert.SerializeObject(table);
//List<ControlMode> model = JsonConvert.DeserializeObject<List<ControlMode>>(json);
//cmd.Transaction.Commit();
//return model[0];
}
} catch (Exception ex) { if (cmd.Transaction != null) cmd.Transaction.Rollback(); log.Error(ex.Message); throw new Exception(ex.Message); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } conn.Dispose(); } } }
/// <summary>
/// 晶华立库调用erp数据重传
/// </summary>
/// <param name="cmd"></param>
/// <param name="language"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public static void InsertErrLog(string Url, string JsonStr, string msg, string UserCode, string WorkPoint, SqlCommand cmd) { try { string sql = @"INSERT INTO ICSAPIErrorLog(ID,Url,JosnStr,ErrorMsg,Status,WorkPoint,MUSER,
MUSERName,MTIME) SELECT NEWID(),'{0}','{1}','{2}',0,'{4}' ,F_Account ,F_RealName ,SYSDATETIME() FROM Sys_SRM_User WHERE F_Account='{3}' and F_Location='{4}'";
sql = string.Format(sql, Url, JsonStr, msg, UserCode, WorkPoint); if (!DBHelper.ExecuteNonQuery(sql, cmd)) { throw new Exception("报错信息记录失败!"); }
} catch (Exception ex) { if (cmd.Transaction != null) cmd.Transaction.Rollback(); log.Error(ex.Message); throw new Exception(ex.Message); } }
/// <summary>
/// 获取车间对应仓库
/// </summary>
/// <param name="cmd"></param>
/// <param name="language"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public static DataTable GetWHCode() { using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString)) { conn.Open(); SqlCommand cmd = new SqlCommand(); ControlMode contro = new ControlMode(); SqlTransaction sqlTran = conn.BeginTransaction(); cmd.Transaction = sqlTran; cmd.Connection = conn; try { string sql = @"SELECT DISTINCT
b.F_ItemName AS CName, STUFF(( SELECT ',' + b2.F_ItemCode FROM Sys_SRM_ItemsDetail b2 WHERE b2.F_ItemName = b.F_ItemName ORDER BY b2.F_ItemCode FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 1, '') AS WHCode FROM Sys_SRM_Items a LEFT JOIN Sys_SRM_ItemsDetail b ON a.F_Id = b.F_ItemId WHERE a.F_EnCode = 'workShopToWareHouse' GROUP BY b.F_ItemName";
DataTable table = DBHelper.SQlReturnData(sql, cmd); if (table == null || table.Rows.Count <= 0) { return null; } else { return table; //string json = JsonConvert.SerializeObject(table);
//List<ControlMode> model = JsonConvert.DeserializeObject<List<ControlMode>>(json);
//cmd.Transaction.Commit();
//return model[0];
}
} catch (Exception ex) { if (cmd.Transaction != null) cmd.Transaction.Rollback(); log.Error(ex.Message); throw new Exception(ex.Message); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } conn.Dispose(); } } }
/// <summary>
/// 获取单据是否需要检验
/// </summary>
/// <param name="cmd"></param>
/// <param name="language"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public static bool GetOrderIns(string orderType) { using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString)) { conn.Open(); SqlCommand cmd = new SqlCommand(); ControlMode contro = new ControlMode(); SqlTransaction sqlTran = conn.BeginTransaction(); cmd.Transaction = sqlTran; cmd.Connection = conn; try { string sql = @"select b.* from Sys_SRM_ItemsDetail b inner join Sys_SRM_Items a on a.F_Id=b.F_ItemId where
b.F_ItemCode = '" + orderType + "' and b.F_EnabledMark= 1 and a.F_EnabledMark= 1 and a.F_ENCODE = 'ICSInspectionCheck' " +
"union " + @"select b.* from Sys_SRM_ItemsDetail b inner join Sys_SRM_Items a on a.F_Id=b.F_ItemId where
b.F_ItemName = '" + orderType + @"' and b.F_EnabledMark = 1 and a.F_EnabledMark = 1 and a.F_ENCODE = 'ICSInspectionCheck'";
DataTable table = DBHelper.SQlReturnData(sql, cmd); if (table == null || table.Rows.Count <= 0) { return false; } else { return true; //string json = JsonConvert.SerializeObject(table);
//List<ControlMode> model = JsonConvert.DeserializeObject<List<ControlMode>>(json);
//cmd.Transaction.Commit();
//return model[0];
}
} catch (Exception ex) { if (cmd.Transaction != null) cmd.Transaction.Rollback(); log.Error(ex.Message); throw new Exception(ex.Message); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } conn.Dispose(); } } } /// <summary>
/// 根据条码获取信息
/// </summary>
/// <param name="LotNo"></param>
/// <param name="WorkPoint"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public static string QueryLotNo(string LotNo,string WorkPoint,SqlCommand command=null) { using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString)) { SqlCommand cmd; if (command == null) { conn.Open(); cmd = new SqlCommand(); SqlTransaction sqlTran = conn.BeginTransaction(); cmd.Transaction = sqlTran; cmd.Connection = conn; } else cmd = command; try { string sql = @"SELECT a.ID,
con.ContainerCode, con.ContainerName, a.LotNo, a.InvCode, inv.InvName, inv.InvStd, inv.InvUnit,-- {0} inv.AmountUnit, ext.ID AS ExtensionID, ext.ProjectCode, ext.Version, ext.BatchCode, ext.Brand, ext.cFree1, ext.cFree2, ext.cFree3, ext.cFree4, ext.cFree5, ext.cFree6, ext.cFree7, ext.cFree8, ext.cFree9, ext.cFree10, a.MUSER AS [ USER ], a.MTIME AS [ MTime ] FROM ICSInventoryLot a LEFT JOIN ICSContainerLot conlot ON a.LotNo = conlot.LotNo AND a.WorkPoint = conlot.WorkPoint LEFT JOIN ICSContainer con ON conlot.ContainerID = con.ID AND conlot.WorkPoint = con.WorkPoint INNER JOIN ICSInventory inv ON a.InvCode = inv.InvCode AND a.WorkPoint = inv.WorkPoint INNER JOIN ICSExtension ext ON a.ExtensionID = ext.ID AND a.WorkPoint = ext.WorkPoint WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
sql = string.Format(sql, LotNo, WorkPoint); DataTable table = DBHelper.SQlReturnData(sql, cmd); string json = JsonConvert.SerializeObject(table); //List<LotNoMode> model = JsonConvert.DeserializeObject<List<LotNoMode>>(json);
if(command==null) cmd.Transaction.Commit(); return json; } catch (Exception ex) { if (cmd.Transaction != null&& command==null) cmd.Transaction.Rollback(); log.Error(ex.Message); throw new Exception(ex.Message); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } conn.Dispose(); } } }
}}
|