protected override ResultStatus Save(PokeBall pokeBall)
        {
            //PB不管資料有無異動都會存檔

            #region ue_save_before
            if (gvMain.RowCount == 0)
            {
                MessageDisplay.Error("下方視窗無資料無法進行存檔,請先執行「讀取/預覽」!");
                return(ResultStatus.Fail);
            }

            //0. 先結束編輯
            gvGBF.CloseEditor();
            gvMain.CloseEditor();

            string showMsg = "";
            //1. 寫LOG到ci.PLLOG
            try {
                showMsg = "異動紀錄(PLLOG)更新資料庫錯誤! ";
                DataTable dtPLLOG     = dao30203.d_30203_pllog();
                DataTable dtPL1Insert = dao30203.d_30203_PL1Insert(txtDate.Text.Replace("/", "").AsString());

                int    i;
                int    PL1NewRowCount = 0;
                string ls_prod_type, ls_prod_subtype, ls_kind_id;
                for (i = 0; i < gvMain.RowCount; i++)
                {
                    if (gvMain.GetRowCellValue(i, "Is_NewRow").AsString() == "1")
                    {
                        ls_kind_id = gvMain.GetRowCellValue(i, "PL1_KIND_ID").AsString();
                        DataTable dtProdType = dao30203.ProdType(ls_kind_id);
                        if (dtProdType.Rows.Count == 0)
                        {
                            MessageDisplay.Error("商品 " + ls_kind_id + " 無商品基本資料,無法新增!");
                            return(ResultStatus.Fail);
                        }
                        ls_prod_type    = dtProdType.Rows[0]["PROD_TYPE"].AsString();
                        ls_prod_subtype = dtProdType.Rows[0]["PROD_SUBTYPE"].AsString();

                        gvMain.SetRowCellValue(i, "PL1_YMD", txtDate.Text.Replace("/", "").AsString());
                        gvMain.SetRowCellValue(i, "PL1_PROD_TYPE", ls_prod_type);
                        gvMain.SetRowCellValue(i, "PL1_PROD_SUBTYPE", ls_prod_subtype);
                        gvMain.SetRowCellValue(i, "PL1_999", gvMain.GetRowCellValue(i, "PL1_LEGAL").AsDecimal() * 3);
                        gvMain.SetRowCellValue(i, "PL1_CUR_NATURE", 0);
                        gvMain.SetRowCellValue(i, "PL1_CUR_LEGAL", 0);
                        gvMain.SetRowCellValue(i, "PL1_CUR_999", gvMain.GetRowCellValue(i, "PL1_CUR_LEGAL").AsDecimal() * 3);
                        gvMain.SetRowCellValue(i, "PL1_PREV_AVG_QNTY", 0);
                        gvMain.SetRowCellValue(i, "PL1_PREV_AVG_OI", 0);
                        gvMain.SetRowCellValue(i, "PL1_AVG_QNTY", 0);
                        gvMain.SetRowCellValue(i, "PL1_AVG_OI", 0);
                        gvMain.SetRowCellValue(i, "PL1_CHANGE_RANGE", 0);
                        gvMain.SetRowCellValue(i, "PL1_CP_999", gvMain.GetRowCellValue(i, "PL1_CP_LEGAL").AsDecimal() * 3);
                        gvMain.SetRowCellValue(i, "PL1_999_ADJ", "+");
                        gvMain.SetRowCellValue(i, "PL1_UPD_TIME", DateTime.Now);
                        gvMain.SetRowCellValue(i, "PL1_UPD_USER_ID", GlobalInfo.USER_ID);
                        if (gvMain.GetRowCellValue(i, "PL1_NATURE_ADJ").AsString().Equals(""))
                        {
                            gvMain.SetRowCellValue(i, "PL1_NATURE_ADJ", " ");
                        }
                        else
                        {
                            gvMain.SetRowCellValue(i, "PL1_NATURE_ADJ", gvMain.GetRowCellValue(i, "PL1_NATURE_ADJ").AsString());
                        }
                        if (gvMain.GetRowCellValue(i, "PL1_LEGAL_ADJ").AsString().Equals(""))
                        {
                            gvMain.SetRowCellValue(i, "PL1_LEGAL_ADJ", " ");
                        }
                        else
                        {
                            gvMain.SetRowCellValue(i, "PL1_LEGAL_ADJ", gvMain.GetRowCellValue(i, "PL1_LEGAL_ADJ").AsString());
                        }

                        //下列add by Tom
                        PL1NewRowCount++;
                        dtPL1Insert.Rows.Add();
                        dtPL1Insert.Rows[dtPL1Insert.Rows.Count - 1]["PL1_KIND_ID"]       = ls_kind_id;
                        dtPL1Insert.Rows[dtPL1Insert.Rows.Count - 1]["PL1_YMD"]           = txtDate.Text.Replace("/", "").AsString();
                        dtPL1Insert.Rows[dtPL1Insert.Rows.Count - 1]["PL1_PROD_TYPE"]     = ls_prod_type;
                        dtPL1Insert.Rows[dtPL1Insert.Rows.Count - 1]["PL1_PROD_SUBTYPE"]  = ls_prod_subtype;
                        dtPL1Insert.Rows[dtPL1Insert.Rows.Count - 1]["PL1_999"]           = gvMain.GetRowCellValue(i, "PL1_999").AsDecimal();
                        dtPL1Insert.Rows[dtPL1Insert.Rows.Count - 1]["PL1_CUR_NATURE"]    = 0;
                        dtPL1Insert.Rows[dtPL1Insert.Rows.Count - 1]["PL1_CUR_LEGAL"]     = 0;
                        dtPL1Insert.Rows[dtPL1Insert.Rows.Count - 1]["PL1_CUR_999"]       = gvMain.GetRowCellValue(i, "PL1_CUR_999").AsDecimal();
                        dtPL1Insert.Rows[dtPL1Insert.Rows.Count - 1]["PL1_PREV_AVG_QNTY"] = 0;
                        dtPL1Insert.Rows[dtPL1Insert.Rows.Count - 1]["PL1_PREV_AVG_OI"]   = 0;
                        dtPL1Insert.Rows[dtPL1Insert.Rows.Count - 1]["PL1_AVG_QNTY"]      = 0;
                        dtPL1Insert.Rows[dtPL1Insert.Rows.Count - 1]["PL1_AVG_OI"]        = 0;
                        dtPL1Insert.Rows[dtPL1Insert.Rows.Count - 1]["PL1_CHANGE_RANGE"]  = 0;
                        dtPL1Insert.Rows[dtPL1Insert.Rows.Count - 1]["PL1_CP_999"]        = gvMain.GetRowCellValue(i, "PL1_CP_999").AsDecimal();
                        dtPL1Insert.Rows[dtPL1Insert.Rows.Count - 1]["PL1_UPD_TIME"]      = gvMain.GetRowCellValue(i, "PL1_UPD_TIME");
                        dtPL1Insert.Rows[dtPL1Insert.Rows.Count - 1]["PL1_UPD_USER_ID"]   = gvMain.GetRowCellValue(i, "PL1_UPD_USER_ID");
                        dtPL1Insert.Rows[dtPL1Insert.Rows.Count - 1]["PL1_999_ADJ"]       = "+";
                        dtPL1Insert.Rows[dtPL1Insert.Rows.Count - 1]["PL1_NATURE_ADJ"]    = gvMain.GetRowCellValue(i, "PL1_NATURE_ADJ");
                        dtPL1Insert.Rows[dtPL1Insert.Rows.Count - 1]["PL1_LEGAL_ADJ"]     = gvMain.GetRowCellValue(i, "PL1_LEGAL_ADJ");
                        dtPL1Insert.Rows[dtPL1Insert.Rows.Count - 1]["PL1_NATURE"]        = gvMain.GetRowCellValue(i, "PL1_NATURE").AsDecimal();
                        dtPL1Insert.Rows[dtPL1Insert.Rows.Count - 1]["PL1_CP_NATURE"]     = gvMain.GetRowCellValue(i, "PL1_CP_NATURE").AsDecimal();
                        dtPL1Insert.Rows[dtPL1Insert.Rows.Count - 1]["PL1_CP_LEGAL"]      = gvMain.GetRowCellValue(i, "PL1_CP_LEGAL").AsDecimal();
                        dtPL1Insert.Rows[dtPL1Insert.Rows.Count - 1]["PL1_LEGAL"]         = gvMain.GetRowCellValue(i, "PL1_LEGAL").AsDecimal();
                    }
                    if (gvMain.GetRowCellValue(i, "PL1_NATURE").AsDecimal() == gvMain.GetRowCellValue(i, "PL1_NATURE_ORG").AsDecimal() &&
                        gvMain.GetRowCellValue(i, "PL1_LEGAL").AsDecimal() == gvMain.GetRowCellValue(i, "PL1_LEGAL_ORG").AsDecimal())
                    {
                        continue;
                    }
                    if (gvMain.GetRowCellValue(i, "PL1_NATURE").AsDecimal() != gvMain.GetRowCellValue(i, "PL1_NATURE_ORG").AsDecimal())
                    {
                        dtPLLOG.Rows.Add();
                        //dtPLLOG.Rows[dtPLLOG.Rows.Count - 1]["PLLOG_YMD"] = gvMain.GetRowCellValue(i, "PL1_YMD").AsString();
                        dtPLLOG.Rows[dtPLLOG.Rows.Count - 1]["PLLOG_YMD"]       = txtDate.Text.Replace("/", "").AsString();
                        dtPLLOG.Rows[dtPLLOG.Rows.Count - 1]["PLLOG_KIND_ID"]   = gvMain.GetRowCellValue(i, "PL1_KIND_ID").AsString();
                        dtPLLOG.Rows[dtPLLOG.Rows.Count - 1]["PLLOG_DATA_TYPE"] = "N";
                        dtPLLOG.Rows[dtPLLOG.Rows.Count - 1]["PLLOG_ORG_VALUE"] = gvMain.GetRowCellValue(i, "PL1_NATURE_ORG").AsDecimal().AsString();
                        dtPLLOG.Rows[dtPLLOG.Rows.Count - 1]["PLLOG_UPD_VALUE"] = gvMain.GetRowCellValue(i, "PL1_NATURE").AsDecimal().AsString();
                        dtPLLOG.Rows[dtPLLOG.Rows.Count - 1]["PLLOG_W_TIME"]    = DateTime.Now;
                        dtPLLOG.Rows[dtPLLOG.Rows.Count - 1]["PLLOG_W_USER_ID"] = GlobalInfo.USER_ID;
                    }
                    if (gvMain.GetRowCellValue(i, "PL1_LEGAL").AsDecimal() != gvMain.GetRowCellValue(i, "PL1_LEGAL_ORG").AsDecimal())
                    {
                        dtPLLOG.Rows.Add();
                        //dtPLLOG.Rows[dtPLLOG.Rows.Count - 1]["PLLOG_YMD"] = gvMain.GetRowCellValue(i, "PL1_YMD").AsString();
                        dtPLLOG.Rows[dtPLLOG.Rows.Count - 1]["PLLOG_YMD"]       = txtDate.Text.Replace("/", "").AsString();
                        dtPLLOG.Rows[dtPLLOG.Rows.Count - 1]["PLLOG_KIND_ID"]   = gvMain.GetRowCellValue(i, "PL1_KIND_ID").AsString();
                        dtPLLOG.Rows[dtPLLOG.Rows.Count - 1]["PLLOG_DATA_TYPE"] = "E";
                        dtPLLOG.Rows[dtPLLOG.Rows.Count - 1]["PLLOG_ORG_VALUE"] = gvMain.GetRowCellValue(i, "PL1_LEGAL_ORG").AsDecimal().AsString();
                        dtPLLOG.Rows[dtPLLOG.Rows.Count - 1]["PLLOG_UPD_VALUE"] = gvMain.GetRowCellValue(i, "PL1_LEGAL").AsDecimal().AsString();
                        dtPLLOG.Rows[dtPLLOG.Rows.Count - 1]["PLLOG_W_TIME"]    = DateTime.Now;
                        dtPLLOG.Rows[dtPLLOG.Rows.Count - 1]["PLLOG_W_USER_ID"] = GlobalInfo.USER_ID;

                        gvMain.SetRowCellValue(i, "PL1_999", gvMain.GetRowCellValue(i, "PL1_LEGAL").AsDecimal() * 3);
                        dtPL1Insert.Rows[dtPL1Insert.Rows.Count - 1]["PL1_999"] = gvMain.GetRowCellValue(i, "PL1_999").AsDecimal();
                    }
                }
                // 寫入DB
                ResultData myResultData = dao30203.updatePLLOG(dtPLLOG);
                #endregion

                string ls_ymd, ls_eff_ymd, ls_eff_ymd_lower;
                bool   delResult = false;
                ls_ymd           = txtDate.Text.Replace("/", "");
                ls_eff_ymd       = txtEffDate.Text.Replace("/", "");
                ls_eff_ymd_lower = txtEffDateLower.Text.Replace("/", "");
                //2. 刪除資料 PL2,PL2B
                showMsg   = "PL2刪除失敗";
                delResult = dao30203.DeletePL2ByDate(ls_ymd);
                if (!delResult)
                {
                    MessageDisplay.Error(showMsg);
                    return(ResultStatus.Fail);
                }
                showMsg   = "PL2B刪除失敗";
                delResult = dao30203.DeletePL2BByDate(ls_ymd);
                if (!delResult)
                {
                    MessageDisplay.Error(showMsg);
                    return(ResultStatus.Fail);
                }

                //3. 新增 PL2
                showMsg = "確認資料(PL2)更新資料庫錯誤! ";
                DataTable dtInsertPL2 = dao30203.d_30203_pl2(ls_ymd);
                for (i = 0; i < gvMain.RowCount; i++)
                {
                    dtInsertPL2.Rows.Add();
                    if (gvMain.GetRowCellValue(i, "PL1_NATURE_ADJ").AsString() == "-")
                    {
                        dtInsertPL2.Rows[dtInsertPL2.Rows.Count - 1]["PL2_EFFECTIVE_YMD"] = ls_eff_ymd_lower;
                    }
                    else
                    {
                        dtInsertPL2.Rows[dtInsertPL2.Rows.Count - 1]["PL2_EFFECTIVE_YMD"] = ls_eff_ymd;
                    }
                    //dtInsertPL2.Rows[dtInsertPL2.Rows.Count - 1]["PL2_YMD"] = gvMain.GetRowCellValue(i, "PL1_YMD").AsString();
                    dtInsertPL2.Rows[dtInsertPL2.Rows.Count - 1]["PL2_YMD"]         = txtDate.Text.Replace("/", "").AsString();
                    dtInsertPL2.Rows[dtInsertPL2.Rows.Count - 1]["PL2_KIND_ID"]     = gvMain.GetRowCellValue(i, "PL1_KIND_ID").ToString();
                    dtInsertPL2.Rows[dtInsertPL2.Rows.Count - 1]["PL2_NATURE"]      = gvMain.GetRowCellValue(i, "PL1_NATURE").AsInt();
                    dtInsertPL2.Rows[dtInsertPL2.Rows.Count - 1]["PL2_LEGAL"]       = gvMain.GetRowCellValue(i, "PL1_LEGAL").AsInt();
                    dtInsertPL2.Rows[dtInsertPL2.Rows.Count - 1]["PL2_999"]         = gvMain.GetRowCellValue(i, "PL1_999").AsInt();
                    dtInsertPL2.Rows[dtInsertPL2.Rows.Count - 1]["PL2_NATURE_ADJ"]  = gvMain.GetRowCellValue(i, "PL1_NATURE_ADJ").ToString();
                    dtInsertPL2.Rows[dtInsertPL2.Rows.Count - 1]["PL2_LEGAL_ADJ"]   = gvMain.GetRowCellValue(i, "PL1_LEGAL_ADJ").ToString();
                    dtInsertPL2.Rows[dtInsertPL2.Rows.Count - 1]["PL2_999_ADJ"]     = gvMain.GetRowCellValue(i, "PL1_999_ADJ").ToString();
                    dtInsertPL2.Rows[dtInsertPL2.Rows.Count - 1]["PL2_PREV_NATURE"] = gvMain.GetRowCellValue(i, "PL1_CUR_NATURE").AsInt();
                    dtInsertPL2.Rows[dtInsertPL2.Rows.Count - 1]["PL2_PREV_LEGAL"]  = gvMain.GetRowCellValue(i, "PL1_CUR_LEGAL").AsInt();
                    dtInsertPL2.Rows[dtInsertPL2.Rows.Count - 1]["PL2_PREV_999"]    = gvMain.GetRowCellValue(i, "PL1_CUR_999").AsInt();
                    dtInsertPL2.Rows[dtInsertPL2.Rows.Count - 1]["PL2_W_TIME"]      = DateTime.Now;
                    dtInsertPL2.Rows[dtInsertPL2.Rows.Count - 1]["PL2_W_USER_ID"]   = GlobalInfo.USER_ID;
                    if (gvMain.GetRowCellValue(i, "Is_NewRow").AsString() == "1")//add by tom
                    {
                        dtInsertPL2.Rows[dtInsertPL2.Rows.Count - 1]["PL2_999_ADJ"]    = "+";
                        dtInsertPL2.Rows[dtInsertPL2.Rows.Count - 1]["PL2_NATURE_ADJ"] = gvMain.GetRowCellValue(i, "PL1_NATURE_ADJ");
                        dtInsertPL2.Rows[dtInsertPL2.Rows.Count - 1]["PL2_LEGAL_ADJ"]  = gvMain.GetRowCellValue(i, "PL1_LEGAL_ADJ");
                    }
                }
                // 寫入DB
                myResultData = dao30203.updatePL2(dtInsertPL2);

                //4. 新增 PL2B
                showMsg = "確認資料(PL2B)更新資料庫錯誤! ";
                DataTable dtInsertPL2B = dao30203.d_30203_pl2b(ls_ymd);
                for (i = 0; i < gvGBF.RowCount; i++)
                {
                    dtInsertPL2B.Rows.Add();
                    dtInsertPL2B.Rows[dtInsertPL2B.Rows.Count - 1]["PL2B_EFFECTIVE_YMD"]         = ls_eff_ymd;
                    dtInsertPL2B.Rows[dtInsertPL2B.Rows.Count - 1]["PL2B_YMD"]                   = ls_ymd;
                    dtInsertPL2B.Rows[dtInsertPL2B.Rows.Count - 1]["PL2B_PROD_TYPE"]             = gvGBF.GetRowCellValue(i, "PL1B_PROD_TYPE");
                    dtInsertPL2B.Rows[dtInsertPL2B.Rows.Count - 1]["PL2B_PROD_SUBTYPE"]          = gvGBF.GetRowCellValue(i, "PL1B_PROD_SUBTYPE");
                    dtInsertPL2B.Rows[dtInsertPL2B.Rows.Count - 1]["PL2B_KIND_ID"]               = gvGBF.GetRowCellValue(i, "PL1B_KIND_ID");
                    dtInsertPL2B.Rows[dtInsertPL2B.Rows.Count - 1]["PL2B_NATURE_LEGAL_MTH"]      = gvGBF.GetRowCellValue(i, "PL1B_NATURE_LEGAL_MTH");
                    dtInsertPL2B.Rows[dtInsertPL2B.Rows.Count - 1]["PL2B_NATURE_LEGAL_TOT"]      = gvGBF.GetRowCellValue(i, "PL1B_NATURE_LEGAL_TOT");
                    dtInsertPL2B.Rows[dtInsertPL2B.Rows.Count - 1]["PL2B_999_MTH"]               = gvGBF.GetRowCellValue(i, "PL1B_999_MTH");
                    dtInsertPL2B.Rows[dtInsertPL2B.Rows.Count - 1]["PL2B_999_NEARBY_MTH"]        = gvGBF.GetRowCellValue(i, "PL1B_999_NEARBY_MTH");
                    dtInsertPL2B.Rows[dtInsertPL2B.Rows.Count - 1]["PL2B_999_TOT"]               = gvGBF.GetRowCellValue(i, "PL1B_999_TOT");
                    dtInsertPL2B.Rows[dtInsertPL2B.Rows.Count - 1]["PL2B_PREV_NATURE_LEGAL_MTH"] = gvGBF.GetRowCellValue(i, "PL1B_PREV_NATURE_LEGAL_MTH");
                    dtInsertPL2B.Rows[dtInsertPL2B.Rows.Count - 1]["PL2B_PREV_NATURE_LEGAL_TOT"] = gvGBF.GetRowCellValue(i, "PL1B_PREV_NATURE_LEGAL_TOT");
                    dtInsertPL2B.Rows[dtInsertPL2B.Rows.Count - 1]["PL2B_PREV_999_MTH"]          = gvGBF.GetRowCellValue(i, "PL1B_PREV_999_MTH");
                    dtInsertPL2B.Rows[dtInsertPL2B.Rows.Count - 1]["PL2B_PREV_999_NEARBY_MTH"]   = gvGBF.GetRowCellValue(i, "PL1B_PREV_999_NEARBY_MTH");
                    dtInsertPL2B.Rows[dtInsertPL2B.Rows.Count - 1]["PL2B_PREV_999_TOT"]          = gvGBF.GetRowCellValue(i, "PL1B_PREV_999_TOT");
                    dtInsertPL2B.Rows[dtInsertPL2B.Rows.Count - 1]["PL2B_ADJ"]                   = gvGBF.GetRowCellValue(i, "PL1B_ADJ");
                    dtInsertPL2B.Rows[dtInsertPL2B.Rows.Count - 1]["PL2B_W_TIME"]                = DateTime.Now;
                    dtInsertPL2B.Rows[dtInsertPL2B.Rows.Count - 1]["PL2B_W_USER_ID"]             = GlobalInfo.USER_ID;
                }
                // 寫入DB
                myResultData = dao30203.updatePL2B(dtInsertPL2B);

                //5. 更新 PL1 (gvMain資料,gvGBF不需寫入DB)
                showMsg = "確認資料(PL1)更新資料庫錯誤! ";
                DataTable dtPL1 = gcMain.DataSource as DataTable;
                if (PL1NewRowCount > 0)
                {
                    for (int x = 0; x < PL1NewRowCount; x++)
                    {
                        dtPL1.Rows[dtPL1.Rows.Count - 1].Delete();
                    }
                }
                myResultData = dao30203.updatePL1(dtPL1);
                //add by Tom
                if (PL1NewRowCount > 0)
                {
                    showMsg      = "確認資料(PL1)更新資料庫錯誤(Insert)! ";
                    myResultData = dao30203.updatePL1(dtPL1Insert);
                }
                //end add by Tom
            } catch (Exception ex) {
                MessageDisplay.Error(showMsg);
                WriteLog(ex);
            }
            return(ResultStatus.Success);
        }
