예제 #1
0
    /// GridView 在產生事件時引發
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gv_Detail_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        switch (e.CommandName)
        {
            case "New":
                try
                {
                    if (this.gv_Detail.EditIndex != -1)
                    {
                        ShowErrorMessage("請將編輯的資料列做更新,再按[存檔]");
                    }
                    else
                    {
                        DataTable Dt = (DataTable)Session["IFM032_DTL_" + PageTimeStamp.Value];
                        DataRow dRow;

                        if (Dt == null || Dt.Rows.Count == 0)//沒有明細資料
                        {
                            IFMModel.BCO.MaintainSysRequest BCO = new IFMModel.BCO.MaintainSysRequest(ConnectionDB);
                            Dt = BCO.QuerySchema();

                            dRow = Dt.NewRow();
                            dRow["PHASE_NAME"] = "";
                            dRow["EMP_NAME"] = "";
                            dRow["START_DATE"] = "";
                            dRow["END_DATE"] = "";
                            dRow["PHASE_HOUR"] = 0;
                        }
                        else
                        {
                            dRow = Dt.NewRow();
                        }

                        Dt.Rows.Add(dRow);
                        Session["IFM032_DTL_" + PageTimeStamp.Value] = Dt;
                        this.setGV(Dt.Rows.Count - 1, Dt, true);
                    }

                    //bind 開發人員(=MIS窗口)
                    DataTable Dt2 = (DataTable)Session["IFM032_DTL_" + PageTimeStamp.Value];
                    if (Dt2 != null && Dt2.Rows.Count > 0)
                    {
                        IFMModel.BCO.MaintainSysRequest BCO = new IFMModel.BCO.MaintainSysRequest(ConnectionDB);
                        DataTable Dt3 = BCO.GetMis();

                        int j = Dt2.Rows.Count - 1;
                        DropDownList ddl_Emp = ((DropDownList)gv_Detail.Rows[j].Cells[1].Controls[1].FindControl("ddl_Emp"));
                        ddl_Emp.DataSource = Dt3;
                        ddl_Emp.DataTextField = "emp_name";
                        ddl_Emp.DataValueField = "emp_id";
                        ddl_Emp.DataBind();
                    }

                }
                catch (Exception ex)
                { this.ErrorMsgLabel.Text = ex.ToString(); }
                finally { }
                //finally { SetPageStatus(); }
                break;

            case "del":
                if (this.txt_PageStatus.Text == "EDIT" || this.txt_PageStatus.Text == "EDIT")
                {
                    DataTable Dt = (DataTable)Session["IFM032_DTL_" + PageTimeStamp.Value];
                    int j = Convert.ToInt32(e.CommandArgument);

                    string phasecode = ((Label)gv_Detail.Rows[j].Cells[5].Controls[1].FindControl("labphcode")).Text;


                    for (int i = 0; i < Dt.Rows.Count; i++)
                    {
                        if (Convert.ToString(Dt.Rows[i].RowState) != Convert.ToString("Deleted"))
                        {
                            if (phasecode == Dt.Rows[i]["PHASE_CODE"].ToString())
                            {
                                Dt.Rows[i].Delete();
                                break;
                            }
                        }
                    }

                    Session["IFM032_DTL_" + PageTimeStamp.Value] = Dt;

                    //this.setGV(0, Dt, false); 
                    this.setGV(-1, Dt, true);//設-1 讓gv_Detail回編輯

                    string nowmode = this.hid_PageStatus.Value;
                    if (nowmode == "EDIT")
                    {

                        #region 切換到檢視模式

                        this.hid_PageStatus.Value = "EDIT";
                        this.txt_PageStatus.Text = "EDIT";
                        #endregion

                    }
                }
                else
                {
                    ShowErrorMessage("請先將狀態切換為[編輯]模式!");
                }
                break;
        }
    }
예제 #2
0
    protected void Btn_Insert_Click(object sender, EventArgs e)
    {
        try
        {
            if (this.gv_Detail.EditIndex != -1)
            {
                ShowErrorMessage("請先將目前編輯的資料列[儲存] [取消]或[刪除],再按[新增]");
                this.TabContainer1.ActiveTabIndex = 1;
            }
            else
            {

                this.TabContainer1.ActiveTabIndex = 1;
                DataTable Dt = (DataTable)Session["IFM032_DTL_" + PageTimeStamp.Value];
                DataRow dRow;

                if (Dt == null || Dt.Rows.Count == 0)//沒有明細資料
                {
                    IFMModel.BCO.MaintainSysRequest BCO = new IFMModel.BCO.MaintainSysRequest(ConnectionDB);
                    Dt = BCO.QuerySchema();

                    dRow = Dt.NewRow();
                    dRow["PHASE_NAME"] = "";
                    dRow["EMP_NAME"] = "";
                    dRow["START_DATE"] = "";
                    dRow["END_DATE"] = "";
                    dRow["PHASE_HOUR"] = 0;
                }
                else
                {
                    dRow = Dt.NewRow();
                }

                Dt.Rows.Add(dRow);
                Session["IFM032_DTL_" + PageTimeStamp.Value] = Dt;
                this.setGV(Dt.Rows.Count - 1, Dt, true);
            }

            //bind 開發人員(=MIS窗口)
            DataTable Dt2 = (DataTable)Session["IFM032_DTL_" + PageTimeStamp.Value];
            if (Dt2 != null && Dt2.Rows.Count > 0)
            {
                IFMModel.BCO.MaintainSysRequest BCO = new IFMModel.BCO.MaintainSysRequest(ConnectionDB);
                DataTable Dt3 = BCO.GetMis();

                int j = Dt2.Rows.Count - 1;
                DropDownList ddl_Emp = ((DropDownList)gv_Detail.Rows[j].Cells[1].Controls[1].FindControl("ddl_Emp"));
                ddl_Emp.DataSource = Dt3;
                ddl_Emp.DataTextField = "emp_name";
                ddl_Emp.DataValueField = "emp_id";
                ddl_Emp.DataBind();
            }

        }
        catch (Exception ex)
        { this.ErrorMsgLabel.Text = ex.ToString(); }
        finally
        {
            SetPageStatus();//新增初始值
        }
    }