Ejemplo n.º 1
0
        private void ExportDaliyReport()
        {
            if (_PathReport.Length <= 0)
            {
                SetMsg("匯出報表至伺服器失敗,沒有設定[每日報表匯出路徑]。");
                Thread.Sleep(300);
                return;
            }

            //先判斷今天是否有測試紀錄;//
            string    DateFrom = DateTime.Today.ToString("yyyy-MM-dd") + " 00:00:00";
            string    DateTo   = DateTime.Today.ToString("yyyy-MM-dd") + " 23:59:59";
            DataTable dtTest   = DaoSQL.Instance.GetTestHistory(DateFrom, DateTo);

            if (dtTest.Rows.Count <= 0)
            {
                return;
            }

            //客戶要求取得全部的測試資料;//
            dtTest           = DaoSQL.Instance.GetTestHistory();
            dtTest.TableName = DateTime.Today.ToString("yyyy-MM-dd");

            //先取得所有資料集;//
            DataSet Ds = new DataSet();

            Ds.Tables.Add(dtTest);

            //String TimeForFileName = DateTime.Now.ToString("yyyy-MM-dd");
            //string FileName = string.Format("./{0}-{1}_{2}.xls", m_Machine.機台代碼, m_Machine.描述, TimeForFileName);
            //客戶要求每次上傳報告都是上傳全部,所以不須加上時間;//
            string FileName = string.Format("./{0}-{1}.xls", m_Machine.機台代碼, m_Machine.描述);

            //輸出檔案成Excel檔;//
            try
            {
                FileExport.ExportDataSetToExcel(Ds, FileName);
            }
            catch (Exception ex)
            {
                Logger.Error(string.Format("匯出報表檔案失敗!\r\n資訊:{0}", ex.Message));
            }

            //將這檔案上傳到指定路徑;//
            try
            {
                NetTranslate.Transport(FileName, _PathReport, Path.GetFileName(FileName));
            }
            catch (Exception Ex)
            {
                Logger.Error(string.Format("傳送報表資訊失敗!\r\n資訊:{0}", Ex.Message));
            }

            //刪除報表檔案;//
            File.Delete(FileName);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 匯出報表按鈕事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnExport_Click(object sender, EventArgs e)
        {
            //先取得資料看有無資訊,沒有的話就不執行匯出動作;//
            if (m_dgvTestHistory.Rows.Count <= 0)
            {
                MessageBoxEx.Show(this, "沒有任何測試紀錄可供匯出檔案.", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            //顯示除儲存檔案視窗;//
            SaveFileDialog Dialog = new SaveFileDialog();

            Dialog.Title            = "匯出檔案";
            Dialog.InitialDirectory = ".\\";
            Dialog.Filter           = "xls files (*.*)|*.xls";

            //因為檔名不允許使用冒號 所以換成空白
            //因為Now一定是有資料 所以不用先判斷是否有資料才取值
            String TimeForFileName = DateTime.Now.ToString("yyyy-MM-dd");

            Dialog.FileName = string.Format("{0}-{1}_{2}.xls", m_Machine.機台代碼, m_Machine.描述, TimeForFileName);

            if (Dialog.ShowDialog() == DialogResult.OK)
            {
                //先取得所有資料集;//
                DataSet Ds = new DataSet();
                Ds.Tables.Add(DaoSQL.Instance.GetTestHistory(m_DateSearchFrom, m_DateSearchTo));

                //輸出檔案成Excel檔;//
                try
                {
                    FileExport.ExportDataSetToExcel(Ds, Dialog.FileName);
                    MessageBoxEx.Show(this, string.Format("匯出檔案成功!\r\n檔名:{0}", Dialog.FileName), "訊息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    MessageBoxEx.Show(this, string.Format("匯出檔案失敗!\r\n資訊:{0}", ex.Message), "訊息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
        }