private void btnInsert_Click(object sender, EventArgs e)
        {
            try
            {
                if (!this.ValidateData())
                {
                    return;
                }

                DataRow dr       = this.result.Detail.NewRow();
                int     rowIndex = gvDetail.SelectedRowIndex;
                this.result.Detail.Rows.InsertAt(dr, rowIndex);

                sp_RPT001_GetWorkPlaceLightDt_Result data = GetDataFromControl();
                data.ID = 0;
                this.SetDataToRow(data, rowIndex);
                this.SetGridError();

                this.gvDetail.ScrollToRow(rowIndex);
            }
            catch (Exception ex)
            {
                rMessageBox.ShowException(this, ex);
            }
        }
 private void SetDataToRow(sp_RPT001_GetWorkPlaceLightDt_Result data, int rowIndex)
 {
     try
     {
         DataGridViewRow dr = gvDetail.Rows[rowIndex];
         if (dr != null)
         {
             dr.Cells[(int)eCol.ID].SetValue(data.ID);
             dr.Cells[(int)eCol.WPL_ID].SetValue(this.result.ID);
             dr.Cells[(int)eCol.LOC_NAME_LV3].SetValue(data.LOC_NAME_LV3);
             dr.Cells[(int)eCol.LOC_NAME_LV2].SetValue(data.LOC_NAME_LV2);
             dr.Cells[(int)eCol.LOC_NAME].SetValue(data.LOC_NAME);
             dr.Cells[(int)eCol.STDLIGHT_ID].SetValue(data.STDLIGHT_ID);
             dr.Cells[(int)eCol.STDLIGHT_NAME].SetValue(data.STDLIGHT_NAME);
             dr.Cells[(int)eCol.STDLIGHT_STANDARD].SetValue(data.STDLIGHT_STANDARD);
             dr.Cells[(int)eCol.RESULT_DAY].SetValue(data.RESULT_DAY);
             dr.Cells[(int)eCol.RESULT_NIGHT].SetValue(data.RESULT_NIGHT);
             dr.Cells[(int)eCol.CONDITION].SetValue(data.CONDITION);
         }
     }
     catch (Exception ex)
     {
         rMessageBox.ShowException(this, ex);
     }
 }
        private sp_RPT001_GetWorkPlaceLightDt_Result GetDataFromControl()
        {
            try
            {
                sp_RPT001_GetWorkPlaceLightDt_Result result = new sp_RPT001_GetWorkPlaceLightDt_Result()
                {
                    WPL_ID            = this.result.ID,
                    LOC_NAME          = txtLocationName.TextValue,
                    LOC_NAME_LV2      = txtLocationLV2.TextValue,
                    LOC_NAME_LV3      = txtLocationLV3.TextValue,
                    STDLIGHT_ID       = txtStdLight.IntValue,
                    STDLIGHT_NAME     = txtStdName.TextValue,
                    STDLIGHT_STANDARD = txtStdValue.NullableIntValue.GetValueOrDefault(),
                    RESULT_DAY        = txtResultDay.NullableIntValue,
                    RESULT_NIGHT      = txtResultNight.NullableIntValue,
                    CONDITION         = txtCondition.TextValue,
                };

                return(result);
            }
            catch (Exception ex)
            {
                rMessageBox.ShowException(this, ex);
                return(null);
            }
        }
        private sp_RPT001_GetWorkPlaceLightDt_Result GetDataFromRow(int rowIndex)
        {
            try
            {
                sp_RPT001_GetWorkPlaceLightDt_Result result = new sp_RPT001_GetWorkPlaceLightDt_Result()
                {
                    WPL_ID            = gvDetail.GetIntValue(rowIndex, (int)eCol.WPL_ID),
                    LOC_NAME          = gvDetail.GetStringValue(rowIndex, (int)eCol.LOC_NAME),
                    LOC_NAME_LV2      = gvDetail.GetStringValue(rowIndex, (int)eCol.LOC_NAME_LV2),
                    LOC_NAME_LV3      = gvDetail.GetStringValue(rowIndex, (int)eCol.LOC_NAME_LV3),
                    STDLIGHT_ID       = gvDetail.GetIntValueOrNull(rowIndex, (int)eCol.STDLIGHT_ID),
                    STDLIGHT_NAME     = gvDetail.GetStringValue(rowIndex, (int)eCol.STDLIGHT_NAME),
                    STDLIGHT_STANDARD = gvDetail.GetIntValue(rowIndex, (int)eCol.STDLIGHT_STANDARD),
                    RESULT_DAY        = gvDetail.GetIntValueOrNull(rowIndex, (int)eCol.RESULT_DAY),
                    RESULT_NIGHT      = gvDetail.GetIntValueOrNull(rowIndex, (int)eCol.RESULT_NIGHT),
                    CONDITION         = gvDetail.GetStringValue(rowIndex, (int)eCol.CONDITION),
                };

                return(result);
            }
            catch (Exception ex)
            {
                rMessageBox.ShowException(this, ex);
                return(null);
            }
        }
        private void ApplySummary()
        {
            try
            {
                TotalSummary total = new TotalSummary();

                if (this.wplResult.Detail.Rows.Count > 0)
                {
                    foreach (DataRow row in this.wplResult.Detail.Rows)
                    {
                        sp_RPT001_GetWorkPlaceLightDt_Result data = new sp_RPT001_GetWorkPlaceLightDt_Result()
                        {
                            RESULT_DAY        = row.Field <int?>("RESULT_DAY"),
                            RESULT_NIGHT      = row.Field <int?>("RESULT_NIGHT"),
                            STDLIGHT_STANDARD = row.Field <int>("STDLIGHT_STANDARD"),
                        };

                        if (data.RESULT_DAY.HasValue && data.RESULT_DAY >= data.STDLIGHT_STANDARD)
                        {
                            total.PassD++;
                        }
                        else if (data.RESULT_DAY.HasValue && data.RESULT_DAY < data.STDLIGHT_STANDARD)
                        {
                            total.NotPassD++;
                        }
                        if (data.RESULT_NIGHT.HasValue && data.RESULT_NIGHT >= data.STDLIGHT_STANDARD)
                        {
                            total.PassN++;
                        }
                        else if (data.RESULT_NIGHT.HasValue && data.RESULT_NIGHT < data.STDLIGHT_STANDARD)
                        {
                            total.NotPassN++;
                        }
                    }
                }

                lblPassD.Text   = total.PassD.ToString();
                lblPassN.Text   = total.PassN.ToString();
                lblNoPassD.Text = total.NotPassD.ToString();
                lblNoPassN.Text = total.NotPassN.ToString();

                lblTotalD.Text = (total.PassD + total.NotPassD).ToString();
                lblTotalN.Text = (total.PassN + total.NotPassN).ToString();

                lblTotalPass.Text    = (total.PassD + total.PassN).ToString();
                lblTotalNotPass.Text = (total.NotPassD + total.NotPassN).ToString();

                lblTotalAll.Text = (total.PassD + total.PassN + total.NotPassD + total.NotPassN).ToString();
            }
            catch (Exception ex)
            {
                rMessageBox.ShowException(this, ex);
            }
        }
        private void gvDetail_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                int rowIndex = gvDetail.SelectedRowIndex;
                sp_RPT001_GetWorkPlaceLightDt_Result data = this.GetDataFromRow(rowIndex);

                if (data != null)
                {
                    this.SetDataToControl(data);
                }
            }
            catch (Exception ex)
            {
                rMessageBox.ShowException(this, ex);
            }
        }
        private void btnEdit_Click(object sender, EventArgs e)
        {
            try
            {
                if (!this.ValidateData())
                {
                    return;
                }

                int rowIndex = gvDetail.SelectedRowIndex;

                sp_RPT001_GetWorkPlaceLightDt_Result data = GetDataFromControl();
                this.SetDataToRow(data, rowIndex);
                this.SetGridError();
            }
            catch (Exception ex)
            {
                rMessageBox.ShowException(this, ex);
            }
        }
        private void SetDataToControl(sp_RPT001_GetWorkPlaceLightDt_Result data)
        {
            try
            {
                txtLocationLV3.Text             = data.LOC_NAME_LV3;
                txtLocationLV2.Text             = data.LOC_NAME_LV2;
                txtLocationName.Text            = data.LOC_NAME;
                txtStdLight.IntValue            = data.STDLIGHT_ID;
                txtStdName.Text                 = data.STDLIGHT_NAME;
                txtStdValue.NullableIntValue    = data.STDLIGHT_STANDARD;
                txtResultDay.NullableIntValue   = data.RESULT_DAY;
                txtResultNight.NullableIntValue = data.RESULT_NIGHT;
                txtCondition.Text               = data.CONDITION;

                CtrlUtil.EnableControls(txtStdValue.NullableIntValue.HasValue, txtStdName);
            }
            catch (Exception ex)
            {
                rMessageBox.ShowException(this, ex);
            }
        }