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.
269 lines
11 KiB
269 lines
11 KiB
using DBUtility;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Web;
|
|
|
|
namespace PaintingScreen.Handler
|
|
{
|
|
public class StationPlanFunction
|
|
{
|
|
public static DataTable GetTableContent()
|
|
{
|
|
DataTable res = new DataTable();
|
|
try
|
|
{
|
|
// string sql = @"
|
|
// SELECT [StationID]
|
|
// ,[StationNo]
|
|
// INTO #station
|
|
// FROM tb_Station
|
|
// WHERE StationNo LIKE 'IM%'
|
|
// ORDER BY StationNo
|
|
//
|
|
//
|
|
// SELECT a.InjectionPlanID,a.StationID,b.StationNo,a.StockNo,a.PlanCount,a.BeginTime,a.EndTime,a.PartNo
|
|
// INTO #temp
|
|
// FROM tb_InjectionPlan a
|
|
// RIGHT JOIN #station b
|
|
// ON a.StationID = b.StationID
|
|
// WHERE a.IsFinish IS NULL OR a.IsFinish = 0
|
|
// ORDER BY b.StationNo,a.BeginTime
|
|
//
|
|
// SELECT aa.StationNo,ff.ModelName,cc.ProductName,aa.PlanCount,aa.BeginTime,aa.EndTime
|
|
// FROM #temp aa
|
|
// JOIN
|
|
// (
|
|
// SELECT StationNo,MIN(BeginTime) BeginTime FROM #temp GROUP BY StationNo
|
|
// ) bb
|
|
// ON aa.StationNo = bb.StationNo AND aa.BeginTime = bb.BeginTime
|
|
// LEFT JOIN
|
|
// (
|
|
// SELECT StockNo,PartNo,ProductName FROM dbo.tb_Product
|
|
// ) cc
|
|
// ON aa.StockNo = cc.StockNo OR aa.PartNo = cc.PartNo
|
|
// LEFT JOIN tb_Product dd
|
|
// ON aa.stockNo = dd.stockNo
|
|
// LEFT JOIN tb_Model_Product ee
|
|
// ON dd.ProductID = ee.ProuctID
|
|
// LEFT JOIN tb_ModelInfo ff
|
|
// ON ee.ModelID = ff.ID
|
|
//
|
|
//
|
|
//
|
|
// DROP TABLE #station;
|
|
// DROP TABLE #temp;
|
|
// ";
|
|
string sql = @"
|
|
SELECT [StationID]
|
|
,[StationNo]
|
|
INTO #station
|
|
FROM tb_Station
|
|
WHERE StationNo LIKE 'IM%'
|
|
ORDER BY StationNo
|
|
|
|
|
|
SELECT a.InjectionPlanID,a.StationID,b.StationNo,a.StockNo,a.PlanCount,a.BeginTime,a.EndTime,a.PartNo
|
|
INTO #temp
|
|
FROM tb_InjectionPlan a
|
|
RIGHT JOIN #station b
|
|
ON a.StationID = b.StationID
|
|
WHERE a.IsFinish IS NULL OR a.IsFinish = 0
|
|
ORDER BY b.StationNo,a.BeginTime
|
|
|
|
|
|
|
|
SELECT * INTO #nextPlanTemp FROM #temp WHERE StationNo IN (
|
|
SELECT StationNo FROM #temp GROUP BY StationNo HAVING COUNT(0) > 1
|
|
)
|
|
ORDER BY StationNo,BeginTime
|
|
|
|
SELECT * into #nptmp
|
|
FROM #nextPlanTemp
|
|
WHERE BeginTime IN (
|
|
SELECT MAX(beginTime) beginTime FROM #nextPlanTemp GROUP BY StationNo
|
|
)
|
|
|
|
SELECT np.StationNo, tp.ProductName INTO #nextPlan FROM #nptmp np
|
|
JOIN tb_Product tp
|
|
ON np.stockNo = tp.stockNo
|
|
|
|
|
|
SELECT aa.StationNo,ff.ModelName,cc.ProductName,aa.PlanCount,aa.BeginTime,aa.EndTime,gg.ProductName nextPlan
|
|
FROM #temp aa
|
|
JOIN
|
|
(
|
|
SELECT StationNo,MIN(BeginTime) BeginTime FROM #temp GROUP BY StationNo
|
|
) bb
|
|
ON aa.StationNo = bb.StationNo AND aa.BeginTime = bb.BeginTime
|
|
LEFT JOIN
|
|
(
|
|
SELECT StockNo,PartNo,ProductName FROM dbo.tb_Product
|
|
) cc
|
|
ON aa.StockNo = cc.StockNo OR aa.PartNo = cc.PartNo
|
|
LEFT JOIN tb_Product dd
|
|
ON aa.stockNo = dd.stockNo
|
|
LEFT JOIN tb_Model_Product ee
|
|
ON dd.ProductID = ee.ProuctID
|
|
LEFT JOIN tb_ModelInfo ff
|
|
ON ee.ModelID = ff.ID
|
|
LEFT JOIN #nextPlan gg
|
|
ON gg.StationNo = aa.StationNo
|
|
|
|
|
|
DROP TABLE #station;
|
|
DROP TABLE #temp;
|
|
DROP TABLE #nextPlanTemp;
|
|
DROP TABLE #nptmp;
|
|
DROP TABLE #nextPlan;
|
|
";
|
|
res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.WriteLogManager(ex);
|
|
LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
|
|
}
|
|
return res;
|
|
}
|
|
|
|
public static Mould GetMouldInfo(string mouleNo)
|
|
{
|
|
Mould mould = new Mould();
|
|
try
|
|
{
|
|
string sql = @"
|
|
SELECT a.ModelName,a.ModelNo,a.PermanentAssetsNo,a.Tonnage
|
|
,a.ServiceLife,a.Supplier Supplier_a,a.PartWeight,a.InjectionPeriod
|
|
,a.LocatingRingSize,a.OutForm
|
|
,a.ModelWeight,a.RunnerForm,a.ModelCavityNo,a.ModelSize
|
|
,b.Purpose,b.State,b.Supplier,b.AddTime,b.Remarks
|
|
FROM tb_ModelInfo a
|
|
JOIN tb_Model_Update b
|
|
ON a.ID = b.ModelID
|
|
WHERE a.ModelNo = '" + mouleNo + @"'
|
|
";
|
|
DataTable dt = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null);
|
|
if (dt != null && dt.Rows.Count > 0)
|
|
{
|
|
mould = (Mould)StationPlanFunction.SetModelValue<Mould>(mould, dt);
|
|
|
|
#region 重复部分赋值
|
|
for (int i = 0; i < 6; i++)
|
|
{
|
|
if (i < dt.Rows.Count)
|
|
{
|
|
for (int j = 0; j < dt.Columns.Count; j++)
|
|
{
|
|
Type t = typeof(Mould);
|
|
PropertyInfo[] props = t.GetProperties();
|
|
foreach (PropertyInfo prop in props)
|
|
{
|
|
if (prop.Name == dt.Columns[j].ColumnName + (i + 1))
|
|
{
|
|
prop.SetValue(mould, dt.Rows[i][j].ToString());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 遍历mould,为null的赋值为""
|
|
|
|
Type tt = typeof(Mould);
|
|
PropertyInfo[] tprops = tt.GetProperties();
|
|
foreach (PropertyInfo prop in tprops)
|
|
{
|
|
if (prop.GetValue(mould) == null)
|
|
{
|
|
prop.SetValue(mould, "");
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.WriteLogManager(ex);
|
|
LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
|
|
}
|
|
return mould;
|
|
}
|
|
|
|
public static T SetModelValue<T>(Object obj, DataTable dt)
|
|
{
|
|
T model = (T)obj;
|
|
if (dt != null && dt.Rows.Count > 0)
|
|
{
|
|
Type t = typeof(T);
|
|
PropertyInfo[] properties = t.GetProperties();
|
|
DataRow dr = dt.Rows[0];
|
|
foreach (PropertyInfo property in properties)
|
|
{
|
|
for (int j = 0; j < dt.Columns.Count; j++)
|
|
{
|
|
if (property.Name == dt.Columns[j].ColumnName)
|
|
{
|
|
property.SetValue(model, dr[j].ToString());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return model;
|
|
}
|
|
}
|
|
|
|
public class Mould
|
|
{
|
|
public string ModelName { get; set; }
|
|
public string ModelNo { get; set; }
|
|
public string PermanentAssetsNo { get; set; }
|
|
public string Tonnage { get; set; }
|
|
public string ServiceLife { get; set; }
|
|
public string Supplier_a { get; set; }
|
|
public string PartWeight { get; set; }
|
|
public string InjectionPeriod { get; set; }
|
|
public string LocatingRingSize { get; set; }
|
|
public string OutForm { get; set; }
|
|
public string ModelWeight { get; set; }
|
|
public string RunnerForm { get; set; }
|
|
public string ModelCavityNo { get; set; }
|
|
public string ModelSize { get; set; }
|
|
public string Purpose1 { get; set; }
|
|
public string State1 { get; set; }
|
|
public string Supplier1 { get; set; }
|
|
public string AddTime1 { get; set; }
|
|
public string Remarks1 { get; set; }
|
|
public string Purpose2 { get; set; }
|
|
public string State2 { get; set; }
|
|
public string Supplier2 { get; set; }
|
|
public string AddTime2 { get; set; }
|
|
public string Remarks2 { get; set; }
|
|
public string Purpose3 { get; set; }
|
|
public string State3 { get; set; }
|
|
public string Supplier3 { get; set; }
|
|
public string AddTime3 { get; set; }
|
|
public string Remarks3 { get; set; }
|
|
public string Purpose4 { get; set; }
|
|
public string State4 { get; set; }
|
|
public string Supplier4 { get; set; }
|
|
public string AddTime4 { get; set; }
|
|
public string Remarks4 { get; set; }
|
|
public string Purpose5 { get; set; }
|
|
public string State5 { get; set; }
|
|
public string Supplier5 { get; set; }
|
|
public string AddTime5 { get; set; }
|
|
public string Remarks5 { get; set; }
|
|
public string Purpose6 { get; set; }
|
|
public string State6 { get; set; }
|
|
public string Supplier6 { get; set; }
|
|
public string AddTime6 { get; set; }
|
|
public string Remarks6 { get; set; }
|
|
}
|
|
|
|
|
|
}
|