using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Data;
|
using System.Drawing;
|
using System.Text;
|
using System.Windows.Forms;
|
using gregn6Lib;
|
using SQLHelper;
|
using DBUtility;
|
using System.IO;
|
using System.Reflection;
|
|
namespace WorkM
|
{
|
public partial class Kf_WIPBal : Form
|
{
|
public Kf_WIPBal()
|
{
|
InitializeComponent();
|
}
|
public DBUtility.frmBillQueryCondition_New frmCondition;
|
public string ViewName = "h_v_Kf_WIPBal";
|
public string ModCaption = "在制品期初";
|
public const string ModName = "3793";
|
public const string ModRightName = "Kf_WIPBal";
|
public const string ModRightNameEdit = ModRightName + "_Edit";
|
public const string ModRightNameCheck = ModRightName + "_Check";
|
public const string ModRightNameClose = ModRightName + "_Close";
|
public const string ModRightNameDelete = ModRightName + "_Delete";
|
public const string ModRightNameMoney = ModRightName + "_Money";
|
//DAL.ClsSc_StationEntrustOutBill oBill = new DAL.ClsSc_StationEntrustOutBill();
|
//public MES_StationEntrustOutBill oFrm;
|
//public MES_StationEntrustOutBill_NoLot oFrm2;
|
Pub_Class.ClsGridListSum oSumGrid = new Pub_Class.ClsGridListSum();
|
public string sDlgWhere = ""; //外窗体递入
|
|
public Int64 HInterID;
|
public string HBillNo;
|
|
public int HQty_QCCol; //期初数量
|
public int HQty_PDCol; //实盘数量
|
public int HQty_CYCol; //差异数量
|
public int HICMOIDCol; //任务单ID
|
public int HMaterIDCol; //产品ID
|
public int HProcNoCol; //工序号
|
public int HProcIDCol; //工序ID
|
public int HYearCol; //年
|
public int HPeriodCol; //月
|
|
|
//
|
private void initGrid()
|
{
|
DBUtility.Xt_BaseBillFun.initGridList(grdMain,this.Name);
|
}
|
//
|
|
private void Display()
|
{
|
ClsCN SubCn = new ClsCN();
|
DataSet DSet;
|
string sSql = "";
|
string sWhere = "";
|
|
int HYear = ClsPub.isInt(cmbHYear.Text);
|
int HPeriod = ClsPub.isInt(cmbHPeriod.Text);
|
string HMaterID = ClsPub.isStrNull(txtProduct.Text);
|
string HProcID = ClsPub.isStrNull(txtPro.Text);
|
string HDeptID = ClsPub.isStrNull(txtHworkshop.Text);
|
sSql = "exec h_p_Kf_WIPBal "+HYear+","+HPeriod+",'"+ HMaterID+"','"+HProcID+"','"+HDeptID+"'" ;
|
//
|
DSet = SubCn.RunProcReturn(sSql, ViewName, ref DBUtility.ClsPub.sExeReturnInfo);
|
//生成首行标题
|
if (DSet == null)
|
{
|
MessageBox.Show("没有返回任何结果,请在过滤框中点击【恢复】按钮,尝试再次查询!" + DBUtility.ClsPub.sExeReturnInfo);
|
return;
|
}
|
//释放冻结
|
DBUtility.Xt_BaseBillFun.CancelFrozenCol(grdMain);
|
//
|
grdMain.DataSource = DSet.Tables[0].DefaultView;
|
//设置合计列
|
string sTotalCol = "";
|
sTotalCol = DBUtility.Gy_BaseFun.GetTotalCols(DSet);
|
string[] sT;
|
sT = sTotalCol.Split(Convert.ToChar(","));
|
oSumGrid.BuildTotalCols(sT);
|
//
|
//冻结
|
int FrCol = DBUtility.ClsPub.isInt(frmCondition.txtFrozenCol.Text);
|
string s = frmCondition.cmbHComplete.Text;
|
DBUtility.Xt_BaseBillFun.DisplayGrid(grdMain, this.Name, s, FrCol);
|
//画线
|
GraphLine();
|
|
Total();
|
////判断金额权限
|
//if (!ClsPub.Security_Log(ModRightNameMoney, 1, false, DBUtility.ClsPub.CurUserName))
|
//{
|
|
// grdMain.Columns[Fun_GetCol("单价")].Visible = false;
|
// grdMain.Columns[Fun_GetCol("金额")].Visible = false;
|
// grdMain.Columns[Fun_GetCol("备注")].Visible = false;
|
//}
|
|
HQty_QCCol = Fun_GetCol("期初数量");
|
HQty_PDCol = Fun_GetCol("实盘数量");
|
HQty_CYCol = Fun_GetCol("差异数量");
|
HICMOIDCol = Fun_GetCol("HICMOInterID");
|
HMaterIDCol = Fun_GetCol("HMaterID");
|
HProcNoCol = Fun_GetCol("工序号");
|
HProcIDCol = Fun_GetCol("HProcID");
|
HYearCol = Fun_GetCol("HYear");
|
HPeriodCol = Fun_GetCol("HPeriod");
|
grdMain.ReadOnly = false;
|
//
|
grdMain.SelectionMode = DataGridViewSelectionMode.CellSelect;
|
grdMain.ClearSelection();
|
}
|
//
|
private void timer1_Tick(object sender, EventArgs e)
|
{
|
timer1.Enabled=false;
|
initGrid();
|
Display();
|
}
|
|
private void tc_Click(object sender, EventArgs e)
|
{
|
this.Close();
|
}
|
|
private void sx_Click(object sender, EventArgs e)
|
{
|
timer1.Enabled = true;
|
}
|
|
private void dj_Click(object sender, EventArgs e)
|
{
|
Sub_ShowBill();
|
}
|
//显示单据
|
private void Sub_ShowBill()
|
{
|
|
}
|
//
|
private Int32 Fun_GetCol(string sCol)
|
{
|
return DBUtility.Xt_BaseBillFun.Fun_GetCol(sCol, grdMain);
|
}
|
//
|
private Int32 Fun_GetCol2(string sCol)
|
{
|
return DBUtility.Xt_BaseBillFun.Fun_GetCol(sCol, grdSub1);
|
}
|
//
|
private void Kf_WIPBal_Load(object sender, EventArgs e)
|
{
|
//
|
frmCondition = new frmBillQueryCondition_New();
|
this.Text = ModCaption;
|
lblCaption.Text = ModCaption;
|
oSumGrid.ogrdMain = grdMain; //初始化 new
|
oSumGrid.oGridsum = grdSum;
|
initGrid();
|
|
|
|
cmbHYear.Items.Clear();
|
|
int sYear = ClsPub.isDate(DBUtility.ClsPub.GetServerDate(-1)).Year;
|
int sPeriod = ClsPub.isDate(DBUtility.ClsPub.GetServerDate(-1)).Month;
|
cmbHYear.Items.Add(sYear);
|
cmbHYear.Items.Add(sYear - 1);
|
cmbHYear.Items.Add(sYear - 2);
|
cmbHYear.Items.Add(sYear - 3);
|
cmbHYear.SelectedIndex = 0;
|
cmbHPeriod.Text = sPeriod.ToString();
|
}
|
|
private void grdMain_DblClick(object sender, EventArgs e)
|
{
|
Sub_ShowBill();
|
}
|
|
private void cx_Click(object sender, EventArgs e)
|
{
|
frmCondition = new frmBillQueryCondition_New();
|
SetCondition(frmCondition, ViewName, this.Name);
|
frmCondition.ShowDialog();
|
if (frmCondition.Tag.ToString() == "OK")
|
{
|
Display();
|
}
|
}
|
|
public void SetCondition(frmBillQueryCondition_New frmCondition, string ViewName, string Name)
|
{
|
frmCondition.Tag = "";
|
frmCondition.ViewName = ViewName;
|
frmCondition.ModName = Name;
|
}
|
|
private void xz_Click(object sender, EventArgs e)
|
{
|
Kf_WIPBal_Add oAdd = new Kf_WIPBal_Add();
|
int sYear = ClsPub.isDate(DBUtility.ClsPub.GetServerDate(-1)).Year;
|
oAdd.cmbHYear.Items.Add(sYear);
|
oAdd.cmbHYear.Items.Add(sYear - 1);
|
oAdd.cmbHYear.Items.Add(sYear - 2);
|
oAdd.cmbHYear.Items.Add(sYear - 3);
|
oAdd.cmbHYear.Text = cmbHYear.Text;
|
oAdd.cmbHPeriod.Text = cmbHPeriod.Text;
|
oAdd.ShowDialog();
|
Display();
|
}
|
|
private void sc_Click(object sender, EventArgs e)
|
{
|
if (MessageBox.Show("确定要删除选中记录?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
|
{
|
Sub_DeleteBill();
|
}
|
}
|
//删除
|
private void Sub_DeleteBill()
|
{
|
if (grdMain.CurrentRow == null)
|
{
|
MessageBox.Show("请选择要删除的记录!","提示");
|
return;
|
}
|
ClsCN oCn = new ClsCN();
|
Int64 HICMOID = 0;
|
Int64 HMaterID = 0;
|
Int64 HProcNo = 0;
|
Int64 HProcID = 0;
|
double HQty = 0;
|
double HQCQty = 0;
|
int HYear = 0;
|
int HPeriod = 0;
|
|
|
HICMOID = ClsPub.isLong(grdMain.Rows[grdMain.CurrentRow.Index].Cells[HICMOIDCol].Value);
|
HMaterID = ClsPub.isLong(grdMain.Rows[grdMain.CurrentRow.Index].Cells[HMaterIDCol].Value);
|
HProcNo = ClsPub.isLong(grdMain.Rows[grdMain.CurrentRow.Index].Cells[HProcNoCol].Value);
|
HProcID = ClsPub.isLong(grdMain.Rows[grdMain.CurrentRow.Index].Cells[HProcIDCol].Value);
|
HYear = ClsPub.isInt(grdMain.Rows[grdMain.CurrentRow.Index].Cells[HYearCol].Value);
|
HPeriod = ClsPub.isInt(grdMain.Rows[grdMain.CurrentRow.Index].Cells[HPeriodCol].Value);
|
|
oCn.RunProc("delete Kf_WIPBal where HYear=" + HYear + " and HPeriod=" + HPeriod +
|
" and HICMOInterID=" + HICMOID + " and HMaterID=" + HMaterID + " and HProcNo=" + HProcNo + " and HProcID=" + HProcID);
|
Display();
|
}
|
|
private void timer2_Tick(object sender, EventArgs e)
|
{
|
timer2.Enabled = false;
|
//frmCondition = new frmBillQueryCondition_New();
|
//SetCondition(frmCondition, ViewName, this.Name);
|
//frmCondition.ShowDialog();
|
//if (frmCondition.Tag.ToString() == "OK")
|
//{
|
timer1.Enabled = true;
|
//}
|
}
|
|
|
|
private void bclk_Click(object sender, EventArgs e)
|
{
|
//保存列宽
|
DBUtility.Xt_BaseBillFun.SaveGrid(grdMain, this.Name);
|
}
|
|
private void mrlk_Click(object sender, EventArgs e)
|
{
|
DBUtility.Xt_BaseBillFun.DefaultGridView(grdMain, this.Name);
|
}
|
//
|
private void GraphLine()
|
{
|
int MainIDCol = Fun_GetCol("hmainid");
|
int SubIDCol = Fun_GetCol("hsubid");
|
string s = frmCondition.cmbHComplete.Text;
|
long n=0;
|
DBUtility.Xt_BaseBillFun.GraphLine(grdMain, MainIDCol, SubIDCol, s,ref n);
|
//显示
|
lbldj.Text = "查询出 " + n.ToString() + " 张单据";
|
lbljl.Text = "共有 " + grdMain.RowCount.ToString() + " 条记录";
|
}
|
//审核
|
private void sh_Click(object sender, EventArgs e)
|
{
|
this.Sub_CheckBill();
|
}
|
|
//审核单据
|
private void Sub_CheckBill()
|
{
|
|
}
|
//反审单据
|
private void Sub_AbandonCheck()
|
{
|
|
}
|
//反审核
|
private void qsh_Click(object sender, EventArgs e)
|
{
|
Sub_AbandonCheck();
|
}
|
|
private void GraphicsGrid()
|
{
|
DBUtility.Xt_BaseBillFun.GraphicsGrid(grdMain);
|
}
|
|
#region //打印设置
|
|
GridppReport Report;
|
//预览
|
private void yl_Click(object sender, EventArgs e)
|
{
|
Int64 lngBillKey = 0;
|
string sInterID = "";
|
if (grdMain.CurrentRow == null)
|
return;
|
for (int i = 0; i < grdMain.SelectedRows.Count; i++)
|
{
|
lngBillKey = DBUtility.ClsPub.isLong(grdMain.SelectedRows[i].Cells[Fun_GetCol("hmainid")].Value);
|
if (lngBillKey == 0)
|
return;
|
sInterID = sInterID + lngBillKey.ToString() + ",";
|
}
|
if (sInterID.Length > 1)
|
{
|
sInterID = sInterID.Remove(sInterID.Length - 1, 1);
|
}
|
|
SQLHelper.ClsCN oCn = new ClsCN();
|
DataSet Ds;
|
Ds = oCn.RunProcReturn("exec h_p_MES_StationEntrustOutBill_DY '" + sInterID + "','" + ClsPub.CurUserName + "'", "h_p_MES_StationEntrustOutBill_DY");
|
|
grdSub1.DataSource = Ds.Tables[0].DefaultView;
|
|
//选择打印模板
|
BLL.Gy_OpenTmp oFrm = new BLL.Gy_OpenTmp();
|
oFrm.sBillName = ModName;
|
oFrm.sBillModel = ModCaption;
|
oFrm.ShowDialog();
|
if (oFrm.OKTag == Pub_Class.ClsPub.Enum_OKTag.OKTag_OK)
|
{
|
//
|
Sub_SetReport(oFrm.sOpenTmp);
|
Report.PrintPreview(false);
|
}
|
}
|
|
private void Sub_SetReport(string sOpenTmp)
|
{
|
//判断行数
|
//
|
Report = new GridppReport();
|
Report.LoadFromFile(DBUtility.ClsPub.AppPath + @"\" + sOpenTmp + ".grf"); //here .
|
Report.BeforePostRecord += new _IGridppReportEvents_BeforePostRecordEventHandler(ReportBeforePostRecord);
|
Report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportFetchRecordByDataTable);
|
}
|
//打印赋值表头
|
private void ReportBeforePostRecord()//
|
{
|
|
Report.FieldByName("供应商").AsString = DBUtility.ClsPub.isStrNull(grdSub1.Rows[0].Cells[Fun_GetCol2("供应商")].Value);
|
Report.FieldByName("日期").AsString = DBUtility.ClsPub.isStrNull(grdSub1.Rows[0].Cells[Fun_GetCol2("日期")].Value);
|
Report.FieldByName("制单").AsString = DBUtility.ClsPub.isStrNull(grdSub1.Rows[0].Cells[Fun_GetCol2("制单")].Value);
|
Report.FieldByName("验收").AsString = DBUtility.ClsPub.isStrNull(grdSub1.Rows[0].Cells[Fun_GetCol2("验收")].Value);
|
}
|
private void ReportFetchRecordByDataTable()
|
{
|
DataTable oDt = new DataTable();
|
BLL.Utility.FillRecordToReport(Report, grdSub1, oDt, 0);
|
}
|
|
#endregion
|
//
|
private void grdMain_Paint(object sender, PaintEventArgs e)
|
{
|
GraphicsGrid();
|
}
|
|
//合计 new
|
private void Total()
|
{
|
if (grdMain.Rows.Count > 0 && grdMain.ColumnCount>0)
|
{
|
oSumGrid.SetGridsum();
|
//oSumGrid.Total();
|
oSumGrid.TotalAll();
|
}
|
}
|
//合计 new
|
private void grdMain_ColumnWidthChanged(object sender, DataGridViewColumnEventArgs e)
|
{
|
Total();
|
}
|
//合计 new
|
private void grdMain_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
|
{
|
Total();
|
}
|
//引出EXCEL
|
private void dc_Click(object sender, EventArgs e)
|
{
|
DBUtility.Gy_BaseFun.DataToExcel(this.Text, grdMain);
|
//BLL.ClsPub_BLL.DataGridViewToExcel2(grdMain, this.Text, "");
|
}
|
|
private void dy_Click(object sender, EventArgs e)
|
{
|
|
|
}
|
|
private void txtHBillNo_KeyDown(object sender, KeyEventArgs e)
|
{
|
if (e.KeyCode == Keys.Enter)
|
{
|
Sub_FastQuery();
|
}
|
}
|
//快速过滤
|
private void Sub_FastQuery()
|
{
|
|
Display();
|
}
|
|
|
private void txtHLotNo_KeyDown(object sender, KeyEventArgs e)
|
{
|
if (e.KeyCode == Keys.Enter)
|
{
|
Sub_FastQuery();
|
}
|
}
|
|
private void txtHCenterID_KeyDown(object sender, KeyEventArgs e)
|
{
|
if (e.KeyCode == Keys.Enter)
|
{
|
Sub_FastQuery();
|
}
|
}
|
|
private void txtHProcID_KeyDown(object sender, KeyEventArgs e)
|
{
|
if (e.KeyCode == Keys.Enter)
|
{
|
Sub_FastQuery();
|
}
|
}
|
|
private void chkYC_CheckedChanged(object sender, EventArgs e)
|
{
|
Sub_FastQuery();
|
}
|
//网格编辑前判断
|
private void grdMain_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
|
{
|
int i = grdMain.CurrentCell.ColumnIndex;
|
if (i != HQty_PDCol )
|
{
|
e.Cancel = true;
|
}
|
|
}
|
//网格编辑后处理
|
private void grdMain_CellEndEdit(object sender, DataGridViewCellEventArgs e)
|
{
|
Save();
|
}
|
public void Save()
|
{
|
ClsCN oCn = new ClsCN();
|
Int64 HICMOID = 0;
|
Int64 HMaterID = 0;
|
Int64 HProcNo = 0;
|
Int64 HProcID = 0;
|
double HQty = 0;
|
double HQCQty = 0;
|
int HYear = 0;
|
int HPeriod = 0;
|
|
int i = grdMain.CurrentCell.ColumnIndex;
|
if (i == HQty_PDCol)
|
{
|
HICMOID = ClsPub.isLong(grdMain.Rows[grdMain.CurrentRow.Index].Cells[HICMOIDCol].Value);
|
HMaterID = ClsPub.isLong(grdMain.Rows[grdMain.CurrentRow.Index].Cells[HMaterIDCol].Value);
|
HProcNo = ClsPub.isLong(grdMain.Rows[grdMain.CurrentRow.Index].Cells[HProcNoCol].Value);
|
HProcID = ClsPub.isLong(grdMain.Rows[grdMain.CurrentRow.Index].Cells[HProcIDCol].Value);
|
HQty = ClsPub.isDoule(grdMain.Rows[grdMain.CurrentRow.Index].Cells[HQty_PDCol].Value);
|
HQCQty = ClsPub.isDoule(grdMain.Rows[grdMain.CurrentRow.Index].Cells[HQty_QCCol].Value);
|
HYear = ClsPub.isInt(grdMain.Rows[grdMain.CurrentRow.Index].Cells[HYearCol].Value);
|
HPeriod = ClsPub.isInt(grdMain.Rows[grdMain.CurrentRow.Index].Cells[HPeriodCol].Value);
|
|
oCn.RunProc("update Kf_WIPBal set HBeginDiff=" + HQty + "-HBeginQty where HYear=" + HYear + " and HPeriod=" + HPeriod +
|
" and HICMOInterID=" + HICMOID + " and HMaterID=" + HMaterID + " and HProcNo=" + HProcNo + " and HProcID=" + HProcID);
|
|
grdMain.Rows[grdMain.CurrentRow.Index].Cells[HQty_CYCol].Value = ClsPub.isStrNull(HQty - HQCQty);
|
}
|
}
|
|
private void yr_Click(object sender, EventArgs e)
|
{
|
Kf_WIPBal_DR oDR = new Kf_WIPBal_DR();
|
int sYear = ClsPub.isDate(DBUtility.ClsPub.GetServerDate(-1)).Year;
|
oDR.cmbHYear.Items.Add(sYear);
|
oDR.cmbHYear.Items.Add(sYear - 1);
|
oDR.cmbHYear.Items.Add(sYear - 2);
|
oDR.cmbHYear.Items.Add(sYear - 3);
|
oDR.cmbHYear.Text = cmbHYear.Text;
|
oDR.cmbHPeriod.Text = cmbHPeriod.Text;
|
oDR.ShowDialog();
|
Display();
|
}
|
|
private void cmdfind_Click(object sender, EventArgs e)
|
{
|
Display();
|
}
|
}
|
}
|