Пример #1
0
        protected override ResultStatus Retrieve()
        {
            base.Retrieve(gcMain);
            if (!emDate.IsDate(emDate.Text, "日期輸入錯誤!"))
            {
                return(ResultStatus.Fail);
            }

            //存檔和刪除都是GridView的操作,應該要等讀取後才出現這些按鈕
            _ToolBtnSave.Enabled = true;
            _ToolBtnDel.Enabled  = true;
            //messagebox(gs_t_warning,"下方視窗無資料無法進行轉檔,請先執行「讀取/預覽」!",StopSign!)
            _ToolBtnExport.Enabled = true;

            string isYMD = YMDlookUpEdit.EditValue.AsString();

            gcMain.DataSource = b30290.List30290GridData(isYMD).Clone();

            int cnt = b30290.DataCount(isYMD);

            if (cnt > 0)
            {
                retrieveChoose = MessageDisplay.Choose("已存在相同生效日期資料,按「是」讀取已存檔資料,按「否」為重新產至資料");
                if (retrieveChoose == DialogResult.Yes)
                {
                    gcMain.DataSource = b30290.List30290GridData(isYMD);
                    return(ResultStatus.Success);
                }
            }
            //已存在相同生效日期資料,按「否」重新產至資料
            RowsCopy(isYMD);

            return(ResultStatus.Success);
        }
Пример #2
0
        protected DialogResult ConfirmToExitWithoutSave(DataTable dt)
        {
            DialogResult myDialogResult = DialogResult.No;

            if (dt.GetChanges() != null && dt.GetChanges().Rows.Count != 0)
            {
                foreach (DataRow row in dt.GetChanges().Rows)
                {
                    if (row.RowState == DataRowState.Deleted)
                    {
                        myDialogResult = MessageDisplay.Choose("未完成存檔,請問是否要離開作業?");
                        return(myDialogResult);
                    }

                    foreach (object item in row.ItemArray)
                    {
                        if ((item is string && string.IsNullOrEmpty(item.AsString())) || item is DBNull)
                        {
                            // 代表都沒有修改資料
                        }
                        else
                        {
                            myDialogResult = MessageDisplay.Choose("未完成存檔,請問是否要離開作業?");
                            return(myDialogResult);
                        }
                    }
                }
            }

            return(myDialogResult);
        }
Пример #3
0
 private bool OutputChooseMessage(string str) {
    DialogResult ChooseResult = MessageDisplay.Choose(str);
    if (ChooseResult == DialogResult.No) {
       EndExport();
       return false;
    }
    return true;
 }
Пример #4
0
 private void btnClear_Click(object sender, EventArgs e)
 {
     if (MessageDisplay.Choose("確定刪除所有資料?").AsBool())
     {
         while (gvMain.DataRowCount != 0)
         {
             gvMain.DeleteRow(0);
         }
     }
 }
