using System; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Collections; using DBUtility; namespace APSM { public partial class Gy_WorkTimes : Form { private DateTime BDate; private DateTime EDate; private DateTime XQDate; public DBUtility.frm_B_BillQueryCondition_New frmCondition; public const string ViewName = "h_v_Gy_WorkTimesList"; //public string CheckProcName = "h_p_Gy_WorkTimes"; //20141020 public string ModName = "工厂日历"; public const string BillName = "Gy_WorkTimes"; public const string ModRightNameEdit = BillName + "_Edit"; public const string ModRightNameDelete = BillName + "_Delete"; public DBUtility.ClsPub.Enum_InputMode InputMode; //录入状态标志(0-非录入状态 1-增加 2-修改) public long HItemID;//项目ID public long HSourceID;//资源ID DAL.ClsGy_PlanShifts_Ctl oPs = new DAL.ClsGy_PlanShifts_Ctl(); DAL.ClsGy_PlanShifts_View oPsHlp = new DAL.ClsGy_PlanShifts_View(); DAL.ClsGy_Source_Ctl oSou = new DAL.ClsGy_Source_Ctl(); DAL.ClsGy_Source_View oSouHlp = new DAL.ClsGy_Source_View(); TreeNode CurNode = new TreeNode(); public Gy_WorkTimes() { InitializeComponent(); } #region 固定代码 //保存GRID列宽 //窗体加载 private void Gy_WorkTimes_Load(object sender, EventArgs e) { cmbYear.Items.Clear(); cmbYear.Items.Add(DateTime.Today.Year - 3); cmbYear.Items.Add(DateTime.Today.Year - 2); cmbYear.Items.Add(DateTime.Today.Year - 1); cmbYear.Items.Add(DateTime.Today.Year); cmbYear.Items.Add(DateTime.Today.Year + 1); cmbYear.Items.Add(DateTime.Today.Year + 2); cmbYear.Items.Add(DateTime.Today.Year + 3); cmbYear.Items.Add(DateTime.Today.Year + 4); cmbYear.Items.Add(DateTime.Today.Year + 5); cmbYear.Items.Add(DateTime.Today.Year + 6); cmbYear.Items.Add(DateTime.Today.Year + 7); cmbYear.SelectedIndex = 3; frmCondition = new DBUtility.frm_B_BillQueryCondition_New(); LoadTree(); initGrid(); RefreshTool(); } //加载子结点 private void LoadAllNodes(TreeNode sNode) { SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); if (sNode != null) { try { long sName = Convert.ToInt64(sNode.Name.Substring(1, sNode.Name.Length - 1)); sNode.Nodes.Clear(); string sSQL = ""; if (HSourceID == 0) { sSQL = "select hitemid,hnumber,hname from Gy_Source where HParentID='" + sName + "' order by Hnumber"; } else { sSQL = "select hitemid,hnumber,hname from Gy_Source where HItemID=" + HSourceID + " order by Hnumber"; } DataSet Ds = oCn.RunProcReturn(sSQL, "Gy_Source", ref ClsPub.sExeReturnInfo); for (int i = 0; i < Ds.Tables[0].Rows.Count; i++) { TreeNode oNode = sNode.Nodes.Add("T" + Ds.Tables[0].Rows[i]["HItemID"].ToString(), Ds.Tables[0].Rows[i]["HNumber"].ToString() + "-" + Ds.Tables[0].Rows[i]["HName"].ToString(), 0, 1); } sNode.Expand(); } catch (Exception e) { MessageBox.Show("加载子项目失败!" + e.Message, "提示"); } } } //加载树形 private void LoadTree() { try { tv.Nodes.Clear(); tv.ImageList = imageList1; TreeNode sNode = tv.Nodes.Add("T0", "生产资源", 0, 1); LoadAllNodes(sNode); } catch (Exception e) { MessageBox.Show("加载树型失败!" + e.Message, "提示"); } } //树型 单击 private void tv_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { CurNode = e.Node; if (CurNode != null) { if (CurNode.Nodes.Count == 0 && HSourceID == 0) LoadAllNodes(CurNode); Display(); } } //初始化GRID private void initGrid() { //Gy_ICMOSortBillFun.initGridVS_Times(grd, ref BDate, ref EDate, this.Name, ref XQDate, cmbYear); } //显示列表 private void Display() { DateTime Date; ////禁用 红色显示 20141020 //Sub_ShowStopFlag(); //得到工作中心默认上班时间 long sID = Convert.ToInt64(CurNode.Name.Substring(1, CurNode.Name.Length - 1)); Single sWorkTimes = 8; //sWorkTimes = oSouHlp.GetInfoByName(sName); //根据资源得到工作中心的工时 // // for (int r = 0; r <= 22; r = r + 2) { BDate = DBUtility.ClsPub.isDate(cmbYear.Text.ToString() + "-" + Convert.ToString(r / 2 + 1) + "-01"); EDate = BDate.AddMonths(1); EDate = EDate.AddDays(-1); TimeSpan t = EDate - BDate;//获取2个时间的相隔天数 // for (int c = 1; c <= DBUtility.ClsPub.isInt(t.Days + 1); c++) { if (DBUtility.ClsPub.isStrNull(CurNode.Name) != null && DBUtility.ClsPub.isStrNull(CurNode.Text) != "") { Date = DBUtility.ClsPub.isDate(cmbYear.Text.ToString() + "-" + Convert.ToString(r / 2 + 1) + "-" + grd.Rows[r].Cells[c].Value.ToString()); if (oPsHlp.GetInfoByDate_Line(sID, Date.ToShortDateString())) { grd.Rows[r + 1].Cells[c].Value = DBUtility.ClsPub.isDoule(oPsHlp.omodel.HOverTimes, 0); } else { if (Date.DayOfWeek == DayOfWeek.Sunday) { grd.Rows[r + 1].Cells[c].Value = "0"; } else { if (oSouHlp.GetInfoByID(sID)) { //grd.set_TextMatrix(r + 1, c, DBUtility.ClsPub.isDoule(oPsHlp.omodel.HOverTimes, 1)); grd.Rows[r + 1].Cells[c].Value = DBUtility.ClsPub.isDoule(oSouHlp.omodel.HWorkTimes, 0); } else { //grd.set_TextMatrix(r + 1, c, sWorkTimes.ToString()); grd.Rows[r + 1].Cells[c].Value = sWorkTimes.ToString(); } } } } } } } //退出模块 private void tc_Click(object sender, EventArgs e) { this.Close(); } //刷新 private void xs_Click(object sender, EventArgs e) { Display(); } //刷新TOOLBAR private void RefreshTool() { if (InputMode == DBUtility.ClsPub.Enum_InputMode.InputMode_View) { stTab.SelectedIndex = 0; stTab.TabPages.Remove(this.tabPage1); stTab.TabPages.Add(this.tabPage1); grd.Enabled = true; tc.Enabled = true; //tz.Enabled = true; xs.Enabled = true; } else { stTab.SelectedIndex = 1; stTab.TabPages.Remove(this.tabPage1); stTab.TabPages[0].Hide(); grd.Enabled = false; //tc.Enabled = true; //tz.Enabled = false; xs.Enabled = false; } } //取消按钮 private void cmdCancel_Click(object sender, EventArgs e) { InputMode = DBUtility.ClsPub.Enum_InputMode.InputMode_View; RefreshTool(); } //得到对应列 private Int32 Fun_GetCol(string sCol,DataGridView grd) { return 1; //return Gy_ICMOSortBillFun.Fun_GetCol_VS(sCol, grd); } //private void bclk_Click(object sender, EventArgs e) //{ // //保存列宽 // Gy_ICMOSortBillFun.SaveGrid(grd, this.Name, DBUtility.ClsPub.AppPath); //} private void mrlk_Click(object sender, EventArgs e) { //for (int i = 1; i <= 12; i++) //{ // grdMain(i).AutoSize(0, grdMain(i).Cols - 1, false, 1); // //参数解释 开始列 ,结束列,是否以最大列宽为准,最小列宽 // Gy_ICMOSortBillFun.SaveGrid(grdMain(i), this.Name, DBUtility.ClsPub.AppPath); //} } ////选中行是否正常 //private bool AllowRow() //{ // if (grdMain.Row >= grdMain.FixedRows && grdMain.Row <= grdMain.Rows - 1) // return true; // else // return false; //} //时间控件 private void timer1_Tick(object sender, EventArgs e) { timer1.Enabled = false; LoadTree(); initGrid(); } #endregion #region 类的读写 //读取类 到 控件 private void ShowData(long sItemID) { // } //写入类 从控件 private bool WriteClass(double sWorktimes, Int64 sSourceID, DateTime sDate) { oPs.oModel.HOverTimes = sWorktimes; oPs.oModel.HRemark = ""; oPs.oModel.HShiftsID = 0; oPs.oModel.HSourceID = sSourceID; oPs.oModel.HDate = sDate; return true; } #endregion #region 界面控件处理 #endregion ////检测按钮 20141020 //private void jc_Click(object sender, EventArgs e) //{ // BLL.ClsPub_BLL.Sub_CheckUseStatus(grdMain, HItemIDCol, CheckProcName); // Display(); //} ////禁用项目 红色字体 20141020 //public void Sub_ShowStopFlag() //{ // BLL.ClsPub_BLL.Sub_ShowStopFlag(grdMain, Fun_GetCol("禁用标记")); //} private void cmbYear_TextChanged(object sender, EventArgs e) { initGrid(); } private void cmbYear_SelectedIndexChanged(object sender, EventArgs e) { initGrid(); } //查询 private void cx_Click(object sender, EventArgs e) { frmCondition = new DBUtility.frm_B_BillQueryCondition_New(); DBUtility.Gy_BaseFun.SetCondition(frmCondition, ViewName, this.Name); frmCondition.ShowDialog(); if (frmCondition.Tag.ToString() == "OK") { Display(); } } //修改(批量修改) private void xg_Click(object sender, EventArgs e) { Gy_WorkTimesDlg oDlg = new Gy_WorkTimesDlg(); oDlg.ShowDialog(); //Display(); } //CellBeginEdit事件:在触发该事件时单元格还没有获得焦点,我们可以通过设置事件参数e来决定是否执行对单元格的编辑,如下 private void grd_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e) { // //执行编辑,这个一般不用写 // e.Cancel = true; // //不执行编辑,这个一般是通过条件判断是否执行编辑,如果条件不成立,即不允许对单元格进行编辑 // e.Cancel = false; } //CellParsing事件:在该事件中我们可以对输入的文本进行格式化,如将输入的英文字母全部改成大写等等,如下 private void grd_CellParsing(object sender, DataGridViewCellParsingEventArgs e) { /* * 这里必须是通过e.Value来获得重新输入的值 * 如果是通过this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()这种方法获得 * 那么获得值将是原来的值,并不是用户刚刚输入的值 * 这个也正可以对用户输入的数据进行验证,如果不符合则将原来的值再赋给该单元格,不进行修改 * 切记!!!!! * 在这里必须将e.ParsingApplied属性设置为true,否则刚刚用户输入的值不会更新 * 还是会将原来的值赋给该单元格 * */ e.Value = e.Value.ToString().ToUpper(); e.ParsingApplied = true; //MessageBox.Show(this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()); } private void grd_CellEndEdit(object sender, DataGridViewCellEventArgs e) { DateTime Date = DBUtility.ClsPub.isDate(cmbYear.Text.ToString() + "-" + DBUtility.ClsPub.isInt(e.RowIndex / 2 + 1).ToString() + "-" + grd.Rows[e.RowIndex - 1].Cells[e.ColumnIndex].Value.ToString()); if (DBUtility.ClsPub.isStrNull(CurNode.Name) != null && DBUtility.ClsPub.isStrNull(CurNode.Text) != "") { Int64 sName = Convert.ToInt64(CurNode.Name.Substring(1, CurNode.Name.Length - 1)); double sWorktimes = DBUtility.ClsPub.isDoule(grd.Rows[e.RowIndex].Cells[e.ColumnIndex].Value); // WriteClass(sWorktimes, sName, Date); oPs.AddNew(); Display(); } } //private void grdMain_BeforeEdit(object sender, AxVSFlex7._IVSFlexGridEvents_BeforeEditEvent e) //{ // if (DBUtility.ClsPub.GridToColor(grdMain.get_Cell(VSFlex7.CellPropertySettings.flexcpBackColor, grdMain.Row, grdMain.Col, grdMain.Row, grdMain.Col)) == DBUtility.ClsPub.Enum_Color.hx_Write) // { // // // } // else // { // e.cancel = true; // } //} //private void tz_Click(object sender, EventArgs e) //{ // Gy_WorkTimesDlg oDlg = new Gy_WorkTimesDlg(); // oDlg.ShowDialog(); // Display(); //} //private void grdMain_AfterEdit(object sender, AxVSFlex7._IVSFlexGridEvents_AfterEditEvent e) //{ // DateTime Date = DBUtility.ClsPub.isDate(cmbYear.Text.ToString() + "-" + DBUtility.ClsPub.isInt(grdMain.Row / 2 + 1).ToString() + "-" + grdMain.get_TextMatrix(grdMain.Row - 1, grdMain.Col).ToString()); // if (DBUtility.ClsPub.isStrNull(CurNode.Name) != null && DBUtility.ClsPub.isStrNull(CurNode.Text) != "") // { // Int64 sName = Convert.ToInt64(CurNode.Name.Substring(1, CurNode.Name.Length - 1)); // double sWorktimes = DBUtility.ClsPub.isDoule(grdMain.get_TextMatrix(grdMain.Row, grdMain.Col)); // // // WriteClass(sWorktimes, sName, Date); // oPs.AddNew(); // Display(); // } //} //private void cmdHSource_Click(object sender, EventArgs e) //{ // DAL.ClsGy_Source_View oSource = new DAL.ClsGy_Source_View(); // oSource.WherePart = txtHSource.Text.Trim(); // if (oSource.RefreshView()) // { // txtHSource.Text = oSource.oModel.HName; // txtHSource.Tag = oSource.oModel.HItemID; // HSourceID = oSource.oModel.HItemID; // } // else // { // txtHSource.Text = ""; // txtHSource.Tag = "0"; // HSourceID = 0; // } // LoadTree(); //} //private void ww_Click(object sender, EventArgs e) //{ // Gy_WorkTimesWWDlg oDlg = new Gy_WorkTimesWWDlg(); // oDlg.HSourceID = DBUtility.ClsPub.isLong(txtHSource.Tag); // oDlg.ShowDialog(); // Display(); //} } }