using NFine.Data.Extensions; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using NFine.Code; using NFine.Repository; using System.Data.Common; using NFine.Domain._03_Entity.SRM; using ICS.Application.Entity; using Newtonsoft.Json; using System.Configuration; using System.Data.SqlClient; using ICS.Data; using Newtonsoft.Json.Linq; using NFine.Domain._03_Entity.WMS; namespace NFine.Application.WMS { public class BasicSettingsApp : RepositoryFactory { /// /// 删除库位 /// /// 传入ID /// public string DeleteStack(string keyValue) { //站点信息 string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; keyValue = keyValue.Substring(1, keyValue.Length - 2); string sql = string.Empty; sql = string.Format(@"DELETE FROM dbo.ICSLocation WHERE ID IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint); try { SqlHelper.ExecuteNonQuery(sql); } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 删除不良原因 /// /// 传入ID /// public string DeleteBadCode(string keyValue) { //站点信息 string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; keyValue = keyValue.Substring(1, keyValue.Length - 2); string sql = string.Empty; sql = string.Format(@"DELETE FROM dbo.ICSBadCode WHERE ID IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint); try { SqlHelper.ExecuteNonQuery(sql); } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 获取库房信息 /// /// public DataTable GetWarehouse() { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string sql = @" select '' as WarehouseCode,'' as WarehouseName union all SELECT [WarehouseCode],[WarehouseName] FROM [ICSWarehouse] WITH (NOLOCK) WHERE 1=1 "; //string role = NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode; //if (role != "admin") //{ // sql += " and b.WorkPoint='" + WorkPoint + "'"; //} sql += " and WorkPoint='" + WorkPoint + "'"; DataTable dt = SqlHelper.GetDataTableBySql(sql); return dt; } /// /// 新增库位 /// /// /// public string InsertStack(string keyValue) { var queryParam = keyValue.ToJObject(); string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; string StackSql = @"select * from ICSWarehouse where WarehouseCode='{0}' and WorkPoint='{1}'"; StackSql = string.Format(StackSql, queryParam["Warehouse"].ToString(), WorkPoint); DataTable dt = SqlHelper.GetDataTableBySql(StackSql); string sql = string.Empty; sql = @"INSERT INTO dbo.ICSLocation ( ID ,LocationCode ,LocationName ,WHID ,MUSER , MUSERName ,MTIME ,WorkPoint ,Region,Row,GoodsShelf ,Tier,Grid) Values(NEWID(),'{0}','{1}','{2}','{3}','{4}',GETDATE(),'{5}','{6}','{7}','{8}','{9}','{10}')"; sql = string.Format(sql, queryParam["StackCode"].ToString(), queryParam["StackName"].ToString(), dt.Rows[0]["ID"].ToString(), MUSER, MUSERNAME, WorkPoint, queryParam["Qu"].ToString(), queryParam["Pai"].ToString(), queryParam["Jia"].ToString(), queryParam["Ceng"].ToString(), queryParam["Ge"].ToString()); try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { } else { msg = "新增失败"; } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 新增不良代码 /// /// /// public string InsertBadCode(string keyValue) { var queryParam = keyValue.ToJObject(); string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; string sql = string.Empty; sql = @"INSERT INTO dbo.ICSBadCode ( ID ,BadCode ,BadDesc ,MUSER , MUSERName ,MTIME ,WorkPoint,BCGroupID ) Values(NEWID(),'{0}','{1}','{2}','{3}',GETDATE(),'{4}','NULL')"; sql = string.Format(sql, queryParam["BadCode"].ToString(), queryParam["BadDesc"].ToString(), MUSER, MUSERNAME, WorkPoint); try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { } else { msg = "新增失败"; } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 修改不良代码 /// /// /// public string UpdateBadCode(string keyValue) { var queryParam = keyValue.ToJObject(); string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; string sql = string.Empty; sql = @"UPDATE dbo.ICSBadCode set BadCode='{0}',BadDesc='{1}',MUSER='{2}',MUSERName='{3}',MTIME=GetDate(),WorkPoint='{4}' WHERE ID='{5}'"; sql = string.Format(sql, queryParam["BadCode"].ToString(), queryParam["BadDesc"].ToString(), MUSER, MUSERNAME, WorkPoint, queryParam["ID"].ToString()); try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { } else { msg = "新增失败"; } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 修改库位 /// /// /// public string UpdateStack(string keyValue) { var queryParam = keyValue.ToJObject(); string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; string StackSql = @"select * from ICSWarehouse where WarehouseCode='{0}'"; StackSql = string.Format(StackSql, queryParam["Warehouse"].ToString()); DataTable dt = SqlHelper.GetDataTableBySql(StackSql); string sql = string.Empty; sql = @"UPDATE dbo.ICSLocation set LocationCode='{0}',LocationName='{1}',WHID='{2}',MUSER='{3}',MUSERName='{4}',MTIME=GETDATE(),WorkPoint='{5}',Region='{7}',Row='{8}',GoodsShelf ='{9}',Tier='{10}',Grid='{11}' WHERE ID='{6}'"; sql = string.Format(sql, queryParam["StackCode"].ToString(), queryParam["StackName"].ToString(), dt.Rows[0]["ID"].ToString(), MUSER, MUSERNAME, WorkPoint, queryParam["ID"].ToString(), queryParam["Qu"].ToString(), queryParam["Pai"].ToString(), queryParam["Jia"].ToString(), queryParam["Ceng"].ToString(), queryParam["Ge"].ToString()); try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { } else { msg = "修改失败"; } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 新增类型 /// /// /// public string InsertICSType(string keyValue) { var queryParam = keyValue.ToJObject(); string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; string sql = string.Empty; sql = @"INSERT INTO dbo.ICSType ( ID ,TableCode ,ColumnCode ,Code,Name, Enable,MTIME,MUSER ,MUSERName ,WorkPoint ) Values(NEWID(),'{0}','{1}','{2}','{3}','{4}',GETDATE(),'{5}','{6}','{7}') "; sql = string.Format(sql, queryParam["TableCode"].ToString(), queryParam["ColumnCode"].ToString(), queryParam["Code"].ToString(), queryParam["Name"].ToString(), queryParam["Enable"].ToString(), MUSER, MUSERNAME, WorkPoint); try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { } else { msg = "新增失败"; } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 修改类型 /// /// /// public string UpdateICSType(string keyValue) { var queryParam = keyValue.ToJObject(); string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; string sql = string.Empty; sql = @"UPDATE dbo.ICSType set TableCode='{0}',ColumnCode='{1}',Code='{2}',Name='{3}',Enable='{4}',MTIME=GETDATE(),MUSER='{5}',MUSERName='{6}',WorkPoint='{7}' WHERE ID='{8}'"; sql = string.Format(sql, queryParam["TableCode"].ToString(), queryParam["ColumnCode"].ToString(), queryParam["Code"].ToString(), queryParam["Name"].ToString(), queryParam["Enable"].ToString(), MUSER, MUSERNAME, WorkPoint, queryParam["ID"].ToString()); try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { } else { msg = "修改失败"; } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 删除类型 /// /// 传入ID /// public string DeleteICSType(string keyValue) { //站点信息 string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; keyValue = keyValue.Substring(1, keyValue.Length - 2); string sql = string.Empty; sql = string.Format(@"DELETE FROM dbo.ICSType WHERE ID IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint); try { SqlHelper.ExecuteNonQuery(sql); } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 修改参数配置 /// /// /// public string UpdateICSConfiguration(string keyValue) { var queryParam = keyValue.ToJObject(); string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; string sql = string.Empty; sql = @"UPDATE dbo.ICSConfiguration set Code='{0}',Name='{1}',Enable='{2}',Figure='{3}',MTIME=GETDATE(),MUSER='{4}',MUSERName='{5}',WorkPoint='{6}' WHERE ID='{7}'"; sql = string.Format(sql, queryParam["Code"].ToString(), queryParam["Name"].ToString(), queryParam["Enable"].ToString(), queryParam["Figure"].ToString(), MUSER, MUSERNAME, WorkPoint, queryParam["ID"].ToString()); try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { } else { msg = "修改失败"; } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 新增参数配置 /// /// /// public string InsertICSConfiguration(string keyValue) { var queryParam = keyValue.ToJObject(); string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; string sql = string.Empty; sql = @"INSERT INTO dbo.ICSConfiguration ( ID ,Code ,Name ,Enable,Figure,MTIME,MUSER ,MUSERName ,WorkPoint ) Values(NEWID(),'{0}','{1}','{2}','{3}',GETDATE(),'{4}','{5}','{6}') "; sql = string.Format(sql, queryParam["Code"].ToString(), queryParam["Name"].ToString(), queryParam["Enable"].ToString(), queryParam["Figure"].ToString(), MUSER, MUSERNAME, WorkPoint); try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { } else { msg = "新增失败"; } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 删除参数配置 /// /// 传入ID /// public string DeleteICSConfiguration(string keyValue) { //站点信息 string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; keyValue = keyValue.Substring(1, keyValue.Length - 2); string sql = string.Empty; sql = string.Format(@"DELETE FROM dbo.ICSConfiguration WHERE ID IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint); try { SqlHelper.ExecuteNonQuery(sql); } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 修改启用配置 /// /// /// public string UpdateICSExtensionEnable(string keyValue) { var queryParam = keyValue.ToJObject(); string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; string sql = string.Empty; sql = @"UPDATE dbo.ICSExtensionEnable set ColCode='{0}',ColName='{1}',Enable='{2}',MTIME=GETDATE(),MUSER='{3}',MUSERName='{4}',WorkPoint='{5}' WHERE ID='{6}'"; sql = string.Format(sql, queryParam["ColCode"].ToString(), queryParam["ColName"].ToString(), queryParam["Enable"].ToString(), MUSER, MUSERNAME, WorkPoint, queryParam["ID"].ToString()); try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { } else { msg = "修改失败"; } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 新增启用配置 /// /// /// public string InsertICSExtensionEnable(string keyValue) { var queryParam = keyValue.ToJObject(); string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; string sql = string.Empty; sql = @"INSERT INTO dbo.ICSExtensionEnable ( ID ,ColCode ,ColName ,Enable,MTIME,MUSER ,MUSERName ,WorkPoint ) Values(NEWID(),'{0}','{1}','{2}',GETDATE(),'{3}','{4}','{5}') "; sql = string.Format(sql, queryParam["ColCode"].ToString(), queryParam["ColName"].ToString(), queryParam["Enable"].ToString(), MUSER, MUSERNAME, WorkPoint); try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { } else { msg = "新增失败"; } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 删除启用配置 /// /// 传入ID /// public string DeleteICSExtensionEnable(string keyValue) { //站点信息 string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; keyValue = keyValue.Substring(1, keyValue.Length - 2); string sql = string.Empty; sql = string.Format(@"DELETE FROM dbo.ICSExtensionEnable WHERE ID IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint); try { SqlHelper.ExecuteNonQuery(sql); } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } //不良代码 public DataTable GetICSBadCodeGroup(ref Pagination jqgridparam, string queryJson) { DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" select ID,BCGCode,BCGDesc,MUSER,MUSERName,MTIME from ICSBadCodeGroup "; sql += " WHERE 1=1"; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["BadCode"].ToString())) { sql += " and BCGCode like '%" + queryParam["BadCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BadCodeName"].ToString())) { sql += " and BCGDesc like '%" + queryParam["BadCodeName"].ToString() + "%' "; } } sql = string.Format(sql); DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } //不良原因 public DataTable GetICSBadReasonGroup(ref Pagination jqgridparam, string queryJson) { DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" select ID,BRGCode,BRGDesc,MUSER,MUSERName,MTIME from ICSBadReasonGroup "; sql += " WHERE 1=1"; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["BadReason"].ToString())) { sql += " and BRGCode like '%" + queryParam["BadReason"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BadReasonName"].ToString())) { sql += " and BRGDesc like '%" + queryParam["BadReasonName"].ToString() + "%' "; } } sql = string.Format(sql); DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } //不良代码子表 public DataTable GetICSBadCodeGroupdetil(string ID, ref Pagination jqgridparam) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); //var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @"select BCGroupID,BadCode,BadDesc,MUSERName,MTIME from ICSBadCode where BCGroupID='" + ID + "' "; return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } public DataTable GetICSBadCode(string BRGCode, ref Pagination jqgridparam) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); //var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @"select BRGroupID,BadReasonCode,BadReasonDesc,MUSERName,MTIME from ICSBadReason WHERE BRGroupID='" + BRGCode + "' "; return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } /// /// 不良原因子表查询 /// /// /// /// public DataTable GetICSBadReason(string BRGCode, ref Pagination jqgridparam) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); //var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @"select BRGroupID,BadReasonCode,BadReasonDesc,MUSERName,MTIME from ICSBadReason WHERE BRGroupID='" + BRGCode + "' "; return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } /// /// 不良原因子表查询2 /// /// /// /// public DataTable GetICSBadReason2(string BRGCode, ref Pagination jqgridparam) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); //var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @"select BRGroupID,BadReasonCode,BadReasonDesc,MUSERName,MTIME from ICSBadReason WHERE BRGroupID='" + BRGCode + "' "; return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } public void DeleteBCItem(string ID) { string sql = "DELETE FROM dbo.ICSBadCode WHERE ID='" + ID + "'"; SqlHelper.ExecuteNonQuery(sql); } public void DeleteItem(string ID) { string sql = "DELETE FROM dbo.ICSBadReason WHERE ID='" + ID + "'"; SqlHelper.ExecuteNonQuery(sql); } //不良代码新增 public void SubICSBadCodeGroupAdd(ICSBadReason main, string BRGCode, string BRGDesc) { string sql = string.Empty; string sqls = string.Empty; string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string NewID = Common.GuId(); List list_Item1 = new List(); if (main.arrayShellFabricItem != null) { list_Item1 = JsonConvert.DeserializeObject>(main.arrayShellFabricItem); } string connString = SqlHelper.DataCenterConnString; SqlConnection conn = new SqlConnection(connString); conn.Open(); SqlTransaction sqlTran = conn.BeginTransaction(); SqlCommand cmd = new SqlCommand(); cmd.Transaction = sqlTran; cmd.Connection = conn; sql = @"IF EXISTS( select BCGCode from ICSBadCodeGroup where BCGCode='{0}') BEGIN RAISERROR('系统中已存在相同编号的不良代码编号!',16,1); RETURN END INSERT INTO dbo.ICSBadCodeGroup ( ID ,BCGCode ,BCGDesc, MTIME,MUSER ,MUSERName ,WorkPoint ) Values('{5}','{0}','{1}',GETDATE(),'{2}','{3}','{4}')"; sql = string.Format(sql, BRGCode, BRGDesc, MUSER, MUSERNAME, WorkPoint, NewID); try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { foreach (ICSBadReason Item in list_Item1) { sqls = @"IF EXISTS( select BadCode from ICSBadCode where BadCode=@BadReasonCode) BEGIN RAISERROR('系统中已存在相同编号的不良代码编号!',16,1); RETURN END INSERT INTO dbo.ICSBadCode ( ID ,BCGroupID,BadCode ,BadDesc, MTIME,MUSER ,MUSERName ,WorkPoint ) Values(@ID,'{0}',@BadReasonCode,@BadReasonDesc,GETDATE(),'{1}','{2}','{3}')"; sqls = string.Format(sqls, NewID, MUSER, MUSERNAME, WorkPoint); SqlParameter[] sp_Item = { new SqlParameter("@ID",DbType.String){ Value= Item.ID}, new SqlParameter("@BadReasonCode",DbType.String){ Value= Item.BadReasonCode}, new SqlParameter("@BadReasonDesc",DbType.String){ Value= Item.BadReasonDesc}, }; SqlCommandHelper.CmdExecuteNonQuery(sqls, sp_Item, cmd); } cmd.Transaction.Commit(); } } catch (Exception ex) { cmd.Transaction.Rollback(); throw new Exception(ex.Message); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } conn.Dispose(); } } //不良原因新增 public void SubICSBadReasonGroupAdd(ICSBadReason main, string BRGCode, string BRGDesc) { string sql = string.Empty; string sqls = string.Empty; string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string NewID = Common.GuId(); List list_Item1 = new List(); if (main.arrayShellFabricItem != null) { list_Item1 = JsonConvert.DeserializeObject>(main.arrayShellFabricItem); } string connString = SqlHelper.DataCenterConnString; SqlConnection conn = new SqlConnection(connString); conn.Open(); SqlTransaction sqlTran = conn.BeginTransaction(); SqlCommand cmd = new SqlCommand(); cmd.Transaction = sqlTran; cmd.Connection = conn; sql = @"IF EXISTS( select BRGCode from ICSBadReasonGroup where BRGCode='{0}') BEGIN RAISERROR('系统中已存在相同编号的不良原因组编号!',16,1); RETURN end INSERT INTO dbo.ICSBadReasonGroup ( ID ,BRGCode ,BRGDesc, MTIME,MUSER ,MUSERName ,WorkPoint ) Values('{5}','{0}','{1}',GETDATE(),'{2}','{3}','{4}')"; sql = string.Format(sql, BRGCode, BRGDesc, MUSER, MUSERNAME, WorkPoint, NewID); try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { foreach (ICSBadReason Item in list_Item1) { sqls = @"IF EXISTS(select BadReasonCode from ICSBadReason where BadReasonCode=@BadReasonCode) BEGIN RAISERROR('系统中已存在相同编号的不良原因编号!',16,1); RETURN end INSERT INTO dbo.ICSBadReason ( ID ,BRGroupID,BadReasonCode ,BadReasonDesc, MTIME,MUSER ,MUSERName ,WorkPoint ) Values(@ID,'{0}',@BadReasonCode,@BadReasonDesc,GETDATE(),'{1}','{2}','{3}')"; sqls = string.Format(sqls, NewID, MUSER, MUSERNAME, WorkPoint); SqlParameter[] sp_Item = { new SqlParameter("@ID",DbType.String){ Value= Item.ID}, new SqlParameter("@BadReasonCode",DbType.String){ Value= Item.BadReasonCode}, new SqlParameter("@BadReasonDesc",DbType.String){ Value= Item.BadReasonDesc}, }; SqlCommandHelper.CmdExecuteNonQuery(sqls, sp_Item, cmd); } cmd.Transaction.Commit(); } } catch (Exception ex) { cmd.Transaction.Rollback(); throw new Exception(ex.Message); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } conn.Dispose(); } } public DataTable GetICSBadCodeGroupdetil2(string ID) { string sql = string.Empty; DataTable dt = null; sql = string.Format(@"select * from ICSBadCode where BCGroupID='{0}'", ID); dt = SqlHelper.GetDataTableBySql(sql); return dt; } public DataTable GetICSBadReason2(string BRGCode) { string sql = string.Empty; DataTable dt = null; sql = string.Format(@"select * from ICSBadReason where BRGroupID='{0}'", BRGCode); dt = SqlHelper.GetDataTableBySql(sql); return dt; } public void UpdateICSBadCodeGroup(ICSBadReason main, string BID, string BRGCode, string BRGDesc) { string sql = string.Empty; string sqls = string.Empty; string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; List list_Item1 = new List(); if (main.arrayShellFabricItem != null) { list_Item1 = JsonConvert.DeserializeObject>(main.arrayShellFabricItem); } string connString = SqlHelper.DataCenterConnString; SqlConnection conn = new SqlConnection(connString); conn.Open(); SqlTransaction sqlTran = conn.BeginTransaction(); SqlCommand cmd = new SqlCommand(); cmd.Transaction = sqlTran; cmd.Connection = conn; sql = @"UPDATE dbo.ICSBadCodeGroup set BCGCode='{0}',BCGDesc='{1}',MTIME=GETDATE(),MUSER='{2}',MUSERName='{3}',WorkPoint='{4}' WHERE ID='{5}'"; sql = string.Format(sql, BRGCode, BRGDesc, MUSER, MUSERNAME, WorkPoint, BID); try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { foreach (ICSBadReason Item in list_Item1) { sqls = @" IF NOT EXISTS(SELECT * FROM ICSBadCode WHERE ID=@ID) BEGIN INSERT INTO ICSBadCode( ID,BCGroupID,BadCode,BadDesc,MTIME,MUSER,MUSERName,WorkPoint) VALUES (@ID,'{0}',@BadReasonCode,@BadReasonDesc,getdate(),'{1}','{2}','{3}') END ELSE BEGIN UPDATE dbo.ICSBadCode set BCGroupID='{0}',BadCode=@BadReasonCode,BadDesc=@BadReasonDesc,MTIME=GETDATE(),MUSER='{1}',MUSERName='{2}',WorkPoint='{3}' WHERE ID=@ID end "; sqls = string.Format(sqls, BID, MUSER, MUSERNAME, WorkPoint); SqlParameter[] sp_Item = { new SqlParameter("@ID",DbType.String){ Value= Item.ID}, new SqlParameter("@BadReasonCode",DbType.String){ Value= Item.BadReasonCode}, new SqlParameter("@BadReasonDesc",DbType.String){ Value= Item.BadReasonDesc}, }; SqlCommandHelper.CmdExecuteNonQuery(sqls, sp_Item, cmd); } cmd.Transaction.Commit(); } } catch (Exception ex) { cmd.Transaction.Rollback(); throw new Exception(ex.Message); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } conn.Dispose(); } } public void UpdateICSBadReasonGroup(ICSBadReason main, string BID, string BRGCode, string BRGDesc) { string sql = string.Empty; string sqls = string.Empty; string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; List list_Item1 = new List(); if (main.arrayShellFabricItem != null) { list_Item1 = JsonConvert.DeserializeObject>(main.arrayShellFabricItem); } string connString = SqlHelper.DataCenterConnString; SqlConnection conn = new SqlConnection(connString); conn.Open(); SqlTransaction sqlTran = conn.BeginTransaction(); SqlCommand cmd = new SqlCommand(); cmd.Transaction = sqlTran; cmd.Connection = conn; sql = @"UPDATE dbo.ICSBadReasonGroup set BRGCode='{0}',BRGDesc='{1}',MTIME=GETDATE(),MUSER='{2}',MUSERName='{3}',WorkPoint='{4}' WHERE ID='{5}'"; sql = string.Format(sql, BRGCode, BRGDesc, MUSER, MUSERNAME, WorkPoint, BID); try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { foreach (ICSBadReason Item in list_Item1) { sqls = @" IF NOT EXISTS(SELECT * FROM ICSBadReason WHERE ID=@ID) BEGIN INSERT INTO ICSBadReason( ID,BRGroupID,BadReasonCode,BadReasonDesc,MTIME,MUSER,MUSERName,WorkPoint) VALUES (@ID,'{0}',@BadReasonCode,@BadReasonDesc,getdate(),'{1}','{2}','{3}') END ELSE BEGIN UPDATE dbo.ICSBadReason set BRGroupID='{0}',BadReasonCode=@BadReasonCode,BadReasonDesc=@BadReasonDesc,MTIME=GETDATE(),MUSER='{1}',MUSERName='{2}',WorkPoint='{3}' WHERE ID=@ID end "; sqls = string.Format(sqls, BID, MUSER, MUSERNAME, WorkPoint); SqlParameter[] sp_Item = { new SqlParameter("@ID",DbType.String){ Value= Item.ID}, new SqlParameter("@BadReasonCode",DbType.String){ Value= Item.BadReasonCode}, new SqlParameter("@BadReasonDesc",DbType.String){ Value= Item.BadReasonDesc}, }; SqlCommandHelper.CmdExecuteNonQuery(sqls, sp_Item, cmd); } cmd.Transaction.Commit(); } } catch (Exception ex) { cmd.Transaction.Rollback(); throw new Exception(ex.Message); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } conn.Dispose(); } } /// /// 删除不良代码组 /// /// 传入ID /// public string DeleteICSBadCodeGroup(string keyValue) { //站点信息 string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; keyValue = keyValue.Substring(1, keyValue.Length - 2); string sql = string.Empty; sql += string.Format(@"DELETE FROM dbo.ICSBadCodeGroup WHERE ID IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint); sql += string.Format(@"DELETE FROM dbo.ICSBadCode WHERE BCGroupID IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint); try { if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0) { } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 删除不良原因组 /// /// 传入ID /// public string DeleteICSBadReasonGroup(string keyValue) { //站点信息 string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; keyValue = keyValue.Substring(1, keyValue.Length - 2); string sql = string.Empty; sql += string.Format(@"DELETE FROM dbo.ICSBadReasonGroup WHERE ID IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint); sql += string.Format(@"DELETE FROM dbo.ICSBadReason WHERE BRGroupID IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint); try { if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0) { } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 初次加载查询检验项目组 /// /// /// public DataTable GetICSInspectionGroup(ref Pagination jqgridparam, string queryJson) { DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @"select ID,GroupCode,GroupName,Enable,MUSER,MUSERName,MTIME from ICSInspectionGroup "; sql += " WHERE 1=1"; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["ListCode"].ToString())) { sql += " and GroupCode like '%" + queryParam["ListCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ListName"].ToString())) { sql += " and GroupName like '%" + queryParam["ListName"].ToString() + "%' "; } } sql = string.Format(sql); DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } /// /// 检验项目子表查询 /// /// /// /// public DataTable ICSInspectionList(string GroupCode, ref Pagination jqgridparam) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); //var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @"select GroupID,ListCode,ListName,Unit,SetValueMax,SetValueMin,Enable,MUSERName,MTIME from ICSInspectionList WHERE GroupID='" + GroupCode + "' "; return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } /// /// 根据id删除自动表 /// /// public void DeleteList(string ID) { string sql = "DELETE FROM dbo.ICSInspectionList WHERE ID='" + ID + "'"; SqlHelper.ExecuteNonQuery(sql); } /// /// 检查项目组修改 /// /// /// /// /// /// public void UpdateICSInspectionGroup(ICSInspectionList main, string BID, string GroupCode, string GroupName, string Enable) { string sql = string.Empty; string sqls = string.Empty; string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; List list_Item1 = new List(); if (main.arrayShellFabricItem != null) { list_Item1 = JsonConvert.DeserializeObject>(main.arrayShellFabricItem); } string connString = SqlHelper.DataCenterConnString; SqlConnection conn = new SqlConnection(connString); conn.Open(); SqlTransaction sqlTran = conn.BeginTransaction(); SqlCommand cmd = new SqlCommand(); cmd.Transaction = sqlTran; cmd.Connection = conn; sql = @"UPDATE dbo.ICSInspectionGroup set GroupCode='{0}',GroupName='{1}',Enable='{2}',MTIME=GETDATE(),MUSER='{3}',MUSERName='{4}',WorkPoint='{5}' WHERE ID='{6}'"; sql = string.Format(sql, GroupCode, GroupName, Enable, MUSER, MUSERNAME, WorkPoint, BID); try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { foreach (ICSInspectionList Item in list_Item1) { sqls = @" IF NOT EXISTS(SELECT * FROM ICSInspectionList WHERE ID=@ID) BEGIN INSERT INTO ICSInspectionList( ID,GroupID,ListCode,ListName,Unit,SetValueMax,SetValueMin,Enable,MTIME,MUSER,MUSERName,WorkPoint) VALUES (@ID,'{0}',@ListCode,@ListName,@Unit,@SetValueMax,@SetValueMin,@Enable,getdate(),'{1}','{2}','{3}') END ELSE BEGIN UPDATE dbo.ICSInspectionList set GroupID='{0}',ListCode=@ListCode,ListName=@ListName,Unit=@Unit,SetValueMax=@SetValueMax,SetValueMin=@SetValueMin,Enable=@Enable,MTIME=GETDATE(),MUSER='{1}',MUSERName='{2}',WorkPoint='{3}' WHERE ID=@ID end "; sqls = string.Format(sqls, BID, MUSER, MUSERNAME, WorkPoint); SqlParameter[] sp_Item = { new SqlParameter("@ID",DbType.String){ Value= Item.ID}, new SqlParameter("@ListCode",DbType.String){ Value= Item.ListCode}, new SqlParameter("@ListName",DbType.String){ Value= Item.ListName}, new SqlParameter("@Unit",DbType.String){ Value= Item.Unit}, new SqlParameter("@SetValueMax",DbType.String){ Value= Item.SetValueMax}, new SqlParameter("@SetValueMin",DbType.String){ Value= Item.SetValueMin}, new SqlParameter("@Enable",DbType.String){ Value= Item.Enable}, }; SqlCommandHelper.CmdExecuteNonQuery(sqls, sp_Item, cmd); } cmd.Transaction.Commit(); } } catch (Exception ex) { cmd.Transaction.Rollback(); throw new Exception(ex.Message); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } conn.Dispose(); } } /// /// 检查项目组新增 /// /// /// /// public void ICSInspectionGroupAdd(ICSInspectionList main, string GroupCode, string GroupName, string Enable) { string sql = string.Empty; string sqls = string.Empty; string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string ID = Guid.NewGuid().ToString(); List list_Item1 = new List(); if (main.arrayShellFabricItem != null) { list_Item1 = JsonConvert.DeserializeObject>(main.arrayShellFabricItem); } string connString = SqlHelper.DataCenterConnString; SqlConnection conn = new SqlConnection(connString); conn.Open(); SqlTransaction sqlTran = conn.BeginTransaction(); SqlCommand cmd = new SqlCommand(); cmd.Transaction = sqlTran; cmd.Connection = conn; sql = @" IF EXISTS(select GroupCode from ICSInspectionGroup where GroupCode='{0}') BEGIN RAISERROR('系统中已存在相同编号的检查项目组编号!',16,1); RETURN end INSERT INTO dbo.ICSInspectionGroup ( ID ,GroupCode ,GroupName,Enable, MTIME,MUSER ,MUSERName ,WorkPoint ) Values('{6}','{0}','{1}','{2}',GETDATE(),'{3}','{4}','{5}')"; sql = string.Format(sql, GroupCode, GroupName, Enable, MUSER, MUSERNAME, WorkPoint,ID); try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { foreach (ICSInspectionList Item in list_Item1) { sqls = @" IF EXISTS(select ListCode from ICSInspectionList where ListCode=@ListCode) BEGIN RAISERROR('系统中已存在相同编号的检验项目代码!',16,1); RETURN end INSERT INTO dbo.ICSInspectionList ( ID ,GroupID,ListCode ,ListName, Unit,SetValueMax ,SetValueMin,Enable,MTIME,MUSER ,MUSERName ,WorkPoint ) Values(@ID,'{0}',@ListCode,@ListName,@Unit,@SetValueMax,@SetValueMin,@Enable,getdate(),'{1}','{2}','{3}')"; sqls = string.Format(sqls, ID, MUSER, MUSERNAME, WorkPoint); SqlParameter[] sp_Item = { new SqlParameter("@ID",DbType.String){ Value= Item.ID}, new SqlParameter("@ListCode",DbType.String){ Value= Item.ListCode}, new SqlParameter("@ListName",DbType.String){ Value= Item.ListName}, new SqlParameter("@Unit",DbType.String){ Value= Item.Unit}, new SqlParameter("@SetValueMax",DbType.String){ Value= Item.SetValueMax}, new SqlParameter("@SetValueMin",DbType.String){ Value= Item.SetValueMin}, new SqlParameter("@Enable",DbType.String){ Value= Item.Enable}, }; SqlCommandHelper.CmdExecuteNonQuery(sqls, sp_Item, cmd); } cmd.Transaction.Commit(); } } catch (Exception ex) { cmd.Transaction.Rollback(); throw new Exception(ex.Message); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } conn.Dispose(); } } /// /// 动态子表修改加载页面 /// /// /// public DataTable ICSInspectionList2(string GroupCode) { string sql = string.Empty; DataTable dt = null; sql = string.Format(@"SELECT ID,GroupID,ListCode,ListName,Unit,SetValueMax,SetValueMin, case when Enable='1' then '是' else '否' end as Enable, MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1 FROM dbo.ICSInspectionList where GroupID='{0}'", GroupCode); dt = SqlHelper.GetDataTableBySql(sql); return dt; } /// /// 删除不良原因组 /// /// 传入ID /// public string DeleteICSInspectionGroup(string keyValue) { //站点信息 string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; keyValue = keyValue.Substring(1, keyValue.Length - 2); string sql = string.Empty; string sqls = string.Empty; sql = string.Format(@"DELETE FROM dbo.ICSInspectionGroup WHERE GroupCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint); try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { sqls = string.Format(@"DELETE FROM dbo.ICSInspectionList WHERE GroupID IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint); SqlHelper.ExecuteNonQuery(sqls); } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 新增料品属性 /// /// /// public string InsertICSInventory(string keyValue) { var queryParam = keyValue.ToJObject(); string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; string sql = string.Empty; sql = @"INSERT INTO dbo.ICSInventory ( ID ,InvCode ,InvName ,InvDesc,InvStd,InvUnit,AmountUnit ,ClassCode ,ClassName ,InvRate,InvVersion,InvBrand,InvIQC ,InvFQC ,EffectiveEnable,EffectiveDays,BatchEnable,LotEnable ,PrintEnable ,WHUser,MTIME,MUSER ,MUSERName ,WorkPoint ) Values(NEWID(),'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}',GETDATE(),'{19}','{20}','{21}') "; sql = string.Format(sql, queryParam["InvCode"].ToString(), queryParam["InvName"].ToString(), queryParam["InvDesc"].ToString(), queryParam["InvStd"].ToString(), queryParam["InvUnit"].ToString(), queryParam["AmountUnit"].ToString(), queryParam["ClassCode"].ToString(), queryParam["ClassName"].ToString(), queryParam["InvRate"].ToString(), queryParam["InvVersion"].ToString(), queryParam["InvBrand"].ToString(), queryParam["InvIQC"].ToString(), queryParam["InvFQC"].ToString(), queryParam["EffectiveEnable"].ToString(), queryParam["EffectiveDays"].ToString(), queryParam["BatchEnable"].ToString(), queryParam["LotEnable"].ToString(), queryParam["PrintEnable"].ToString(), queryParam["WHUser"].ToString(), MUSER, MUSERNAME, WorkPoint); try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { } else { msg = "新增失败"; } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 修改料品属性 /// /// /// public string UpdateICSInventory(string keyValue) { var queryParam = keyValue.ToJObject(); string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; string sql = string.Empty; sql = @"UPDATE dbo.ICSInventory set InvCode='{0}' ,InvName='{1}' ,InvDesc='{2}' ,InvStd='{3}' ,InvUnit='{4}' ,AmountUnit='{5}' ,ClassCode='{6}' ,ClassName='{7}' ,InvRate='{8}' ,InvVersion='{9}' ,InvBrand='{10}' ,InvIQC='{11}' ,InvFQC='{12}' ,EffectiveEnable='{13}' ,EffectiveDays='{14}' ,BatchEnable='{15}' ,LotEnable='{16}' ,PrintEnable='{17}' ,WHUser='{18}' ,MTIME=GETDATE() ,MUSER='{19}' ,MUSERName='{20}' ,WorkPoint='{21}' WHERE ID='{22}'"; sql = string.Format(sql, queryParam["InvCode"].ToString(), queryParam["InvName"].ToString(), queryParam["InvDesc"].ToString(), queryParam["InvStd"].ToString(), queryParam["InvUnit"].ToString(), queryParam["AmountUnit"].ToString(), queryParam["ClassCode"].ToString(), queryParam["ClassName"].ToString(), queryParam["InvRate"].ToString(), queryParam["InvVersion"].ToString(), queryParam["InvBrand"].ToString(), queryParam["InvIQC"].ToString(), queryParam["InvFQC"].ToString(), queryParam["EffectiveEnable"].ToString(), queryParam["EffectiveDays"].ToString(), queryParam["BatchEnable"].ToString(), queryParam["LotEnable"].ToString(), queryParam["PrintEnable"].ToString(), queryParam["WHUser"].ToString(), MUSER, MUSERNAME, WorkPoint, queryParam["ID"].ToString()); try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { } else { msg = "修改失败"; } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 获取下拉料品号获取其他信息 /// public DataTable GetInputValue(string ID) { try { DataTable dt = new DataTable(); //var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @"select InvCode,InvName,InvDesc,InvStd,InvUnit,AmountUnit, ClassCode,ClassName,InvRate,InvVersion,InvBrand,InvIQC, InvFQC,EffectiveEnable,EffectiveDays,BatchEnable,LotEnable,PrintEnable,WHUser from ICSInventory WHERE 1=1 AND ID='{0}' "; sql = string.Format(sql, ID); return Repository().FindTableBySql(sql.ToString()); } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } } /// /// 删除料品属性 /// /// 传入ID /// public string DeleteICSInventory(string keyValue) { //站点信息 string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; keyValue = keyValue.Substring(1, keyValue.Length - 2); string sql = string.Empty; sql = string.Format(@"DELETE FROM dbo.ICSInventory WHERE ID IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint); try { SqlHelper.ExecuteNonQuery(sql); } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 获取料品信息 /// /// /// public DataTable GetICSInventoryInfo(string queryJson, ref Pagination jqgridparam) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @"select ID, InvCode,InvName,InvDesc,InvStd,InvUnit,AmountUnit,ClassCode,ClassName,InvRate,InvVersion,InvBrand, InvIQC,InvFQC,EffectiveEnable,EffectiveDays,BatchEnable,LotEnable,PrintEnable,WHUser from ICSInventory where WorkPoint='{0}' "; sql = string.Format(sql, WorkPoint); if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { sql += " and InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } } // DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } /// /// 获取仓库信息 /// /// /// public DataTable GetICSWarehouseInfo(string queryJson, ref Pagination jqgridparam) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @"select ID,WarehouseCode,WarehouseName ,Enable,BatchEnable,Asset,Proxy,InCost from ICSWarehouse where WorkPoint='{0}' "; sql = string.Format(sql, WorkPoint); if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString())) { sql += " and WarehouseCode like '%" + queryParam["WHCode"].ToString() + "%' "; } } DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } /// /// 新增料品仓库批次关系 /// /// /// public string InsertICSInventoryBatchEnable(string keyValue, string keyValue2) { List InvCodeList = keyValue.Substring(1, keyValue.Length - 3).Split(',').ToList(); List WarehouseCodeList = keyValue2.Substring(1, keyValue2.Length - 3).Split(',').ToList(); string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; string sql = string.Empty; foreach (var item in InvCodeList) { foreach (var itemwh in WarehouseCodeList) { sql += @"IF EXISTS(select InvCode,WHCode from ICSInventoryBatchEnable where InvCode={0} and WHCode={1}) BEGIN RAISERROR('请勿重复绑定料品仓库关系!',16,1); RETURN end INSERT INTO dbo.ICSInventoryBatchEnable ( ID ,InvCode ,WHCode ,BatchEnable,MTIME,MUSER ,MUSERName ,WorkPoint ) Values(NEWID(),{0},{1},'{2}',GETDATE(),'{3}','{4}','{5}') "; sql = string.Format(sql, item, itemwh, '1'.ToString(), MUSER, MUSERNAME, WorkPoint); } } try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { } else { msg = "新增失败"; } } catch (Exception ex) { msg = ex.Message; } return msg; } /// /// 修改料品仓库批次关系 /// /// /// public string UpdateICSInventoryBatchEnable(string keyValue) { var queryParam = keyValue.ToJObject(); string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; string sql = string.Empty; sql = @"UPDATE dbo.ICSInventoryBatchEnable set InvCode='{0}',WHCode='{1}',BatchEnable='{2}',MTIME=GETDATE(),MUSER='{3}',MUSERName='{4}',WorkPoint='{5}' WHERE ID='{6}'"; sql = string.Format(sql, queryParam["InvCode"].ToString(), queryParam["WHCode"].ToString(), queryParam["BatchEnable"].ToString(), MUSER, MUSERNAME, WorkPoint, queryParam["ID"].ToString()); try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { } else { msg = "修改失败"; } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 删除料品仓库批次关系 /// /// 传入ID /// public string DeleteICSInventoryBatchEnable(string keyValue) { //站点信息 string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; keyValue = keyValue.Substring(1, keyValue.Length - 2); string sql = string.Empty; sql = string.Format(@"DELETE FROM dbo.ICSInventoryBatchEnable WHERE ID IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint); try { SqlHelper.ExecuteNonQuery(sql); } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 获取库位信息 /// /// /// public DataTable GetICSLocation(string queryJson, ref Pagination jqgridparam) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @"select ID,LocationCode,LocationName,WHID,MUSER,MUSERName,MTIME,WorkPoint from ICSLocation where WorkPoint='{0}' "; sql = string.Format(sql, WorkPoint); if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["LocationCode"].ToString())) { sql += " and LocationCode like '%" + queryParam["LocationCode"].ToString() + "%' "; } } //DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } /// /// 新增料品仓库批次关系 /// /// /// public string InsertICSInventoryLocation(string keyValue, string keyValue2) { List InvCodeList = keyValue.Substring(1, keyValue.Length - 3).Split(',').ToList(); List LocationCodeList = keyValue2.Substring(1, keyValue2.Length - 3).Split(',').ToList(); string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; string sql = string.Empty; try { foreach (var item in InvCodeList) { foreach (var itemwh in LocationCodeList) { sql += @"IF EXISTS(select InvCode,LocationCode from ICSInventoryLocation where InvCode={0} and LocationCode={1}) BEGIN RAISERROR('请勿重复绑定料品库位关系!',16,1); RETURN end INSERT INTO dbo.ICSInventoryLocation ( ID ,InvCode ,LocationCode ,Enable,MTIME,MUSER ,MUSERName ,WorkPoint ) Values(NEWID(),{0},{1},'{2}',GETDATE(),'{3}','{4}','{5}') "; sql = string.Format(sql, item, itemwh, '1'.ToString(), MUSER, MUSERNAME, WorkPoint); } } if (SqlHelper.ExecuteNonQuery(sql) > 0) { } else { msg = "新增失败"; } } catch (Exception ex) { msg = ex.Message; } return msg; } /// /// 修改料品库位绑定关系 /// /// /// public string UpdateICSInventoryLocation(string keyValue) { var queryParam = keyValue.ToJObject(); string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; string sql = string.Empty; sql = @"UPDATE dbo.ICSInventoryLocation set InvCode='{0}',LocationCode='{1}',Enable='{2}',MTIME=GETDATE(),MUSER='{3}',MUSERName='{4}',WorkPoint='{5}' WHERE ID='{6}'"; sql = string.Format(sql, queryParam["InvCode"].ToString(), queryParam["LocationCode"].ToString(), queryParam["Enable"].ToString(), MUSER, MUSERNAME, WorkPoint, queryParam["ID"].ToString()); try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { } else { msg = "修改失败"; } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 删除料品仓库批次关系 /// /// 传入ID /// public string DeleteICSInventoryLocation(string keyValue) { //站点信息 string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; keyValue = keyValue.Substring(1, keyValue.Length - 2); string sql = string.Empty; sql = string.Format(@"DELETE FROM dbo.ICSInventoryLocation WHERE ID IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint); try { SqlHelper.ExecuteNonQuery(sql); } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 新增包装、容器 /// /// /// public string InsertICSContainer(string keyValue) { string msg = ""; try { var queryParam = keyValue.ToJObject(); string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string sql = string.Empty; sql = @"IF EXISTS(select ContainerCODE from ICSContainer where ContainerCODE='{1}' ) RAISERROR('容器:{1},已存在!',16,1) else INSERT INTO dbo.ICSContainer ( ID ,ContainerID ,ContainerCODE ,ContainerName,Memo,MTIME,MUSER ,MUSERName ,WorkPoint ) Values(NEWID(),'{0}','{1}','{2}','{3}',GETDATE(),'{4}','{5}','{6}') "; sql = string.Format(sql, queryParam["ContainerID"].ToString(), queryParam["ContainerCODE"].ToString(), queryParam["ContainerName"].ToString(), queryParam["Memo"].ToString(), MUSER, MUSERNAME, WorkPoint); if (SqlHelper.ExecuteNonQuery(sql) > 0) { } else { msg = "新增失败"; } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 修改包装、容器 /// /// /// public string UpdateICSContainer(string keyValue) { var queryParam = keyValue.ToJObject(); string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; string sql = string.Empty; sql = @" IF EXISTS(select ContainerCODE from ICSContainer where ContainerCODE='{1}' ) RAISERROR('容器:{1},已存在!',16,1) UPDATE dbo.ICSContainer set ContainerID='{0}',ContainerCODE='{1}',ContainerName='{2}',Memo='{3}',MTIME=GETDATE(),MUSER='{4}',MUSERName='{5}',WorkPoint='{6}' WHERE ID='{7}'"; sql = string.Format(sql, queryParam["ContainerID"].ToString(), queryParam["ContainerCODE"].ToString(), queryParam["ContainerName"].ToString(), queryParam["Memo"].ToString(), MUSER, MUSERNAME, WorkPoint, queryParam["ID"].ToString()); try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { } else { msg = "修改失败"; } } catch (Exception ex) { msg = ex.Message; } return msg; } /// /// 删除包装、容器 /// /// 传入ID /// public string DeleteICSContainer(string keyValue) { //站点信息 string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; keyValue = keyValue.Substring(1, keyValue.Length - 2); string sql = string.Empty; sql = string.Format(@"DELETE FROM dbo.ICSContainer WHERE ID IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint); try { SqlHelper.ExecuteNonQuery(sql); } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 新增包装、容器关联条码 /// /// /// public string InsertICSContainerLot(string keyValue) { var queryParam = keyValue.ToJObject(); string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; string sql = string.Empty; sql = @"INSERT INTO dbo.ICSContainerLot ( ID ,ContainerID ,LotNo ,MTIME,MUSER ,MUSERName ,WorkPoint ) Values(NEWID(),'{0}','{1}',getdate(),'{2}','{3}','{4}') "; sql = string.Format(sql, queryParam["ContainerID"].ToString(), queryParam["LotNo"].ToString(), MUSER, MUSERNAME, WorkPoint); try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { } else { msg = "新增失败"; } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 修改包装、容器 /// /// /// public string UpdateICSContainerLot(string keyValue) { var queryParam = keyValue.ToJObject(); string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; string sql = string.Empty; sql = @"UPDATE dbo.ICSContainerLot set ContainerID='{0}',LotNo='{1}',MTIME=GETDATE(),MUSER='{2}',MUSERName='{3}',WorkPoint='{4}' WHERE ID='{5}'"; sql = string.Format(sql, queryParam["ContainerID"].ToString(), queryParam["LotNo"].ToString(), MUSER, MUSERNAME, WorkPoint, queryParam["ID"].ToString()); try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { } else { msg = "修改失败"; } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 删除包装、容器 /// /// 传入ID /// public string DeleteICSContainerLot(string keyValue) { //站点信息 string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; keyValue = keyValue.Substring(1, keyValue.Length - 2); string sql = string.Empty; sql = string.Format(@"DELETE FROM dbo.ICSContainerLot WHERE ID IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint); try { SqlHelper.ExecuteNonQuery(sql); } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 获取料品信息 /// /// public DataTable GetInvCode() { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string sql = @" select '' as InvCode,'' as InvName union all SELECT InvCode,InvName FROM ICSInventory WITH (NOLOCK) WHERE 1=1 "; string role = NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode; if (role != "admin") { sql += " and b.WorkPoint='" + WorkPoint + "'"; } DataTable dt = SqlHelper.GetDataTableBySql(sql); return dt; } /// /// 获取不良代码信息 /// /// public DataTable GetBCGroup() { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string sql = @"select '' as ID,'' as BCGDesc union all SELECT ID,BCGDesc FROM ICSBadCodeGroup WITH (NOLOCK) WHERE 1=1 "; string role = NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode; if (role != "admin") { sql += " and b.WorkPoint='" + WorkPoint + "'"; } DataTable dt = SqlHelper.GetDataTableBySql(sql); return dt; } /// /// 获取不良原因信息 /// /// public DataTable BRGroupID() { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string sql = @"select '' as ID,'' as BRGDesc union all SELECT ID,BRGDesc FROM ICSBadReasonGroup WITH (NOLOCK) WHERE 1=1 "; string role = NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode; if (role != "admin") { sql += " and b.WorkPoint='" + WorkPoint + "'"; } DataTable dt = SqlHelper.GetDataTableBySql(sql); return dt; } /// /// 新增料品不良信息 /// /// /// public string InsertInventoryBadGroup(string keyValue) { var queryParam = keyValue.ToJObject(); string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; string sql = string.Empty; sql = @"INSERT INTO dbo.ICSInventoryBadGroup ( ID,InvCode,BCGroupID,BRGroupID,Enable,MUSER,MUSERName,MTIME,WorkPoint) Values(NEWID(),'{0}','{1}','{2}','{3}','{4}','{5}',getdate(),'{6}')"; sql = string.Format(sql, queryParam["InvCode"].ToString(), queryParam["BCGroupID"].ToString(), queryParam["BRGroupID"].ToString(), queryParam["Enable"].ToString(), MUSER, MUSERNAME, WorkPoint); try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { } else { msg = "新增失败"; } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 修改料品不良信息 /// /// /// public string UpdateInventoryBadGroup(string keyValue) { var queryParam = keyValue.ToJObject(); string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; string sql = string.Empty; sql = @"UPDATE dbo.ICSInventoryBadGroup set BCGroupID='{0}',BRGroupID='{1}',Enable='{2}',MUSER='{3}',MUSERName='{4}',MTIME=GetDate(),WorkPoint='{5}' WHERE ID='{6}'"; sql = string.Format(sql, queryParam["BCGroupID"].ToString(), queryParam["BRGroupID"].ToString(), queryParam["Enable"].ToString(), MUSER, MUSERNAME, WorkPoint, queryParam["ID"].ToString()); try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { } else { msg = "修改失败"; } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 删除料品不良信息 /// /// 传入ID /// public string DeleteInventoryBadGroup(string keyValue) { //站点信息 string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; keyValue = keyValue.Substring(1, keyValue.Length - 2); string sql = string.Empty; sql = string.Format(@"DELETE FROM dbo.ICSInventoryBadGroup WHERE ID IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint); try { SqlHelper.ExecuteNonQuery(sql); } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } //库位导入 public string SetData_PR(String savePath) { //数据获取 try { int index = 1; string msg = ""; string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; SqlConnection conn = SqlHelper.GetDataCenterConn(); string sql = ""; int count = 0; DataTable data = FileToExcel.ExcelToTable(savePath); foreach (DataRow dr in data.Rows) { index++; var StackCode = ""; var StackName = ""; //string GUID = Guid.NewGuid().ToString(); string KuFang = dr["库房编码"].ToString().Trim().ToUpper(); string Qu = dr["区"].ToString().Trim().ToUpper(); string Pai = dr["排"].ToString().Trim().ToUpper(); string Jia = dr["货架"].ToString().Trim().ToUpper(); string Ceng = dr["层"].ToString().Trim().ToUpper(); string Ge = dr["格"].ToString().Trim().ToUpper(); if (KuFang == "" || KuFang == null) { throw new Exception("第 " + index + " 行库房编码不能为空!"); } if (Qu == "" && Pai == "" && Jia == "" && Ceng == "" && Ge == "") { throw new Exception("第 " + index + " 区、排、货架、层、格至少填写一项!"); } string sqlWH = @"select ID from ICSWarehouse where WarehouseCode='{0}' and WorkPoint='{1}'"; sqlWH = string.Format(sqlWH, KuFang, WorkPoint); DataTable dd = SqlHelper.CmdExecuteDataTable(sqlWH); if (dd == null || dd.Rows.Count <= 0) { throw new Exception("库房编码: " + KuFang + " 不存在!"); } string WHID = dd.Rows[0]["ID"].ToString(); StackCode = KuFang; StackName = KuFang + "仓库"; if (Qu != "") { StackCode += "-" + Qu; StackName += Qu + "区"; } if (Pai != "") { StackCode += "-" + Pai; StackName += Pai + "排"; } if (Jia != "") { StackCode += "-" + Jia; StackName += Jia + "货架"; } if (Ceng != "") { StackCode += "-" + Ceng; StackName += Ceng + "层"; } if (Ge != "") { StackCode += "-" + Ge; StackName += Ge + "格"; } string sqls = @"select LocationCode from ICSLocation where LocationCode='{0}' and WorkPoint='{1}'"; sqls = string.Format(sqls, StackCode, WorkPoint); DataTable dnum = SqlHelper.CmdExecuteDataTable(sqls); if (dnum != null && dnum.Rows.Count > 0) { throw new Exception("库位: " + StackCode + " 已存在!"); } else { sql += @"Insert INto ICSLocation Values (newid(),'{0}','{1}','{2}','{3}','{4}',getdate(),'{5}','')"; } sql = string.Format(sql, StackCode, StackName, WHID, MUSER, MUSERNAME, WorkPoint); } count = SqlHelper.CmdExecuteNonQueryLi(sql); if (count > 0) { msg = "导入成功"; } else { return "无有效的导入数据。"; } return msg; } catch (Exception ex) { return ex.Message; } } /// ///启用的料品库位绑定关系 /// public string EnableInventoryLocation(string keyValue) { //站点信息 string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; keyValue = keyValue.Substring(1, keyValue.Length - 2); string sql = string.Empty; sql = string.Format(@"update ICSInventoryLocation set Enable='1' where ID in ({0}) and WorkPoint='{1}'", keyValue.TrimEnd(','), WorkPoint); try { SqlHelper.ExecuteNonQuery(sql); } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// ///禁用的料品库位绑定关系 /// public string ForbiddenInventoryLocation(string keyValue) { //站点信息 string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; keyValue = keyValue.Substring(1, keyValue.Length - 2); string sql = string.Empty; sql = string.Format(@"update ICSInventoryLocation set Enable='0' where ID in ({0}) and WorkPoint='{1}'", keyValue.TrimEnd(','), WorkPoint); try { SqlHelper.ExecuteNonQuery(sql); } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// ///启用的料品仓库绑定关系 /// public string EnableBatchEnable(string keyValue) { //站点信息 string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; keyValue = keyValue.Substring(1, keyValue.Length - 2); string sql = string.Empty; sql = string.Format(@"update ICSInventoryBatchEnable set BatchEnable='1' where ID in ({0}) and WorkPoint='{1}'", keyValue.TrimEnd(','), WorkPoint); try { SqlHelper.ExecuteNonQuery(sql); } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// ///禁用的料品仓库绑定关系 /// public string ForbiddenBatchEnable(string keyValue) { //站点信息 string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; keyValue = keyValue.Substring(1, keyValue.Length - 2); string sql = string.Empty; sql = string.Format(@"update ICSInventoryBatchEnable set BatchEnable='0' where ID in ({0}) and WorkPoint='{1}'", keyValue.TrimEnd(','), WorkPoint); try { SqlHelper.ExecuteNonQuery(sql); } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } public string CreateLableDataSource(string Sys_LableDataSource) { string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; string sql = string.Empty; string SqlTxt = ""; JArray res = (JArray)JsonConvert.DeserializeObject(Sys_LableDataSource); foreach (var item in res) { JObject jo = (JObject)item; if (jo["DbParas"].ToString().Trim() != "") { string[] dbvs = jo["DbParas"].ToString().Trim().Split(','); List vs = new List(); foreach (string s in dbvs) { if (!string.IsNullOrEmpty(s)) { vs.Add(s); } } SqlTxt = string.Format(jo["FormatSqlTxt"].ToString(), vs.ToArray()); } else { SqlTxt = jo["FormatSqlTxt"].ToString(); } sql += @"INSERT INTO dbo.Sys_LableDataSource (ID,WorkPointCode,OtherDataBaseID,WorkPointDataFlag,SysDataFlag,SqlTxt,SourceName,FormatSqlTxt,Paras,DbParas,LinkCols,CreateUserID,CreateDate,ModifyUserID,ModifyDate,Link2Cols ) Values(NEWID(),'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}',getdate(),'{11}',getdate(),'{12}')"; sql = string.Format(sql, WorkPoint, jo["OtherDataBaseID"].ToString(), jo["WorkPointDataFlag"].ToString(), jo["SysDataSourceFlag"].ToString(), SqlTxt, jo["SourceName"].ToString(), jo["FormatSqlTxt"].ToString(), jo["Paras"].ToString(), jo["DbParas"].ToString(), jo["LinkCols"].ToString(), MUSER, MUSER, jo["Link2Cols"].ToString()); } try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { } else { msg = "新增失败"; } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } public DataTable GetTXT(string ID) { DataTable dt = new DataTable(); //var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @"SELECT ID, WorkPointCode, OtherDataBaseID, WorkPointDataFlag, SysDataFlag, SqlTxt, SourceName, FormatSqlTxt, Paras, DbParas, LinkCols, CreateUserID, CreateDate, ModifyUserID, ModifyDate, Link2Cols FROM dbo.Sys_LableDataSource where ID='" + ID + "'"; return Repository().FindTableBySql(sql.ToString()); } public string updateLableDataSource(string Sys_LableDataSource) { string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; string sql = string.Empty; string SqlTxt = ""; JArray res = (JArray)JsonConvert.DeserializeObject(Sys_LableDataSource); foreach (var item in res) { JObject jo = (JObject)item; if (jo["DbParas"].ToString().Trim() != "") { string[] dbvs = jo["DbParas"].ToString().Trim().Split(','); List vs = new List(); foreach (string s in dbvs) { if (!string.IsNullOrEmpty(s)) { vs.Add(s); } } SqlTxt = string.Format(jo["FormatSqlTxt"].ToString(), vs.ToArray()); } else { SqlTxt = jo["FormatSqlTxt"].ToString(); } sql += @"UPDATE dbo.Sys_LableDataSource set WorkPointCode='{0}',OtherDataBaseID='{1}',WorkPointDataFlag='{2}',SysDataFlag='{3}',SqlTxt='{4}',SourceName='{5}',FormatSqlTxt='{6}',Paras='{7}',DbParas='{8}',LinkCols='{9}',ModifyUserID='{10}',ModifyDate=getdate(),Link2Cols='{11}' WHERE ID='{12}'"; sql = string.Format(sql, WorkPoint, jo["OtherDataBaseID"].ToString(), jo["WorkPointDataFlag"].ToString(), jo["SysDataSourceFlag"].ToString(), SqlTxt, jo["SourceName"].ToString(), jo["FormatSqlTxt"].ToString(), jo["Paras"].ToString(), jo["DbParas"].ToString(), jo["LinkCols"].ToString(), MUSER, jo["Link2Cols"].ToString(), jo["ID"].ToString()); } try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { } else { msg = "修改失败"; } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } public string DeleteLableDataSource(string keyValue) { //站点信息 string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; keyValue = keyValue.Substring(1, keyValue.Length - 2); string sql = string.Empty; sql = string.Format(@"DELETE FROM dbo.Sys_LableDataSource WHERE ID IN ({0}) ", keyValue.TrimEnd(',')); try { SqlHelper.ExecuteNonQuery(sql); } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } public DataTable GetLableType() { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(','); string sql = @" select '' as F_ItemCode,'' as F_ItemName union all SELECT DISTINCT a.F_ItemCode,isnull(a.F_ItemName,'') as F_ItemName FROM dbo.Sys_SRM_ItemsDetail a left join Sys_SRM_Items b on a.F_ItemId=b.F_Id where b.F_EnCode='BQ001'"; string role = NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode; DataTable dt = SqlHelper.GetDataTableBySql(sql); return dt; } public DataTable GetSys_LablesID() { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(','); string sql = @" select '' as ID,'' as LableName union all select distinct ID,LableName from Sys_Lables"; string role = NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode; DataTable dt = SqlHelper.GetDataTableBySql(sql); return dt; } public string CreateLables(string txtLableName, string sel_LableType, string sel_LableSourceID) { string UserId = NFine.Code.OperatorProvider.Provider.GetCurrent().UserId; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; string sql = string.Empty; string LableCode = ""; string SqlTxt = string.Format(@"SELECT MAX(A.LableCode) AS LableCode FROM Sys_Lables A "); ; DataSet ds = SqlHelper.GetDataSetBySql(SqlTxt); DataTable dts = ds.Tables[0]; if (dts != null && dts.Rows.Count > 0) { string lot = dts.Rows[0]["LableCode"].ToString(); LableCode = (Convert.ToInt64(lot) + 1).ToString().PadLeft(5, '0'); } else { LableCode = "00001"; } sql += @" INSERT INTO dbo.Sys_Lables (ID,WorkPointCode,LableType,LableCode,LableName,LableXml,LableSourceID,CreateUserID,CreateDate,ModifyUserID,ModifyDate,FileAddress ) Values(NEWID(),'{0}','{1}','{2}','{3}','','{4}','{5}',getdate(),'{6}',getdate(),'')"; sql = string.Format(sql, WorkPoint, sel_LableType, LableCode, txtLableName, sel_LableSourceID, UserId, UserId); try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { } else { msg = "新增失败"; } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } public DataTable GetLabelTXT(string ID) { DataTable dt = new DataTable(); //var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @"select ID,WorkPointCode,LableType,LableCode,LableName,LableXml,LableSourceID,CreateUserID,CreateDate,ModifyUserID,ModifyDate,FileAddress from Sys_Lables where ID='" + ID + "'"; return Repository().FindTableBySql(sql.ToString()); } public string updateLables(string ID, string txtLableName, string sel_LableType, string sel_LableSourceID) { string UserId = NFine.Code.OperatorProvider.Provider.GetCurrent().UserId; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; string sql = string.Empty; sql += @"update Sys_Lables set LableType='{0}' ,LableName='{1}' ,LableSourceID='{2}',ModifyUserID='{3}',ModifyDate=getdate() where ID='{4}'"; sql = string.Format(sql, sel_LableType, txtLableName, sel_LableSourceID, UserId, ID); try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { } else { msg = "修改失败"; } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } public string DeleteICSLabelTemplate(string keyValue) { //站点信息 string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; keyValue = keyValue.Substring(1, keyValue.Length - 2); string sql = string.Empty; sql = string.Format(@"DELETE FROM dbo.Sys_Lables WHERE ID IN ({0}) ", keyValue.TrimEnd(',')); try { SqlHelper.ExecuteNonQuery(sql); } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } //获取父容器 public DataTable GetContainerID() { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(','); string sql = @" select '' as ID,'' as ContainerName union all SELECT DISTINCT a.ID,a.ContainerName FROM dbo.ICSContainer a "; string role = NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode; if (role != "admin") { sql += " and b.WorkPoint in(" + WorkPoint + ")"; } DataTable dt = SqlHelper.GetDataTableBySql(sql); return dt; } public int UpLoadLabelFile(string ID, string fileName) { DataTable dt = new DataTable(); string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(','); string sql = ""; sql = string.Format(@"update Sys_Lables set FileAddress='{0}' where ID='{1}'", fileName, ID); StringBuilder Str = new StringBuilder(sql); return Repository().ExecuteBySql(Str); } public int UpLoadFiles(string LotNo, string fileName) { DataTable dt = new DataTable(); string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(','); string sql = ""; sql = string.Format(@"update ICSInspection set FileName='{0}' where LotNo='{1}' and Enable='1'", fileName, LotNo); StringBuilder Str = new StringBuilder(sql); return Repository().ExecuteBySql(Str); } //包装容器 public DataTable GetSendContainer(ref Pagination jqgridparam, string queryJson) { DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @"select top 0 ID,ContainerID,ContainerCode,ContainerName,Memo,MUSER,MUSERName,MTIME,WorkPoint from ICSContainer"; sql += " WHERE 1=1"; sql = string.Format(sql); return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } public DataTable GetContainerInfo(string Code) { DataTable dt = new DataTable(); //var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" select ID,ContainerID,ContainerCode,ContainerName,Memo,MUSER,MUSERName,MTIME,WorkPoint from ICSContainer where ContainerCode='{0}'"; sql = string.Format(sql, Code); return Repository().FindTableBySql(sql.ToString()); } public DataTable GetBindContainerID(string SireCode) { DataTable dt = new DataTable(); //var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" select ID from ICSContainer where ContainerCode='{0}'"; sql = string.Format(sql, SireCode); return Repository().FindTableBySql(sql.ToString()); } public string BindingContainerID(string ICSMTDOC, string SireID) { string msg = ""; try { string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string sql = string.Empty; JArray res = (JArray)JsonConvert.DeserializeObject(ICSMTDOC); foreach (var item in res) { JObject jo = (JObject)item; sql += @" IF NOT EXISTS(SELECT ContainerCode FROM ICSContainer WHERE ContainerCode='{1}' ) BEGIN RAISERROR('容器:{1} 不存在!',16,1); RETURN END IF EXISTS(select ContainerID from ICSContainer where ContainerCode='{1}' and isnull(ContainerID,'')<>'') BEGIN RAISERROR('容器:{1},已绑定父容器!',16,1); RETURN END update ICSContainer set ContainerID='{0}' WHERE ContainerCode = '{1}' and WorkPoint ='{2}'"; sql = string.Format(sql, SireID, jo["ContainerCode"].ToString(), WorkPoint); } if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0) { } else { msg = "绑定失败"; } } catch (Exception ex) { msg = ex.Message; } return msg; } //包装容器关联条码 public DataTable GetSendContainerLot(ref Pagination jqgridparam, string queryJson) { DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" select top 0 a.ID, a.LotNo,a.InvCode,b.InvName,b.InvStd,b.InvUnit, a.ProductDate,a.Quantity from ICSInventoryLot a left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint"; sql = string.Format(sql); return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } public DataTable GetContainerLotInfo(string LotNo) { DataTable dt = new DataTable(); //var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" select a.ID, a.LotNo,a.InvCode,b.InvName,b.InvStd,b.InvUnit, a.ProductDate,a.Quantity from ICSInventoryLot a left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint where a.LotNo='{0}'"; sql = string.Format(sql, LotNo); return Repository().FindTableBySql(sql.ToString()); } public string BindingContainerLotID(string ICSMTDOC, string SireID, string SireCode) { string msg = ""; try { string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string sql = string.Empty; JArray res = (JArray)JsonConvert.DeserializeObject(ICSMTDOC); foreach (var item in res) { JObject jo = (JObject)item; sql += @" IF NOT EXISTS(SELECT ContainerCode FROM ICSContainer WHERE ContainerCode='{5}') BEGIN RAISERROR('容器:{5} 不存在!',16,1); RETURN END IF NOT EXISTS(select LotNo from ICSInventoryLot where LotNo='{1}') BEGIN RAISERROR('条码:{1},不存在!',16,1); RETURN END IF EXISTS(select LotNo from ICSContainerLot where LotNo ='{1}') BEGIN RAISERROR('条码:{1},已绑定容器!',16,1); RETURN END INSERT INTO ICSContainerLot (ID,ContainerID,LotNo,MUSER,MUSERName,WorkPoint,MTIME ) Values(NEWID(),'{0}','{1}','{2}','{3}','{4}',getdate())"; sql = string.Format(sql, SireID, jo["LotNo"].ToString(), MUSER, MUSERNAME, WorkPoint, SireCode); } if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0) { } else { msg = "绑定失败"; } } catch (Exception ex) { msg = ex.Message; } return msg; } /// /// 删除站点 /// /// 传入ID /// public string DeleteWorkPoint(string keyValue) { //站点信息 string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; keyValue = keyValue.Substring(1, keyValue.Length - 2); string sql = string.Empty; sql = string.Format(@"DELETE FROM dbo.sys_WorkPoint WHERE ID IN ({0}) ", keyValue.TrimEnd(','), WorkPoint); try { SqlHelper.ExecuteNonQuery(sql); } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 新增站点 /// /// /// public string InsertWorkPoint(string keyValue) { var queryParam = keyValue.ToJObject(); string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; string sql = string.Empty; string pwd = SqlHelper.ToMd5(queryParam["DataBasePwd"].ToString()); sql = @"INSERT INTO dbo.sys_WorkPoint ( ID ,WorkPointCode ,WorkPointName ,ServerName,DataBaseName,DataBaseUser,DataBasePwd, StartFlag,CreateDate,CreateUserCode ) Values(NEWID(),'{0}','{1}','{2}','{3}','{4}','{5}','{6}',GETDATE(),'{7}') "; sql = string.Format(sql, queryParam["WorkPointCode"].ToString(), queryParam["WorkPointName"].ToString(), queryParam["ServerName"].ToString(), queryParam["DataBaseName"].ToString(), queryParam["DataBaseUser"].ToString(), pwd, queryParam["StartFlag"].ToString(), MUSER); try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { } else { msg = "新增失败"; } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 修改站点 /// /// /// public string UpdateWorkPoint(string keyValue) { var queryParam = keyValue.ToJObject(); string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; string pwd = SqlHelper.ToMd5(queryParam["DataBasePwd"].ToString()); string sql = string.Empty; sql = @"UPDATE dbo.sys_WorkPoint set WorkPointCode='{0}',WorkPointName='{1}',ServerName='{2}',DataBaseName='{3}',StartFlag='{4}' ,DataBaseUser='{5}',DataBasePwd='{6}',ModifyDate=GETDATE(),ModifyUserCode='{7}' WHERE ID='{8}'"; sql = string.Format(sql, queryParam["WorkPointCode"].ToString(), queryParam["WorkPointName"].ToString(), queryParam["ServerName"].ToString(), queryParam["DataBaseName"].ToString(), queryParam["StartFlag"].ToString(), queryParam["DataBaseUser"].ToString(), pwd , MUSER, queryParam["ID"].ToString()); try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { } else { msg = "修改失败"; } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } public Sys_WorkPoint GetWorkPoint(string Id) { Sys_WorkPoint model = new Sys_WorkPoint(); string sql = string.Empty; sql = string.Format(@"SELECT ID, WorkPointCode, WorkPointName, ServerName, DataBaseName, DataBaseUser, DataBasePwd, StartFlag, CreateUserCode, CreateDate, ModifyUserCode, ModifyDate FROM Sys_WorkPoint WHERE ID='{0}'", Id); DataTable dt = SqlHelper.GetDataTableBySql(sql); if (dt != null && dt.Rows.Count > 0) { model.ID = dt.Rows[0]["ID"].ToString(); model.WorkPointCode = dt.Rows[0]["WorkPointCode"].ToString(); model.WorkPointName = dt.Rows[0]["WorkPointName"].ToString(); model.ServerName = dt.Rows[0]["ServerName"].ToString(); model.DataBaseName = dt.Rows[0]["DataBaseName"].ToString(); model.DataBaseUser = dt.Rows[0]["DataBaseUser"].ToString(); model.DataBasePwd = SqlHelper.FromMd5(dt.Rows[0]["DataBasePwd"].ToString()); model.StartFlag = dt.Rows[0]["StartFlag"].ToString(); } return model; } public DataTable GetICSInventoryLotInfo(string ID) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); //var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" SELECT a.ID, a.LotNo, a.InvCode, a.ProductDate, a.ExpirationDate, a.Quantity, a.Amount, a.ExtensionID, a.Type, a.PrintTimes, a.LastPrintUser, a.LastPrintTime, a.MUSER, a.MUSERName, a.MTIME, a.WorkPoint, a.EATTRIBUTE1, b.InvName, b.InvUnit, c.Enable FROM dbo.ICSInventoryLot a left join ICSInventory b on a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint left join ICSInspection c on a.LotNo=c.LotNo AND a.WorkPoint=b.WorkPoint and c.Enable='1' WHERE a.ID='" + ID + "'"; sql += " and a.WorkPoint='" + WorkPoint + "'"; return Repository().FindTableBySql(sql.ToString()); } public int UpdateExpirationDate(string ID, string ExpirationDate, string Inv,string LotNo, string InvCode, string Quantity) { decimal QualifiedQuantity = 0; decimal UnqualifiedQuantity = 0; if (Inv=="1"){QualifiedQuantity = Convert.ToDecimal(Quantity);}else {UnqualifiedQuantity = Convert.ToDecimal(Quantity); } string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string sqls = string.Empty; sqls = @"update ICSInspection set Enable='0' WHERE LotNO='{0}' and Enable='1' and WorkPoint='{1}'"; sqls = string.Format(sqls, LotNo, WorkPoint); SqlHelper.CmdExecuteNonQueryLi(sqls); string sql = string.Empty; sql += @"UPDATE ICSInventoryLot SET ExpirationDate='{0}' where ID='{1}' AND WorkPoint='{2}'"; sql += @"INSERT INTO dbo.ICSInspection ( ID ,LotNo ,InvCode ,Quantity,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity,Type,Result,ExpirationDate,Enable,MUSER,MUSERName,MTIME,WorkPoint ) Values(NEWID(),'{3}','{4}','{5}','{6}','{7}',0,'4','{8}','{0}','1','{9}','{10}',GETDATE(),'{2}')"; sql = string.Format(sql, ExpirationDate,ID, WorkPoint, LotNo, InvCode, Quantity, QualifiedQuantity, UnqualifiedQuantity, Inv, MUSER, MUSERNAME); int count = SqlHelper.CmdExecuteNonQueryLi(sql); return count; } //修改多语言 public string UpdateSys_Language(string keyValue) { var queryParam = keyValue.ToJObject(); string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; string sql = string.Empty; sql = @"UPDATE Sys_Language set Code='{0}',CnValue='{1}',TwValue='{2}',EnValue='{3}' WHERE ID='{4}'"; sql = string.Format(sql, queryParam["Code"].ToString(), queryParam["CnValue"].ToString(), queryParam["TwValue"].ToString(), queryParam["EnValue"].ToString(), queryParam["ID"].ToString()); try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { } else { msg = "修改失败"; } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } //新增多语言 public string InsertSys_Language(string keyValue) { var queryParam = keyValue.ToJObject(); string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; string sql = string.Empty; sql = @" IF EXISTS(SELECT * FROM Sys_Language WHERE Code='{0}' ) begin RAISERROR('代码重复请重新输入!',16,1) end INSERT INTO Sys_Language ( ID ,Code ,CnValue ,TwValue,EnValue ) Values(NEWID(),'{0}','{1}','{2}','{3}') "; sql = string.Format(sql, queryParam["Code"].ToString(), queryParam["CnValue"].ToString(), queryParam["TwValue"].ToString(), queryParam["EnValue"].ToString()); try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { } else { msg = "新增失败"; } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } public string GetSerialCode(string workPointCode, string tbName, string colName, string Pre, int numLen) { string sql = "EXEC Addins_GetSerialCode '{0}','{1}','{2}','{3}',{4}"; sql = string.Format(sql, new object[] { workPointCode, tbName, colName, Pre, numLen }); return DbHelper.ExecuteScalar(CommandType.Text, sql).ToString(); } public DataTable GetSys_Language(string ID) { DataTable dt = new DataTable(); //var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @"select ID,Code,CnValue,TwValue,EnValue from Sys_Language WHERE 1 =1 and ID='" + ID + "' "; return Repository().FindTableBySql(sql.ToString()); } /// /// 删除多语言 /// /// 传入ID /// public string DeleteSys_Language(string keyValue) { string msg = ""; keyValue = keyValue.Substring(1, keyValue.Length - 2); string sql = string.Empty; sql = string.Format(@"DELETE FROM Sys_Language WHERE ID IN ({0})", keyValue.TrimEnd(',')); try { SqlHelper.ExecuteNonQuery(sql); } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } //料品检验项目 public DataTable GetICSInventoryInspectionGroup(ref Pagination jqgridparam, string queryJson) { DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @"select ID,InvCode,GroupCode,GroupName, case when Enable='1' then '是' else '否' end as Enable, MUSER,MUSERName,MTIME,WorkPoint from ICSInventoryInspectionGroup "; sql += " WHERE 1=1"; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { sql += " and InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["GroupCode"].ToString())) { sql += " and GroupCode like '%" + queryParam["GroupCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["GroupName"].ToString())) { sql += " and GroupName like '%" + queryParam["GroupName"].ToString() + "%' "; } } sql = string.Format(sql); DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } //料品检验项目子表 public DataTable ICSInventoryInspectionList(string ID, ref Pagination jqgridparam) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); //var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" select ID,InvGroupID,ListCode,ListName,Unit,SetValueMax, SetValueMin, CASE WHEN Enable=0 THEN '否' else '是' END Enable, MUSERName,MTIME,WorkPoint from ICSInventoryInspectionList WHERE InvGroupID='" + ID + "'"; return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } // 删除料品检验项目子表 public string DeleteICSInventoryInspectionGroup(string keyValue) { //站点信息 string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; keyValue = keyValue.Substring(1, keyValue.Length - 2); string sql = string.Empty; sql += string.Format(@"DELETE FROM dbo.ICSInventoryInspectionGroup WHERE ID IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint); sql += string.Format(@"DELETE FROM dbo.ICSInventoryInspectionList WHERE InvGroupID IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint); try { if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0) { } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } public DataTable Getinv(string invcode, ref Pagination jqgridparam) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; List parameter = new List(); DataTable table = new DataTable(); string wherestr = ""; if (!string.IsNullOrEmpty(invcode)) { wherestr += " and invcode like '%" + invcode + "%'"; } string sql = "select ID,InvCode,InvName,InvDesc,InvUnit,WorkPoint from ICSInventory where workpoint='" + WorkPoint + "'" + wherestr; return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } public DataTable GetGroupCode() { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string role = NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode; string sql = @"select '' as ID,'' as GroupName union all SELECT distinct ID,GroupName FROM ICSInspectionGroup where WorkPoint='{0}'"; sql = string.Format(sql, WorkPoint); DataTable dt = SqlHelper.GetDataTableBySql(sql); return dt; } public void DeleteINvItem(string ID) { string sql = "DELETE FROM dbo.ICSInventoryInspectionList WHERE ID='" + ID + "'"; SqlHelper.ExecuteNonQuery(sql); } public DataTable GetICSInventoryInspectionList(string ListCode, ref Pagination jqgridparam) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); //var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @"select ID,ListCode,ListName,Unit,SetValueMax,SetValueMin,Enable,MUSERName,MTIME from ICSInventoryInspectionList WHERE ListCode='" + ListCode + "' "; return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } public DataTable GetInspectionListInfo(string ID) { DataTable dt = new DataTable(); //var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" select ID,ListCode,ListName,Unit,SetValueMax,SetValueMin, CASE WHEN Enable=0 THEN '否' else '是' END Enable from ICSInspectionList where GroupID='{0}'"; sql = string.Format(sql, ID); return Repository().FindTableBySql(sql.ToString()); } //新增 public void SubICSInventoryInspectionGroupAdd(ICSInventoryInspectionGroup main, string ID, string InvCode) { string sql = string.Empty; string sqls = string.Empty; string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string NewID = Common.GuId(); List list_Item1 = new List(); if (main.arrayShellFabricItem != null) { list_Item1 = JsonConvert.DeserializeObject>(main.arrayShellFabricItem); } string connString = SqlHelper.DataCenterConnString; SqlConnection conn = new SqlConnection(connString); conn.Open(); SqlTransaction sqlTran = conn.BeginTransaction(); SqlCommand cmd = new SqlCommand(); cmd.Transaction = sqlTran; cmd.Connection = conn; sql = @" INSERT INTO dbo.ICSInventoryInspectionGroup ( ID ,InvCode ,GroupCode ,GroupName , Enable ,MUSER ,MUSERName ,MTIME ,WorkPoint ) SELECT '{0}','{1}',GroupCode,GroupName,Enable,'{2}','{3}',getdate(),'{4}' FROM dbo.ICSInspectionGroup WHERE ID='{5}'"; sql = string.Format(sql, NewID, InvCode, MUSER, MUSERNAME, WorkPoint, ID); try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { foreach (ICSInventoryInspectionGroup Item in list_Item1) { sqls = @" INSERT INTO dbo.ICSInventoryInspectionList ( ID ,InvGroupID,ListCode,ListName,Unit,SetValueMax,SetValueMin,Enable , MTIME,MUSER ,MUSERName ,WorkPoint ) Values(@ID,'{0}',@ListCode,@ListName,@Unit,@SetValueMax,@SetValueMin,@Enable,GETDATE(),'{1}','{2}','{3}')"; sqls = string.Format(sqls, NewID, MUSER, MUSERNAME, WorkPoint); SqlParameter[] sp_Item = { new SqlParameter("@ID",DbType.String){ Value= Item.ID}, new SqlParameter("@ListCode",DbType.String){ Value= Item.ListCode}, new SqlParameter("@ListName",DbType.String){ Value= Item.ListName}, new SqlParameter("@Unit",DbType.String){ Value= Item.Unit}, new SqlParameter("@SetValueMax",DbType.String){ Value= Item.SetValueMax}, new SqlParameter("@SetValueMin",DbType.String){ Value= Item.SetValueMin}, new SqlParameter("@Enable",DbType.String){ Value= Item.Enable}, }; SqlCommandHelper.CmdExecuteNonQuery(sqls, sp_Item, cmd); } cmd.Transaction.Commit(); } } catch (Exception ex) { cmd.Transaction.Rollback(); throw new Exception(ex.Message); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } conn.Dispose(); } } public DataTable GetICSInventoryInspectionList2(string BID) { string sql = string.Empty; DataTable dt = null; sql = string.Format(@" select ID,ListCode,ListName,Unit,SetValueMax,SetValueMin, CASE WHEN Enable='1' THEN '是' else '否' END Enable from ICSInventoryInspectionList where InvGroupID='{0}'", BID); dt = SqlHelper.GetDataTableBySql(sql); return dt; } //修改 public void UpdateICSInventoryInspectionGroup(ICSInventoryInspectionGroup main, string BID, string ID, string InvCode) { string sql = string.Empty; string sqls = string.Empty; string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; List list_Item1 = new List(); if (main.arrayShellFabricItem != null) { list_Item1 = JsonConvert.DeserializeObject>(main.arrayShellFabricItem); } string connString = SqlHelper.DataCenterConnString; SqlConnection conn = new SqlConnection(connString); conn.Open(); SqlTransaction sqlTran = conn.BeginTransaction(); SqlCommand cmd = new SqlCommand(); cmd.Transaction = sqlTran; cmd.Connection = conn; sql = @"update b set b.InvCode='{0}',b.GroupCode=a.GroupCode,b.GroupName=a.GroupName,b.Enable=a.Enable,b.MTIME=GETDATE(),b.MUSER='{1}',b.MUSERName='{2}',b.WorkPoint='{3}' from ICSInspectionGroup a ,ICSInventoryInspectionGroup b where a.ID='{4}' and b.ID='{5}'"; sql = string.Format(sql, InvCode, MUSER, MUSERNAME, WorkPoint, ID,BID); try { if (SqlHelper.ExecuteNonQuery(sql) > 0) { foreach (ICSInventoryInspectionGroup Item in list_Item1) { sqls = @" IF NOT EXISTS(SELECT * FROM ICSInventoryInspectionList WHERE ID=@ID) BEGIN INSERT INTO dbo.ICSInventoryInspectionList ( ID ,InvGroupID,ListCode,ListName,Unit,SetValueMax,SetValueMin,Enable , MTIME,MUSER ,MUSERName ,WorkPoint ) Values(@ID,'{0}',@ListCode,@ListName,@Unit,@SetValueMax,@SetValueMin,@Enable,GETDATE(),'{1}','{2}','{3}') END ELSE BEGIN UPDATE dbo.ICSInventoryInspectionList set InvGroupID='{0}',ListCode=@ListCode,ListName=@ListName,Unit=@Unit,SetValueMax=@SetValueMax,SetValueMin=@SetValueMin,Enable=@Enable,MTIME=GETDATE(),MUSER='{1}',MUSERName='{2}',WorkPoint='{3}' WHERE ID=@ID end "; sqls = string.Format(sqls, BID, MUSER, MUSERNAME, WorkPoint); SqlParameter[] sp_Item = { new SqlParameter("@ID",DbType.String){ Value= Item.ID}, new SqlParameter("@ListCode",DbType.String){ Value= Item.ListCode}, new SqlParameter("@ListName",DbType.String){ Value= Item.ListName}, new SqlParameter("@Unit",DbType.String){ Value= Item.Unit}, new SqlParameter("@SetValueMax",DbType.String){ Value= Item.SetValueMax}, new SqlParameter("@SetValueMin",DbType.String){ Value= Item.SetValueMin}, new SqlParameter("@Enable",DbType.String){ Value= Item.Enable}, }; SqlCommandHelper.CmdExecuteNonQuery(sqls, sp_Item, cmd); } cmd.Transaction.Commit(); } } catch (Exception ex) { cmd.Transaction.Rollback(); throw new Exception(ex.Message); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } conn.Dispose(); } } } }