Beispiel #2
0
        protected override ResultStatus Save(PokeBall pokeBall)
        {
            //PB不管資料有無異動都會存檔
            string showMsg = "";

            try {
                #region ue_save_before
                gvMain.CloseEditor();

                //0. 確認是否填入正確公告日期
                //if (txtEffDateB.Text == "1901/01/01")
                if (txtEffDate.getTextValue() == "1901/01/01")
                {
                    MessageDisplay.Error("提高-公告日期非正確日期!");
                    return(ResultStatus.Fail);
                }
                //if (txtEffDateLowerB.Text == "1901/01/01")
                if (txtEffDateLower.getTextValue() == "1901/01/01")
                {
                    MessageDisplay.Error("降低-公告日期非正確日期!");
                    return(ResultStatus.Fail);
                }

                //1. 寫LOG到ci.PLLOG
                showMsg = "異動紀錄(PLLOG)更新資料庫錯誤! ";
                DataTable dtPLLOG    = dao30203.d_30203_pllog();
                DataTable dtGridView = (DataTable)gcMain.DataSource;
                foreach (DataRow dr in dtGridView.Rows)
                {
                    if (dr["PLS1_CP_LEVEL"].AsString() == dr["PLS1_LEVEL_ORG"].AsString())
                    {
                        continue;
                    }
                    DataRow drNew = dtPLLOG.NewRow();
                    drNew["PLLOG_YMD"]       = dr["PLS1_YMD"];
                    drNew["PLLOG_KIND_ID"]   = dr["PLS1_KIND_ID2"];
                    drNew["PLLOG_DATA_TYPE"] = " ";
                    drNew["PLLOG_ORG_VALUE"] = dr["PLS1_LEVEL_ORG"];
                    drNew["PLLOG_UPD_VALUE"] = dr["PLS1_CP_LEVEL"];
                    drNew["PLLOG_W_TIME"]    = DateTime.Now;
                    drNew["PLLOG_W_USER_ID"] = GlobalInfo.USER_ID;
                    dtPLLOG.Rows.Add(drNew);
                }

                //2. 寫入DB
                ResultData myResultData = dao30203.updatePLLOG2_30222use(dtPLLOG);
                #endregion
                showMsg      = "PLS1更新資料庫錯誤! ";
                myResultData = dao30222.updatePLS1(dtGridView);//更新PLS1

                int    f;
                string ymd, effYmd, effYmdLower;
                bool   delResult = false;
                //3. 判斷是否有已確認之資料
                //ymd = txtDate.Text.Replace("/", "");
                ymd = textDayNew.getTextValue().Replace("/", "");
                f   = dao30222.checkData(ymd);
                if (f > 0)
                {
                    DialogResult result = MessageDisplay.Choose("已確認,是否刪除舊有資料?");
                    if (result == DialogResult.No)
                    {
                        return(ResultStatus.FailButNext);
                    }
                    //3.1 刪除PLS2
                    showMsg   = "PLS2刪除失敗";
                    delResult = dao30222.DeletePLS2ByDate(ymd);
                    if (!delResult)
                    {
                        MessageDisplay.Error(showMsg);
                        return(ResultStatus.FailButNext);
                    }
                }
                //4. 新增PLS2
                showMsg = "確認資料(PLS2)更新資料庫錯誤! ";
                //effYmd = txtEffDateB.Text.Replace("/", "");
                //effYmdLower = txtEffDateLowerB.Text.Replace("/", "");
                effYmd      = txtEffDate.getTextValue().Replace("/", "");
                effYmdLower = txtEffDateLower.getTextValue().Replace("/", "");
                DataTable dtPLS2 = dao30222.d_30222_pls2(ymd);
                dtPLS2.Clear();
                foreach (DataRow dr in dtGridView.Rows)
                {
                    DataRow drNew = dtPLS2.NewRow();
                    if (dr["PLS1_LEVEL_ADJ"].ToString() == "-")
                    {
                        drNew["PLS2_EFFECTIVE_YMD"] = effYmdLower;
                    }
                    else
                    {
                        drNew["PLS2_EFFECTIVE_YMD"] = effYmd;
                    }
                    //for   j = 2 to 16
                    for (int k = 1; k < 16; k++)
                    {
                        drNew[k] = dr[k];
                    }
                    //drNew["PLS2_YMD"] = dr["PLS1_YMD"];
                    //drNew["PLS2_KIND_ID2"] = dr["PLS1_KIND_ID2"];
                    //drNew["PLS2_FUT"] = dr["PLS1_FUT"];
                    //drNew["PLS2_OPT"] = dr["PLS1_OPT"];
                    //drNew["PLS2_SID"] = dr["PLS1_SID"];

                    //drNew["PLS2_LEVEL_ADJ"] = dr["PLS1_LEVEL_ADJ"];
                    //drNew["PLS2_LEVEL"] = dr["PLS1_CP_LEVEL"];
                    //drNew["PLS2_NATURE"] = dr["PLS1_CP_NATURE"];
                    //drNew["PLS2_LEGAL"] = dr["PLS1_CP_LEGAL"];
                    //drNew["PLS2_999"] = dr["PLS1_CP_999"];

                    //drNew["PLS2_PREV_LEVEL"] = dr["PLS1_CUR_LEVEL"];
                    //drNew["PLS2_PREV_NATURE"] = dr["PLS1_CUR_NATURE"];
                    //drNew["PLS2_PREV_LEGAL"] = dr["PLS1_CUR_LEGAL"];
                    //drNew["PLS2_PREV_999"] = dr["PLS1_CUR_999"];
                    //drNew["PLS2_KIND_GRP2"] = dr["KIND_GRP2"];

                    drNew["PLS2_W_TIME"]    = DateTime.Now;
                    drNew["PLS2_W_USER_ID"] = GlobalInfo.USER_ID;
                    dtPLS2.Rows.Add(drNew);
                }
                //5. 寫入DB
                myResultData = dao30222.updatePLS2(dtPLS2);
            } catch (Exception ex) {
                MessageDisplay.Error(showMsg);
                throw ex;
            }
            return(ResultStatus.Success);
        }