Browse Source

添加机台物料消耗统计

master
sc 2 months ago
parent
commit
a3d7e03ddd
  1. 43
      MainWindow.xaml.cs

43
MainWindow.xaml.cs

@ -4,6 +4,7 @@ using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
@ -57,6 +58,27 @@ namespace StatisticsUI
{
/*定位选中行及指定列单元格文本信息*/
DataGridStatistics_ProductCode = (DataGridStatistics.Columns[0].GetCellContent(DataGridStatistics.Items[rownum]) as TextBlock).Text;//定位第0列,原料代码
try
{
string T = "SELECT d.Machine AS MachineName, ISNULL(SUM(dbr.DispenseGrams)/1000, 0) " +
"AS TotalDispenseGrams FROM DyelotsBulkedRecipe dbr " +
"INNER JOIN Dyelots d ON dbr.Dyelot = d.Dyelot WHERE " +
"dbr.ProductCode = '" + DataGridStatistics_ProductCode + "'" +
"AND Created >= '" + query_start + " " + date_start_time + "' AND Created< '" +
query_end + " " + date_end_time + "'" +
"GROUP BY d.Machine ORDER BY d.Machine";
conn_SC.OpenAsync(); //连接数据库
Gram.Clear();
SqlDataAdapter Grame_ = new SqlDataAdapter(T, Connstr_SC);
Grame_.Fill(Gram);
DataGridStatistics_mac.ItemsSource = Gram.DefaultView;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "错误");//返回无效
}
finally { conn_SC.Close(); }
}
}
@ -89,7 +111,7 @@ namespace StatisticsUI
Machine_sql =
"SELECT m.Name AS MachineName," +
"COUNT(DISTINCT d.Dyelot) AS DyelotCount," +
"COUNT(DISTINCT CASE WHEN dbr.DispenseResult = 301" +
"COUNT(DISTINCT CASE WHEN (dbr.DispenseResult = 301 OR dbr.DyeResult = 301) " +
"THEN CONCAT(dbr.Dyelot, '|', dbr.ReDye, '', '|', dbr.StepNumber, '')" +
"END ) AS UniqueRecipeCount FROM Machines m LEFT JOIN Dyelots d ON m.Name = d.Machine " +
"AND d.CreationTime >= '" + query_start + " " + date_start_time + "' AND d.CreationTime < '" + query_end +
@ -106,7 +128,7 @@ namespace StatisticsUI
Machine_sql =
"SELECT m.Name AS MachineName," +
"COUNT(DISTINCT d.Dyelot) AS DyelotCount," +
"COUNT(DISTINCT CASE WHEN dbr.DispenseResult = 301 AND dbr.ProductType = '"+type+
"COUNT(DISTINCT CASE WHEN (dbr.DispenseResult = 301 OR dbr.DyeResult = 301) AND dbr.ProductType = '" + type+
"' THEN CONCAT(dbr.Dyelot, '|', dbr.ReDye, '', '|', dbr.StepNumber, '')END"+
" ) AS UniqueRecipeCount FROM Machines m LEFT JOIN Dyelots d ON m.Name = d.Machine " +
"AND d.CreationTime >= '" + query_start + " " + date_start_time + "' AND d.CreationTime < '" + query_end +
@ -124,10 +146,23 @@ namespace StatisticsUI
DataGridStatistics.ItemsSource = DyelotsBulkedRecipe.DefaultView;
Machine_.Fill(Machine);
for (int i = Machine.Rows.Count - 1; i >= 0; i--)
{
DataRow row = Machine.Rows[i];
// 检查目标列是否为0(处理DBNull情况)
if (row["DyelotCount"] != DBNull.Value &&
Convert.ToDouble(row["DyelotCount"]) == 0)
{
Machine.Rows.RemoveAt(i);
}
}
Machine.AcceptChanges();
DataGridStatistics_mac.ItemsSource = Machine.DefaultView;
}
catch (Exception ex)
{
{
MessageBox.Show(ex.Message, "错误");//返回无效时间弹窗
}
finally
{
@ -152,7 +187,7 @@ namespace StatisticsUI
Machine_Gram.Columns.Add("UniqueRecipeCount", typeof(string));
this.query_date_start.Text = DateTime.Now.ToString("yyyy-MM-dd"); ;//传递开始日期
this.query_date_end.Text = DateTime.Now.ToString("yyyy-MM-dd"); ;//传递结束日期
this.query_date_end.Text = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd"); ;//传递结束日期
}
}
}

Loading…
Cancel
Save