Пример #5
0
 protected bool ConfirmToDelete(int rowNum)
 {
     if (MessageDisplay.Choose("確定刪除第" + rowNum + "筆資料?") == DialogResult.Yes)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #6
0
        /// <summary>
        /// 確認日期 有資料時清除PLS4相關日期資料
        /// </summary>
        /// <returns></returns>
        private bool WfChkDate()
        {
            //確認:比對日期
            if (!emProdDate.IsDate(emProdDate.Text, "「比對期貨/選擇權商品基準日期」非正確日期格式"))
            {
                return(false);
            }

            string lsYMD;

            //確認:計算日期
            lsYMD = emDate.Text.Replace("/", "");
            DialogResult ChooseResult = MessageDisplay.Choose($"請確認「計算日期 :{emDate.Text}」是否正確?");

            if (ChooseResult == DialogResult.No)
            {
                return(false);
            }

            //重新讀取資料
            Retrieve();
            DataTable dt = (DataTable)gcMain.DataSource;

            if (dt == null)
            {
                return(false);
            }

            if (dt.Rows.Count > 0)
            {
                DialogResult ChooseResult1 = MessageDisplay.Choose($"「計算日期 :{emDate.Text}」資料已存在,是否刪除?");
                if (ChooseResult1 == DialogResult.No)
                {
                    return(false);
                }
                DialogResult ChooseResult2 = MessageBox.Show($"「計算日期 :{emDate.Text}」資料確定刪除?", "注意", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                if (ChooseResult2 == DialogResult.Cancel)
                {
                    return(false);
                }
                //刪除相關日期條件已存在的資料
                dao20231.DeletePLS4(lsYMD);
            }

            DialogResult ChooseResult3 = MessageBox.Show($"請確認「比對期貨/選擇權商品基準日期 :{emDate.Text}」是否正確?", "注意", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);

            if (ChooseResult3 == DialogResult.Cancel)
            {
                return(false);
            }
            return(true);
        }
Пример #7
0
        protected override ResultStatus RunBefore(PokeBall args)
        {
            string txfServer = gvMain.GetRowCellValue(1, "TXF_SERVER").AsString();

            if (txfServer != GlobalDaoSetting.GetConnectionInfo.ConnectionName)
            {
                MessageDisplay.Warning("作業Server(" + txfServer + ") 不等於連線Server(" + GlobalDaoSetting.GetConnectionInfo.ConnectionName + ")");
                return(ResultStatus.Fail);
            }

            string inputDate = txtOcfDate.Text;
            string nowDate   = DateTime.Now.ToString(txtOcfDate.Properties.EditFormat.FormatString);

            if (OCF_TYPE == "D")
            {
                if (inputDate != nowDate)
                {
                    if (MessageDisplay.Choose("交易日期(" + inputDate + ") 不等於今日(" + nowDate + "),是否要繼續?") == DialogResult.No)
                    {
                        return(ResultStatus.Fail);
                    }
                }
                if (servicePrefix1.HasLogspDone(Convert.ToDateTime(inputDate), _ProgramID))
                {
                    if (MessageDisplay.Choose(_ProgramID + " 作業 " + inputDate + "「曾經」執行過,\n是否要繼續?\n\n★★★建議先執行 [預覽] 確認執行狀態") == DialogResult.No)
                    {
                        return(ResultStatus.Fail);
                    }
                }

                if (!servicePrefix1.setOCF(txtOcfDate.DateTimeValue, _DB_TYPE, GlobalInfo.USER_ID))
                {
                    return(ResultStatus.Fail);
                }
            }
            else if (OCF_TYPE == "M")
            {
                if (inputDate != nowDate)
                {
                    if (MessageDisplay.Choose("月份(" + inputDate + ") 不等於本月(" + nowDate + "),是否要繼續?") == DialogResult.No)
                    {
                        return(ResultStatus.Fail);
                    }
                }
            }


            GridHelper.AcceptText(gcMain);

            return(base.RunBefore(args));
        }
Пример #8
0
        private void btnClear_Click(object sender, EventArgs e)
        {
            BaseButton btn    = (BaseButton)sender;
            string     module = btn.Name.Split('_')[0];
            GridView   gv     = GetGridView(module);

            if (MessageDisplay.Choose("確定刪除" + module + "設定所有資料?").AsBool())
            {
                while (gv.DataRowCount != 0)
                {
                    gv.DeleteRow(0);
                }
            }
        }
Пример #9
0
        /// <summary>
        /// 確認日期 有資料時清除PLS4相關日期資料
        /// </summary>
        /// <returns></returns>
        private string WfChkDate()
        {
            string lsYMD;

            //確認:計算日期
            lsYMD = emDate.Text.Replace("/", "");
            DialogResult ChooseResult = MessageDisplay.Choose($"請確認「計算日期 :{emDate.Text}」是否正確?");

            if (ChooseResult == DialogResult.No)
            {
                return("E");
            }

            //刪除舊有資料
            DataTable data = dao20231.List20231(lsYMD);

            if (data.Rows.Count > 0)
            {
                DialogResult ChooseResult1 = MessageDisplay.Choose($"「計算日期 :{emDate.Text}」資料已存在,是否刪除?");
                if (ChooseResult1 == DialogResult.No)
                {
                    return("E");
                }

                DialogResult ChooseResult2 = MessageBox.Show($"「計算日期 :{emDate.Text}」資料確定刪除?", "注意", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                if (ChooseResult2 == DialogResult.Cancel)
                {
                    return("E");
                }

                //刪除相關日期條件已存在的資料
                dao20231.DeletePLS4(lsYMD);
            }

            //確認:比對日期
            if (!emProdDate.IsDate(emProdDate.Text, "「比對期貨/選擇權商品基準日期」非正確日期格式"))
            {
                return("E");
            }

            DialogResult ChooseResult3 = MessageBox.Show($"請確認「比對期貨/選擇權商品基準日期 :{emDate.Text}」是否正確?", "注意", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);

            if (ChooseResult3 == DialogResult.Cancel)
            {
                return("E");
            }

            return("");
        }
Пример #10
0
        protected override ResultStatus DeleteRow()
        {
            string       ls_rtn = GlobalInfo.OCF_DATE.ToString("yyyyMMdd");
            DialogResult result = MessageDisplay.Choose($"請問確定要刪除{GlobalInfo.OCF_DATE.ToString("yyyy/MM/dd")}資料嗎?", MessageBoxDefaultButton.Button2);

            if (result == DialogResult.Yes)
            {
                int res = dao20232.DeleteStw(ls_rtn);
                if (res <= 0)
                {
                    MessageDisplay.Error($"刪除 {GlobalInfo.OCF_DATE.ToString("yyyy/MM/dd")} 資料失敗", GlobalInfo.ErrorText);
                    WriteLog($"sqlca.sqlcode= {res}");
                    return(ResultStatus.Fail);
                }
                else
                {
                    MessageDisplay.Info("刪除完成!", GlobalInfo.ResultText);
                }
            }
            return(ResultStatus.Success);
        }
Пример #11
0
        public bool setOCF(DateTime OCF_DATE, string DB_TYPE, string USER_ID)
        {
            OCF    ocf   = new OCF(DB_TYPE);
            BO_OCF boOCF = ocf.GetOCF();

            if (boOCF == null)
            {
                MessageDisplay.Error("交易日期檔(OCF)讀取錯誤!");
                return(false);
            }

            if (DB_TYPE == "futAH" || DB_TYPE == "optAH")
            {
                if (MessageDisplay.Choose($"請確定交易日期({boOCF.OCF_DATE.AsString("yyyy/MM/dd")}) 沒有例外而遞延日期?\r\n(eg.颱風,災害...)") == System.Windows.Forms.DialogResult.No)
                {
                    return(false);
                }
            }

            //清除異動紀錄檔
            daoFutAHOCFUPD.Delete();
            daoOptAHOCFUPD.Delete();

            if (DB_TYPE == "futAH")
            {
                daoFutAHOCFUPD.Insert(boOCF.OCF_PREV_DATE, boOCF.OCF_DATE, OCF_DATE, USER_ID);
                ConnectionInfo connectionInfo = SettingDragons.Instance.GetConnectionInfo(DB_TYPE);
                ResultData     resultData     = serviceCommon.ExecuteStoredProcedure(connectionInfo, "futAH.sp_FAH_chg_OCF_Hdata", null, false);
            }
            else if (DB_TYPE == "optAH")
            {
                daoOptAHOCFUPD.Insert(boOCF.OCF_PREV_DATE, boOCF.OCF_DATE, OCF_DATE, USER_ID);
                ConnectionInfo connectionInfo = SettingDragons.Instance.GetConnectionInfo(DB_TYPE);
                ResultData     resultData     = serviceCommon.ExecuteStoredProcedure(connectionInfo, "optAH.sp_OAH_chg_OCF_Hdata", null, false);
            }

            //更新OCF_DATE
            return(ocf.UpdateDate(OCF_DATE));
        }
Пример #12
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);
        }
Пример #13
0
        protected override ResultStatus Retrieve()
        {
            try
            {
                gcMain.DataSource = null; //清空grid
                                          //1. 讀取資料
                //string ymd = txtDate.Text.Replace("/", "");
                string    ymd     = textDayNew.getTextValue().Replace("/", "");
                DataTable dt30222 = dao30222.d_30222(ymd);
                if (dt30222.Rows.Count == 0)
                {
                    MessageDisplay.Info("PLS1無任何資料!");
                    gcMain.DataSource = dt30222;//空的還是要放進Grid,因為後面可能要塞資料
                }
                else
                {
                    dt30222.Columns.Add("Is_NewRow", typeof(string));
                    gcMain.DataSource = dt30222;
                    gcMain.Focus();
                }

                //2. 確認公告日期
                DataTable dtPostDate = dao30222.PostDate(ymd);
                if (dtPostDate.Rows.Count == 0)
                {
                    MessageDisplay.Info("公告日期無任何資料!");
                    return(ResultStatus.Fail);
                }

                DateTime raiseYmd = dtPostDate.Rows[0]["RAISE_YMD"].AsString() != "" ? dtPostDate.Rows[0]["RAISE_YMD"].AsDateTime("yyyyMMdd") : "1901/01/01".AsDateTime("yyyy/MM/dd");
                DateTime lowerYmd = dtPostDate.Rows[0]["LOWER_YMD"].AsString() != "" ? dtPostDate.Rows[0]["LOWER_YMD"].AsDateTime("yyyyMMdd") : "1901/01/01".AsDateTime("yyyy/MM/dd");
                int      liCount  = dtPostDate.Rows[0]["LI_COUNT"].AsInt();

                if (raiseYmd != default(DateTime))
                {
                    //txtEffDateB.DateTimeValue = raiseYmd;
                    //txtEffDateLowerB.DateTimeValue = lowerYmd;
                    lblEff.Text = "(已確認)";
                }
                else
                {
                    //txtEffDateB.Text = "1901/01/01";
                    //txtEffDateLowerB.Text = "1901/01/01";
                    txtEffDate.setTextValue("1901/01/01");
                    txtEffDateLower.setTextValue("1901/01/01");
                    lblEff.Text = "";
                }

                if (liCount <= 0)
                {
                    return(ResultStatus.Fail);
                }

                //3. 選擇是否重新產製資料
                DialogResult result = MessageDisplay.Choose("已確認資料,按「是」讀取已存檔資料,按「否」為重新產製資料");
                if (result == DialogResult.No)
                {
                    return(ResultStatus.Fail);
                }

                DataTable dt30222PLS2 = dao30222.d_30222_pls2(ymd); //lds_2
                if (dt30222PLS2.Rows.Count == 0)
                {
                    MessageDisplay.Info("PLS2無任何資料!");
                    return(ResultStatus.Fail);
                }

                //gvMain.CloseEditor();
                //DataTable dtGridView = (DataTable)gcMain.DataSource;
                ////dtGridView.PrimaryKey = new DataColumn[] { dtGridView.Columns["PLS1_KIND_ID2"] };
                //DataView dvMain = dtGridView.AsDataView();
                //dvMain.Sort = "PLS1_KIND_ID2";
                //dtGridView = dvMain.ToTable();
                //foreach (DataRow dr in dt30222PLS2.Rows) {
                //   //此時gridview的資料還沒被動過,原本要在gridview中查找(datawindow.find)的資料直接在datasource查找即可
                //   int found = dtGridView.Rows.IndexOf(dtGridView.Select("PLS1_KIND_ID2='" + dr["PLS2_KIND_ID2"].ToString() + "'").FirstOrDefault());
                //   if (found < 0) {
                //      dtGridView.Rows.Add();
                //      found = dtGridView.Rows.Count - 1;
                //   }
                //   //DataRow drFound = dtGridView.Rows[found];

                //   if (dr["PLS2_EFFECTIVE_YMD"].AsString() == lowerYmd.ToString("yyyyMMdd")) {
                //      dtGridView.Rows[found]["PLS1_LEVEL_ADJ"] = "-";
                //   }
                //   //for  j = 2 to 16
                //   for (int k = 1 ; k < 16 ; k++) {
                //      dtGridView.Rows[found][k] = dr[k];
                //   }

                //   dtGridView.Rows[found]["PLS1_W_TIME"] = DateTime.Now;
                //   dtGridView.Rows[found]["PLS1_W_USER_ID"] = GlobalInfo.USER_ID;

                //   //計算欄位COMPUTE_1: if( pls1_kind_id2 <> kind_grp2 ,'小型',' ')
                //   if (dtGridView.Rows[found]["KIND_GRP2"] != DBNull.Value && dtGridView.Rows[found]["PLS1_KIND_ID2"].AsString() != dtGridView.Rows[found]["KIND_GRP2"].AsString()) {
                //      dtGridView.Rows[found]["COMPUTE_1"] = "小型";
                //   } else {
                //      dtGridView.Rows[found]["COMPUTE_1"] = " ";
                //   }
                //}//foreach (DataRow dr in dt30222PLS2.Rows)

                int w = -1;
                foreach (DataRow dr in dt30222PLS2.Rows)
                {
                    w++;
                    int found = dt30222.Rows.IndexOf(dt30222.Select("PLS1_KIND_ID2='" + dt30222PLS2.Rows[w]["PLS2_KIND_ID2"].AsString() + "'").FirstOrDefault());
                    if (found < 0)
                    {
                        DataRow drNew = dt30222.NewRow();
                        dt30222.Rows.Add(drNew);
                        found = dt30222.Rows.Count - 1;
                    }

                    //if (dt30222PLS2.Rows[w]["PLS2_EFFECTIVE_YMD"].AsString() == txtEffDateLowerB.DateTimeValue.ToString("yyyyMMdd"))
                    if (dt30222PLS2.Rows[w]["PLS2_EFFECTIVE_YMD"].AsString() == txtEffDateLower.ToString().Replace("/", ""))
                    {
                        dt30222.Rows[found]["PLS1_LEVEL_ADJ"] = "-";
                    }

                    for (int x = 1; x < 16; x++)
                    {
                        dt30222.Rows[found][x] = dt30222PLS2.Rows[w][x];
                    }

                    dt30222.Rows[found]["PLS1_W_TIME"]    = DateTime.Now;
                    dt30222.Rows[found]["PLS1_W_USER_ID"] = GlobalInfo.USER_ID;

                    //計算欄位COMPUTE_1: if( pls1_kind_id2 <> kind_grp2 ,'小型',' ')
                    if (dt30222.Rows[found]["KIND_GRP2"] != DBNull.Value && dt30222.Rows[found]["PLS1_KIND_ID2"].AsString() != dt30222.Rows[found]["KIND_GRP2"].AsString())
                    {
                        dt30222.Rows[found]["COMPUTE_1"] = "小型";
                    }
                    else
                    {
                        dt30222.Rows[found]["COMPUTE_1"] = " ";
                    }
                }

                gcMain.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Flat;
                gcMain.LookAndFeel.UseDefaultLookAndFeel            = false;
                gvMain.OptionsSelection.EnableAppearanceFocusedRow  = false;
                gvMain.OptionsSelection.EnableAppearanceFocusedCell = false;

                gcMain.DataSource = dt30222;
            } catch (Exception ex) {
                MessageDisplay.Error("讀取錯誤");
                WriteLog(ex, "", false);
            }
            return(ResultStatus.Success);
        }
Пример #14
0
        protected override ResultStatus Save(PokeBall pokeBall)
        {
            int printStep = 0;

            try {
                DataTable dtCurrent = (DataTable)gcMain.DataSource;
                gvMain.CloseEditor();
                gvMain.UpdateCurrentRow();

                DataTable dtChange = dtCurrent.GetChanges();

                if (dtChange == null)
                {
                    MessageDisplay.Warning("沒有變更資料,不需要存檔!", GlobalInfo.WarningText);
                    return(ResultStatus.Fail);
                }
                if (dtChange.Rows.Count == 0)
                {
                    MessageDisplay.Warning("沒有變更資料,不需要存檔!", GlobalInfo.WarningText);
                    return(ResultStatus.Fail);
                }

                DialogResult liRtn;
                int          pos = -1;
                foreach (DataRow dr in dtChange.Rows)
                {
                    pos++;
                    if (dr.RowState == DataRowState.Added || dr.RowState == DataRowState.Modified)
                    {
                        dr["CPR_W_TIME"]    = DateTime.Now;
                        dr["CPR_W_USER_ID"] = GlobalInfo.USER_ID;
                        dr["CPR_DATA_NUM"]  = 0; //隱藏欄位賦值

                        if (dr["CPR_PRICE_RISK_RATE"] == DBNull.Value)
                        {
                            string kind = dr["CPR_KIND_ID"].AsString();

                            liRtn = MessageDisplay.Choose(string.Format("{0}最小風險價格係數欄位為空白,請確認是否為已下市契約", kind), MessageBoxDefaultButton.Button2, GlobalInfo.QuestionText);
                            if (liRtn == DialogResult.No)
                            {
                                return(ResultStatus.Fail);
                            }
                            else
                            {
                                dr["CPR_PRICE_RISK_RATE"] = DBNull.Value;
                            }
                        }

                        gvMain.SetRowCellValue(pos, "CPR_W_TIME", DateTime.Now);
                        gvMain.SetRowCellValue(pos, "CPR_W_USER_ID", GlobalInfo.USER_ID);
                        gvMain.UpdateCurrentRow();
                    }
                } //foreach (DataRow dr in dtCurrent.Rows)
                  //dtChange = dtChange.GetChanges();

                //GridHelper.SetCommonGrid(gvMain);
                //gvMain.BestFitColumns();

                printStep = 1; //跑儲存前確認單
                CheckPrint(gcMain, dtChange, printStep);
                liRtn = MessageDisplay.Choose("已列印確認單,點選確認進行儲存資料", MessageBoxDefaultButton.Button2, GlobalInfo.QuestionText);
                if (liRtn == DialogResult.No)
                {
                    return(ResultStatus.Fail);
                }
                else
                {
                    ResultData result = new HCPR().UpdateData(dtChange);
                    if (result.Status == ResultStatus.Fail)
                    {
                        MessageDisplay.Error("儲存失敗", GlobalInfo.ErrorText);
                        return(ResultStatus.FailButNext);
                    }

                    printStep = 2; //儲存後列印已確認單
                    CheckPrint(gcMain, dtChange, printStep);
                }
            } catch (Exception ex) {
                MessageDisplay.Error("儲存錯誤", GlobalInfo.ErrorText);
                WriteLog(ex, "", false);
                return(ResultStatus.FailButNext);
            } finally {
                DataTable dtAll = dao49010.GetDataList();
                DataTable dt    = dtAll.Clone();
                gcMain.DataSource = dt;

                gvMain.AppearancePrint.BandPanel.Options.UseTextOptions = true;
                gvMain.AppearancePrint.BandPanel.TextOptions.WordWrap   = WordWrap.Wrap;
                gvMain.AppearancePrint.BandPanel.Font = new Font("Microsoft YaHei", 11);

                gvMain.AppearancePrint.Row.Font           = new Font("Microsoft YaHei", 11);
                gvMain.OptionsPrint.AllowMultilineHeaders = true;
                gvMain.AppearancePrint.GroupRow.Font      = new Font("Microsoft YaHei", 11);

                gvMain.BestFitColumns();
                GridHelper.SetCommonGrid(gvMain);

                gridBand9.AppearanceHeader.TextOptions.WordWrap = WordWrap.Wrap;

                gridBand9.Caption = "(輸入方式:如3.5%,則輸入0.035)";

                gvMain.Columns["CPR_PROD_SUBTYPE"].ColumnEdit = lupProdSubtype;
                gvMain.Columns["CPR_KIND_ID"].ColumnEdit      = lupKindId;

                //製作連動下拉選單(觸發事件)
                gvMain.ShownEditor += gvMain_ShownEditor;
                lupProdSubtype.EditValueChanged += lupProdSubtype_EditValueChanged;

                //gcMain.Visible = true;
                gcMain.Focus();
                _ToolBtnPrintAll.Enabled = false;//列印
                this.Refresh();
            }
            gcMain.Visible = false;
            return(ResultStatus.Success);
        }
Пример #15
0
        protected override ResultStatus Export()
        {
            dao30070 = new D30070();
            #region ue_export_before
            string lsRtn;

            lsRtn = PbFunc.f_get_jsw_seq(_ProgramID, "E", 0, txtEDate.DateTimeValue, "0");
            if (lsRtn != "")
            {
                DialogResult liRtn = MessageDisplay.Choose(txtEDate.Text + " 統計資料未轉入完畢,是否要繼續?" + Environment.NewLine + lsRtn);
                if (liRtn == DialogResult.No)
                {
                    lblProcessing.Visible = false;
                    this.Cursor           = Cursors.Arrow;
                    return(ResultStatus.Fail);
                }
            }
            #endregion

            int    rowNum;
            string rptId, lsFile;
            rptId = "30070";
            //複製檔案
            lsFile = PbFunc.wf_copy_file(rptId, rptId);
            if (lsFile == "")
            {
                return(ResultStatus.Fail);
            }
            logTxt = lsFile;

            //開啟檔案
            Workbook workbook = new Workbook();
            workbook.LoadDocument(lsFile);

            rowNum = 0;
            #region wf_30070
            string rptName, lsYmd;
            rptName = "期貨各商品成交值";
            rptId   = "30070";

            //切換Sheet
            Worksheet ws30070 = workbook.Worksheets[0];

            //讀取資料 (每日)
            DataTable dt30070 = dao30070.d_30070(txtSDate.Text.Replace("/", ""), txtEDate.Text.Replace("/", ""));
            if (dt30070.Rows.Count == 0)
            {
                //nothing happens
            }

            lsYmd = "";
            foreach (DataRow dr in dt30070.Rows)
            {
                rowNum += 1;
                ws30070.Cells[rowNum, 0].Value = dr["AA2_YMD"].AsString();
                ws30070.Cells[rowNum, 1].Value = dr["AA2_PARAM_KEY"].AsString();
                ws30070.Cells[rowNum, 2].SetValue(dr["AA2_AMT"]);
            }
            #endregion

            rowNum = 0;
            #region wf_30071
            rptName = "期貨各商品成交值(現貨價格計算)";
            rptId   = "30070_stk";

            //切換Sheet
            Worksheet ws30070stk = workbook.Worksheets[1];

            //讀取資料 (每日)
            DataTable dt30070stk = dao30070.d_30070_stk(txtSDate.Text.Replace("/", ""), txtEDate.Text.Replace("/", ""));
            if (dt30070stk.Rows.Count == 0)
            {
                //nothing happens
            }

            lsYmd = "";
            foreach (DataRow dr in dt30070stk.Rows)
            {
                rowNum += 1;
                ws30070stk.Cells[rowNum, 0].Value = dr["AA2_YMD"].AsString();
                ws30070stk.Cells[rowNum, 1].Value = dr["AA2_PARAM_KEY"].AsString();
                ws30070stk.Cells[rowNum, 2].SetValue(dr["AA2_AMT"]);
            }
            #endregion

            //存檔
            //ws30070.ScrollToRow(0);
            workbook.SaveDocument(lsFile);
            return(ResultStatus.Success);
        }
Пример #16
0
        protected override ResultStatus Export()
        {
            try {
                //ready
                panFilter.Enabled = false;
                labMsg.Visible    = true;
                labMsg.Text       = "開始轉檔...";
                this.Cursor       = Cursors.WaitCursor;
                this.Refresh();
                Thread.Sleep(5);

                string rptId, file, rptName = "",
                       cpYmd = txtSDate.DateTimeValue.ToString("yyyyMMdd");


                #region ue_export_before
                //判斷盤別
                int    rtnInt, seq;
                string rtnStr, grp;
                if (ddlType.Text == "16:15收盤")
                {
                    grp = "1";
                    DialogResult result = MessageDisplay.Choose("盤別為「16:15收盤」,請問是否繼續轉出報表?", MessageBoxDefaultButton.Button2, GlobalInfo.QuestionText);
                    if (result == DialogResult.No)
                    {
                        ShowMsg("已取消轉檔...");
                        return(ResultStatus.Fail);
                    }
                }
                else
                {
                    grp = "2";
                }

                //判斷統計資料轉檔已完成
                for (int f = 1; f <= 2; f++)
                {
                    if (grp == "1")
                    {
                        if (f == 1)
                        {
                            seq = 13;
                        }
                        else
                        {
                            seq = 23;
                        }
                    }
                    else
                    {
                        seq = 17;
                        f   = 2;
                    }
                    //check JSW
                    rtnStr = PbFunc.f_get_jsw_seq(_ProgramID, "E", seq, txtSDate.DateTimeValue, "0");
                    if (rtnStr != "")
                    {
                        DialogResult result = MessageDisplay.Choose(" 統計資料未轉入完畢,是否要繼續?", MessageBoxDefaultButton.Button2, GlobalInfo.QuestionText);
                        if (result == DialogResult.No)
                        {
                            return(ResultStatus.Fail);
                        }
                    }
                }

                //判斷20110作業已完成
                rtnInt = dao30010.check20110(txtSDate.Text);
                if (rtnInt == 0)
                {
                    DialogResult result = MessageDisplay.Choose("無 " + txtSDate.Text + " 現貨資料 (資料來自20110作業)," +
                                                                Environment.NewLine + "請問是否繼續轉出報表?", MessageBoxDefaultButton.Button2, GlobalInfo.QuestionText);
                    if (result == DialogResult.No)
                    {
                        ShowMsg("已取消轉檔...");
                        return(ResultStatus.Fail);
                    }
                }
                #endregion

                rptId = "30010_";

                //複製檔案
                file = wfCopy30010(rptId + grp, grp);
                if (file == "")
                {
                    return(ResultStatus.Fail);
                }

                //開啟檔案
                Workbook workbook = new Workbook();
                workbook.LoadDocument(file);
                flag = 0;

                //切換Sheet
                Worksheet ws30011 = workbook.Worksheets["30011"];

                /* Sheet:30011 */
                wf_30012(rptId, rptName, ws30011);
                wf_30011(rptId, rptName, ws30011);

                /* Sheet:30013 */
                //切換Sheet
                Worksheet ws30013 = workbook.Worksheets["30013"];

                DataTable dtRowCount = dao30010.getRowIndexandCount();
                if (dtRowCount.Rows.Count == 0)
                {
                    MessageDisplay.Error("無法取得30013總列數");
                    return(ResultStatus.Fail);
                }
                int totalRowcount = dtRowCount.Rows[0]["LI_TOT_ROWCOUNT"].AsInt();

                //上市股票
                int rowIndex = dtRowCount.Rows[0]["II_OLE_ROW"].AsInt() - 1;
                if (rowIndex > 0)
                {
                    rowIndex = wf_30013("STF", "F", totalRowcount, "1", rowIndex, ws30013);
                }
                //上櫃股票
                rowIndex = rowIndex + 2;
                if (rowIndex > 0)
                {
                    rowIndex = wf_30013("STF", "F", totalRowcount, "2", rowIndex, ws30013);
                }
                //ETF股票
                rowIndex = rowIndex + 2;
                if (rowIndex > 0)
                {
                    rowIndex = wf_30013("ETF", "F", totalRowcount, "%", rowIndex, ws30013);
                }
                //上市選擇權
                rowIndex = rowIndex + 2;
                if (rowIndex > 0)
                {
                    rowIndex = wf_30013("STC", "O", totalRowcount, "1", rowIndex, ws30013);
                }
                //上櫃選擇權
                rowIndex = rowIndex + 2;
                if (rowIndex > 0)
                {
                    rowIndex = wf_30013("STC", "O", totalRowcount, "2", rowIndex, ws30013);
                }
                //ETF選擇權
                rowIndex = rowIndex + 2;
                if (rowIndex > 0)
                {
                    rowIndex = wf_30013("ETC", "O", totalRowcount, "%", rowIndex, ws30013);
                }

                /* Sheet:30014 */
                Worksheet ws30014 = workbook.Worksheets["30014"];

                wf_30014(ws30014);

                wf_30015(ws30014);

                //Eurex
                wf_30016(ws30014);

                if (flag <= 0)
                {
                    File.Delete(file);
                    return(ResultStatus.Fail);
                }

                //存檔
                ws30014.ScrollToRow(0);
                ws30013.ScrollToRow(0);
                ws30011.ScrollToRow(0);
                workbook.SaveDocument(file);
                ShowMsg("轉檔完成");
                return(ResultStatus.Success);
            } catch (Exception ex) {
                MessageDisplay.Error("輸出錯誤");
                WriteLog(ex);
            } finally {
                panFilter.Enabled = true;
                labMsg.Text       = "";
                labMsg.Visible    = false;
                this.Cursor       = Cursors.Arrow;
            }
            return(ResultStatus.Fail);
        }
Пример #17
0
        protected override ResultStatus Retrieve()
        {
            if (gbReportType.EditValue.Equals("rb_date"))
            {
                string lsRtn = PbFunc.f_get_jsw_seq(_ProgramID, "E", 0, emEndDate.DateTimeValue, gbMarket.EditValue.Equals("rb_market_1") ? "1" : "0");
                if (lsRtn != "")
                {
                    DialogResult ChooseResult = MessageDisplay.Choose(emEndDate.Text + " 統計資料未轉入完畢,是否要繼續?" + Environment.NewLine + lsRtn);
                    if (ChooseResult == DialogResult.No)
                    {
                        stMsgTxt.Visible = false;
                        return(ResultStatus.Fail);
                    }
                }
            }

            if (!StartRetrieve())
            {
                return(ResultStatus.Fail);
            }

            if (!GetData())
            {
                return(ResultStatus.Fail);
            }

            if (gbDetial.EditValue.Equals("rb_gdate"))
            {
                decimal TotR = 0, TotM = 0, llR = 0, llM = 0;
                string  lsProdId = "", lsYMD = "";
                foreach (DataRow dr in _Data.Rows)
                {
                    if (lsProdId != dr["AMM0_PROD_ID"].AsString() || lsYMD != dr["AMM0_YMD"].AsString())
                    {
                        llR      = dr["AMM0_MARKET_R_CNT"].AsDecimal();
                        llM      = dr["AMM0_MARKET_M_QNTY"].AsDecimal();
                        TotR     = TotR + llR;
                        TotM     = TotM + llM;
                        lsProdId = dr["AMM0_PROD_ID"].AsString();
                        lsYMD    = dr["AMM0_YMD"].AsString();
                    }
                    else
                    {
                        //當遇到造市者沒有足月時,造成總計不同
                        //皆以最大值為全市場值
                        if (llR < dr["AMM0_MARKET_R_CNT"].AsDecimal() || llM < dr["AMM0_MARKET_M_QNTY"].AsDecimal())
                        {
                            TotR = TotR - llR;
                            TotM = TotM - llM;
                            llR  = dr["AMM0_MARKET_R_CNT"].AsDecimal();
                            llM  = dr["AMM0_MARKET_M_QNTY"].AsDecimal();
                            TotR = TotR + llR;
                            TotM = TotM + llM;
                        }
                    }
                }//foreach (DataRow dr in dt.Rows)
                _Data.Rows[0]["TOT_R"] = TotR;
                _Data.Rows[0]["TOT_M"] = TotM;
            }

            documentViewer1.DocumentSource = null;

            //報表內容選擇分日期
            if (gbDetial.EditValue.Equals("rb_gdate"))
            {
                _RW50030            = new RW50030();
                _RW50030.DataSource = _Data;
                _RW50030.SetSortType(_D500Xx.SortType);
                _Report = _RW50030;
            }
            else
            {
                List <ReportProp> caption = new List <ReportProp> {
                    new ReportProp {
                        DataColumn = "CP_ROW", Caption = "筆數", CellWidth = 45, Expression = new DevExpress.XtraReports.UI.ExpressionBinding[] {
                            new DevExpress.XtraReports.UI.ExpressionBinding("BeforePrint", "Text", "[DataSource.CurrentRowIndex]+1")
                        }
                    },
                    new ReportProp {
                        DataColumn = "AMM0_YMD", Caption = "日期", CellWidth = gbDetial.EditValue.Equals("rb_gnodate")?110:50, DetailRowFontSize = 8.25f
                    },
                    new ReportProp {
                        DataColumn = "AMM0_BRK_NO", Caption = "期貨商代號", CellWidth = 57
                    },
                    new ReportProp {
                        DataColumn = "BRK_ABBR_NAME", Caption = "期貨商名稱", CellWidth = 150, Expression = new DevExpress.XtraReports.UI.ExpressionBinding[] {
                            new DevExpress.XtraReports.UI.ExpressionBinding("BeforePrint", "Text", "[BRK_ABBR_NAME]"),
                            new DevExpress.XtraReports.UI.ExpressionBinding("BeforePrint", "Font.Size", "Iif ( len(trim([BRK_ABBR_NAME]) ) >8.25 , 9, 9.75)")
                        }
                    },
                    new ReportProp {
                        DataColumn = "AMM0_ACC_NO", Caption = "投資人帳號", CellWidth = 53
                    },
                    new ReportProp {
                        DataColumn = "AMM0_OM_QNTY", Caption = "一般委託成交量", CellWidth = 65, textAlignment = TextAlignment.MiddleRight, TextFormatString = "{0:#,##0}", HeaderFontSize = 9
                    },
                    new ReportProp {
                        DataColumn = "AMM0_QM_QNTY", Caption = "報價成交量", CellWidth = 65, textAlignment = TextAlignment.MiddleRight, TextFormatString = "{0:#,##0}"
                    },
                    new ReportProp {
                        DataColumn = "AMM0_BTRADE_M_QNTY", Caption = "鉅額交易成交量", CellWidth = 70, textAlignment = TextAlignment.MiddleRight, TextFormatString = "{0:#,##0}", HeaderFontSize = 9
                    },
                    new ReportProp {
                        DataColumn = "CP_M_QNTY", Caption = "造市者總成交量", CellWidth = 70, textAlignment = TextAlignment.MiddleRight, TextFormatString = "{0:#,##0}"
                    },
                    new ReportProp {
                        DataColumn = "CP_RATE_M", Caption = "總成交量市佔率(%)", CellWidth = 55, textAlignment = TextAlignment.MiddleRight, TextFormatString = "{0:##0.0#}", HeaderFontSize = 8f
                    },
                    new ReportProp {
                        DataColumn = "AMM0_VALID_CNT", Caption = "有效報價筆數", CellWidth = 60, textAlignment = TextAlignment.MiddleRight, TextFormatString = "{0:#,##0}", HeaderFontSize = 8f
                    },
                    new ReportProp {
                        DataColumn = "AMM0_MARKET_R_CNT", Caption = "全市場詢價筆數", CellWidth = 70, textAlignment = TextAlignment.MiddleRight, TextFormatString = "{0:#,##0}"
                    },
                    new ReportProp {
                        DataColumn = "AMM0_MARKET_M_QNTY", Caption = "全市場總成交量", CellWidth = 70, textAlignment = TextAlignment.MiddleRight, TextFormatString = "{0:#,##0}"
                    },
                    new ReportProp {
                        DataColumn = "CP_KEEP_TIME", Caption = "累計維持時間(分)", CellWidth = 65, textAlignment = TextAlignment.MiddleRight
                    }
                };

                //商品名稱會根據列印順序有所不同
                ReportProp productName = new ReportProp {
                    DataColumn = "AMM0_PROD_ID", Caption = "商品名稱", CellWidth = 100
                };
                if (_D500Xx.SortType == "P")
                {
                    caption.Insert(2, productName);//選擇商品,商品名稱會位於第三欄
                }
                else
                {
                    caption.Insert(5, productName);//選擇造勢者,商品名稱會位於第六欄
                }
                _Report = new defReport(_Data, caption);
            }

            ShowReport(_Report);

            _ToolBtnPrintAll.Enabled = true;
            _ToolBtnExport.Enabled   = true;
            return(ResultStatus.Success);
        }
Пример #18
0
        protected override ResultStatus Export()
        {
            try {
                this.Cursor = Cursors.WaitCursor;
                this.Refresh();
                Thread.Sleep(5);
                lblProcessing.Visible = true;
                ShowMsg("開始轉檔...");
                dao42030 = new D42030();
                #region ue_export_before
                //1. 判斷資料已轉入
                int    rtn;
                string ymd = txtSDate.Text.Replace("/", "");
                rtn = dao42030.mgr5Count(ymd);
                if (rtn == 0)
                {
                    DialogResult result = MessageDisplay.Choose(" 當日上市證券保證金適用比例資料未轉入完畢,是否要繼續?");
                    if (result == DialogResult.No)
                    {
                        ShowMsg("");
                        return(ResultStatus.Fail);
                    }
                }
                //2. 130批次作業做完
                string rtnStr;
                rtnStr = PbFunc.f_chk_130_wf(_ProgramID, txtSDate.DateTimeValue, "1");
                if (rtnStr != "")
                {
                    DialogResult result = MessageDisplay.Choose(txtSDate.Text + "-" + rtnStr + ",是否要繼續?");
                    if (result == DialogResult.No)
                    {
                        ShowMsg("");
                        return(ResultStatus.Fail);
                    }
                }
                #endregion

                string rptName, rptId, file;
                int    rowStart;
                rptName = "上市證券保證金概況表";
                rptId   = "42030";

                //1. 讀取資料(保證金適用比例級距)
                DataTable dt42030 = dao42030.d_42030(ymd);
                if (dt42030.Rows.Count == 0)
                {
                    MessageDisplay.Info(txtSDate.Text + "," + rptId + '-' + rptName + ",讀取「當日上市證券保證金適用比例」無任何資料!");
                    ShowMsg("");
                    return(ResultStatus.Fail);
                }

                //2. 複製檔案
                file = PbFunc.wf_copy_file(rptId, rptId);
                if (file == "")
                {
                    ShowMsg("");
                    return(ResultStatus.Fail);
                }

                //3. 開啟檔案
                Workbook workbook = new Workbook();
                workbook.LoadDocument(file);
                ShowMsg(rptId + '-' + rptName + " 轉檔中...");

                //4. 切換Sheet
                Worksheet ws42030 = workbook.Worksheets[0];
                ws42030.Cells[0, 0].Value = txtSDate.DateTimeValue.ToString("yyyy年MM月dd日") + ws42030.Cells[0, 0].Value;
                rowStart = 4;

                //5. 從A5開始放資料
                ws42030.Import(dt42030, false, rowStart, 0);

                //6. 刪除空白列
                int rowIndex = dt42030.Rows.Count;
                if (2000 > rowIndex)
                {
                    ws42030.Rows.Remove(rowIndex + rowStart, 2000 - rowIndex);
                }

                //7. 存檔
                ws42030.ScrollToRow(0);
                workbook.SaveDocument(file);
                ShowMsg("轉檔成功");
            }
            catch (Exception ex) {
                MessageDisplay.Error("輸出錯誤");
                ShowMsg("轉檔錯誤");
                throw ex;
            }
            finally {
                this.Cursor = Cursors.Arrow;
                this.Refresh();
                Thread.Sleep(5);
            }
            return(ResultStatus.Success);
        }
Пример #19
0
        //protected override ResultStatus Run(PokeBall args)
        //{
        //    this.BeginInvoke(new MethodInvoker(() => {
        //        args.GridControlMain = gcMain;
        //        args.GridControlSecond = gcLogsp;
        //        args.OcfDate = txtOcfDate.DateTimeValue;
        //        args.OcfType = OCF_TYPE;
        //    }));

        //    ResultStatus result = base.RunAsync(args);

        //    return result;
        //}

        /// <summary>
        /// 1系列功能使用
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        protected override ResultStatus Run(PokeBall args)
        {
            DateTime OcfDate = txtOcfDate.DateTimeValue;

            this.Invoke(new MethodInvoker(() => {
                FormWait formWait = new FormWait();

                SplashScreenManager.ShowForm(this, typeof(FormWait), true, true);

                //SplashScreenManager.ShowForm(this , typeof(FormWait) , true , true , SplashFormStartPosition.Manual , pointWait , ParentFormState.Locked);
            }));

            GridView gv = gvMain;


            DataTable dtLOGSPForRuned = servicePrefix1.ListLogspForRunned(OcfDate, _ProgramID, OCF_TYPE);
            DataView  dvLOGSPForRuned = new DataView(dtLOGSPForRuned);



            servicePrefix1.SetTXF1(" ", _ProgramID);

            for (int i = 0; i < gv.RowCount; i++)
            {
                string TXF_SERVER   = gv.GetRowCellValue(i, "TXF_SERVER").AsString();
                string TXF_DB       = gv.GetRowCellValue(i, "TXF_DB").AsString();
                string TXF_TXN_ID   = gv.GetRowCellValue(i, "TXF_TXN_ID").AsString();
                int    TXF_SEQ_NO   = gv.GetRowCellValue(i, "TXF_SEQ_NO").AsInt();
                string TXF_TYPE     = gv.GetRowCellValue(i, "TXF_TYPE").AsString();
                string TXF_TID      = gv.GetRowCellValue(i, "TXF_TID").AsString();
                string TXF_TID_NAME = gv.GetRowCellValue(i, "TXF_TID_NAME").AsString();
                string TXF_DESC     = gv.GetRowCellValue(i, "TXF_DESC").AsString();
                string TXF_DEFAULT  = gv.GetRowCellValue(i, "TXF_DEFAULT").AsString();
                string TXF_REDO     = gv.GetRowCellValue(i, "TXF_REDO").AsString();
                string TXF_ARG      = gv.GetRowCellValue(i, "TXF_ARG").AsString();
                string TXF_PERIOD   = gv.GetRowCellValue(i, "TXF_PERIOD").AsString();
                string TXF_SERVICE  = gv.GetRowCellValue(i, "TXF_SERVICE").AsString();
                string TXF_FOLDER   = gv.GetRowCellValue(i, "TXF_FOLDER").AsString();
                string TXF_AP_NAME  = gv.GetRowCellValue(i, "TXF_AP_NAME").AsString();
                args.TXF_TID      = TXF_TID;
                args.TXF_TID_NAME = TXF_TID_NAME;

                if (TXF_DEFAULT == "1")
                {
                    DateTime LOGSP_DATE       = OcfDate;
                    string   LOGSP_TXN_ID     = _ProgramID;
                    int      LOGSP_SEQ_NO     = TXF_SEQ_NO;
                    string   LOGSP_TID        = TXF_DESC;
                    string   LOGSP_TID_NAME   = TXF_TID_NAME;
                    DateTime LOGSP_BEGIN_TIME = new DateTime();
                    DateTime LOGSP_END_TIME   = new DateTime();
                    string   LOGSP_MSG        = "";


                    //判斷是否可重覆執行
                    if (TXF_REDO == "N")
                    {
                        dvLOGSPForRuned.RowFilter = "LOGSP_TID='" + LOGSP_TID + "' AND NOT ISNULL(LOGSP_BEGIN_TIME)";
                        if (dvLOGSPForRuned.Count != 0)
                        {
                            if (MessageDisplay.Choose(TXF_TID + " ★★★曾經執行過且不可重覆執行,是否強迫繼續執行 ?") == DialogResult.No)
                            {
                                return(ResultStatus.Fail);
                            }
                        }
                    }


                    #region 開始執行
                    LOGSP_BEGIN_TIME = DateTime.Now;

                    string nextYmd = PbFunc.f_ocf_date(2, _DB_TYPE);
                    if (!string.IsNullOrEmpty(TXF_PERIOD))
                    {
                        switch (TXF_PERIOD)
                        {
                        case "M":    //月底執行
                            if (OcfDate.ToString("yyyyMM") == PbFunc.Left(nextYmd, 6))
                            {
                                LOGSP_MSG = "完成! (今日非月底,不需執行)";
                                this.Invoke(new MethodInvoker(() => { gv.SetRowCellValue(i, "TXF_DEFAULT", 0); }));
                            }
                            break;

                        case "W":    //週最後一天執行
                            if (Convert.ToInt32(OcfDate.DayOfWeek) < Convert.ToInt32(nextYmd.AsDateTime("yyyyMMdd").DayOfWeek))
                            {
                                LOGSP_MSG = "完成! (今日非本週最後1天,不需執行)";
                                this.Invoke(new MethodInvoker(() => { gv.SetRowCellValue(i, "TXF_DEFAULT", 0); }));
                            }
                            break;

                        case "Y":    //年底執行
                            if (OcfDate.ToString("yyyy") == PbFunc.Left(nextYmd, 4))
                            {
                                LOGSP_MSG = "完成! (今日非本年度最後1日,不需執行)";
                                this.Invoke(new MethodInvoker(() => { gv.SetRowCellValue(i, "TXF_DEFAULT", 0); }));
                            }
                            break;
                        }
                        LOGSP_END_TIME = DateTime.Now;

                        servicePrefix1.SaveLogsp(LOGSP_DATE, LOGSP_TXN_ID, LOGSP_SEQ_NO, LOGSP_TID, LOGSP_TID_NAME, LOGSP_BEGIN_TIME, LOGSP_END_TIME, LOGSP_MSG, OCF_TYPE);
                        continue;
                    }


                    //開始前執行特別的Function
                    string rtnText = RunBeforeEveryItem(args);
                    if (!string.IsNullOrEmpty(rtnText))
                    {
                        if (PbFunc.Left(rtnText, 4) == "不需執行")
                        {
                            LOGSP_MSG = "完成! (" + rtnText + ")";
                            gv.SetRowCellValue(i, "ERR_MSG", LOGSP_MSG);
                            gv.SetRowCellValue(i, "TXF_DEFAULT", 0);
                            LOGSP_END_TIME = DateTime.Now;

                            servicePrefix1.SaveLogsp(LOGSP_DATE, LOGSP_TXN_ID, LOGSP_SEQ_NO, LOGSP_TID, LOGSP_TID_NAME, LOGSP_BEGIN_TIME, LOGSP_END_TIME, LOGSP_MSG, OCF_TYPE);
                        }
                        else
                        {
                            if (MessageDisplay.Choose($"{rtnText}是否強迫繼續執行?", MessageBoxDefaultButton.Button2).AsInt() == 2)
                            {
                                gv.SetRowCellValue(i, "ERR_MSG", rtnText);
                                continue;
                            }
                        }
                    }

                    //記錄正在執行
                    servicePrefix1.SetTXF1(TXF_TID, _ProgramID);

                    servicePrefix1.SaveLogs(LOGSP_DATE, TXF_TID, DateTime.Now, GlobalInfo.USER_ID, "開始執行");

                    ResultData resultData = new ResultData();
                    string     fileName   = "";
                    switch (TXF_TYPE)
                    {
                    //Informatica
                    case "I":
                        fileName   = $@"{GlobalInfo.DEFAULT_BATCH_ErrSP_DIRECTORY_PATH}\{TXF_SERVER}_{TXF_TXN_ID}_{TXF_SEQ_NO}_infor";
                        resultData = serviceCommon.ExecuteInfoWorkFlow(TXF_TID, UserProgInfo, TXF_FOLDER, TXF_SERVICE, TXF_AP_NAME, fileName);
                        break;

                    //SP
                    case "S":
                        List <DbParameterEx> listParams = null;

                        // 如果這個SP有參數的話
                        if (TXF_ARG == "Y")
                        {
                            DataTable dtTXFPARM = serviceCommon.ListTXFPARM(TXF_SERVER, TXF_DB, TXF_TXN_ID, TXF_TID);

                            if (dtTXFPARM.Rows.Count > 0)
                            {
                                listParams = new List <DbParameterEx>();
                            }

                            foreach (DataRow row in dtTXFPARM.Rows)
                            {
                                string TXFPARM_ARG      = row["TXFPARM_ARG"].AsString();
                                string TXFPARM_ARG_TYPE = row["TXFPARM_ARG_TYPE"].AsString();
                                string TXFPARM_DEFAULT  = row["TXFPARM_DEFAULT"].AsString();

                                DbParameterEx paramEx;

                                switch (TXFPARM_ARG)
                                {
                                case "":
                                    paramEx = new DbParameterEx("", TXFPARM_DEFAULT);
                                    listParams.Add(paramEx);
                                    break;

                                case "em_ymd":
                                    paramEx = new DbParameterEx("", OcfDate.ToString("yyyyMMdd"));
                                    listParams.Add(paramEx);
                                    break;

                                case "em_ym":
                                    paramEx = new DbParameterEx("", OcfDate.ToString("yyyyMM"));
                                    listParams.Add(paramEx);
                                    break;

                                case "em_date":
                                    paramEx        = new DbParameterEx();
                                    paramEx.DbType = DbTypeEx.Date;
                                    paramEx.Name   = "";
                                    paramEx.Value  = OcfDate;
                                    listParams.Add(paramEx);
                                    break;

                                default:
                                    break;
                                }
                            }
                        }

                        ConnectionInfo connectionInfo = SettingDragons.Instance.GetConnectionInfo(TXF_DB);

                        try
                        {
                            resultData = serviceCommon.ExecuteStoredProcedure(connectionInfo, string.Format("{0}.{1}", TXF_DB, TXF_TID), listParams, true);
                        }
                        catch (Exception ex)
                        {
                            resultData.Status = ResultStatus.Fail;
                            string msg =
                                fileName = $@"{GlobalInfo.DEFAULT_BATCH_ErrSP_DIRECTORY_PATH}\{TXF_SERVER}_{TXF_TXN_ID}_{TXF_SEQ_NO}.err";
                            System.IO.File.WriteAllText(fileName, ex.Message);
                            resultData.returnString = $"請通知「{TXF_AP_NAME}」 作業執行失敗!\n{ex.Message}";
                        }

                        break;

                    //視窗功能
                    case "W":
                        this.Invoke(new MethodInvoker(() => { resultData = ExecuteForm(args); }));

                        break;

                    default:
                        break;
                    }

                    LOGSP_END_TIME = DateTime.Now;

                    if (resultData.Status == ResultStatus.Success)
                    {
                        LOGSP_MSG = "執行正常完成!";
                    }
                    else
                    {
                        LOGSP_MSG = "作業執行失敗!";

                        servicePrefix1.SaveLogsp(LOGSP_DATE, LOGSP_TXN_ID, LOGSP_SEQ_NO, LOGSP_TID, LOGSP_TID_NAME, LOGSP_BEGIN_TIME, LOGSP_END_TIME, LOGSP_MSG, OCF_TYPE);

                        //MessageDisplay.Error("序號" + LOGSP_SEQ_NO + "的" + LOGSP_TID + "," + LOGSP_MSG);
                        MessageDisplay.Error(resultData.returnString);

                        this.Invoke(new MethodInvoker(() => {
                            SplashScreenManager.CloseForm();
                            gv.SetRowCellValue(i, "ERR_MSG", LOGSP_MSG);
                        }));

                        return(ResultStatus.Fail);
                    }

                    this.Invoke(new MethodInvoker(() => { gv.SetRowCellValue(i, "ERR_MSG", LOGSP_MSG); }));

                    servicePrefix1.SaveLogsp(LOGSP_DATE, LOGSP_TXN_ID, LOGSP_SEQ_NO, LOGSP_TID, LOGSP_TID_NAME, LOGSP_BEGIN_TIME, LOGSP_END_TIME, LOGSP_MSG, OCF_TYPE);
                    servicePrefix1.SaveLogs(LOGSP_DATE, TXF_TID, DateTime.Now, GlobalInfo.USER_ID, "執行完畢");

                    #endregion 開始執行


                    #region 執行特別的程式


                    this.Invoke(new MethodInvoker(() => {
                        gv.SetRowCellValue(i, "TXF_DEFAULT", 0);
                        RunAfterEveryItem(args);
                    }));

                    #endregion 執行特別的程式

                    //流程時間控制
                    DataTable dtJRF = servicePrefix1.ListJrf(_ProgramID, TXF_TID);
                    if (dtJRF.Rows.Count > 0)
                    {
                        string JRF_DO_TXN_ID   = dtJRF.Rows[0]["JRF_DO_TXN_ID"].AsString();
                        string JRF_DO_JOB_TYPE = dtJRF.Rows[0]["JRF_DO_TXN_ID"].AsString();
                        string JRF_DO_SEQ_NO   = dtJRF.Rows[0]["JRF_DO_TXN_ID"].AsString();
                        string JRF_SW_CODE     = dtJRF.Rows[0]["JRF_DO_TXN_ID"].AsString();
                        servicePrefix1.UpdateJsw(JRF_DO_TXN_ID, JRF_DO_JOB_TYPE, JRF_DO_SEQ_NO, JRF_SW_CODE, OcfDate, DateTime.Now, GlobalInfo.USER_ID);
                    }
                }
                else
                {
                    // 沒勾選項目的話清空狀態
                    this.Invoke(new MethodInvoker(() => { gv.SetRowCellValue(i, "ERR_MSG", ""); }));
                }
                if (i == gv.RowCount - 1 && OCF_TYPE == "D")
                {
                    servicePrefix1.setCIOCF();
                }
            }


            //全部結束
            servicePrefix1.SetTXF1(" ", _ProgramID);

            this.Invoke(new MethodInvoker(() => { SplashScreenManager.CloseForm(); }));

            return(ResultStatus.Success);
        }
Пример #20
0
        protected override ResultStatus Save(PokeBall pokeBall)
        {
            try
            {
                if (gvDetail.RowCount == 0)
                {
                    MessageDisplay.Info("沒有變更資料,不需要存檔!");
                    return(ResultStatus.Fail);
                }
                #region ue_save_before
                gvMain.CloseEditor();
                gvMain.UpdateCurrentRow();
                gvDetail.CloseEditor();
                gvDetail.UpdateCurrentRow();

                string   stockID, ymd, kindID, adjTypeName, opType, dbname, flag;
                string   issueBeginYmd, issueEndYmd, implBeginYmd, implEndYmd, pubYmd, tradeYmd, mocfYmd, nextYmd;
                int      found, count, row, col, currRow;
                decimal  ldblRate;
                DateTime ldtWTIME = DateTime.Now;

                DataTable dtGrid = (DataTable)gcDetail.DataSource;
                found = dtGrid.Rows.IndexOf(dtGrid.Select("OP_TYPE <> ' '").FirstOrDefault());
                if (found == -1)
                {
                    MessageDisplay.Warning("沒有變更資料,不需要存檔!");
                    return(ResultStatus.Fail);
                }

                if (dtGrid.Rows.Count == 0)
                {
                    MessageDisplay.Warning("無明細資料,請重新產生明細");
                    return(ResultStatus.FailButNext);
                }

                DataTable dtMGD2;                             //ids_mgd2
                DataTable dtMGD2Log = dao40071.d_40071_log(); //ids_old
                dtMGD2Log.Clear();                            //只取schema

                for (int f = 0; f < dtGrid.Rows.Count; f++)
                {
                    if (dtGrid.Rows[f].RowState == DataRowState.Deleted)
                    {
                        continue;
                    }
                    DataRow dr = dtGrid.Rows[f];
                    opType  = dr["OP_TYPE"].ToString();
                    flag    = dr["DATA_FLAG"].AsString();
                    stockID = dr["STOCK_ID"].AsString();

                    //檢查同一標的的級距是否一致
                    if ((f + 1) < dtGrid.Rows.Count)
                    {
                        if (stockID == dtGrid.Rows[f + 1]["STOCK_ID"].AsString() &&
                            dr["M_CUR_LEVEL"].AsString() != dtGrid.Rows[f + 1]["M_CUR_LEVEL"].AsString())
                        {
                            MessageDisplay.Error(stockID + "的級距不一致");
                            return(ResultStatus.FailButNext);
                        }
                    }

                    //檢查有異動的資料
                    if (opType != " ")
                    {
                        kindID        = dr["KIND_ID"].AsString();
                        ymd           = dr["YMD"].ToString();
                        issueBeginYmd = dr["ISSUE_BEGIN_YMD"].ToString();
                        //issueEndYmd = dr["ISSUE_END_YMD"].ToString(); by tom
                        //implBeginYmd = dr["IMPL_BEGIN_YMD"].ToString();
                        //implEndYmd = dr["IMPL_END_YMD"].ToString();
                        //pubYmd = dr["PUB_YMD"].ToString();
                        issueEndYmd  = dr["ISSUE_END_YMD"].AsString().Replace("/", "");
                        implBeginYmd = dr["IMPL_BEGIN_YMD"].AsString().Replace("/", "");
                        implEndYmd   = dr["IMPL_END_YMD"].AsString().Replace("/", "");
                        pubYmd       = dr["PUB_YMD"].AsString().Replace("/", "");

                        if (ymd != implBeginYmd)
                        {
                            DialogResult result = MessageDisplay.Choose(stockID + "," + kindID + "交易日不等於處置起日,請問是否更新");
                            if (result == DialogResult.No)
                            {
                                return(ResultStatus.FailButNext);
                            }
                        }
                        if (issueEndYmd != implEndYmd)
                        {
                            DialogResult result = MessageDisplay.Choose(stockID + "," + kindID + "生效迄日不等於處置迄日,請問是否更新");
                            if (result == DialogResult.No)
                            {
                                return(ResultStatus.FailButNext);
                            }
                        }

                        //處置期間首日+1個月
                        mocfYmd = PbFunc.relativedate(implBeginYmd.AsDateTime("yyyyMMdd"), 30).ToString("yyyyMMdd");

                        /*次一營業日*/
                        nextYmd = daoMOCF.GetNextTradeDay(implBeginYmd, mocfYmd);
                        if (issueBeginYmd != nextYmd)
                        {
                            DialogResult result = MessageDisplay.Choose(stockID + "," + kindID + "生效起日不等於處置起日之次一營業日,請問是否更新");
                            if (result == DialogResult.No)
                            {
                                return(ResultStatus.FailButNext);
                            }
                        }

                        dtMGD2 = dao40072.d_40072(ymd, isAdjType, stockID);

                        //資料修改,將修改前舊資料寫入log
                        if (opType == "U")
                        {
                            dtMGD2.Filter("mgd2_kind_id = '" + kindID + "'");
                            foreach (DataRow drU in dtMGD2.Rows)
                            {
                                currRow = dtMGD2Log.Rows.Count;
                                dtMGD2Log.Rows.Add();
                                for (col = 0; col < dtMGD2.Columns.Count; col++)
                                {
                                    //先取欄位名稱,因為兩張table欄位順序不一致
                                    dbname = dtMGD2.Columns[col].ColumnName;
                                    if (dbname == "CPSORT")
                                    {
                                        continue;                     //這個欄位是拿來排序用的,故無需複製
                                    }
                                    dtMGD2Log.Rows[currRow][dbname] = drU[col];
                                }
                                if (flag == "Y")
                                {
                                    dtMGD2Log.Rows[currRow]["MGD2_L_TYPE"] = "U";
                                }
                                if (flag == "N")
                                {
                                    dtMGD2Log.Rows[currRow]["MGD2_L_TYPE"] = "D";
                                }
                                dtMGD2Log.Rows[currRow]["MGD2_L_USER_ID"] = GlobalInfo.USER_ID;
                                dtMGD2Log.Rows[currRow]["MGD2_L_TIME"]    = ldtWTIME;
                            }
                        }

                        /******************************************
                        *  確認商品是否在同一交易日不同情境下設定過
                        ******************************************/
                        DataTable dtSet = dao40071.IsSetOnSameDay(kindID, ymd, isAdjType);
                        if (dtSet.Rows.Count == 0)
                        {
                            MessageDisplay.Info("MGD2 " + kindID + " 無任何資料!");
                            return(ResultStatus.FailButNext);
                        }
                        count       = dtSet.Rows[0]["LI_COUNT"].AsInt();
                        adjTypeName = dtSet.Rows[0]["LS_ADJ_TYPE_NAME"].AsString();
                        if (count > 0)
                        {
                            MessageDisplay.Error(kindID + ",交易日(" + ymd + ")在" + adjTypeName + "已有資料");
                            return(ResultStatus.FailButNext);
                        }

                        /*********************************
                         * 確認商品是否在同一生效日區間設定過
                         * 生效起日若與生效迄日相同,不重疊
                         * ex: 10/11的至10/31一般交易時段結束止,10/30的從10/31一般交易時段結束後始>>應不重疊
                         *************************************/
                        dtSet       = dao40071.IsSetInSameSession(kindID, ymd, issueBeginYmd, issueEndYmd);
                        count       = dtSet.Rows[0]["LI_COUNT"].AsInt();
                        adjTypeName = dtSet.Rows[0]["LS_ADJ_TYPE_NAME"].AsString();
                        tradeYmd    = dtSet.Rows[0]["LS_TRADE_YMD"].AsString();
                        if (count > 0)
                        {
                            MessageDisplay.Error(kindID + "," + adjTypeName + ",交易日(" + tradeYmd + ")在同一生效日區間內已有資料");
                            return(ResultStatus.FailButNext);
                        }

                        //判斷調整幅度是否為0
                        //ldblRate = dr["ADJ_RATE"].AsDecimal(); by tom
                        ldblRate = dr["ADJ_RATE"].AsDecimal() - 1;
                        if (ldblRate == 0)
                        {
                            MessageDisplay.Error("商品調整幅度不可為0");
                            return(ResultStatus.FailButNext);
                        }
                    } //if (ls_op_type != " ")
                }     //for (int f = 0; f < dtGrid.Rows.Count; f++)
                #endregion
                string prodType;

                DataTable dtTemp = dao40072.d_40072(); //ids_tmp
                foreach (DataRow dr in dtGrid.Rows)
                {
                    if (dr.RowState == DataRowState.Deleted)
                    {
                        continue;
                    }
                    opType = dr["OP_TYPE"].ToString();
                    //只更新有異動的資料
                    if (opType != " ")
                    {
                        kindID        = dr["KIND_ID"].AsString();
                        stockID       = dr["STOCK_ID"].AsString();
                        issueBeginYmd = dr["ISSUE_BEGIN_YMD"].ToString();
                        //issueEndYmd = dr["ISSUE_END_YMD"].ToString(); by tom
                        //implBeginYmd = dr["IMPL_BEGIN_YMD"].ToString();
                        //implEndYmd = dr["IMPL_END_YMD"].ToString();
                        //pubYmd = dr["PUB_YMD"].ToString();
                        issueEndYmd  = dr["ISSUE_END_YMD"].AsString().Replace("/", "");
                        implBeginYmd = dr["IMPL_BEGIN_YMD"].AsString().Replace("/", "");
                        implEndYmd   = dr["IMPL_END_YMD"].AsString().Replace("/", "");
                        pubYmd       = dr["PUB_YMD"].AsString().Replace("/", "");
                        ymd          = dr["YMD"].ToString();
                        //ldblRate = dr["ADJ_RATE"].AsDecimal();
                        ldblRate = dr["ADJ_RATE"].AsDecimal() - 1;

                        //刪除已存在資料
                        if (daoMGD2.DeleteMGD2(ymd, isAdjType, stockID, kindID) < 0)
                        {
                            MessageDisplay.Error("MGD2資料刪除失敗");
                            return(ResultStatus.FailButNext);
                        }

                        if (dr["DATA_FLAG"].AsString() == "Y")
                        {
                            currRow  = dtTemp.Rows.Count;
                            prodType = dr["PROD_TYPE"].AsString();
                            dtTemp.Rows.Add();
                            dtTemp.Rows[currRow]["MGD2_YMD"]       = ymd;
                            dtTemp.Rows[currRow]["MGD2_PROD_TYPE"] = prodType;
                            dtTemp.Rows[currRow]["MGD2_KIND_ID"]   = kindID;
                            dtTemp.Rows[currRow]["MGD2_STOCK_ID"]  = stockID;
                            dtTemp.Rows[currRow]["MGD2_ADJ_TYPE"]  = isAdjType;

                            dtTemp.Rows[currRow]["MGD2_ADJ_RATE"]        = ldblRate;
                            dtTemp.Rows[currRow]["MGD2_ADJ_CODE"]        = "Y";
                            dtTemp.Rows[currRow]["MGD2_ISSUE_BEGIN_YMD"] = issueBeginYmd;
                            dtTemp.Rows[currRow]["MGD2_ISSUE_END_YMD"]   = issueEndYmd;
                            dtTemp.Rows[currRow]["MGD2_IMPL_BEGIN_YMD"]  = implBeginYmd;

                            dtTemp.Rows[currRow]["MGD2_IMPL_END_YMD"] = implEndYmd;
                            dtTemp.Rows[currRow]["MGD2_PUB_YMD"]      = pubYmd;
                            dtTemp.Rows[currRow]["MGD2_PROD_SUBTYPE"] = dr["PROD_SUBTYPE"];
                            dtTemp.Rows[currRow]["MGD2_PARAM_KEY"]    = dr["PARAM_KEY"];
                            dtTemp.Rows[currRow]["MGD2_CUR_CM"]       = dr["CM_CUR_A"];

                            dtTemp.Rows[currRow]["MGD2_CUR_MM"]    = dr["MM_CUR_A"];
                            dtTemp.Rows[currRow]["MGD2_CUR_IM"]    = dr["IM_CUR_A"];
                            dtTemp.Rows[currRow]["MGD2_CUR_LEVEL"] = dr["M_CUR_LEVEL"];
                            dtTemp.Rows[currRow]["MGD2_CM"]        = dr["CM_A"];
                            dtTemp.Rows[currRow]["MGD2_MM"]        = dr["MM_A"];

                            dtTemp.Rows[currRow]["MGD2_IM"]            = dr["IM_A"];
                            dtTemp.Rows[currRow]["MGD2_CURRENCY_TYPE"] = dr["CURRENCY_TYPE"];
                            dtTemp.Rows[currRow]["MGD2_SEQ_NO"]        = dr["SEQ_NO"];
                            dtTemp.Rows[currRow]["MGD2_OSW_GRP"]       = dr["OSW_GRP"];
                            dtTemp.Rows[currRow]["MGD2_AMT_TYPE"]      = dr["AMT_TYPE"];

                            dtTemp.Rows[currRow]["MGD2_W_TIME"]    = ldtWTIME;
                            dtTemp.Rows[currRow]["MGD2_W_USER_ID"] = GlobalInfo.USER_ID;

                            /******************************
                             *    AB TYTPE:	-期貨
                             *                A選擇權A值
                             *                B選擇權B值
                             *******************************/
                            if (prodType == "F")
                            {
                                dtTemp.Rows[currRow]["MGD2_AB_TYPE"] = "-";
                            }
                            else
                            {
                                dtTemp.Rows[currRow]["MGD2_AB_TYPE"] = "A";
                                //複製一筆一樣的,AB Type分開存
                                dtTemp.ImportRow(dtTemp.Rows[currRow]);
                                //dtTemp.Rows.Add(dtTemp.Rows[ii_curr_row]);//會跳錯
                                currRow = dtTemp.Rows.Count - 1;
                                dtTemp.Rows[currRow]["MGD2_AB_TYPE"] = "B";
                                dtTemp.Rows[currRow]["MGD2_CUR_CM"]  = dr["CM_CUR_B"];
                                dtTemp.Rows[currRow]["MGD2_CUR_MM"]  = dr["MM_CUR_B"];
                                dtTemp.Rows[currRow]["MGD2_CUR_IM"]  = dr["IM_CUR_B"];
                                dtTemp.Rows[currRow]["MGD2_CM"]      = dr["CM_B"];

                                dtTemp.Rows[currRow]["MGD2_MM"] = dr["MM_B"];
                                dtTemp.Rows[currRow]["MGD2_IM"] = dr["IM_B"];
                            }
                        } //if (dr["DATA_FLAG"].AsString()=="Y")
                    }     //if (ls_op_type != " ")
                }         //foreach (DataRow dr in dtGrid.Rows)

                //Update DB
                //ids_tmp.update()
                if (dtTemp.Rows.Count > 0)
                {
                    ResultData myResultData = daoMGD2.UpdateMGD2(dtTemp);
                    if (myResultData.Status == ResultStatus.Fail)
                    {
                        MessageDisplay.Error("更新資料庫MGD2錯誤! ");
                        return(ResultStatus.FailButNext);
                    }
                }
                //ids_old.update()
                if (dtMGD2Log.Rows.Count > 0)
                {
                    ResultData myResultData = daoMGD2L.UpdateMGD2L(dtMGD2Log);
                    if (myResultData.Status == ResultStatus.Fail)
                    {
                        MessageDisplay.Error("更新資料庫MGD2L錯誤! ");
                        return(ResultStatus.FailButNext);
                    }
                }
                //Write LOGF
                WriteLog("變更資料 ", "Info", "I");
                //報表儲存pdf
                ReportHelper            _ReportHelper   = new ReportHelper(gcDetail, _ProgramID, this.Text);
                CommonReportLandscapeA3 reportLandscape = new CommonReportLandscapeA3();//設定為橫向列印
                reportLandscape.printableComponentContainerMain.PrintableComponent = gcDetail;
                reportLandscape.IsHandlePersonVisible = false;
                reportLandscape.IsManagerVisible      = false;
                _ReportHelper.Create(reportLandscape);
                _ReportHelper.Export(FileType.PDF, _ReportHelper.FilePath);
                MessageDisplay.Info("報表儲存完成!");
            }
            catch (Exception ex)
            {
                MessageDisplay.Error("儲存錯誤");
                throw ex;
            }
            return(ResultStatus.Success);
        }
Пример #21
0
        /// <summary>
        /// 顯示明細
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDetail_Click(object sender, EventArgs e)
        {
            try
            {
                //重設gridview
                gcDetail.DataSource = null;

                int     row, col, found;
                string  prodType, prodTypeName, kindID, stockID, paramKey, abroad, implBeginYmd, issueBeginYmd, mocfYmd;
                string  opType;
                decimal ldcRate;
                gvMain.CloseEditor();
                gvMain.UpdateCurrentRow();

                DataTable dtGrid = dao40071.d_40071_detail(); //ids_tmp 空的,拿來重置gcDetail
                dtGrid.Columns["ADJ_TYPE"].ColumnName = "OP_TYPE";
                dtGrid.Columns["DATA_YMD"].ColumnName = "YMD";
                //dtTemp.Columns["CM_A * NVL(MGT6_REF_XXX,1)"].ColumnName = "CM_A"; 沒成功撈到資料的話欄位名稱不會變?
                DataTable dtMGD2 = dao40072.d_40072(); //ids_mgd2 空的

                txtSDate.Text = "1901/01/01";
                prodType      = "S";
                paramKey      = "ST%";
                abroad        = "%";
                kindID        = "%";

                //產生明細檔
                DataTable dtInput = (DataTable)gcMain.DataSource;
                foreach (DataRow drInput in dtInput.Rows)
                {
                    opType       = "I";
                    stockID      = drInput["STOCK_ID"].ToString();
                    implBeginYmd = drInput["IMPL_BEGIN_YMD"].ToString();

                    //交易日為處置期間之首日
                    drInput["YMD"] = implBeginYmd.Replace("/", "").AsString();
                    implBeginYmd   = implBeginYmd.Replace("/", "").AsString();
                    dtMGD2         = dao40072.d_40072(drInput["YMD"].AsDateTime().ToString("yyyyMMdd"), isAdjType, stockID);
                    if (dtMGD2.Rows.Count > 0)
                    {
                        DialogResult result = MessageDisplay.Choose(stockID + "資料已存在,是否重新產製資料,若不重產資料,請按「預覽」!");
                        if (result == DialogResult.No)
                        {
                            return;
                        }
                        opType = "U";
                    }

                    //處置期間首日+1個月

                    DateTime tmp = DateTime.ParseExact(implBeginYmd, "yyyyMMdd", null);
                    mocfYmd = PbFunc.relativedate(tmp, 30).ToString("yyyyMMdd");
                    /*次一營業日*/
                    //implBeginYmd = implBeginYmd.AsDateTime().ToString("yyyyMMdd");
                    issueBeginYmd = daoMOCF.GetNextTradeDay(implBeginYmd, mocfYmd);

                    //終止生效日為處置期間迄日
                    drInput["ISSUE_END_YMD"] = drInput["IMPL_END_YMD"];
                    //開始生效日為處置期間首日之次一個營業日
                    drInput["ISSUE_BEGIN_YMD"] = issueBeginYmd;

                    //判斷是否有空值
                    for (col = 0; col < dtInput.Columns.Count; col++)
                    {
                        if (dtInput.Columns[col].ColumnName == "CPSORT")
                        {
                            continue;                                              //這欄是排序用的毋須判斷
                        }
                        if (drInput[col] == DBNull.Value || drInput[col].ToString() == "")
                        {
                            MessageDisplay.Warning("請確認資料是否輸入完成!");
                            return;
                        }
                    }
                    stockID = stockID + "%";

                    //調整倍數(計算用1+調整倍數)
                    ldcRate = drInput["RATE"].AsDecimal() - 1;

                    //這邊才去讀SP
                    DataTable dtTemp = dao40071.d_40071_detail(implBeginYmd, prodType, paramKey, abroad, kindID, stockID, ldcRate);
                    dtTemp.Columns["ADJ_TYPE"].ColumnName = "OP_TYPE";
                    dtTemp.Columns["DATA_YMD"].ColumnName = "YMD";
                    if (dtTemp.Columns["CM_A*NVL(MGT6_REF_XXX,1)"] != null)
                    {
                        dtTemp.Columns["CM_A*NVL(MGT6_REF_XXX,1)"].ColumnName = "CM_A";                                                     //沒撈到值的話欄位名稱不會變,若資料為個股類也不會變
                    }
                    foreach (DataRow drTemp in dtTemp.Rows)
                    {
                        drTemp["ISSUE_BEGIN_YMD"] = issueBeginYmd;
                        drTemp["ISSUE_END_YMD"]   = drInput["impl_end_ymd"];
                        drTemp["IMPL_BEGIN_YMD"]  = implBeginYmd;
                        drTemp["IMPL_END_YMD"]    = drInput["impl_end_ymd"];
                        drTemp["PUB_YMD"]         = drInput["pub_ymd"];
                        drTemp["YMD"]             = implBeginYmd;
                        drTemp["OP_TYPE"]         = opType;
                        drTemp["ADJ_RATE"]        = drInput["RATE"];
                    }

                    //將資料複製到明細表
                    //dtGrid = dtTemp.Clone();
                    foreach (DataRow drTemp in dtTemp.Rows)
                    {
                        dtGrid.ImportRow(drTemp);
                    }
                    dtGrid.AcceptChanges();
                    gcDetail.DataSource = dtGrid;
                }//foreach (DataRow drInput in dtInput.Rows)

                //sort("stock_id A prod_type A ")
                if (dtGrid.Rows.Count != 0)
                {
                    dtGrid = dtGrid.AsEnumerable().OrderBy(x => x.Field <string>("STOCK_ID"))
                             .ThenBy(x => x.Field <string>("PROD_TYPE"))
                             .CopyToDataTable();
                }
                gcDetail.DataSource = dtGrid;

                if (gvDetail.RowCount == 0)
                {
                    MessageDisplay.Warning("無明細資料,請確認「交易日期」及「商品調整幅度」是否填寫正確!");
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageDisplay.Error("顯示明細錯誤");
                throw ex;
            }
        }
Пример #22
0
        protected override ResultStatus Save(PokeBall poke)
        {
            gvMain.CloseEditor();
            gvMain.UpdateCurrentRow();

            DataTable dt       = (DataTable)gcMain.DataSource;
            DataTable dtChange = dt.GetChanges();

            //存檔前檢查
            try {
                //無法經由資料列存取已刪除的資料列資訊。
                if (dtChange != null)
                {
                    //if (dt.Rows.Count <= 0) {
                    //   MessageDisplay.Warning("下方視窗無資料無法進行存檔,請先執行「讀取/預覽」!");
                    //   ShowMsg("轉檔有誤!");
                    //   return ResultStatus.Fail;
                    //}

                    //重新產置資料儲存確認
                    string isYMD     = YMDlookUpEdit.EditValue.ToString();
                    int    dataCount = b30290.DataCount(isYMD);

                    if (dataCount > 0)
                    {
                        DialogResult ChooseResult = MessageDisplay.Choose("已存在相同生效日期資料,請問是否繼續儲存?");
                        if (ChooseResult == DialogResult.Yes)
                        {
                            if (retrieveChoose == DialogResult.No) //一開始讀取資料按「否」重新產至資料
                            {
                                if (!b30290.DeleteData(isYMD))     //刪除已有的資料
                                {
                                    return(ResultStatus.Fail);
                                }
                            }
                        }
                    }

                    //變更儲存日期以及USER_ID
                    foreach (DataRow dr in dt.Rows)
                    {
                        if (dr.RowState != DataRowState.Deleted)
                        {
                            dr["PLP13_W_TIME"]    = DateTime.Now;
                            dr["PLP13_W_USER_ID"] = GlobalInfo.USER_ID;
                        }
                    }
                }
                if (dtChange != null)
                {
                    try {
                        dtChange    = dt.GetChanges();
                        this.Cursor = Cursors.WaitCursor;
                        ShowMsg("存檔中...");
                        //儲存PLP13
                        ResultData myResultData = b30290.UpdateData(dtChange);
                        //初始訊息選擇狀態
                        retrieveChoose = DialogResult.None;
                    }
                    catch (Exception ex) {
                        WriteLog(ex);
                    }
                    //Write LOGF
                    WriteLog("變更資料 " + logtxt, "Info", "I", false);
                    return(ResultStatus.Success);
                }
                else
                {
                    MessageBox.Show("沒有變更資料,不需要存檔!", "注意", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            catch (Exception ex) {
                WriteLog(ex);
            }
            finally {
                Export();//存檔後轉出Excel
            }

            return(ResultStatus.Success);
        }
Пример #23
0
        /// <summary>
        /// 顯示明細
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDetail_Click(object sender, EventArgs e)
        {
            //重設gridview
            gcDetail.DataSource = null;

            int    row, col, found;
            string prodType, kindID, stockID, issueBeginYmd, ymd, paramKey, abroad;
            string opType, colname;

            gvMain.CloseEditor();
            gvMain.UpdateCurrentRow();


            DataTable dtGrid = dao40071.d_40071_detail(); //ids_tmp 空的,拿來重置gcDetail

            dtGrid.Columns["ADJ_TYPE"].ColumnName = "OP_TYPE";
            dtGrid.Columns["DATA_YMD"].ColumnName = "YMD";
            //dtTemp.Columns["CM_A * NVL(MGT6_REF_XXX,1)"].ColumnName = "CM_A"; 沒成功撈到資料的話欄位名稱不會變?
            DataTable dtMGD2 = dao40072.d_40072(); //ids_mgd2 空的

            prodType      = "S";
            paramKey      = "ST%";
            abroad        = "%";
            kindID        = "%";
            this.ymd      = txtSDate.DateTimeValue.ToString("yyyyMMdd");
            issueBeginYmd = txtEffectiveSDate.DateTimeValue.ToString("yyyyMMdd");

            //產生明細檔
            DataTable dtInput = (DataTable)gcMain.DataSource;

            if (dtInput.Columns[dtInput.Columns.Count - 1].ColumnName == "CPSORT")
            {
                dtInput.Columns.Remove(dtInput.Columns["CPSORT"]);                                                                //把拿來排序的運算欄位刪掉
            }
            foreach (DataRow drInput in dtInput.Rows)
            {
                opType  = "I";
                stockID = drInput["STOCK_ID"].ToString();

                dtMGD2 = dao40072.d_40072(this.ymd, isAdjType, stockID);
                if (dtMGD2.Rows.Count > 0)
                {
                    DialogResult result = MessageDisplay.Choose(stockID + "資料已存在,是否重新產製資料,若不重產資料,請按「預覽」!");
                    if (result == DialogResult.No)
                    {
                        return;
                    }
                    opType = "U";
                }

                for (col = 0; col < dtInput.Columns.Count; col++)
                {
                    colname = dtInput.Columns[col].ColumnName;
                    //級距為從其高,保證金B值可不填
                    if (drInput["M_LEVEL"].AsString() == "Z" && colname.IndexOf("_B") >= 0)
                    {
                        continue;
                    }
                    if (drInput[col] == DBNull.Value || drInput[col].ToString() == "")
                    {
                        MessageDisplay.Error("請確認資料是否輸入完成!");
                        return;
                    }
                }

                stockID = stockID + "%";

                //調整幅度=0
                //這邊才去讀SP
                DataTable dtTemp = dao40071.d_40071_detail(this.ymd, prodType, paramKey, abroad, kindID, stockID, 0);
                dtTemp.Columns["ADJ_TYPE"].ColumnName = "OP_TYPE";
                dtTemp.Columns["DATA_YMD"].ColumnName = "YMD";
                if (dtTemp.Columns["CM_A*NVL(MGT6_REF_XXX,1)"] != null)
                {
                    dtTemp.Columns["CM_A*NVL(MGT6_REF_XXX,1)"].ColumnName = "CM_A";                                                 //沒撈到值的話欄位名稱不會變,若資料為個股類也不會變
                }
                foreach (DataRow drTemp in dtTemp.Rows)
                {
                    drTemp["ISSUE_BEGIN_YMD"] = issueBeginYmd;
                    drTemp["YMD"]             = this.ymd;
                    drTemp["M_LEVEL"]         = drInput["M_LEVEL"];
                    drTemp["CM_A"]            = drInput["CM_A"];
                    drTemp["MM_A"]            = drInput["MM_A"];
                    drTemp["IM_A"]            = drInput["IM_A"];
                    if (drTemp["CM_B"] != DBNull.Value)
                    {
                        drTemp["CM_B"] = drInput["CM_B"];
                    }
                    if (drTemp["MM_B"] != DBNull.Value)
                    {
                        drTemp["MM_B"] = drInput["MM_B"];
                    }
                    if (drTemp["IM_B"] != DBNull.Value)
                    {
                        drTemp["IM_B"] = drInput["IM_B"];
                    }
                    drTemp["ADJ_RSN"] = drInput["ADJ_RSN"];
                    drTemp["OP_TYPE"] = opType;
                }

                //將資料複製到明細表
                //dtGrid = dtTemp.Clone();
                foreach (DataRow drTemp in dtTemp.Rows)
                {
                    dtGrid.ImportRow(drTemp);
                }
                dtGrid.AcceptChanges();
                gcDetail.DataSource = dtGrid;
            }//foreach (DataRow drInput in dtInput.Rows)

            //sort("stock_id A prod_type A ")
            if (dtGrid.Rows.Count != 0)
            {
                dtGrid = dtGrid.AsEnumerable().OrderBy(x => x.Field <string>("STOCK_ID"))
                         .ThenBy(x => x.Field <string>("PROD_TYPE"))
                         .CopyToDataTable();
            }
            gcDetail.DataSource = dtGrid;

            if (gvDetail.RowCount == 0)
            {
                MessageDisplay.Warning("無明細資料,請確認「交易日期」及「商品調整幅度」是否填寫正確!");
                return;
            }
        }
Пример #24
0
        /// <summary>
        /// 按下[匯出]按鈕時
        /// </summary>
        /// <returns></returns>
        protected override ResultStatus Export()
        {
            //1.check
            if (gvKind.DataRowCount <= 0)
            {
                MessageDisplay.Normal("選擇的日期必須有契約資訊,請重新選擇日期");
                return(ResultStatus.Fail);
            }

            //1.1檢查最少必須勾選一筆商品
            gvDate.CloseEditor();      //ken,一定要先呼叫這兩個函數,最後點選的那筆才會被記錄起來
            gvDate.UpdateCurrentRow(); //ken,一定要先呼叫這兩個函數,最後點選的那筆才會被記錄起來
            gvKind.CloseEditor();      //ken,一定要先呼叫這兩個函數,最後點選的那筆才會被記錄起來
            gvKind.UpdateCurrentRow(); //ken,一定要先呼叫這兩個函數,最後點選的那筆才會被記錄起來
            DataTable dtTemp   = (DataTable)gcKind.DataSource;
            bool      haveKind = false;

            foreach (DataRow drKind in dtTemp.Rows)
            {
                if (drKind["CPR_SELECT"].AsString() == "Y")
                {
                    haveKind = true;
                    break;
                }
            }

            if (!haveKind)
            {
                MessageDisplay.Normal("必須勾選一筆契約");
                return(ResultStatus.Fail);
            }

            if (chkModel.CheckedItemsCount < 1)
            {
                MessageDisplay.Error("請至少勾選一種指標種類", GlobalInfo.ErrorText);
                return(ResultStatus.Fail);
            }

            //1.2檢查統計資料是否已經轉入完畢
            string FinishedJob = PbFunc.f_get_jsw(_ProgramID, "E", txtEndDate.Text);

            if (FinishedJob != "Y")
            {
                DialogResult chooseResult = MessageDisplay.Choose(string.Format("{0} 統計資料未轉入完畢,是否要繼續?", txtEndDate.Text), MessageBoxDefaultButton.Button2, GlobalInfo.QuestionText);
                if (chooseResult != DialogResult.Yes)
                {
                    return(ResultStatus.Fail);
                }
            }

            try {
                //2.開始轉出資料
                panFilter.Enabled = panSecond.Enabled = false;
                labMsg.Visible    = true;
                labMsg.Text       = "開始轉檔...";
                this.Refresh();

                //2.1 copy template xlsx to target path and open
                Workbook workbook             = new Workbook();
                string   originalFilePath     = Path.Combine(GlobalInfo.DEFAULT_EXCEL_TEMPLATE_DIRECTORY_PATH, _ProgramID + "." + FileType.XLSX.ToString().ToLower());
                string   excelDestinationPath = "";

                DataTable dtDate = (DataTable)gcDate.DataSource;

                #region 指標:SMA,EWMA,MAX
                foreach (CheckedListBoxItem item in chkModel.Items)
                {
                    if (item.CheckState == CheckState.Unchecked)
                    {
                        continue;
                    }

                    int    sheetIndex = 0;
                    int    flag       = 0;
                    string modelType  = "";
                    switch (item.Value)
                    {
                    case "chkSma":
                        excelDestinationPath = Path.Combine(GlobalInfo.DEFAULT_REPORT_DIRECTORY_PATH,
                                                            _ProgramID + "_SMA_" + DateTime.Now.ToString("yyyy.MM.dd-HH.mm.ss.") + FileType.XLSX.ToString().ToLower());
                        modelType = "S";
                        break;

                    case "chkEwma":
                        excelDestinationPath = Path.Combine(GlobalInfo.DEFAULT_REPORT_DIRECTORY_PATH,
                                                            _ProgramID + "_EWMA_" + DateTime.Now.ToString("yyyy.MM.dd-HH.mm.ss.") + FileType.XLSX.ToString().ToLower());
                        modelType = "E";
                        break;

                    case "chkMax":
                        excelDestinationPath = Path.Combine(GlobalInfo.DEFAULT_REPORT_DIRECTORY_PATH,
                                                            _ProgramID + "_MAX_" + DateTime.Now.ToString("yyyy.MM.dd-HH.mm.ss.") + FileType.XLSX.ToString().ToLower());
                        modelType = "M";
                        break;
                    }

                    //copy template and change filename
                    File.Copy(originalFilePath, excelDestinationPath, true);
                    workbook.LoadDocument(excelDestinationPath);

                    #region 時段
                    //每個時間區間為一個sheet,總共5個
                    foreach (DataRow drDate in dtDate.Rows)
                    {
                        string monDiff   = drDate["MON_DIFF"].AsString();                     //期間
                        string startDate = drDate["SDATE"].AsDateTime().ToString("yyyyMMdd"); //資料起日
                        string endDate   = drDate["EDATE"].AsDateTime().ToString("yyyyMMdd"); //資料迄日
                                                                                              //DateTime startDate = drDate["SDATE"].AsDateTime();//資料起日
                                                                                              //DateTime endDate = drDate["EDATE"].AsDateTime();//資料迄日
                        int dayCount = drDate["DAY_CNT"].AsInt();                             //天數

                        //2.2跳到指定sheet,寫檔頭
                        Worksheet worksheet = workbook.Worksheets[sheetIndex++];
                        worksheet.Cells[1, 2].Value  = cbxSubType.Text;
                        worksheet.Cells[2, 11].Value = string.Format("列印日期:{0}", DateTime.Now.ToString("yyyy/MM/dd"));
                        worksheet.Cells[2, 1].Value  = string.Format("{0}({1}~{2}),計{3}天",
                                                                     monDiff,
                                                                     drDate["SDATE"].AsDateTime().ToString("yyyy/MM/dd"),
                                                                     drDate["EDATE"].AsDateTime().ToString("yyyy/MM/dd"),
                                                                     dayCount.ToString());

                        #region                 //2.3分別讀取每個商品的詳細資訊
                        int rowIndex      = 7;
                        int emptyRowCount = 60; //template 空白行的數量
                        int kindCount     = 0;

                        //逐一看勾選的商品有哪些
                        foreach (DataRow drKind in dtTemp.Rows)
                        {
                            if (drKind["CPR_SELECT"].AsString() != "Y")
                            {
                                continue;
                            }

                            kindCount++;
                            string  kindId   = drKind["cpr_kind_id"].AsString();          //契約ID
                            Decimal riskRate = drKind["cpr_price_risk_rate"].AsDecimal(); //現行最小風險價格係數
                            Decimal interval = drKind["risk_interval"].AsDecimal();       //最小風險價格係數級距

                            //2.3.1讀取子table data
                            DataTable dtSingleKind = dao48030.ListKindByKindId(startDate, endDate, riskRate, interval, kindId, modelType);
                            if (dtSingleKind.Rows.Count <= 0)
                            {
                                labMsg.Text += string.Format("{0},{1}~{2}無任何資料!\r\n", kindId, startDate, endDate);
                                this.Refresh();
                                continue;
                            }

                            //2.3.2寫入明細
                            //ken,原則上一個商品只會找到一筆明細(已經group by)
                            DataRow drDetail  = dtSingleKind.Rows[0];
                            int     tempCount = drDetail["cnt"].AsInt();
                            Decimal level_1   = drDetail["level_1"].AsDecimal();
                            Decimal level_23  = drDetail["level_23"].AsDecimal();
                            Decimal level_4   = drDetail["level_4"].AsDecimal();

                            worksheet.Cells[rowIndex, 0].Value = drDetail["mg1_kind_id"].AsString();
                            worksheet.Cells[rowIndex, 1].Value = drDetail["avg_risk"].AsDecimal();
                            worksheet.Cells[rowIndex, 2].Value = drDetail["max_risk"].AsDecimal();
                            worksheet.Cells[rowIndex, 3].Value = drDetail["min_risk"].AsDecimal();
                            worksheet.Cells[rowIndex, 4].Value = riskRate;

                            worksheet.Cells[rowIndex, 6].Value  = level_1;
                            worksheet.Cells[rowIndex, 7].Value  = Math.Round(level_1 / tempCount, 4, MidpointRounding.AwayFromZero);
                            worksheet.Cells[rowIndex, 8].Value  = level_23;
                            worksheet.Cells[rowIndex, 9].Value  = Math.Round(level_23 / tempCount, 4, MidpointRounding.AwayFromZero);
                            worksheet.Cells[rowIndex, 10].Value = level_4;
                            worksheet.Cells[rowIndex, 11].Value = Math.Round(level_4 / tempCount, 4, MidpointRounding.AwayFromZero);

                            worksheet.Cells[rowIndex, 12].Value = interval;

                            rowIndex++;
                            flag++;
                        }//foreach (DataRow drKind in dtTemp.Rows) 商品
                        #endregion

                        //2.4刪除空白列 (結束商品foreach才刪除空白列,跑下一個sheet)
                        if (kindCount < emptyRowCount)
                        {
                            worksheet.Rows.Remove(rowIndex, emptyRowCount - kindCount);
                        }
                    }//foreach (DataRow drDate in dtDate.Rows) 時段
                    #endregion

                    //2.9存檔
                    if (flag > 0)
                    {
                        workbook.SaveDocument(excelDestinationPath);
                    }
                    else
                    {
                        File.Delete(excelDestinationPath);
                    }
                }//foreach (CheckedListBoxItem item in chkModel.Items) 指標
                #endregion

                //if (FlagAdmin)
                //   System.Diagnostics.Process.Start(excelDestinationPath);

                return(ResultStatus.Success);
            } catch (Exception ex) {
                WriteLog(ex);
            } finally {
                panFilter.Enabled = panSecond.Enabled = true;
                labMsg.Text       = "";
                labMsg.Visible    = false;
            }
            return(ResultStatus.Fail);
        }
Пример #25
0
        protected override ResultStatus Export()
        {
            try {
                this.Cursor = Cursors.WaitCursor;
                this.Refresh();
                Thread.Sleep(5);
                lblProcessing.Visible = true;
                ShowMsg("開始轉檔...");
                string rptId = "42011", file, rptName = "股票期貨風險價格係數機動評估指標";

                #region ue_export_before
                //判斷資料已轉入
                daoMGR3 = new MGR3();
                int    rtn;
                string ymd = txtSDate.DateTimeValue.ToString("yyyyMMdd");
                rtn = daoMGR3.mgr3Count(ymd);
                if (rtn == 0)
                {
                    DialogResult result = MessageDisplay.Choose(" 當日保證金適用比例資料未轉入完畢,是否要繼續?");
                    if (result == DialogResult.No)
                    {
                        lblProcessing.Visible = false;
                        return(ResultStatus.Fail);
                    }
                }
                //130批次作業做完
                string rtnStr;
                rtnStr = PbFunc.f_chk_130_wf(_ProgramID, txtSDate.DateTimeValue, "5");
                if (rtnStr != "")
                {
                    DialogResult result = MessageDisplay.Choose(txtSDate.Text + "-" + rtnStr + ",是否要繼續?");
                    if (result == DialogResult.No)
                    {
                        lblProcessing.Visible = false;
                        return(ResultStatus.Fail);
                    }
                }

                //是否勾選任一報表
                if (!cbx1.Checked && !cbx2.Checked && !cbx3.Checked)
                {
                    MessageDisplay.Error("未勾選任何報表!");
                    return(ResultStatus.Fail);
                }
                #endregion

                //取前一交易日
                DateTime lastDate = dao42011.GetLastDate(txtSDate.DateTimeValue);
                if (lastDate == DateTime.MinValue)
                {
                    MessageDisplay.Warning(txtSDate.Text + ",讀取前一交易日失敗!");
                    return(ResultStatus.Fail);
                }

                //讀取資料(保證金適用比例級距)
                DataTable dt42011 = dao42011.d_42011_detl(txtSDate.DateTimeValue, lastDate, txtRange.Text.AsDecimal() / 100,
                                                          txtRate2Ref.Text.AsDecimal() / 100, txtRate3Ref.Text.AsDecimal() / 100, txtRate4Ref.Text.AsDecimal() / 100,
                                                          txtRate1.Text.AsDecimal() / 100, txtRate2.Text.AsDecimal() / 100, txtRate3.Text.AsDecimal() / 100, txtRate4.Text.AsDecimal() / 100);
                if (dt42011.Rows.Count == 0)
                {
                    MessageDisplay.Info(txtSDate.Text + "," + rptId + '-' + rptName + ",無任何資料!");
                    lblProcessing.Visible = false;
                    return(ResultStatus.Fail);
                }
                dt42011.Sort("APDK_KIND_GRP2, APDK_KIND_LEVEL, MGR3_KIND_ID");

                //複製檔案
                file = PbFunc.wf_copy_file(rptId, rptId);
                if (file == "")
                {
                    return(ResultStatus.Fail);
                }

                //開啟檔案
                Workbook workbook = new Workbook();
                workbook.LoadDocument(file);

                //切換Sheet
                Worksheet ws = workbook.Worksheets[0];
                ws.Cells[0, 15].Value = txtSDate.DateTimeValue.Year + "年" + txtSDate.DateTimeValue.Month + "月" + txtSDate.DateTimeValue.Day + "日";

                //表1
                ShowMsg(rptId + '-' + rptName + " 轉檔中...");
                int minusRow;
                minusRow = wf_42011_1(ws, dt42011);
                minusRow = wf_42011_2(minusRow, ws, dt42011);
                minusRow = wf_42011_3(minusRow, ws, dt42011);

                //存檔
                ws.ScrollToRow(0);
                workbook.SaveDocument(file);
                ShowMsg("轉檔成功");
            } catch (Exception ex) {
                ShowMsg("轉檔錯誤");
                MessageDisplay.Error("輸出錯誤");
                throw ex;
            } finally {
                this.Cursor = Cursors.Arrow;
                this.Refresh();
                Thread.Sleep(5);
            }
            return(ResultStatus.Success);
        }
Пример #26
0
        protected override ResultStatus Export()
        {
            try {
                this.Cursor = Cursors.WaitCursor;
                this.Refresh();
                Thread.Sleep(5);
                lblProcessing.Visible = true;
                ShowMsg("開始轉檔...");
                dao43010 = new D43010();
                dao43020 = new D43020();
                #region ue_export_before
                //130批次作業做完
                string rtnStr, oswGrp;
                oswGrp = dwOswGrp.EditValue + "%";
                rtnStr = PbFunc.f_chk_130_wf(_ProgramID, txtSDate.DateTimeValue, oswGrp);
                if (rtnStr != "")
                {
                    DialogResult result = MessageDisplay.Choose(txtSDate.Text + "-" + rtnStr + ",是否要繼續?");
                    if (result == DialogResult.No)
                    {
                        lblProcessing.Visible = false;
                        return(ResultStatus.Fail);
                    }
                }
                #endregion

                string rptName, rptId, file;
                int    rowStart;
                rptName = "股票期貨保證金狀況表-標的證券為受益憑證";
                rptId   = "43010";
                ShowMsg(rptId + '-' + rptName + " 轉檔中...");

                //1. 讀取檔案
                DataTable dt43010 = dao43010.d_43010(txtSDate.DateTimeValue.ToString("yyyyMMdd"), oswGrp, "S");
                if (dt43010.Rows.Count == 0)
                {
                    MessageDisplay.Info(txtSDate.Text + "," + rptId + '-' + rptName + ",無任何資料!");
                    //return ResultStatus.Fail;
                }
                int rowIndex = dt43010.Rows.Count;

                //2. 複製檔案
                file = PbFunc.wf_copy_file(rptId, rptId);
                if (file == "")
                {
                    return(ResultStatus.Fail);
                }

                //3. 開啟檔案
                Workbook workbook = new Workbook();
                workbook.LoadDocument(file);

                //4. 切換Sheet
                Worksheet ws43010  = workbook.Worksheets[0];
                string    dataDate = "資料日期:" + Environment.NewLine + txtSDate.DateTimeValue.Year + "年" + txtSDate.DateTimeValue.Month + "月" + txtSDate.DateTimeValue.Day + "日";
                ws43010.Cells[0, 9].Value    = dataDate;
                ws43010.Cells[35, 14].Value  = dataDate;
                ws43010.Cells[73, 14].Value  = dataDate;
                ws43010.Cells[110, 14].Value = dataDate;

                //5. 填入資料
                int cnt      = 0;
                int f        = 0;
                int rowCount = dt43010.Rows.Count;
                foreach (DataRow dr in dt43010.Rows)
                {
                    //5.1 一、現行收取保證金金額
                    //從B3開始填資料
                    rowStart = 2;
                    cnt      = cnt + 1;
                    ws43010.Cells[rowStart + f, 1].Value = cnt.AsString();
                    ws43010.Cells[rowStart + f, 2].SetValue(dr["MG1_KIND_ID"]);
                    ws43010.Cells[rowStart + f, 3].SetValue(dr["APDK_NAME"]);
                    ws43010.Cells[rowStart + f, 4].SetValue(dr["APDK_STOCK_ID"]);
                    ws43010.Cells[rowStart + f, 5].SetValue(dr["PID_NAME"]);
                    ws43010.Cells[rowStart + f, 6].SetValue(dr["MG1_CUR_CM"]);
                    ws43010.Cells[rowStart + f, 7].SetValue(dr["MG1_CUR_MM"]);
                    ws43010.Cells[rowStart + f, 8].SetValue(dr["MG1_CUR_IM"]);
                    ws43010.Cells[rowStart + f, 9].SetValue(dr["MG1_CUR_CM_RATE"]);
                    ws43010.Cells[rowStart + f, 10].SetValue(dr["MG1_CUR_MM_RATE"]);
                    ws43010.Cells[rowStart + f, 11].SetValue(dr["MG1_CUR_IM_RATE"]);

                    //5.2 二、本日結算保證金計算
                    //SMA 從B41開始填資料
                    rowStart = 40;
                    ws43010.Cells[rowStart + f, 1].Value = cnt.AsString();
                    ws43010.Cells[rowStart + f, 2].SetValue(dr["MG1_KIND_ID"]);
                    ws43010.Cells[rowStart + f, 3].SetValue(dr["APDK_NAME"]);
                    ws43010.Cells[rowStart + f, 4].SetValue(dr["APDK_STOCK_ID"]);
                    ws43010.Cells[rowStart + f, 5].SetValue(dr["PID_NAME"]);

                    ws43010.Cells[rowStart + f, 6].SetValue(dr["MG1_PRICE"]);
                    ws43010.Cells[rowStart + f, 7].SetValue(dr["MG1_XXX"]);
                    ws43010.Cells[rowStart + f, 8].SetValue(dr["MG1_RISK"]);
                    ws43010.Cells[rowStart + f, 9].SetValue(dr["MG1_CP_RISK"]);
                    ws43010.Cells[rowStart + f, 10].SetValue(dr["MG1_MIN_RISK"]);

                    ws43010.Cells[rowStart + f, 11].SetValue(dr["MG1_CP_CM"]);
                    ws43010.Cells[rowStart + f, 12].SetValue(dr["MG1_CUR_CM"]);
                    ws43010.Cells[rowStart + f, 13].SetValue(dr["MG1_CHANGE_RANGE"]);
                    ws43010.Cells[rowStart + f, 14].SetValue(dr["MG1_CHANGE_FLAG"]);
                    f++;
                }//foreach (DataRow dr in dt43010.Rows)
                dt43010 = dao43010.d_43010(txtSDate.DateTimeValue.ToString("yyyyMMdd"), oswGrp, "E");
                cnt     = 0;
                f       = 0;
                foreach (DataRow dr in dt43010.Rows)
                {
                    //EWMA 從B79開始填資料
                    rowStart = 78;
                    cnt      = cnt + 1;
                    ws43010.Cells[rowStart + f, 1].Value = cnt.AsString();
                    ws43010.Cells[rowStart + f, 2].SetValue(dr["MG1_KIND_ID"]);
                    ws43010.Cells[rowStart + f, 3].SetValue(dr["APDK_NAME"]);
                    ws43010.Cells[rowStart + f, 4].SetValue(dr["APDK_STOCK_ID"]);
                    ws43010.Cells[rowStart + f, 5].SetValue(dr["PID_NAME"]);

                    ws43010.Cells[rowStart + f, 6].SetValue(dr["MG1_PRICE"]);
                    ws43010.Cells[rowStart + f, 7].SetValue(dr["MG1_XXX"]);
                    ws43010.Cells[rowStart + f, 8].SetValue(dr["MG1_RISK"]);
                    ws43010.Cells[rowStart + f, 9].SetValue(dr["MG1_CP_RISK"]);
                    ws43010.Cells[rowStart + f, 10].SetValue(dr["MG1_MIN_RISK"]);

                    ws43010.Cells[rowStart + f, 11].SetValue(dr["MG1_CP_CM"]);
                    ws43010.Cells[rowStart + f, 12].SetValue(dr["MG1_CUR_CM"]);
                    ws43010.Cells[rowStart + f, 13].SetValue(dr["MG1_CHANGE_RANGE"]);
                    ws43010.Cells[rowStart + f, 14].SetValue(dr["MG1_CHANGE_FLAG"]);
                    f++;
                }//foreach (DataRow dr in dt43010.Rows)
                dt43010 = dao43010.d_43010(txtSDate.DateTimeValue.ToString("yyyyMMdd"), oswGrp, "M");
                cnt     = 0;
                f       = 0;
                foreach (DataRow dr in dt43010.Rows)
                {
                    //MAX 從B116開始填資料
                    rowStart = 115;
                    cnt      = cnt + 1;
                    ws43010.Cells[rowStart + f, 1].Value = cnt.AsString();
                    ws43010.Cells[rowStart + f, 2].SetValue(dr["MG1_KIND_ID"]);
                    ws43010.Cells[rowStart + f, 3].SetValue(dr["APDK_NAME"]);
                    ws43010.Cells[rowStart + f, 4].SetValue(dr["APDK_STOCK_ID"]);
                    ws43010.Cells[rowStart + f, 5].SetValue(dr["PID_NAME"]);

                    ws43010.Cells[rowStart + f, 6].SetValue(dr["MG1_PRICE"]);
                    ws43010.Cells[rowStart + f, 7].SetValue(dr["MG1_XXX"]);
                    ws43010.Cells[rowStart + f, 8].SetValue(dr["MG1_RISK"]);
                    ws43010.Cells[rowStart + f, 9].SetValue(dr["MG1_CP_RISK"]);
                    ws43010.Cells[rowStart + f, 10].SetValue(dr["MG1_MIN_RISK"]);

                    ws43010.Cells[rowStart + f, 11].SetValue(dr["MG1_CP_CM"]);
                    ws43010.Cells[rowStart + f, 12].SetValue(dr["MG1_CUR_CM"]);
                    ws43010.Cells[rowStart + f, 13].SetValue(dr["MG1_CHANGE_RANGE"]);
                    ws43010.Cells[rowStart + f, 14].SetValue(dr["MG1_CHANGE_FLAG"]);

                    f++;
                }//foreach (DataRow dr in dt43010.Rows)

                //6. 刪除空白列
                int delRowCnt = 30 - rowIndex;
                if (rowIndex < 30)
                {
                    rowStart = 115;
                    ws43010.Rows.Remove(rowIndex + rowStart, delRowCnt);
                    rowStart = 78;
                    ws43010.Rows.Remove(rowIndex + rowStart, delRowCnt);
                    rowStart = 40;
                    ws43010.Rows.Remove(rowIndex + rowStart, delRowCnt);
                    rowStart = 2;
                    ws43010.Rows.Remove(rowIndex + rowStart, delRowCnt);
                }

                #region sheet 2
                rptName = "保證金狀況表";
                rptId   = "40011_stat";
                ShowMsg(rptId + '-' + rptName + " 轉檔中...");

                //1. 讀取檔案
                DataTable dt40011stat = dao43020.d_40011_stat(txtSDate.DateTimeValue.ToString("yyyyMMdd"));
                dt40011stat = dt40011stat.Sort("seq_no, kind_id");
                dt40011stat = dt40011stat.Filter("prod_type ='F' and param_key = 'ETF' and osw_grp like'" + oswGrp + "'");
                if (dt40011stat.Rows.Count == 0)
                {
                    MessageDisplay.Info(txtSDate.Text + "," + rptId + '-' + rptName + ",無任何資料!");
                    //return ResultStatus.Fail;
                }


                //2. 切換Sheet
                ws43010 = workbook.Worksheets["fut_3index"];

                //3. 填入資料
                ws43010.Cells[0, 0].Value = "資料日期:" + Environment.NewLine + txtSDate.DateTimeValue.Year + "年" + txtSDate.DateTimeValue.Month + "月" + txtSDate.DateTimeValue.Day + "日";
                int rowNum = 3 - 1;
                foreach (DataRow dr in dt40011stat.Rows)
                {
                    for (f = 0; f < 37; f++)
                    {
                        ws43010.Cells[rowNum, f].SetValue(dr[f]);
                    }
                    rowNum++;
                }

                #endregion

                //存檔
                ws43010 = workbook.Worksheets[0];
                ws43010.ScrollToRow(0);

                //若所有Sheet皆無資料時,刪除檔案
                if (dt43010.Rows.Count == 0 && dt40011stat.Rows.Count == 0)
                {
                    workbook = null;
                    System.IO.File.Delete(file);
                    return(ResultStatus.Fail);
                }
                workbook.SaveDocument(file);
                ShowMsg("轉檔成功");
            }
            catch (Exception ex) {
                //WriteLog(ex, "", false); 如果不用throw會繼續往下執行(?
                ShowMsg("轉檔錯誤");
                throw ex;
            }
            finally {
                this.Cursor = Cursors.Arrow;
                this.Refresh();
                Thread.Sleep(5);
            }
            return(ResultStatus.Success);
        }
Пример #27
0
        protected override ResultStatus Retrieve()
        {
            try {
                gcMain.DataSource = null;

                dao30203 = new D30203();
                string lsYmd;
                int    found;
                lsYmd = txtDate.Text.Replace("/", "");

                DataTable dt30203 = dao30203.d_30203(lsYmd);
                if (dt30203.Rows.Count == 0)
                {
                    MessageDisplay.Info("PL1無任何資料!");
                }
                else
                {
                    dt30203.Columns.Add("Is_NewRow", typeof(string));
                    gcMain.DataSource = dt30203;
                    gcMain.Visible    = true;
                    gcMain.Focus();
                }

                DataTable dt30203gbf = dao30203.d_30203_gbf();
                if (dt30203gbf.Rows.Count == 0)
                {
                    MessageDisplay.Info("PL1B無任何資料!");
                    return(ResultStatus.Fail);
                }
                gcGBF.DataSource = dt30203gbf;

                //公告日期
                DataTable dtPostDate = dao30203.PostDate(lsYmd);
                if (dtPostDate.Rows.Count == 0)
                {
                    MessageDisplay.Info("公告日期無任何資料!");
                    return(ResultStatus.Fail);
                }
                if (dtPostDate.Rows[0]["RAISE_YMD"].AsDateTime("yyyyMMdd") != default(DateTime))
                {
                    txtEffDate.DateTimeValue      = dtPostDate.Rows[0]["RAISE_YMD"].AsDateTime("yyyyMMdd");
                    txtEffDateLower.DateTimeValue = dtPostDate.Rows[0]["LOWER_YMD"].AsDateTime("yyyyMMdd");
                    lblEff.Text = "(已確認)";
                }
                else
                {
                    lblEff.Text = "";
                }

                DataTable dt30203PL2 = dao30203.d_30203_pl2(lsYmd);
                if (dt30203PL2.Rows.Count == 0)
                {
                    MessageDisplay.Info("PL2無任何資料!");
                    return(ResultStatus.Fail);
                }

                if (dtPostDate.Rows[0]["LI_COUNT"].AsInt() <= 0)
                {
                    return(ResultStatus.Fail);
                }
                DialogResult result = MessageDisplay.Choose("已確認資料,按「是」讀取已存檔資料,按「否」為重新產製資料");
                if (result == DialogResult.No)
                {
                    return(ResultStatus.Fail);
                }

                foreach (DataRow dr in dt30203PL2.Rows)
                {
                    //此時gridview的資料還沒被動過,原本要在gridview中查找(datawindow.find)的資料直接在datasource查找即可
                    DataRow[] find = dt30203.Select("PL1_KIND_ID='" + dr["PL2_KIND_ID"].ToString() + "'");
                    if (find.Length > 0)
                    {
                        found = dt30203.Rows.IndexOf(find[0]);
                    }
                    else
                    {
                        found = -1;
                    }
                    if (found == -1)
                    {
                        InsertRow();
                        found = gvMain.RowCount;
                    }

                    if (dr["PL2_EFFECTIVE_YMD"].AsString() == dtPostDate.Rows[0]["LOWER_YMD"].AsString())
                    {
                        gvMain.SetRowCellValue(found, "PL1_NATURE_ADJ", "-");
                    }
                    gvMain.SetRowCellValue(found, "PL1_YMD", dr["PL2_YMD"].AsString());
                    gvMain.SetRowCellValue(found, "PL1_KIND_ID", dr["PL2_KIND_ID"].ToString());
                    gvMain.SetRowCellValue(found, "PL1_NATURE", dr["PL2_NATURE"]);
                    gvMain.SetRowCellValue(found, "PL1_LEGAL", dr["PL2_LEGAL"]);
                    gvMain.SetRowCellValue(found, "PL1_999", dr["PL2_999"]);
                    gvMain.SetRowCellValue(found, "PL1_NATURE_ADJ", dr["PL2_NATURE_ADJ"].ToString());
                    gvMain.SetRowCellValue(found, "PL1_LEGAL_ADJ", dr["PL2_LEGAL_ADJ"].ToString());
                    gvMain.SetRowCellValue(found, "PL1_999_ADJ", dr["PL2_999_ADJ"].ToString());
                    gvMain.SetRowCellValue(found, "PL1_CUR_NATURE", dr["PL2_PREV_NATURE"]);
                    gvMain.SetRowCellValue(found, "PL1_CUR_LEGAL", dr["PL2_PREV_LEGAL"]);
                    gvMain.SetRowCellValue(found, "PL1_CUR_999", dr["PL2_PREV_999"]);
                }

                DataTable dt30203PL2B = dao30203.d_30203_pl2b(lsYmd);
                if (dt30203PL2B.Rows.Count == 0)
                {
                    MessageDisplay.Info("PL2B無任何資料!");
                    return(ResultStatus.Fail);
                }
                foreach (DataRow dr in dt30203PL2B.Rows)
                {
                    //此時gridview的資料還沒被動過,原本要在gridview中查找(datawindow.find)的資料直接在datasource查找即可
                    DataRow[] find = dt30203gbf.Select("PL1B_KIND_ID='" + dr["PL2B_KIND_ID"].ToString() + "'");
                    if (find.Length > 0)
                    {
                        found = dt30203gbf.Rows.IndexOf(find[0]);
                        gvGBF.SetRowCellValue(found, "PL1B_PROD_TYPE", dr["PL2B_PROD_TYPE"].AsString());
                        gvGBF.SetRowCellValue(found, "PL1B_PROD_SUBTYPE", dr["PL2B_PROD_SUBTYPE"].AsString());
                        gvGBF.SetRowCellValue(found, "PL1B_KIND_ID", dr["PL2B_KIND_ID"].ToString());
                        gvGBF.SetRowCellValue(found, "PL1B_NATURE_LEGAL_MTH", dr["PL2B_NATURE_LEGAL_MTH"].AsInt());
                        gvGBF.SetRowCellValue(found, "PL1B_NATURE_LEGAL_TOT", dr["PL2B_NATURE_LEGAL_TOT"].AsInt());
                        gvGBF.SetRowCellValue(found, "PL1B_999_MTH", dr["PL2B_999_MTH"].AsInt());
                        gvGBF.SetRowCellValue(found, "PL1B_999_NEARBY_MTH", dr["PL2B_999_NEARBY_MTH"].AsInt());
                        gvGBF.SetRowCellValue(found, "PL1B_999_TOT", dr["PL2B_999_TOT"].AsInt());
                        gvGBF.SetRowCellValue(found, "PL1B_PREV_NATURE_LEGAL_MTH", dr["PL2B_PREV_NATURE_LEGAL_MTH"].AsInt());
                        gvGBF.SetRowCellValue(found, "PL1B_PREV_NATURE_LEGAL_TOT", dr["PL2B_PREV_NATURE_LEGAL_TOT"].AsInt());
                        gvGBF.SetRowCellValue(found, "PL1B_PREV_999_MTH", dr["PL2B_PREV_999_MTH"].AsInt());
                        gvGBF.SetRowCellValue(found, "PL1B_PREV_999_NEARBY_MTH", dr["PL2B_PREV_999_NEARBY_MTH"].AsInt());
                        gvGBF.SetRowCellValue(found, "PL1B_PREV_999_TOT", dr["PL2B_PREV_999_TOT"].AsInt());
                        gvGBF.SetRowCellValue(found, "PL1B_ADJ", dr["PL2B_ADJ"].ToString());
                    }
                }
            } catch (Exception ex) {
                WriteLog(ex);
            }

            return(ResultStatus.Success);
        }
Пример #28
0
        /// <summary>
        /// 按下[匯出]按鈕時
        /// </summary>
        /// <returns></returns>
        protected override ResultStatus Export()
        {
            //1.check
            if (gvKind.DataRowCount <= 0)
            {
                MessageDisplay.Normal("選擇的日期必須有契約資訊,請重新選擇日期");
                return(ResultStatus.Fail);
            }

            //1.1檢查最少必須勾選一筆商品
            gvDate.CloseEditor();      //ken,一定要先呼叫這兩個函數,最後點選的那筆才會被記錄起來
            gvDate.UpdateCurrentRow(); //ken,一定要先呼叫這兩個函數,最後點選的那筆才會被記錄起來
            gvKind.CloseEditor();      //ken,一定要先呼叫這兩個函數,最後點選的那筆才會被記錄起來
            gvKind.UpdateCurrentRow(); //ken,一定要先呼叫這兩個函數,最後點選的那筆才會被記錄起來
            DataTable dtTemp   = (DataTable)gcKind.DataSource;
            bool      haveKind = false;

            foreach (DataRow drKind in dtTemp.Rows)
            {
                if (drKind["CPR_SELECT"].AsString() == "Y")
                {
                    haveKind = true;
                    break;
                }
            }

            if (!haveKind)
            {
                MessageDisplay.Normal("必須勾選一筆契約");
                return(ResultStatus.Fail);
            }

            if (chkModel.CheckedItemsCount < 1)
            {
                MessageDisplay.Error("請至少勾選一種指標種類", GlobalInfo.ErrorText);
                return(ResultStatus.Fail);
            }

            //1.2檢查統計資料是否已經轉入完畢
            string FinishedJob = PbFunc.f_get_jsw(_ProgramID, "E", txtEndDate.Text);

            if (FinishedJob != "Y")
            {
                DialogResult chooseResult = MessageDisplay.Choose(string.Format("{0} 統計資料未轉入完畢,是否要繼續?", txtEndDate.Text), MessageBoxDefaultButton.Button2, GlobalInfo.QuestionText);
                if (chooseResult != DialogResult.Yes)
                {
                    return(ResultStatus.Fail);
                }
            }

            string   kindId   = "";
            Workbook workbook = new Workbook();

            try {
                //2.開始轉出資料
                panFilter.Enabled = panSecond.Enabled = false;
                labMsg.Visible    = true;
                labMsg.Text       = "開始轉檔...";
                this.Refresh();

                DataTable dtDate    = (DataTable)gcDate.DataSource;
                string    startDate = dtDate.Rows[dtDate.Rows.Count - 1]["SDATE"].AsDateTime().ToString("yyyyMMdd");
                string    endDate   = dtDate.Rows[dtDate.Rows.Count - 1]["EDATE"].AsDateTime().ToString("yyyyMMdd");

                #region 指標:SMA,EWMA,MAX
                foreach (CheckedListBoxItem item in chkModel.Items)
                {
                    if (item.CheckState == CheckState.Unchecked)
                    {
                        continue;
                    }

                    string modelType = "";
                    string modelName = "";
                    switch (item.Value)
                    {
                    case "chkSma":
                        modelType = "S";
                        modelName = "SMA";
                        break;

                    case "chkEwma":
                        modelType = "E";
                        modelName = "EWMA";
                        break;

                    case "chkMax":
                        modelType = "M";
                        modelName = "MAX";
                        break;
                    }

                    #region 商品
                    //每一個商品都會產生一個excel檔案
                    foreach (DataRow drKind in dtTemp.Rows)
                    {
                        if (drKind["CPR_SELECT"].AsString() != "Y")
                        {
                            continue;
                        }

                        //2.0 get some column data
                        string  effDate      = drKind["cpr_effective_date"].AsDateTime().ToString("yyyy/MM/dd");
                        Decimal lastRiskRate = drKind["last_risk_rate"].AsDecimal(0);
                        Decimal riskRateOrg  = drKind["cpr_price_risk_rate_org"].AsDecimal(0);

                        kindId = drKind["CPR_KIND_ID"].AsString();

                        //2.1 copy template xlsx to target path and open
                        string excelDestinationPath = CopyExcelTemplateFile2(_ProgramID, modelName, kindId);
                        workbook.LoadDocument(excelDestinationPath);
                        Worksheet worksheet = workbook.Worksheets["RawData"];

                        //2.3寫入檔頭[M1:M6]
                        worksheet.Cells[0, 12].Value = kindId;                                    //商品
                        worksheet.Cells[1, 12].Value = drKind["cpr_effective_date"].AsDateTime(); //日期,最近一次調整日期
                        if (drKind["cpr_price_risk_rate"] != DBNull.Value)
                        {
                            worksheet.Cells[2, 12].Value = drKind["cpr_price_risk_rate"].AsDecimal();//百分比,現行最小風險價格係數
                        }
                        if (drKind["last_risk_rate"] != DBNull.Value)
                        {
                            worksheet.Cells[3, 12].Value = drKind["last_risk_rate"].AsDecimal();//百分比,最近一次修改前之最小風險價格係數
                        }
                        if (drKind["risk_interval"] != DBNull.Value)
                        {
                            worksheet.Cells[4, 12].Value = drKind["risk_interval"].AsDecimal(); //百分比,最小風險價格係數級距
                        }
                        worksheet.Cells[5, 12].Value = DateTime.Today;                          //日期,作業日期


                        //2.4讀取子table data (mg1_ymd/mg1_risk/mg1_min_risk)
                        DataTable dtSingleKind = dao48040.ListKindByKindId(kindId, startDate, endDate, modelType);
                        if (dtSingleKind.Rows.Count <= 0)
                        {
                            File.Delete(excelDestinationPath);
                            //workbook.SaveDocument(excelDestinationPath);//存檔
                            labMsg.Text += string.Format("{0},{1}~{2}無任何資料!\r\n", kindId, startDate, endDate);
                            this.Refresh();
                            continue;
                        }

                        #region //2.5寫入五段日期基本資訊[F2:J6]
                        int rowIndex = 2;
                        int pos      = 1;
                        foreach (DataRow drDate in dtDate.Rows)
                        {
                            worksheet.Cells[pos, 5].Value = drDate["SDATE"].AsString(); //資料起日
                            worksheet.Cells[pos, 6].Value = drDate["EDATE"].AsString(); //資料迄日
                            worksheet.Cells[pos, 7].Value = drDate["DAY_CNT"].AsInt();  //天數

                            //ken,使用DataView的Find之前,要指定Sort欄位(可多個欄位)
                            int filterIndex = dtSingleKind.Rows.IndexOf(dtSingleKind.Select($"mg1_ymd >= '{drDate["SDATE"].AsString()}'").FirstOrDefault());
                            if (filterIndex >= 0)
                            {
                                worksheet.Cells[pos, 8].Value = rowIndex + filterIndex;//起日位址(FirstRowIndex)
                            }
                            else
                            {
                                worksheet.Cells[pos, 8].Value = rowIndex;//起日位址(FirstRowIndex)
                            }

                            worksheet.Cells[pos, 9].Value = rowIndex + dtSingleKind.Rows.Count - 1;//迄日位址(LastRowIndex)

                            pos++;
                        }//foreach(DataRow drDate in dtDate.Rows) {
                        #endregion

                        //2.6寫入整個子table (日期/實際風險價格係數/最小風險價格係數)
                        worksheet.Import(dtSingleKind, false, 1, 0);//dataTable, isAddHeader, RowFirstIndex, ColFirstIndex
                        worksheet.Range["A1"].Select();
                        worksheet.ScrollToRow(0);

                        //2.7刪多的圖表(共五個,起始rowIndex=24,每個高31)
                        //ken,從最後一個圖表開始刪除比較正確,才不會跑位,最後圖表rowIndex=148
                        worksheet = workbook.Worksheets["Graph"];
                        int graphRowIndex = 148;
                        int graphHeight   = 31;
                        for (int k = dtDate.Rows.Count - 1; k >= 0; k--)
                        {
                            if (dtDate.Rows[k]["AI2_SELECT"].AsString() == "N")
                            {
                                worksheet.Rows.Remove(graphRowIndex, graphHeight - 1);
                            }
                            graphRowIndex -= graphHeight;
                        }//for(int k = dtDate.Rows.Count - 1;k >= 0;k--) {


                        //2.8寫入[註3]資訊
                        riskRateOrg = Math.Round(riskRateOrg * 100, 1, MidpointRounding.AwayFromZero);
                        if (lastRiskRate == 0)
                        {
                            worksheet.Cells[18, 0].Value = string.Format("註3:上市日起至今最小風險價格係數均為{0}%", riskRateOrg.ToString());
                        }
                        else
                        {
                            lastRiskRate = Math.Round(lastRiskRate * 100, 1, MidpointRounding.AwayFromZero);
                            worksheet.Cells[18, 0].Value = string.Format("註3:最小風險價格係數自{0}起由{1}%調整為{2}",
                                                                         effDate,
                                                                         lastRiskRate.ToString(),
                                                                         riskRateOrg.ToString());
                        }

                        //2.9存檔
                        workbook.SaveDocument(excelDestinationPath);
                    }//foreach (DataRow drKind in dtTemp.Rows) 商品
                    #endregion
                }
                #endregion



                return(ResultStatus.Success);
            } catch (Exception ex) {
                WriteLog(ex, kindId);
            } finally {
                panFilter.Enabled = panSecond.Enabled = true;
                labMsg.Text       = "";
                labMsg.Visible    = false;
            }
            return(ResultStatus.Fail);
        }
Пример #29
0
        protected override ResultStatus Export()
        {
            try {
                #region export before
                //130批次作業做完
                string ls_rtn = PbFunc.f_chk_130_wf(_ProgramID, txtDate.DateTimeValue, "1");
                if (!string.IsNullOrEmpty(ls_rtn.Trim()))
                {
                    DialogResult liRtn = MessageDisplay.Choose(string.Format("{0}-{1},是否要繼續?", txtDate.Text, ls_rtn), MessageBoxDefaultButton.Button2, GlobalInfo.QuestionText);
                    if (liRtn == DialogResult.No)
                    {
                        labMsg.Visible = false;
                        Cursor.Current = Cursors.Arrow;
                        return(ResultStatus.Fail);
                    }
                }
                #endregion

                //0. ready
                panFilter.Enabled = false;
                labMsg.Visible    = true;
                labMsg.Text       = "開始轉檔...";
                this.Cursor       = Cursors.WaitCursor;
                this.Refresh();
                Thread.Sleep(5);

                //1. copy template xls to target path
                string   excelDestinationPath = PbFunc.wf_copy_file(_ProgramID, _ProgramID);
                Workbook workbook             = new Workbook();
                workbook.LoadDocument(excelDestinationPath);

                string ls_logf = "N"; //LOGF記錄每項時間

                if (txtDate.DateTimeValue < DateTime.ParseExact("2010/10/01", "yyyy/MM/dd", null))
                {
                    MessageDisplay.Info("自99年10月1日起,各期貨契約之報酬率改以「當日結算價」及「當日開盤參考價」計算,故產出資料值不會異動至資料庫!", GlobalInfo.WarningText);
                    return(ResultStatus.Fail);
                }

                //2.填資料
                //Sheet:標的現貨收盤價&開盤參考價
                bool result1 = false, result2 = false;

                //資料儲存至Table
                result1 = wf_40021(workbook);
                //if (chkTxt.CheckState == CheckState.Checked) {
                //   result1 = wf_40021(workbook);
                //   if (ls_logf == "Y") {
                //      //wf_logt("40021");

                //      //is_log_time = is_log_time + " - " + string(now())
                //      //f_write_logf(is_txn_id , 'T' , txd_id + ',' + is_log_time)
                //      //is_log_time = string(now())
                //   }
                //}

                //Sheet:Span參數日狀況表(一)(二)(三)
                result2 = wf_40020_7(workbook);

                if (!result1 && !result2)
                {
                    try {
                        workbook = null;
                        File.Delete(excelDestinationPath);
                    } catch (Exception) {
                        //
                    }
                    return(ResultStatus.Fail);
                }

                //存檔
                workbook.SaveDocument(excelDestinationPath);
                labMsg.Visible = false;

                //if (FlagAdmin)
                //   System.Diagnostics.Process.Start(excelDestinationPath);

                return(ResultStatus.Success);
            } catch (Exception ex) {
                WriteLog(ex);
            } finally {
                panFilter.Enabled = true;
                labMsg.Text       = "";
                labMsg.Visible    = false;
                this.Cursor       = Cursors.Arrow;
            }

            return(ResultStatus.Fail);
        }
Пример #30
0
        protected override ResultStatus Export()
        {
            try {
                #region 輸入&日期檢核
                string       lsRtn = PbFunc.f_get_jsw(_ProgramID, "E", txtEndDate.Text);
                DialogResult liRtn;

                if (lsRtn != "Y")
                {
                    liRtn = MessageDisplay.Choose(string.Format("{0} 統計資料未轉入完畢,是否要繼續?", txtEndDate.Text), MessageBoxDefaultButton.Button2, GlobalInfo.QuestionText);
                    if (liRtn == DialogResult.No)
                    {
                        labMsg.Visible = false;
                        Cursor.Current = Cursors.Arrow;
                        return(ResultStatus.Fail);
                    } //if (liRtn == DialogResult.Yes)
                }     //if (lsRtn != "Y")

                //if (!txtStartDate.IsDate(txtStartDate.Text , CheckDate.Start)
                //      || !txtEndDate.IsDate(txtEndDate.Text , CheckDate.End)) {
                //   return ResultStatus.Fail; ;
                //}

                if (string.Compare(txtStartDate.Text, txtEndDate.Text) > 0)
                {
                    MessageDisplay.Error(CheckDate.Datedif, GlobalInfo.ErrorText);
                    return(ResultStatus.Fail);;
                }
                #endregion

                //1. ready
                panFilter.Enabled = false;
                labMsg.Visible    = true;
                labMsg.Text       = "開始轉檔...";
                this.Cursor       = Cursors.WaitCursor;
                this.Refresh();
                Thread.Sleep(5);

                //2. copy template xls to target path
                string excelDestinationPath = PbFunc.wf_copy_file(_ProgramID, _ProgramID);

                //3. open xls
                Workbook workbook = new Workbook();
                workbook.LoadDocument(excelDestinationPath);

                //4. write data
                int  row;
                bool res1 = false, res2 = false, res3 = false;
                row  = 3;
                res1 = wf_30410(workbook, SheetNo.tradeSum, row);

                row  = 4; //PB這邊帶1,但進去後帶回4
                res2 = wf_30411(workbook, SheetNo.tradeDetail, row);

                row  = 4; //PB這邊帶1,但進去後帶回4
                res3 = wf_30412(workbook, SheetNo.oint, row);

                if (!res1 && !res2 && !res3)
                {
                    File.Delete(excelDestinationPath);
                    return(ResultStatus.Fail);
                }

                //5. save
                workbook.SaveDocument(excelDestinationPath);
                labMsg.Visible = false;

                if (FlagAdmin)
                {
                    System.Diagnostics.Process.Start(excelDestinationPath);
                }

                return(ResultStatus.Success);
            } catch (Exception ex) {
                WriteLog(ex);
            } finally {
                panFilter.Enabled = true;
                labMsg.Text       = "";
                labMsg.Visible    = false;
                this.Cursor       = Cursors.Arrow;
            }
            return(ResultStatus.Fail);
        }