You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
255 lines
10 KiB
255 lines
10 KiB
1 year ago
|
using CK.SCP.Models;
|
||
|
using CK.SCP.Models.ExchangeCenterTables;
|
||
|
using CK.SCP.Utils;
|
||
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Data;
|
||
|
using System.Data.Entity.Migrations;
|
||
|
using System.Data.SqlClient;
|
||
|
using System.Linq;
|
||
|
using System.Text;
|
||
|
using System.Threading.Tasks;
|
||
|
|
||
|
namespace CK.SCP.Controller
|
||
|
{
|
||
|
public class UN_EC_CONTROLLER_PART
|
||
|
{
|
||
|
public static void Get_TES_PART_MSTR_List(TES_PART_MSTR p_entity, Action<ResultObject<IQueryable<TES_PART_MSTR>>> p_action)
|
||
|
{
|
||
|
ResultObject<IQueryable<TES_PART_MSTR>> _ret = new ResultObject<IQueryable<TES_PART_MSTR>>();
|
||
|
try
|
||
|
{
|
||
|
using (var db = EntitiesFactory.CreateExchangeCenterInstance())
|
||
|
{
|
||
|
IQueryable<TES_PART_MSTR> q = db.TES_PART_MSTR;
|
||
|
if (!string.IsNullOrEmpty(p_entity.PartCode))
|
||
|
{
|
||
|
q = q.Where(p => p.PartCode.Contains(p_entity.PartCode));
|
||
|
}
|
||
|
if (!string.IsNullOrEmpty(p_entity.Desc1))
|
||
|
{
|
||
|
q = q.Where(p => p.Desc1.Contains(p_entity.Desc1));
|
||
|
}
|
||
|
if (!string.IsNullOrEmpty(p_entity.Desc2))
|
||
|
{
|
||
|
q = q.Where(p => p.Desc2.Contains(p_entity.Desc2));
|
||
|
}
|
||
|
if (!string.IsNullOrEmpty(p_entity.Um))
|
||
|
{
|
||
|
q = q.Where(p => p.Um.Contains(p_entity.Um));
|
||
|
}
|
||
|
if (!string.IsNullOrEmpty(p_entity.ProdLine))
|
||
|
{
|
||
|
q = q.Where(p => p.ProdLine.Contains(p_entity.ProdLine));
|
||
|
}
|
||
|
if (!string.IsNullOrEmpty(p_entity.DsgnGroup))
|
||
|
{
|
||
|
q = q.Where(p => p.DsgnGroup.Contains(p_entity.DsgnGroup));
|
||
|
}
|
||
|
if (!string.IsNullOrEmpty(p_entity.PromotionGroup))
|
||
|
{
|
||
|
q = q.Where(p => p.PromotionGroup.Contains(p_entity.PromotionGroup));
|
||
|
}
|
||
|
if (!string.IsNullOrEmpty(p_entity.PartType))
|
||
|
{
|
||
|
q = q.Where(p => p.PartType.Contains(p_entity.PartType));
|
||
|
}
|
||
|
if (!string.IsNullOrEmpty(p_entity.Status))
|
||
|
{
|
||
|
q = q.Where(p => p.Status.Contains(p_entity.Status));
|
||
|
}
|
||
|
if (!string.IsNullOrEmpty(p_entity.Group))
|
||
|
{
|
||
|
q = q.Where(p => p.Group.Contains(p_entity.Group));
|
||
|
}
|
||
|
if (!string.IsNullOrEmpty(p_entity.Drawing))
|
||
|
{
|
||
|
q = q.Where(p => p.Drawing.Contains(p_entity.Drawing));
|
||
|
}
|
||
|
if (!string.IsNullOrEmpty(p_entity.PartRevision))
|
||
|
{
|
||
|
q = q.Where(p => p.PartRevision.Contains(p_entity.PartRevision));
|
||
|
}
|
||
|
if (!string.IsNullOrEmpty(p_entity.DrawingLocation))
|
||
|
{
|
||
|
q = q.Where(p => p.DrawingLocation.Contains(p_entity.DrawingLocation));
|
||
|
}
|
||
|
if (!string.IsNullOrEmpty(p_entity.Size))
|
||
|
{
|
||
|
q = q.Where(p => p.Size.Contains(p_entity.Size));
|
||
|
}
|
||
|
if (!string.IsNullOrEmpty(p_entity.PriceBreakCategory))
|
||
|
{
|
||
|
q = q.Where(p => p.PriceBreakCategory.Contains(p_entity.PriceBreakCategory));
|
||
|
}
|
||
|
if (p_entity.AuxiliaryMaterial != false)
|
||
|
{
|
||
|
q = q.Where(p => p.AuxiliaryMaterial == p_entity.AuxiliaryMaterial);
|
||
|
}
|
||
|
if (!string.IsNullOrEmpty(p_entity.Qgrade))
|
||
|
{
|
||
|
q = q.Where(p => p.Qgrade.Contains(p_entity.Qgrade));
|
||
|
}
|
||
|
if (p_entity.WmsPartType != 0)
|
||
|
{
|
||
|
q = q.Where(p => p.WmsPartType == p_entity.WmsPartType);
|
||
|
}
|
||
|
if (!string.IsNullOrEmpty(p_entity.ManageWay))
|
||
|
{
|
||
|
q = q.Where(p => p.ManageWay.Contains(p_entity.ManageWay));
|
||
|
}
|
||
|
if (!string.IsNullOrEmpty(p_entity.InventoryCode))
|
||
|
{
|
||
|
q = q.Where(p => p.InventoryCode.Contains(p_entity.InventoryCode));
|
||
|
}
|
||
|
if (!string.IsNullOrEmpty(p_entity.ManageType))
|
||
|
{
|
||
|
q = q.Where(p => p.ManageType.Contains(p_entity.ManageType));
|
||
|
}
|
||
|
if (p_entity.InspectType != null)
|
||
|
{
|
||
|
q = q.Where(p => p.InspectType == p_entity.InspectType);
|
||
|
}
|
||
|
if (p_entity.UID != 0)
|
||
|
{
|
||
|
q = q.Where(p => p.UID == p_entity.UID);
|
||
|
}
|
||
|
if (!string.IsNullOrEmpty(p_entity.CreateUser))
|
||
|
{
|
||
|
q = q.Where(p => p.CreateUser.Contains(p_entity.CreateUser));
|
||
|
}
|
||
|
if (!string.IsNullOrEmpty(p_entity.Remark))
|
||
|
{
|
||
|
q = q.Where(p => p.Remark.Contains(p_entity.Remark));
|
||
|
}
|
||
|
if (!string.IsNullOrEmpty(p_entity.CommandType))
|
||
|
{
|
||
|
q = q.Where(p => p.CommandType.Contains(p_entity.CommandType));
|
||
|
}
|
||
|
if (!string.IsNullOrEmpty(p_entity.Domain))
|
||
|
{
|
||
|
q = q.Where(p => p.Domain.Contains(p_entity.Domain));
|
||
|
}
|
||
|
if (!string.IsNullOrEmpty(p_entity.Site))
|
||
|
{
|
||
|
q = q.Where(p => p.Site.Contains(p_entity.Site));
|
||
|
}
|
||
|
_ret.Result = q;
|
||
|
_ret.State = ReturnStatus.Succeed;
|
||
|
p_action(_ret);
|
||
|
}
|
||
|
}
|
||
|
catch (Exception e)
|
||
|
{
|
||
|
_ret.State = ReturnStatus.Failed;
|
||
|
_ret.ErrorList.Add(e);
|
||
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(TES_PART_MSTR), "Get_TES_PART_MSTR_List", e.Message);
|
||
|
throw e;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
public static DataTable Get_TES_PART_MSTR_List(string p_PartCode, string p_tableName)
|
||
|
{
|
||
|
DataTable dt = new DataTable(); ;
|
||
|
var dbSetting = GlobalConfig.ExchangeCenterDB;
|
||
|
try
|
||
|
{
|
||
|
var strConn = EntitiesFactory.GetEfConnectionString(dbSetting);
|
||
|
SqlConnection conn = new System.Data.SqlClient.SqlConnection();
|
||
|
conn.ConnectionString = strConn;
|
||
|
if (conn.State != ConnectionState.Open)
|
||
|
{
|
||
|
conn.Open();
|
||
|
}
|
||
|
SqlCommand cmd = new SqlCommand();
|
||
|
cmd.Connection = conn;
|
||
|
string _sql = string.Format("select * from {0} where PartCode='{1}'", p_tableName, p_PartCode);
|
||
|
|
||
|
cmd.CommandText = _sql;
|
||
|
|
||
|
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
|
||
|
|
||
|
adapter.Fill(dt);
|
||
|
|
||
|
}
|
||
|
catch (SqlException ex)
|
||
|
{
|
||
|
throw new Exception($"系统无法连接到数据库:{dbSetting},请检查配置的服务器,数据库,用户名和密码等信息是否正确。{Environment.NewLine}{ex}");
|
||
|
}
|
||
|
return dt;
|
||
|
}
|
||
|
|
||
|
public static ResultObject<bool> Save_TES_PART_MSTR(List<long> p_listUid, EnumTaskState p_state)
|
||
|
{
|
||
|
|
||
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
||
|
try
|
||
|
{
|
||
|
using (var db = EntitiesFactory.CreateExchangeCenterInstance())
|
||
|
{
|
||
|
var _lst = db.TES_PART_MSTR.Where(p => p_listUid.Contains(p.UID)).ToList();
|
||
|
foreach (var itm in _lst)
|
||
|
{
|
||
|
db.TES_PART_MSTR.AddOrUpdate(itm);
|
||
|
}
|
||
|
if (db.SaveChanges() != -1)
|
||
|
{
|
||
|
_ret.State = ReturnStatus.Succeed;
|
||
|
_ret.Result = true;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
_ret.State = ReturnStatus.Failed;
|
||
|
_ret.Result = false;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
catch (Exception e)
|
||
|
{
|
||
|
_ret.State = ReturnStatus.Failed;
|
||
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(TES_PART_MSTR), "Save_TES_PART_MSTR", e.Message);
|
||
|
_ret.Result = false;
|
||
|
_ret.ErrorList.Add(e);
|
||
|
throw e;
|
||
|
}
|
||
|
return _ret;
|
||
|
|
||
|
}
|
||
|
public ResultObject<bool> Del_TES_PART_MSTR(List<TES_PART_MSTR> p_entitys)
|
||
|
{
|
||
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
||
|
try
|
||
|
{
|
||
|
using (var db = EntitiesFactory.CreateExchangeCenterInstance())
|
||
|
{
|
||
|
foreach (var itm in p_entitys)
|
||
|
{
|
||
|
db.TES_PART_MSTR.Remove(itm);
|
||
|
}
|
||
|
if (db.SaveChanges() != -1)
|
||
|
{
|
||
|
_ret.State = ReturnStatus.Succeed;
|
||
|
_ret.Result = true;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
_ret.State = ReturnStatus.Failed;
|
||
|
_ret.Result = false;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
catch (Exception e)
|
||
|
{
|
||
|
_ret.State = ReturnStatus.Failed;
|
||
|
_ret.Result = false;
|
||
|
_ret.ErrorList.Add(e);
|
||
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(TES_PART_MSTR), "Del_TES_PART_MSTR", e.Message); throw e;
|
||
|
}
|
||
|
return _ret;
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
}
|