|
|
|
|
using Mesnac.Codd.Session;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace Mesnac.Action.ChemicalWeighing.Product.PptPlan
|
|
|
|
|
{
|
|
|
|
|
public partial class FrmBudget : Form
|
|
|
|
|
{
|
|
|
|
|
public FrmBudget()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FrmBudget_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
#region 生产计划DGV
|
|
|
|
|
|
|
|
|
|
DbHelper dbHelper1 = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
|
|
if (dbHelper1 == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
|
|
|
}
|
|
|
|
|
dbHelper1.ClearParameter();
|
|
|
|
|
dbHelper1.CommandType = CommandType.Text;
|
|
|
|
|
string strSql1 = "SELECT Recipe_Name, Plan_Num, Real_Num, Recipe_ID FROM RT_plan";
|
|
|
|
|
dbHelper1.CommandText = strSql1;
|
|
|
|
|
DataTable table1 = dbHelper1.ToDataTable();
|
|
|
|
|
|
|
|
|
|
//table.Columns.Add("check", typeof(bool));
|
|
|
|
|
//dataGridView1.Columns.Clear();
|
|
|
|
|
//dataGridView1.AutoGenerateColumns = false;
|
|
|
|
|
|
|
|
|
|
DataGridViewCheckBoxColumn dtCheck1 = new DataGridViewCheckBoxColumn();
|
|
|
|
|
dtCheck1.DataPropertyName = "check";
|
|
|
|
|
dtCheck1.HeaderText = "";
|
|
|
|
|
dataGridView1.Columns.Add(dtCheck1);
|
|
|
|
|
dataGridView1.DataSource = table1;
|
|
|
|
|
dataGridView1.Columns[0].Width = 30;
|
|
|
|
|
|
|
|
|
|
dataGridView1.Columns[1].HeaderText = "配方名称";
|
|
|
|
|
dataGridView1.Columns[2].HeaderText = "计划数";
|
|
|
|
|
dataGridView1.Columns[3].HeaderText = "完成数";
|
|
|
|
|
dataGridView1.Columns[4].Visible = false;
|
|
|
|
|
dataGridView1.Columns[1].Width = 120;
|
|
|
|
|
dataGridView1.Columns[1].ReadOnly = true;
|
|
|
|
|
dataGridView1.Columns[2].ReadOnly = true;
|
|
|
|
|
dataGridView1.Columns[3].ReadOnly = true;
|
|
|
|
|
dataGridView1.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable;
|
|
|
|
|
dataGridView1.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable;
|
|
|
|
|
dataGridView1.Columns[3].SortMode = DataGridViewColumnSortMode.NotSortable;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 所有计划DGV(已停用)
|
|
|
|
|
|
|
|
|
|
//DbHelper dbHelper2 = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
|
|
//if (dbHelper2 == null)
|
|
|
|
|
//{
|
|
|
|
|
// throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
|
|
|
//}
|
|
|
|
|
//dbHelper2.ClearParameter();
|
|
|
|
|
//dbHelper2.CommandType = CommandType.Text;
|
|
|
|
|
//string strSql2 = "SELECT Recipe_Name, Plan_Num, Real_Num FROM LR_plan";
|
|
|
|
|
//dbHelper2.CommandText = strSql2;
|
|
|
|
|
//DataTable table2 = dbHelper2.ToDataTable();
|
|
|
|
|
|
|
|
|
|
//DataGridViewCheckBoxColumn dtCheck2 = new DataGridViewCheckBoxColumn();
|
|
|
|
|
//dtCheck2.DataPropertyName = "check";
|
|
|
|
|
//dtCheck2.HeaderText = "";
|
|
|
|
|
//dataGridView3.Columns.Add(dtCheck2);
|
|
|
|
|
//dataGridView3.DataSource = table2;
|
|
|
|
|
//dataGridView3.Columns[0].Width = 30;
|
|
|
|
|
//dataGridView3.Columns[1].HeaderText = "配方名称";
|
|
|
|
|
//dataGridView3.Columns[2].HeaderText = "计划数";
|
|
|
|
|
//dataGridView3.Columns[3].HeaderText = "完成数";
|
|
|
|
|
////dataGridView3.Columns[4].Visible = false;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 生产计划的全选框
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void checkBox1_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if(checkBox1.Checked == true)
|
|
|
|
|
{
|
|
|
|
|
foreach(DataGridViewRow dgvRow in dataGridView1.Rows)
|
|
|
|
|
{
|
|
|
|
|
dgvRow.Cells[0].Value = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
foreach (DataGridViewRow dgvRow in dataGridView1.Rows)
|
|
|
|
|
{
|
|
|
|
|
dgvRow.Cells[0].Value = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//刷新预算详细DGV
|
|
|
|
|
detaildeBudget();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 全部计划的全选框(已停用)
|
|
|
|
|
//private void checkBox2_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
//{
|
|
|
|
|
// if (checkBox2.Checked == true)
|
|
|
|
|
// {
|
|
|
|
|
// foreach (DataGridViewRow dgvRow in dataGridView3.Rows)
|
|
|
|
|
// {
|
|
|
|
|
// dgvRow.Cells[0].Value = true;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// else
|
|
|
|
|
// {
|
|
|
|
|
// foreach (DataGridViewRow dgvRow in dataGridView3.Rows)
|
|
|
|
|
// {
|
|
|
|
|
// dgvRow.Cells[0].Value = false;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// //刷新预算详细DGV
|
|
|
|
|
// detaildeBudget();
|
|
|
|
|
//}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if(e.ColumnIndex == 0) //单击复选框时
|
|
|
|
|
{
|
|
|
|
|
DataGridViewCell dgcell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
|
|
|
|
|
dgcell.Value = (bool)dgcell.EditedFormattedValue;
|
|
|
|
|
//刷新预算详细DGV
|
|
|
|
|
detaildeBudget();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void dataGridView3_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.ColumnIndex == 0) //单击复选框时
|
|
|
|
|
{
|
|
|
|
|
DataGridViewCell dgcell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
|
|
|
|
|
dgcell.Value = (bool)dgcell.EditedFormattedValue;
|
|
|
|
|
//刷新预算详细DGV
|
|
|
|
|
detaildeBudget();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 响应所有复选框选择时 预算详细DGV的数据刷新功能
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void detaildeBudget()
|
|
|
|
|
{
|
|
|
|
|
bool flag = false; //选中行 物料统计标志位
|
|
|
|
|
DbHelper dbHelper3 = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
|
|
StringBuilder strSql3 = new StringBuilder("SELECT a.*, b.消耗kg FROM(SELECT Bin_Serial, Material_name FROM Pmt_Bin LEFT JOIN Pmt_material ON Pmt_Bin.Material_ID = Pmt_material.ID) a LEFT JOIN (SELECT 物料名, SUM(消耗kg) AS 消耗kg FROM(");
|
|
|
|
|
|
|
|
|
|
int i = 0; //用于变量替换的唯一性设置
|
|
|
|
|
foreach (DataGridViewRow dgr in dataGridView1.Rows)
|
|
|
|
|
{
|
|
|
|
|
if (true.Equals(dgr.Cells[0].Value))
|
|
|
|
|
{
|
|
|
|
|
i++;
|
|
|
|
|
if (!flag)
|
|
|
|
|
{
|
|
|
|
|
//第一个满足条件进来的 要append 没有union
|
|
|
|
|
strSql3.Append("(SELECT Material_name AS 物料名, Set_Weight * @Num"+i+ " AS 消耗kg FROM Pmt_material LEFT JOIN Pmt_weigh ON Pmt_weigh.Material_ID = Pmt_material.ID WHERE Recipe_ID = @RecipeId" + i+")");
|
|
|
|
|
strSql3.Replace("@Num" + i, ((int)dgr.Cells[2].Value - (int)dgr.Cells[3].Value).ToString());
|
|
|
|
|
strSql3.Replace("@RecipeId" + i, "'"+dgr.Cells[4].Value+ "'");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//后来进来的append 有union
|
|
|
|
|
strSql3.Append("UNION (SELECT Material_name AS 物料名, Set_Weight * @Num" + i + " AS 消耗kg FROM Pmt_material LEFT JOIN Pmt_weigh ON Pmt_weigh.Material_ID = Pmt_material.ID WHERE Recipe_ID = @RecipeId" + i + ")");
|
|
|
|
|
strSql3.Replace("@Num" + i, ((int)dgr.Cells[2].Value - (int)dgr.Cells[3].Value).ToString());
|
|
|
|
|
strSql3.Replace("@RecipeId" + i, "'" + dgr.Cells[4].Value + "'");
|
|
|
|
|
}
|
|
|
|
|
flag = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 预算详细DGV的数据填充
|
|
|
|
|
|
|
|
|
|
dataGridView2.DataSource = null; //清空预算详细DGV
|
|
|
|
|
label2.Text = "0kg";
|
|
|
|
|
if (flag)
|
|
|
|
|
{
|
|
|
|
|
strSql3.Append(") c GROUP BY 物料名) b ON a.Material_name = b.物料名");
|
|
|
|
|
|
|
|
|
|
if (dbHelper3 == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
|
|
|
}
|
|
|
|
|
dbHelper3.ClearParameter();
|
|
|
|
|
dbHelper3.CommandType = CommandType.Text;
|
|
|
|
|
dbHelper3.CommandText = strSql3.ToString();
|
|
|
|
|
DataTable table1 = dbHelper3.ToDataTable();
|
|
|
|
|
dataGridView2.DataSource = table1;
|
|
|
|
|
dataGridView2.Columns[0].HeaderText = "料仓";
|
|
|
|
|
dataGridView2.Columns[1].HeaderText = "物料名";
|
|
|
|
|
dataGridView2.Columns[2].HeaderText = "消耗(kg)";
|
|
|
|
|
dataGridView2.Columns[2].Width = 120;
|
|
|
|
|
dataGridView2.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
|
|
|
|
|
dataGridView2.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable;
|
|
|
|
|
dataGridView2.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable;
|
|
|
|
|
//所有物料合计重量
|
|
|
|
|
double allWeigh = 0;
|
|
|
|
|
foreach (DataGridViewRow dgr in dataGridView2.Rows)
|
|
|
|
|
{
|
|
|
|
|
if (!String.IsNullOrEmpty(dgr.Cells[2].Value.ToString()))
|
|
|
|
|
{
|
|
|
|
|
allWeigh += Convert.ToDouble(dgr.Cells[2].Value.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
label2.Text = allWeigh.ToString() + "kg";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|