using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CoreFS.CA06;
using Core.Mes.Client.Comm.Control;
using Core.StlMes.Client.YdmPipeManage.Tool;
using Core.Mes.Client.Comm.Tool;
using Core.Mes.Client.Comm.Server;
using System.Collections;
using Core.StlMes.Client.YdmPipeManage;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using Core.StlMes.Client.YdmBase;
namespace Core.StlMes.Client.YdmPipeReport
{
public partial class FrmRunTimeRptZg : FrmBase
{
public FrmRunTimeRptZg()
{
this.IsLoadUserView = true;
InitializeComponent();
}
private Hashtable ShapeRelation = null;
private string beglongCode = "";//部门ID
private string[] arr = null;
private void FrmRunTimeRptZg_Load(object sender, EventArgs e)
{
dtBathYear.Value = DateTime.Parse(DateTime.Now.ToString("yyyy-MM"));
switch(this.CustomInfo)
{
case "STORAGE_NO":
this.cmbStoreNo.Visible = true;
this.ultraLabel1.Visible = true;
BaseMethod.InitStorageCom(cmbStoreNo, dataTable3, this.ValidDataPurviewIds, this.ob);
break;
case "BELONG_CODE":
this.cmbStoreNo.Visible = false;
this.ultraLabel1.Visible = false;
break;
}
}
public override void ToolBar_Click(object sender, string ToolbarKey)
{
switch (ToolbarKey)
{
case"Query":
queryData();
break;
case"Export":
exportData();
break;
case "insertTal":
insertTal();
break;
case"Close":
this.Close();
break;
}
}
///
/// 结转
///
private void insertInital()
{
UltraGridRow row = this.ultraGrid1.ActiveRow;
string dtNowTim = DateTime.Now.ToString("yyyyMM");
if (row == null || row.Index < 0)
{
MessageUtil.ShowWarning("无运行年月信息,无法结转!");
return;
}
DataTable ds = ServerHelper.GetData("com.steering.pss.ydm.Report.FrmRunTimeRptZg.getIntalJZ", new object[] { dtNowTim}, ob);
if (int.Parse(ds.Rows[0][0].ToString()) > 0)
{
MessageUtil.ShowTips("已存在结转数据,不允许重复结转!");
return;
}
ArrayList parm = new ArrayList();
if (MessageUtil.ShowYesNoAndQuestion("是否结转期初数据?") == DialogResult.No) return;
try
{
this.Cursor = Cursors.WaitCursor; //控制鼠标的样式为等待
if (Constant.WaitingForm == null)
{
Constant.WaitingForm = new WaitingForm();
}
Constant.WaitingForm.ShowToUser = true;
Constant.WaitingForm.Show();
Constant.WaitingForm.Update();
foreach (UltraGridRow uRow in ultraGrid1.Rows)
{
//ArrayList ss = new ArrayList();
//ss.Add(uRow.Cells["JUDGE_STOVE_NO"].Value.ToString());
//ss.Add(uRow.Cells["BATCH_NO"].Value.ToString());
//ss.Add(uRow.Cells["BATCH_GROUD_NO"].Value.ToString());
//ss.Add(dtNowTim);
//DataTable ds = ServerHelper.GetData("com.steering.pss.ydm.pipemanage.FrmPipeAdjust.selectYearMoth", new object[] { ss }, ob);
//if (int.Parse(ds.Rows[0]["ACOUNT"].ToString()) > 0)
//{
// MessageUtil.ShowTips("此数据已进行结转转,不允许再次结转!");
// return;
//}
ArrayList list = new ArrayList();
list.Add(uRow.Cells["JUDGE_STOVE_NO"].Value.ToString());
list.Add(uRow.Cells["BATCH_NO"].Value.ToString());
list.Add(uRow.Cells["BATCH_GROUD_NO"].Value.ToString());
list.Add(uRow.Cells["ACT_COUNT"].Value.ToString());
list.Add(uRow.Cells["ACT_WEIGHT"].Value.ToString());
list.Add(uRow.Cells["BAL_YEAR_MONTH"].Value.ToString());
list.Add(this.UserInfo.GetUserName());
list.Add(uRow.Cells["INITIAL_ID"].Value.ToString());
list.Add(uRow.Cells["BELONG_CODE"].Value.ToString());
list.Add(uRow.Cells["BELONG_NAME"].Value.ToString());
parm.Add(list);
}
CoreClientParam ccp = new CoreClientParam();
ccp.ServerName = "com.steering.pss.ydm.Report.FrmRunTimeRpt";
ccp.MethodName = "insertInital";
ccp.ServerParams = new object[] { parm };
ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
if (ccp.ReturnCode != -1)
{
if (ccp.ReturnInfo.Equals("期初数据结转成功!"))
{
MessageUtil.ShowTips(ccp.ReturnInfo);
}
else
{
MessageUtil.ShowTips(ccp.ReturnInfo);
}
}
this.Cursor = Cursors.Default;
Constant.WaitingForm.ShowToUser = false;
Constant.WaitingForm.Close();
Constant.WaitingForm = null;
}
catch (Exception e)
{
this.Cursor = Cursors.Default;
Constant.WaitingForm.ShowToUser = false;
Constant.WaitingForm.Close();
Constant.WaitingForm = null;
}
}
private void SetStaticsInfoC()
{
try
{
if (this.ultraGrid1.Rows.Count == 0)
{
this.ultraGrid1.DisplayLayout.Bands[0].Summaries.Clear();
}
else
{
ArrayList alist = new ArrayList();
alist.Add("ACT_COUNT");
alist.Add("Act_Weight");
CommonMethod.SetStaticsInfoSum(ref this.ultraGrid1, alist, true);
}
}
catch { }
}
///
/// 结转期初数据
///
private void insertTal()
{
string dtYear = this.dtBathYear.Value.ToString("yyyyMM");
string dtNowTim = DateTime.Now.ToString("yyyyMM");
if (!this.dtBathYear.Value.AddMonths(1).ToString("yyyyMM").Equals(dtNowTim))
{
MessageUtil.ShowTips("所选结转年月与当前所在月往后推一月不一致,请重新选择结转年月!");
return;
}
UltraGridRow row = this.ultraGrid1.ActiveRow;
if (row == null || row.Index < 0)
{
MessageUtil.ShowWarning("无库存信息,无法结转!");
return;
}
string[] arr = new string[0];
string departId = ClsBaseInfo.GetDepartIdBySectionId(this.UserInfo.GetDeptid(), this.ob);
DataTable ds = new DataTable();
switch (this.CustomInfo)
{
case "BELONG_CODE":
ds = ServerHelper.GetData("com.steering.pss.ydm.Report.FrmRunTimeRptZg.getIntalJZB", new object[] { dtNowTim, departId }, ob);
break;
case "STORAGE_NO":
List arrlist = arr.ToList();
IQueryable checkMagRows = this.ultraGrid2.Rows.AsQueryable().Where(" CHK = 'True'");
if (checkMagRows.Count() == 0)
{
MessageUtil.ShowTips("请选择对应的仓库!");
return;
}
foreach (UltraGridRow uRow in checkMagRows)
{
arrlist.Add(uRow.Cells["STORAGE_NO"].Value.ToString());
}
arr = arrlist.ToArray();
ds = ServerHelper.GetData("com.steering.pss.ydm.Report.FrmRunTimeRptZg.getIntalJZ", new object[] { dtNowTim, arr }, ob);
break;
}
if (int.Parse(ds.Rows[0][0].ToString()) > 0)
{
MessageUtil.ShowTips("已存在结转数据,不允许重复结转!");
return;
}
ArrayList parm = new ArrayList();
if (MessageUtil.ShowYesNoAndQuestion("是否结转期初数据?") == DialogResult.No) return;
try
{
this.Cursor = Cursors.WaitCursor; //控制鼠标的样式为等待
if (Constant.WaitingForm == null)
{
Constant.WaitingForm = new WaitingForm();
}
Constant.WaitingForm.ShowToUser = true;
Constant.WaitingForm.Show();
Constant.WaitingForm.Update();
foreach (UltraGridRow uRow in ultraGrid1.Rows)
{
if (int.Parse(uRow.Cells["END_COUNT"].Value.ToString()) > 0)
{
ArrayList list = new ArrayList();
list.Add(uRow.Cells["JUDGE_STOVE_NO"].Value.ToString());
list.Add(uRow.Cells["BATCH_NO"].Value.ToString());
list.Add(uRow.Cells["BATCH_GROUD_NO"].Value.ToString());
list.Add(uRow.Cells["END_COUNT"].Value.ToString());
list.Add(uRow.Cells["END_AMOUNT"].Value.ToString());
list.Add(this.dtBathYear.Value.AddMonths(1).ToString("yyyyMM"));
list.Add(this.UserInfo.GetUserName());
parm.Add(list);
}
}
CoreClientParam ccp = new CoreClientParam();
switch (this.CustomInfo)
{
case "BELONG_CODE":
ccp.ServerName = "com.steering.pss.ydm.Report.FrmRunTimeRptZg";
ccp.MethodName = "insertInitalBelog";
ccp.ServerParams = new object[] { parm, departId, dtYear };
break;
case "STORAGE_NO":
ccp.ServerName = "com.steering.pss.ydm.Report.FrmRunTimeRptZg";
ccp.MethodName = "insertInital";
ccp.ServerParams = new object[] { parm, arr, dtYear };
break;
}
ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
if (ccp.ReturnCode != -1)
{
if (ccp.ReturnInfo.Equals("期初数据结转成功!"))
{
MessageUtil.ShowTips(ccp.ReturnInfo);
}
else
{
MessageUtil.ShowTips(ccp.ReturnInfo);
}
}
this.Cursor = Cursors.Default;
Constant.WaitingForm.ShowToUser = false;
Constant.WaitingForm.Close();
Constant.WaitingForm = null;
}
catch (Exception e)
{
this.Cursor = Cursors.Default;
Constant.WaitingForm.ShowToUser = false;
Constant.WaitingForm.Close();
Constant.WaitingForm = null;
}
}
///
/// 导出
///
private void exportData()
{
GridHelper.ulGridToExcel(ultraGrid1, "炉批运行年月收发存汇总");
}
///
/// 查询
///
private void queryData()
{
string yearMothTim = "";
string stoveNo = "";
arr = new string[0];
switch (this.CustomInfo)
{
case "STORAGE_NO":
List arrlist = arr.ToList();
IQueryable checkMagRows = this.ultraGrid2.Rows.AsQueryable().Where(" CHK = 'True'");
if (checkMagRows.Count() == 0)
{
MessageUtil.ShowTips("请选择对应的仓库!");
return;
}
foreach (UltraGridRow uRow in checkMagRows)
{
arrlist.Add(uRow.Cells["STORAGE_NO"].Value.ToString());
}
arr = arrlist.ToArray();
break;
case "BELONG_CODE":
beglongCode = ClsBaseInfo.GetDepartIdBySectionId(this.UserInfo.GetDeptid(), this.ob);
break;
}
DataTable table1 = null;
DataTable table2 = null;
DataTable table3 = null;
try
{
this.Cursor = Cursors.WaitCursor; //控制鼠标的样式为等待
if (Constant.WaitingForm == null)
{
Constant.WaitingForm = new WaitingForm();
}
Constant.WaitingForm.ShowToUser = true;
Constant.WaitingForm.Show();
Constant.WaitingForm.Update();
yearMothTim = this.dtBathYear.Value.ToString("yyyyMM");
string strWhere1 = "", strWhere2 = "", strWhere3 = "", strWhere4 = "";
switch(this.CustomInfo)
{
case "STORAGE_NO":
//上期期初
if (!this.GetOriginalLast(yearMothTim, strWhere1, out table1, arr))
{
}
//本期入库量
if (!this.GetThisIn(yearMothTim, strWhere1, out table2, arr))
{
//return;
}
//本期出库量
if (!this.GetThisOut(yearMothTim, strWhere1, out table3, arr))
{
//return;
}
break;
case "BELONG_CODE":
//上期期初
if (!this.GetOriginalLastB(yearMothTim, strWhere1, out table1, beglongCode))
{
}
//本期入库量
if (!this.GetThisInB(yearMothTim, strWhere1, out table2, beglongCode))
{
//return;
}
//本期出库量
if (!this.GetThisOutB(yearMothTim, strWhere1, out table3, beglongCode))
{
//return;
}
break;
}
//调差
//DataTable table4 = null;
//if (!this.GetAdjust(yearMothTim, strWhere1, out table4, arr))
//{
//}
DataTable table = new DataTable();
string[] strMergeColumns = new string[] { "JUDGE_STOVE_NO", "BATCH_NO", "BATCH_GROUD_NO" };
if (table1 != null)
{
table = table1.DefaultView.ToTable(true, strMergeColumns);
if (table2 != null)
{
table.Merge(table2.DefaultView.ToTable(true, strMergeColumns));
}
if (table3 != null)
{
table.Merge(table3.DefaultView.ToTable(true, strMergeColumns));
}
}
else
{
if (table2 != null)
{
table = table2.DefaultView.ToTable(true, strMergeColumns);
if (table3 != null)
{
table.Merge(table3.DefaultView.ToTable(true, strMergeColumns));
}
}
else
{
if (table3 != null)
{
table = table3.DefaultView.ToTable(true, strMergeColumns);
//if (table4 != null)
//{
// table.Merge(table4.DefaultView.ToTable(true, strMergeColumns));
//}
}
//else
//{
// if (table4 != null)
// {
// table = table4.DefaultView.ToTable(true, strMergeColumns);
// }
//}
}
}
if (table != null)
{
table.DefaultView.Sort = "JUDGE_STOVE_NO, BATCH_NO, BATCH_GROUD_NO";
table = table.DefaultView.ToTable(true, strMergeColumns);
}
else
{
return;
}
string strSort = "", strHeatNo = "", strBactchNo = "", strGroupNo = "";
DataRow newrow;
DataRow[] rows;
this.dataTable1.Rows.Clear();
decimal dWgt = 0.0M,dAjust = 0.0M;
int dCount = 0;
decimal dThisIn_Month = 0.0M, dThisOut_Month = 0.00M;
int dThisIn_MonthCount = 0, dThisOut_MonthCount = 0;
string strRowFilters = "";
for (int i = 0; i < table.Rows.Count; i++)
{
newrow = this.dataTable1.NewRow();
try
{
strHeatNo = Convert.ToString(table.Rows[i]["JUDGE_STOVE_NO"]);//炉号
strBactchNo = Convert.ToString(table.Rows[i]["BATCH_NO"]);//批号
strGroupNo = Convert.ToString(table.Rows[i]["BATCH_GROUD_NO"]);//组号
strRowFilters = string.IsNullOrEmpty(strHeatNo) ? " JUDGE_STOVE_NO is null " : " JUDGE_STOVE_NO = '" + strHeatNo + "' ";
strRowFilters += string.IsNullOrEmpty(strBactchNo) ? " and BATCH_NO is null " : " and BATCH_NO = '" + strBactchNo + "' ";
strRowFilters += string.IsNullOrEmpty(strGroupNo) ? " and BATCH_GROUD_NO is null " : " and BATCH_GROUD_NO = '" + strGroupNo + "' ";
try
{
table1.CaseSensitive = true;
rows = table1.Select(strRowFilters);
if (rows.Length > 0)
{
try
{
dWgt = decimal.Parse(Convert.ToString(rows[0]["WEIGHT"]));
dCount = int.Parse(Convert.ToString(rows[0]["COUNT"]));
}
catch
{
dWgt = 0.0M;
dCount = 0;
}
}
else
{
dWgt = 0.0M;
dCount = 0;
}
}
catch
{
dWgt = 0.0M;
dCount = 0;
}
try
{
table2.CaseSensitive = true;
rows = table2.Select(strRowFilters);
if (rows.Length > 0)
{
try
{
dThisIn_Month = decimal.Parse(Convert.ToString(rows[0]["WEIGHT_MONTH"]));
dThisIn_MonthCount = int.Parse(Convert.ToString(rows[0]["WEIGHT_MONTHCOUNT"]));
}
catch
{
dThisIn_Month = 0.0M;
dThisIn_MonthCount = 0;
}
}
else
{
dThisIn_Month = 0.0M;
dThisIn_MonthCount = 0;
}
}
catch
{
dThisIn_Month = 0.0M;
dThisIn_MonthCount = 0;
}
try
{
table3.CaseSensitive = true;
rows = table3.Select(strRowFilters);
if (rows.Length > 0)
{
try
{
dThisOut_Month = decimal.Parse(Convert.ToString(rows[0]["WEIGHT_MONTH"]));
dThisOut_MonthCount = int.Parse(Convert.ToString(rows[0]["weight_monthcount"]));
}
catch
{
dThisOut_Month = 0.0M;
dThisOut_MonthCount = 0;
}
}
else
{
dThisOut_Month = 0.0M;
dThisOut_MonthCount = 0;
}
}
catch
{
dThisOut_Month = 0.0M;
dThisOut_MonthCount = 0;
}
//try
//{
// table4.CaseSensitive = true;
// rows = table4.Select(strRowFilters);
// if (rows.Length > 0)
// {
// try
// {
// dAjust = decimal.Parse(Convert.ToString(rows[0]["AWEIGHT"]));
// }
// catch
// {
// dAjust = 0.0M;
// }
// }
// else
// {
// dAjust = 0.0M;
// }
//}
//catch
//{
// dAjust = 0.0M;
//}
try
{
newrow["JUDGE_STOVE_NO"] = strHeatNo;
newrow["BATCH_NO"] = strBactchNo;
newrow["BATCH_GROUD_NO"] = strGroupNo;
newrow["ORIGINAL_AMOUNT"] = Convert.ToString(dWgt).Trim();
newrow["ORIGINAL_COUNT"] = Convert.ToString(dCount).Trim();
newrow["MONTH_1"] = dThisIn_Month.ToString().Trim();
newrow["MONTH_1COUNT"] = dThisIn_MonthCount.ToString().Trim();
newrow["MONTH_2"] = dThisOut_Month.ToString().Trim();
newrow["MONTH_2COUNT"] = dThisOut_MonthCount.ToString().Trim();
newrow["END_AMOUNT"] = Convert.ToString(dWgt + dThisIn_Month - dThisOut_Month + dAjust).Trim();
newrow["END_COUNT"] = Convert.ToString(dCount + dThisIn_MonthCount - dThisOut_MonthCount).Trim();
newrow["AWEIGHT"] = Convert.ToString(dAjust).Trim();
try
{
if (ShapeRelation.Contains(strHeatNo))
{
strSort = ShapeRelation[strHeatNo].ToString();
}
else
{
strSort = "";
}
}
catch
{
strSort = "";
}
this.dataSet1.Tables[0].Rows.Add(newrow);
} catch { }
}
catch { }
}
this.SetStaticsInfo();
CommonMethod.SetGridSumArea(this.ultraGrid1);
this.Cursor = Cursors.Default;
Constant.WaitingForm.ShowToUser = false;
Constant.WaitingForm.Close();
Constant.WaitingForm = null;
}
catch (Exception e)
{
this.Cursor = Cursors.Default;
Constant.WaitingForm.ShowToUser = false;
Constant.WaitingForm.Close();
Constant.WaitingForm = null;
}
}
private void SetStaticsInfo()
{
try
{
if (this.ultraGrid1.Rows.Count == 0)
{
this.ultraGrid1.DisplayLayout.Bands[0].Summaries.Clear();
}
else
{
ArrayList alist = new ArrayList();
alist.Add("ORIGINAL_AMOUNT");
alist.Add("ORIGINAL_COUNT");
alist.Add("MONTH_1");
alist.Add("MONTH_1COUNT");
alist.Add("MONTH_2");
alist.Add("MONTH_2COUNT");
alist.Add("END_AMOUNT");
alist.Add("END_COUNT");
alist.Add("AWEIGHT");
CommonMethod.SetStaticsInfoSum(ref this.ultraGrid1, alist, true);
}
}
catch { }
}
//本期出库量
private bool GetThisOut(string yearMothTim, string strWhere, out DataTable table, string[] arr)
{
table = null;
DataSet set = new DataSet();
DataTable ds = ServerHelper.GetData("com.steering.pss.ydm.Report.FrmRunTimeRptZg.getThisOut", new object[] { yearMothTim, strWhere, arr }, this.ob);
if (ds != null && ds.Rows.Count > 0)
{
set.Tables.Add(ds);
table = set.Tables[0];
return true;
}
return false;
}
//本期出库量
private bool GetThisOutB(string yearMothTim, string strWhere, out DataTable table, string belogCode)
{
table = null;
DataSet set = new DataSet();
DataTable ds = ServerHelper.GetData("com.steering.pss.ydm.Report.FrmRunTimeRptZg.getThisOutB", new object[] { yearMothTim, strWhere, belogCode }, this.ob);
if (ds != null && ds.Rows.Count > 0)
{
set.Tables.Add(ds);
table = set.Tables[0];
return true;
}
return false;
}
//本期入库量
private bool GetThisIn(string yearMothTim,string strWhere, out DataTable table, string[] arr)
{
table = null;
DataSet set = new DataSet();
DataTable ds = ServerHelper.GetData("com.steering.pss.ydm.Report.FrmRunTimeRptZg.getThisIn", new object[] { yearMothTim, strWhere, arr }, this.ob);
if (ds != null && ds.Rows.Count > 0)
{
set.Tables.Add(ds);
table = set.Tables[0];
return true;
}
return false;
}
private bool GetThisInB(string yearMothTim, string strWhere, out DataTable table, string belogCode)
{
table = null;
DataSet set = new DataSet();
DataTable ds = ServerHelper.GetData("com.steering.pss.ydm.Report.FrmRunTimeRptZg.getThisInB", new object[] { yearMothTim, strWhere, belogCode }, this.ob);
if (ds != null && ds.Rows.Count > 0)
{
set.Tables.Add(ds);
table = set.Tables[0];
return true;
}
return false;
}
//期初
private bool GetOriginalLast(string yearMothTim, string strWhere, out DataTable table, string[] arr)
{
table = null;
DataSet set = new DataSet();
DataTable ds = ServerHelper.GetData("com.steering.pss.ydm.Report.FrmRunTimeRptZg.getOriginalLast", new object[] { yearMothTim, strWhere, arr }, this.ob);
if (ds != null && ds.Rows.Count > 0)
{
set.Tables.Add(ds);
table = set.Tables[0];
return true;
}
return false;
}
//期初(所属权)
private bool GetOriginalLastB(string yearMothTim, string strWhere, out DataTable table, string belogCode)
{
table = null;
DataSet set = new DataSet();
DataTable ds = ServerHelper.GetData("com.steering.pss.ydm.Report.FrmRunTimeRptZg.getOriginalLastB", new object[] { yearMothTim, strWhere, belogCode }, this.ob);
if (ds != null && ds.Rows.Count > 0)
{
set.Tables.Add(ds);
table = set.Tables[0];
return true;
}
return false;
}
private void ultraPopupControlContainer1_Closed(object sender, EventArgs e)
{
this.ultraLabel3.Text = "";
foreach (UltraGridRow uRow in this.ultraGrid2.Rows)
{
if (uRow.Cells["CHK"].Value.ToString() == "True")
{
this.ultraLabel3.Text += uRow.Cells["STORAGE_NAME"].Text + " ";
}
}
}
private void cmbStoreNo_AfterDropDown(object sender, EventArgs e)
{
Point p = ultraGroupBox1.PointToScreen(cmbStoreNo.Location);
p.Y += 22;
this.ultraPopupControlContainer1.Show(p);
}
}
}