using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Pub_Class; namespace PayM { public partial class Pay_OtherMoney_Dlg : Form { public Pay_OtherMoney_Dlg() { InitializeComponent(); } //定义 public const Int16 HTagCol = 0; public const Int16 HSnoCol = 1; public const Int16 HItemIDCol = 2; public const Int16 HItemNameCol = 3; public const Int16 HMoneyCol = 4; public const Int16 HRemarkCol = 5; public const string ModName = "99999"; public const string ModCaption = "其他补扣项目"; public const string ModRightName = "Kf_ProductInBill"; 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 ModRightNameHide = ModRightName + "_Hide"; public bool BillChange; // public DBUtility.ClsPub.Enum_BillStatus BillStatus; public long HInterID; public string HBillType; public double HMoney; public Int64 KeyID; public bool grdStatus = true; public bool BillRedblue = false;//红蓝单标记 DAL.ClsPay_OtherMoney BillNew = new DAL.ClsPay_OtherMoney(); public DAL.ClsPay_OtherMoney BillOld = new DAL.ClsPay_OtherMoney(); ClsGridViewSum oSumGrid = new ClsGridViewSum(); //------------------------------------------------------------------------- #region 固定代码 private void Total() { oSumGrid.Total(); } //清空界面 public void Sub_ClearBill() { //清空界面控件 for 控件 //foreach (Control ct in P1.Controls) //{ // switch (ct.GetType().Name) // { // case "ListBox": // ((ListBox)ct).Items.Clear(); // break; // case "CheckBox": // ((CheckBox)ct).Checked = false; // break; // case "RadioButton": // break; // case "ComboBox": // ((ComboBox)ct).SelectedIndex = 0; // break; // case "TextBox": // ((TextBox)ct).Text = ""; // break; // case "DateTimePicker": // ((DateTimePicker)ct).Value = DateTime.Today; // break; // default: // break; // } //} // initGrid(); } 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 grdMain_LeaveCell(object sender, EventArgs e) { oSumGrid.LeaveCell(); } private void grdMain_CellValueChanged(object sender, DataGridViewCellEventArgs e) { RowCount(e.RowIndex, 0); } //窗体加载 private void Pay_OtherMoney_Dlg_Load(object sender, EventArgs e) { //打印初始化 oSumGrid.NoCol = HSnoCol; oSumGrid.ogrdMain = grdMain; oSumGrid.oGridsum = grdSum; initGrid(); if (this.HBillType == "补贴") { this.Text = "补贴明细"; } else { this.Text = "扣款明细"; } } //退出按钮 private void tc_Click(object sender, EventArgs e) { this.Close(); } #endregion #region 读写类 //显示单据 public void Sub_ShowBill() { if (BillOld.ShowBill(HInterID, ref ClsPub.sExeReturnInfo) == false) { MessageBox.Show(ClsPub.sExeReturnInfo, "提示"); return; } // //加载表体 DAL.ClsGy_DeductItem_View oMater = new DAL.ClsGy_DeductItem_View(); DAL.ClsGy_SubsidyItem_View oMater1 = new DAL.ClsGy_SubsidyItem_View(); int i = 0; foreach (Model.ClsPay_OtherMoneySub oSub in BillOld.DetailColl) { if (i >= grdMain.RowCount - 1) grdMain.Rows.Add(); grdMain.Rows[i].Cells[HSnoCol].Value = i + 1; // grdMain.Rows[i].Cells[HItemIDCol].Value = oSub.HItemID.ToString(); if (this.HBillType == "扣款") { if (oMater.GetInfoByID(oSub.HItemID)) { grdMain.Rows[i].Cells[HItemNameCol].Value = oMater.omodel.HName; } else { grdMain.Rows[i].Cells[HItemNameCol].Value = ""; } } else { if (oMater1.GetInfoByID(oSub.HItemID)) { grdMain.Rows[i].Cells[HItemNameCol].Value = oMater1.omodel.HName; } else { grdMain.Rows[i].Cells[HItemNameCol].Value = ""; } } // grdMain.Rows[i].Cells[HMoneyCol].Value = oSub.HMoney.ToString(); grdMain.Rows[i].Cells[HRemarkCol].Value = oSub.HRemark.ToString(); i = i + 1; } } //单据完整性判断 未完成 private bool Sub_AllowSave() { //明细表是否为零行 bool b = false; for (int i = 0; i < grdMain.RowCount; i++) { if (!IsNullRow(i)) { b = true; break; } } if (b == false) { MessageBox.Show("明细行不存在!", "提示"); return false; } return true; } public bool Sub_SaveBill() { if (!Sub_AllowSave())//单据完整性判断 return false; this.label1.Focus(); this.HMoney = 0; //明细类赋值 BillNew.DetailColl = new List(); for (int i = 0; i <= grdMain.RowCount - 1; i++) { if (ClsPub.isLong(grdMain.Rows[i].Cells[HItemIDCol].Value) != 0) { Model.ClsPay_OtherMoneySub oSub = new Model.ClsPay_OtherMoneySub(); // oSub.HItemID = ClsPub.isLong(grdMain.Rows[i].Cells[HItemIDCol].Value); oSub.HMoney = ClsPub.isDoule(grdMain.Rows[i].Cells[HMoneyCol].Value); oSub.HRemark = ClsPub.isStrNull(grdMain.Rows[i].Cells[HRemarkCol].Value); oSub.HType = this.HBillType; // this.HMoney = this.HMoney + oSub.HMoney; // BillNew.DetailColl.Add(oSub); } } if (BillStatus == DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew) { if (BillNew.AddBill(ref ClsPub.sExeReturnInfo)) { this.HInterID = BillNew.omodel.HInterID; return true; } else { MessageBox.Show("保存失败!原因:" + ClsPub.sExeReturnInfo, "提示"); return false; } } else { if (BillNew.ModifyBill(this.HInterID, ref ClsPub.sExeReturnInfo)) { this.HInterID = BillNew.omodel.HInterID; return true; } else { MessageBox.Show("保存失败!原因:" + ClsPub.sExeReturnInfo, "提示"); return false; } } } #endregion #region 窗体处理方法 //初始化GRID private void initGrid() { grdMain.ColumnCount = 6; //总列数 DBUtility.Xt_BaseBillFun.initGridFst(grdMain, this.Name); //= grdMain.Columns[HSnoCol].HeaderText = "序号"; grdMain.Columns[HItemIDCol].HeaderText = "项目ID"; //标题列 显示名 grdMain.Columns[HItemNameCol].HeaderText = "补扣项目"; grdMain.Columns[HMoneyCol].HeaderText = "金额"; grdMain.Columns[HRemarkCol].HeaderText = "备注"; //============================================================================= //格式化 ////隐藏列 grdMain.Columns[HTagCol].Visible = false; grdMain.Columns[HItemIDCol].Visible = false; //设置可编辑列 string sAllowCol = HMoneyCol.ToString() + "," + HRemarkCol.ToString(); //设置合计列 string sTotalCol = HMoneyCol.ToString(); //格式化网格 DBUtility.Xt_BaseBillFun.initGridLast(sAllowCol, sTotalCol, oSumGrid); } private void RowCount(int sRow, int sTag) { } //增行按钮 未完成 private void AddRow_Click(object sender, EventArgs e) { oSumGrid.Sub_AddRow(); } //删行按纽 未完成 private void DelRow_Click(object sender, EventArgs e) { } //是否是空行 private bool IsNullRow(int Row) { if (ClsPub.isLong(grdMain.Rows[Row].Cells[HItemIDCol].Value) == 0) { return true; } return false; } #endregion private void qr_Click(object sender, EventArgs e) { if (!Sub_SaveBill()) { return; } this.Close(); } private void timer1_Tick(object sender, EventArgs e) { timer1.Enabled = false; if (BillOld.ShowBill(this.HInterID, ref ClsPub.sExeReturnInfo) == false) { this.BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew; Sub_AddBill(); } else { this.BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_Modify; Sub_ShowBill(); } } private void Sub_AddBill() { DataSet Ds; SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); initGrid(); if (this.HBillType == "扣款") { Ds = oCn.RunProcReturn("select * from Gy_DeductItem ", "Gy_DeductItem"); } else { Ds = oCn.RunProcReturn("select * from Gy_SubsidyItem ", "Gy_SubsidyItem"); } if (Ds.Tables[0].Rows.Count == 0 || Ds == null) { return; } for (int i = 0; i <= Ds.Tables[0].Rows.Count - 1; i++) { grdMain.Rows[i].Cells[HItemIDCol].Value = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[i]["HItemID"]); grdMain.Rows[i].Cells[HItemNameCol].Value = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[i]["HName"]); } } //帮助函数 private void Sub_GridKey(int sKeyCode, int sRow, int sCol, DataGridViewTextBoxEditingControl oEdit) { if (!grdStatus) { return; } oSumGrid.EditStatus = true; switch (sKeyCode) { case 118: //F7 { switch (sCol) { default: break; } break; } case 117: //F6 { switch (sCol) { default: break; } break; } default: break; } } private void grdMain_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e) { int i = grdMain.CurrentCell.ColumnIndex; if (DBUtility.Xt_BaseBillFun.AllowEdit(grdStatus, oSumGrid, i)) { e.Cancel = true; } } private void grdMain_CellEndEdit(object sender, DataGridViewCellEventArgs e) { DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid); RowCount(e.RowIndex, 0); //计算 金额 单价 // if (this.EditingControl != null) //释放事件 { EditingControl.KeyDown -= new KeyEventHandler(this.EditingControl_KeyDown); this.EditingControl = null; } } private void grdMain_CellLeave(object sender, DataGridViewCellEventArgs e) { if (!grdStatus) { return; } DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid); // } private void grdMain_ColumnWidthChanged(object sender, DataGridViewColumnEventArgs e) { DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid); } private void grdMain_RowHeadersWidthChanged(object sender, EventArgs e) { DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid); } private void grdMain_Scroll(object sender, ScrollEventArgs e) { DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid); oSumGrid.DisplayCurRow(); } DataGridViewTextBoxEditingControl EditingControl; private void grdMain_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { if (grdMain.CurrentCell != null) { if (e.Control is DataGridViewTextBoxEditingControl) { this.EditingControl = (DataGridViewTextBoxEditingControl)e.Control; //增加委托处理 this.EditingControl.KeyDown += new KeyEventHandler(this.EditingControl_KeyDown); } } } private void EditingControl_KeyDown(object sender, KeyEventArgs e) { //业务处理 Sub_GridKey(e.KeyValue, grdMain.CurrentRow.Index, grdMain.CurrentCell.ColumnIndex, EditingControl); } } }