/*******************************************************************************
* Copyright(c) 2015 DongkeSoft All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:F_P_00002.cs
* 2.功能描述:成型结算信息表
* 编辑履历:
* 作者 日期 版本 修改内容
* 陈晓野 2017/01/11 1.00 新建
*******************************************************************************/
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using Dongke.IBOSS.PRD.Basics.BaseControls;
using Dongke.IBOSS.PRD.Basics.BaseResources;
using Dongke.IBOSS.PRD.Client.CommonModule;
using Dongke.IBOSS.PRD.Client.Controls;
using Dongke.IBOSS.PRD.WCF.DataModels;
using Dongke.IBOSS.PRD.WCF.Proxys;
namespace Dongke.IBOSS.PRD.Client.Public
{
///
/// 成型结算信息表
///
public partial class F_P_00002 : DKFormBase
{
#region 功能条码
//public const string PreMonthCN = "#前月#";
//public const string CurMonthCN = "#当月#";
//public const string QUITCN = "#退出#";
//public const string NextPageCN = "#下一页#";
//public const string PrePageCN = "#上一页#";
//public const string NextRowCN = "#下一行#";
//public const string PreRowCN = "#上一行#";
//public const string CurRowCN = "#当日#";
//public const string Month00CN = "#合计#";
public const string PreMonth = "#PREMONTH#";
public const string CurMonth = "#CURMONTH#";
public const string QUIT = "#QUIT#";
public const string NextPage = "#NEXTPAGE#";
public const string PrePage = "#PREPAGE#";
public const string NextRow = "#NEXTROW#";
public const string PreRow = "#PREROW#";
public const string CurRow = "#CURROW#";
public const string Month00 = "#00#";
public const string Month01 = "#01#";
public const string Month02 = "#02#";
public const string Month03 = "#03#";
public const string Month04 = "#04#";
public const string Month05 = "#05#";
public const string Month06 = "#06#";
public const string Month07 = "#07#";
public const string Month08 = "#08#";
public const string Month09 = "#09#";
public const string Month10 = "#10#";
public const string Month11 = "#11#";
public const string Month12 = "#12#";
public const string Month13 = "#13#";
public const string Month14 = "#14#";
public const string Month15 = "#15#";
public const string Month16 = "#16#";
public const string Month17 = "#17#";
public const string Month18 = "#18#";
public const string Month19 = "#19#";
public const string Month20 = "#20#";
public const string Month21 = "#21#";
public const string Month22 = "#22#";
public const string Month23 = "#23#";
public const string Month24 = "#24#";
public const string Month25 = "#25#";
public const string Month26 = "#26#";
public const string Month27 = "#27#";
public const string Month28 = "#28#";
public const string Month29 = "#29#";
public const string Month30 = "#30#";
public const string Month31 = "#31#";
#endregion
#region 成员变量
// 窗体的单例模式
private static F_P_00002 _instance;
private long _showLimitTime = 0;
private long _LimitTime = 120;
private F_P_000021 _frmUserCode = new F_P_000021();
private bool _isLoading = false;
private DataSet _dataSet = null;
#endregion
#region 构造函数
public F_P_00002()
{
InitializeComponent();
// 窗体显示的Title
this.Text = "成型结算";
this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE;
this.tsbtnClose.Text = ButtonText.TSBTN_CLOSE;
this.lblUserCode.Text = null;
this.dgv0.AutoGenerateColumns = false;
this.dgv1.AutoGenerateColumns = false;
this.dgv2.AutoGenerateColumns = false;
this.dgv3.AutoGenerateColumns = false;
this.dgv4.AutoGenerateColumns = false;
this.dgvM.AutoGenerateColumns = false;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
//this.tsbtnAdaptive_Click(null, null);
}
#endregion
#region 单例模式
///
/// 单例模式,防止重复创建窗体
///
public static F_P_00002 Instance
{
get
{
if (_instance == null || _instance.IsDisposed)
{
_instance = new F_P_00002();
}
return _instance;
}
}
#endregion
#region 事件处理
///
/// 窗体加载事件
///
///
///
private void F_P_00002_Load(object sender, EventArgs e)
{
try
{
string showLimitTime = System.Configuration.ConfigurationManager.AppSettings["ShowLimitTime"];
long time = 0;
if (!long.TryParse(showLimitTime, out time))
{
_LimitTime = time;
}
//this.BindPage();
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
private void F_P_00002_Shown(object sender, EventArgs e)
{
this.ResetForm();
}
private void F_P_00002_FormClosed(object sender, FormClosedEventArgs e)
{
_instance = null;
}
private void tsbtnClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void F_P_00002_SizeChanged(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Maximized;
}
private void timer1_Tick(object sender, EventArgs e)
{
SetShowTime(this._showLimitTime);
this._showLimitTime--;
}
private void btnResetForm_Click(object sender, EventArgs e)
{
this.ResetForm();
}
#endregion
#region 私有方法
///
/// 绑定下拉列表值
///
///
private void BindPage()
{
//绑定数据来源下拉列表
//ServiceResultEntity sre = (ServiceResultEntity)DoAsync(new BaseAsyncMethod(() =>
//{
// return PublicModuleProxy.Service.GetRptProcedureModule(F_P_00001.AccountID);
//}));
//this.dropRptProcedure.DataSource = sre.Data.Tables[Constant.INT_IS_ZERO];
//this.dropRptProcedure.ValueMember = "Rptprocedureid";
//this.dropRptProcedure.DisplayMember = "Rptprocedurename";
}
///
/// 根据界面查询条件获取数据集
///
private ServiceResultEntity GetSearchData()
{
try
{
if (string.IsNullOrWhiteSpace(this._frmUserCode.UserCode))
{
return null;
}
//if (string.IsNullOrEmpty(this.dropRptProcedure.Text))
//{
// return null;
//}
////se.RptProcedureID = Convert.ToInt32(this.dropRptProcedure.SelectedValue);
//DataRowView drv = this.dropRptProcedure.SelectedItem as DataRowView;
//int? pid = null;
//if (drv != null)
//{
// pid = int.Parse(drv["SProcedureid"].ToString());
//}
//if (!pid.HasValue)
//{
// return null;
//}
string usercode = this._frmUserCode.UserCode;
//DateTime selectDate = this._frmUserCode.DateStart;
DateTime selectDate = this._frmUserCode.DateMonth;
ServiceResultEntity sre = (ServiceResultEntity)DoAsync(() =>
{
return PublicModuleProxy.Service.GetFP00002Data(F_P_00001.AccountID,
usercode, selectDate);
});
return sre;
}
catch (Exception ex)
{
throw ex;
}
}
private void SetShowTime(long time)
{
if (time == 0)
{
this.ResetForm();
return;
}
string t = time.ToString();
int l = t.Length;
if (l >= 3)
{
pic3.Image = GetTimePic(t[0]);
pic2.Image = GetTimePic(t[1]);
pic1.Image = GetTimePic(t[2]);
}
else if (l == 2)
{
pic3.Image = Dongke.IBOSS.PRD.Client.Public.Properties.Resources.num_0;
pic2.Image = GetTimePic(t[0]);
pic1.Image = GetTimePic(t[1]);
}
else if (l == 1)
{
pic3.Image = Dongke.IBOSS.PRD.Client.Public.Properties.Resources.num_0;
pic2.Image = Dongke.IBOSS.PRD.Client.Public.Properties.Resources.num_0;
pic1.Image = GetTimePic(t[0]);
}
}
private Bitmap GetTimePic(char num)
{
switch (num)
{
case '0':
return Dongke.IBOSS.PRD.Client.Public.Properties.Resources.num_0;
case '1':
return Dongke.IBOSS.PRD.Client.Public.Properties.Resources.num_1;
case '2':
return Dongke.IBOSS.PRD.Client.Public.Properties.Resources.num_2;
case '3':
return Dongke.IBOSS.PRD.Client.Public.Properties.Resources.num_3;
case '4':
return Dongke.IBOSS.PRD.Client.Public.Properties.Resources.num_4;
case '5':
return Dongke.IBOSS.PRD.Client.Public.Properties.Resources.num_5;
case '6':
return Dongke.IBOSS.PRD.Client.Public.Properties.Resources.num_6;
case '7':
return Dongke.IBOSS.PRD.Client.Public.Properties.Resources.num_7;
case '8':
return Dongke.IBOSS.PRD.Client.Public.Properties.Resources.num_8;
case '9':
return Dongke.IBOSS.PRD.Client.Public.Properties.Resources.num_9;
default:
return Dongke.IBOSS.PRD.Client.Public.Properties.Resources.num_0;
}
}
private void ClearGridData()
{
this._isLoading = true;
try
{
this.lblUserCode.Text = null;
//this.gb0.Text = "总体信息";
this.gbm.Text = "月度信息【 】";
this.gb1.Text = "成检缺陷明细【 】";
this.gb2.Text = "后道损坯明细【 】";
this.gb3.Text = "半检不合格明细【 】";
this.gb4.Text = "返工(合格)明细【 】";
this.dgvM.DataSource = null;
this.dgv0.DataSource = null;
this.dgv1.DataSource = null;
this.dgv2.DataSource = null;
this.dgv3.DataSource = null;
this.dgv4.DataSource = null;
this._dataSet = null;
}
finally
{
this._isLoading = false;
}
}
private void AutoResizeColumns()
{
this.dgv0.AutoResizeColumns();
this.dgv1.AutoResizeColumns();
this.dgv2.AutoResizeColumns();
this.dgv3.AutoResizeColumns();
this.dgv4.AutoResizeColumns();
this.dgvM.AutoResizeColumns();
}
private void ResetSearch()
{
timerShow.Stop();
this.ClearGridData();
this.AutoResizeColumns();
pic3.Image = Dongke.IBOSS.PRD.Client.Public.Properties.Resources.num_0;
pic2.Image = Dongke.IBOSS.PRD.Client.Public.Properties.Resources.num_0;
pic1.Image = Dongke.IBOSS.PRD.Client.Public.Properties.Resources.num_0;
}
private void ResetForm()
{
this.ResetSearch();
if (this._frmUserCode.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.SearchData();
}
else
{
this.Close();
}
}
private void SearchData()
{
try
{
this.ResetSearch();
if (F_P_00001.AutoUp())
{
return;
}
this.gb0.Text = string.Format("总体信息【{0}】", DateTime.Now.ToString("yyyy-MM-dd"));
this.lblUserCode.Text = this._frmUserCode.UserCode;
ServiceResultEntity sre = this.GetSearchData();
if (sre == null)
{
this._frmUserCode.ErrorMessges = "没有查询到任何数据";
this.ResetForm();
return;
}
if (sre.Status == Constant.ServiceResultStatus.Other)
{
this._frmUserCode.ErrorMessges = sre.Message + "【" + this._frmUserCode.UserCode + "】";
this.ResetForm();
return;
}
this._dataSet = sre.Data;
if (this._dataSet != null)
{
this._isLoading = true;
this.dgvM.DataSource = this._dataSet.Tables["DataM"];
this.dgv0.DataSource = this._dataSet.Tables["DataD"];
this._isLoading = false;
_currentRowIndex = -1;
this.dgvM_SelectionChanged(null, null);
}
else
{
this.ResetForm();
return;
}
this.AutoResizeColumns();
this.txtKey.Focus();
//string showLimitTime = System.Configuration.ConfigurationManager.AppSettings["ShowLimitTime"];
//if (!long.TryParse(showLimitTime, out _showLimitTime))
//{
// _showLimitTime = 120;
//}
_showLimitTime = _LimitTime;
//SetShowTime(_showLimitTime);
timerShow.Start();
}
catch (Exception ex)
{
this._isLoading = false;
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
this.ResetForm();
}
finally
{
this._isLoading = false;
}
}
#endregion
private int _currentRowIndex = -1;
private void dgvM_SelectionChanged(object sender, EventArgs e)
{
if (this._isLoading || this._dataSet == null || this.dgvM.Rows.Count <= 0 || this.dgvM.CurrentRow == null)
{
return;
}
if (_currentRowIndex == this.dgvM.CurrentRow.Index)
{
return;
}
try
{
_currentRowIndex = this.dgvM.CurrentRow.Index;
DataRowView drv = this.dgvM.CurrentRow.DataBoundItem as DataRowView;
if (drv == null)
{
return;
}
string cddate = drv["cdate"] + "";
string rowFilter = null;
this.gbm.Text = string.Format("月度信息【{0} {1}】", cddate, drv["goodscode"]);
//this.gb1.Text = string.Format("成检缺陷明细【{0} {1}】", cddate, drv["goodscode"]);
//this.gb2.Text = string.Format("后道损坯明细【{0} {1}】", cddate, drv["goodscode"]);
//this.gb3.Text = string.Format("半检不合格明细【{0} {1}】", cddate, drv["goodscode"]);
//this.gb4.Text = string.Format("返工(合格)明细【{0} {1}】", cddate, drv["goodscode"]);
if (cddate == "合计")
{
rowFilter = string.Format("goodscode = '{0}'", drv["goodscode"]);
}
else
{
rowFilter = string.Format("goodscode = '{0}' and cdate = '{1}'", drv["goodscode"], cddate);
}
this.dgv1.DataSource = null;
this.dgv2.DataSource = null;
this.dgv3.DataSource = null;
this.dgv4.DataSource = null;
// 成检明细
this._dataSet.Tables["DataCC"].DefaultView.RowFilter = rowFilter;
// 后道损明细
this._dataSet.Tables["DataNS"].DefaultView.RowFilter = rowFilter;
// 半检不合格明细
this._dataSet.Tables["DataSC"].DefaultView.RowFilter = rowFilter;
// 返工合格明细
this._dataSet.Tables["DataRC"].DefaultView.RowFilter = rowFilter;
this.dgv1.DataSource = this._dataSet.Tables["DataCC"];
this.dgv2.DataSource = this._dataSet.Tables["DataNS"];
this.dgv3.DataSource = this._dataSet.Tables["DataSC"];
this.dgv4.DataSource = this._dataSet.Tables["DataRC"];
this.gb1.Text = string.Format("成检缺陷明细【{0} {1}】({2})", cddate, drv["goodscode"], this.dgv1.RowCount);
this.gb2.Text = string.Format("后道损坯明细【{0} {1}】({2})", cddate, drv["goodscode"], this.dgv2.RowCount);
this.gb3.Text = string.Format("半检不合格明细【{0} {1}】({2})", cddate, drv["goodscode"], this.dgv3.RowCount);
this.gb4.Text = string.Format("返工(合格)明细【{0} {1}】({2})", cddate, drv["goodscode"], this.dgv4.RowCount);
this.AutoResizeColumns();
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
private void F_P_00002_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
this.txtKey.Focus();
}
}
private void txtKey_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
string text = this.txtKey.Text.Trim().ToUpper();
this.txtKey.Clear();
if (text.Length < 3 || !text.StartsWith("#") || !text.EndsWith("#"))
{
return;
}
if (QUIT == text)
{
this.btnResetForm_Click(null, null);
return;
}
if (NextPage == text)
{
// 下一页
int last = -1;
if (this.dgv0.VerticalScrollBarVisible)
{
last = this.dgv0.FirstDisplayedScrollingRowIndex + this.dgv0.DisplayedRowCount(false);
if (last < this.dgv0.RowCount)
{
this.dgv0.FirstDisplayedScrollingRowIndex = last;
}
}
if (this.dgv1.VerticalScrollBarVisible)
{
last = this.dgv1.FirstDisplayedScrollingRowIndex + this.dgv1.DisplayedRowCount(false);
if (last < this.dgv1.RowCount)
{
this.dgv1.FirstDisplayedScrollingRowIndex = last;
}
}
if (this.dgv2.VerticalScrollBarVisible)
{
last = this.dgv2.FirstDisplayedScrollingRowIndex + this.dgv2.DisplayedRowCount(false);
if (last < this.dgv2.RowCount)
{
this.dgv2.FirstDisplayedScrollingRowIndex = last;
}
}
if (this.dgv3.VerticalScrollBarVisible)
{
last = this.dgv3.FirstDisplayedScrollingRowIndex + this.dgv3.DisplayedRowCount(false);
if (last < this.dgv3.RowCount)
{
this.dgv3.FirstDisplayedScrollingRowIndex = last;
}
}
if (this.dgv4.VerticalScrollBarVisible)
{
last = this.dgv4.FirstDisplayedScrollingRowIndex + this.dgv4.DisplayedRowCount(false);
if (last < this.dgv4.RowCount)
{
this.dgv4.FirstDisplayedScrollingRowIndex = last;
}
}
if (this.dgvM.VerticalScrollBarVisible)
{
last = this.dgvM.FirstDisplayedScrollingRowIndex + this.dgvM.DisplayedRowCount(false);
if (last < this.dgvM.RowCount)
{
this.dgvM.FirstDisplayedScrollingRowIndex = last;
}
}
}
else if (PrePage == text)
{
// 上一页
int last = this.dgv0.FirstDisplayedScrollingRowIndex;
if (last > 0)
{
last = last - this.dgv0.DisplayedRowCount(false);
if (last < 0)
{
last = 0;
}
this.dgv0.FirstDisplayedScrollingRowIndex = last;
}
last = this.dgv1.FirstDisplayedScrollingRowIndex;
if (last > 0)
{
last = last - this.dgv1.DisplayedRowCount(false);
if (last < 0)
{
last = 0;
}
this.dgv1.FirstDisplayedScrollingRowIndex = last;
}
last = this.dgv2.FirstDisplayedScrollingRowIndex;
if (last > 0)
{
last = last - this.dgv2.DisplayedRowCount(false);
if (last < 0)
{
last = 0;
}
this.dgv2.FirstDisplayedScrollingRowIndex = last;
}
last = this.dgv3.FirstDisplayedScrollingRowIndex;
if (last > 0)
{
last = last - this.dgv3.DisplayedRowCount(false);
if (last < 0)
{
last = 0;
}
this.dgv3.FirstDisplayedScrollingRowIndex = last;
}
last = this.dgv4.FirstDisplayedScrollingRowIndex;
if (last > 0)
{
last = last - this.dgv4.DisplayedRowCount(false);
if (last < 0)
{
last = 0;
}
this.dgv4.FirstDisplayedScrollingRowIndex = last;
}
last = this.dgvM.FirstDisplayedScrollingRowIndex;
if (last > 0)
{
last = last - this.dgvM.DisplayedRowCount(false);
if (last < 0)
{
last = 0;
}
this.dgvM.FirstDisplayedScrollingRowIndex = last;
}
}
else if (this.dgvM.RowCount > 0)
{
if (PreRow == text)
{
// 上一条
int index = this._currentRowIndex - 1;
if (index < 0)
{
index = this.dgvM.RowCount - 1;
}
this.dgvM.CurrentCell = this.dgvM.Rows[index].Cells["gmcdate"];
this.dgvM_SelectionChanged(null, null);
}
else if (NextRow == text)
{
// 下一条
int index = this._currentRowIndex + 1;
if (index >= this.dgvM.RowCount)
{
index = 0;
}
this.dgvM.CurrentCell = this.dgvM.Rows[index].Cells["gmcdate"];
this.dgvM_SelectionChanged(null, null);
}
else
{
string monthFlag = null;
if (CurRow == text)
{
// 当前日期
foreach (DataGridViewRow item in this.dgvM.Rows)
{
if ((item.Cells["gmcdate"].Value + "") != "合计")
{
monthFlag = (item.Cells["gmcdate"].Value + "");
//this.dgvM.CurrentCell = item.Cells["gmcdate"];
//this.dgvM_SelectionChanged(null, null);
//this._currentRowIndex = item.Index;
break;
}
}
}
else
{
monthFlag = text.Replace("#", "");
}
if (monthFlag == "00")
{
monthFlag = "合计";
}
int firstIndex = -1;
foreach (DataGridViewRow item in this.dgvM.Rows)
{
if ((item.Cells["gmcdate"].Value + "").EndsWith(monthFlag))
{
if (firstIndex == -1)
{
firstIndex = item.Index;
}
if (this._currentRowIndex < item.Index)
{
this.dgvM.CurrentCell = item.Cells["gmcdate"];
this.dgvM_SelectionChanged(null, null);
//this._currentRowIndex = item.Index;
break;
}
}
else
{
if (firstIndex > -1)
{
this.dgvM.CurrentCell = this.dgvM.Rows[firstIndex].Cells["gmcdate"];
this.dgvM_SelectionChanged(null, null);
//this._currentRowIndex = firstIndex;
break;
}
}
}
if (firstIndex == -1)
{
//this.dgvM.CurrentCell = this.dgvM.Rows[this.dgvM.RowCount - 1].Cells["gmcdate"];
this.dgvM.CurrentCell = this.dgvM.Rows[0].Cells["gmcdate"];
this.dgvM_SelectionChanged(null, null);
}
}
}
}
}
}
}