Esempio n. 1
0
        /// <summary>
        /// 讀取查詢月份資料
        /// </summary>
        /// <returns></returns>
        protected override ResultStatus Retrieve()
        {
            base.Retrieve();
            daoAM22F = new AM22F();
            string    as_ym       = txtMonth.Text.Replace("/", "");
            DataTable returnTable = daoAM22F.ListData(as_ym);

            if (returnTable.Rows.Count == 0)
            {
                MessageBox.Show("無任何資料", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            gcMain.DataSource = returnTable;
            gcMain.Visible    = true;
            gcMain.Focus(); base.Retrieve();

            return(ResultStatus.Success);
        }
Esempio n. 2
0
        protected override ResultStatus Import()
        {
            //base.Import();
            //1.讀檔並寫入DataTable
            try {
                lblProcessing.Visible = true;
                DataTable      dtReadTxt = new DataTable();
                OpenFileDialog open      = new OpenFileDialog();
                open.Filter   = "*.txt (*.txt)|*.txt";
                open.Title    = "請點選儲存檔案之目錄";
                open.FileName = "6250_政府基金(L)_日明細.txt";
                DialogResult openResult = open.ShowDialog();
                if (openResult == DialogResult.OK)
                {
                    using (StreamReader sr = new StreamReader(open.FileName, System.Text.Encoding.Default)) {
                        string line;
                        while ((line = sr.ReadLine()) != null)
                        {
                            string[] items = line.Split('\t');
                            daoAM22F = new AM22F();
                            string    as_ym       = txtMonth.Text.Replace("/", "");
                            DataTable returnTable = daoAM22F.ListData(as_ym);

                            //填入欄位名稱
                            if (dtReadTxt.Columns.Count == 0)
                            {
                                foreach (DataColumn column in returnTable.Columns)
                                {
                                    dtReadTxt.Columns.Add(column.ColumnName, typeof(string));
                                }
                            }
                            dtReadTxt.Rows.Add(items);
                        }
                    }
                }
                else
                {
                    lblProcessing.Visible = false;
                    return(ResultStatus.Fail);
                }
                //2.確認資料年月&畫面年月(讀取資料)
                string datadate = dtReadTxt.Rows[0][3].AsString();
                if (datadate != txtMonth.Text.Replace("/", ""))
                {
                    DialogResult result = MessageBox.Show("資料年月(" + datadate + ")與畫面年月不同,是否將畫面改為資料年月?", "注意", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.No)
                    {
                        return(ResultStatus.Fail);
                    }
                    else
                    {
                        txtMonth.Text = datadate.SubStr(0, 4) + "/" + datadate.SubStr(4, 2);
                        Retrieve();
                    }
                }

                //3.刪除舊有資料
                string ls_symd = "", ls_eymd = "";
                if (gvMain.DataRowCount > 0)
                {
                    DialogResult result = MessageBox.Show("資料年月(" + datadate + ")資料已存在,是否刪除?", "注意", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.No)
                    {
                        return(ResultStatus.Fail);
                    }
                    else
                    {
                        ls_symd   = datadate + "01";
                        ls_eymd   = datadate + "31";
                        datadate += "%";
                        dao28512.DeleteByDate(datadate);
                    }
                }

                ls_symd = ls_eymd;
                ls_eymd = "";
                for (int i = 0; i < dtReadTxt.Rows.Count; i++)
                {
                    //找起始日期
                    if (ls_symd.AsInt() > dtReadTxt.Rows[i]["AM2F_YMD"].AsInt())
                    {
                        ls_symd = dtReadTxt.Rows[i]["AM2F_YMD"].AsString();
                    }

                    //找終止日期
                    if (ls_eymd.AsInt() < dtReadTxt.Rows[i]["AM2F_YMD"].AsInt())
                    {
                        ls_eymd = dtReadTxt.Rows[i]["AM2F_YMD"].AsString();
                    }

                    if (String.IsNullOrEmpty(dtReadTxt.Rows[i]["AM2F_PC_CODE"].AsString()))
                    {
                        string replaceEmpty = " ";
                        dtReadTxt.Rows[i]["AM2F_PC_CODE"] = replaceEmpty;
                    }
                    if (dtReadTxt.Rows[i]["AM2F_KIND_ID"].AsString() == "8888888")
                    {
                        string replaceEmpty = "STC";
                        dtReadTxt.Rows[i]["AM2F_PC_CODE"] = replaceEmpty;
                    }
                }

                PokeBall pb = new PokeBall();
                gcMain.DataSource = dtReadTxt;
                Save(pb);
                Run(pb);
            } catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }

            return(ResultStatus.Success);
        }