//檢視異常報表 protected void but_OK_Report_Click(object sender, EventArgs e) { #region try { DataTable dt = new DataTable(); this.gv_OKData.Visible = false; this.gv_ErrorData.Visible = false; if (this.TextBoxRowCountLimit.Text.Trim() == "") { this.TextBoxRowCountLimit.Text = "500"; } VGRModel.VDS_VGR08_BCO bco = new VGRModel.VDS_VGR08_BCO(ConnectionDB); if (this.rdoType1.Checked == true) { hid_Query_Type.Value = "1"; } else if (this.rdoType2.Checked) { hid_Query_Type.Value = "2"; } else { hid_Query_Type.Value = "3"; } dt = bco.QueryOKByFind(hid_Query_Type.Value, Session["UID"].ToString(), Convert.ToDateTime(System.DateTime.Now.ToShortDateString()), Convert.ToDateTime(System.DateTime.Now.ToShortDateString()), Convert.ToInt32(this.TextBoxRowCountLimit.Text.Trim())); #region 資料與GridView繫結 //抓取本頁初次登記的時間 if (dt.Rows.Count == 0) { ErrorMsgLabel.Text = "查無資料!"; } else { string SessionIDName = "VGR081_OK_" + PageTimeStamp.Value; this.gv_OKData.Visible = true; Session["SessionID"] = SessionIDName; Session[SessionIDName] = dt; this.gv_OKData.DataSource = dt; if (this.TextBoxPagesize.Text == "") this.gv_OKData.PageSize = 10; else this.gv_OKData.PageSize = Convert.ToInt32(this.TextBoxPagesize.Text); this.gv_OKData.PageIndex = 0; this.gv_OKData.DataBind(); } #endregion } catch (Exception ex) { this.ErrorMsgLabel.Text = ex.Message; } finally { } #endregion }
//查詢 protected void ButtonQueryOK_Click(object sender, EventArgs e) { #region try { this.gv_ErrorData.Visible = false; this.gv_OKData.Visible = false; #region 檢查條件 this.ErrorMsgLabel.Text = ""; string s_CheckPage = CheckPage(sender); if (s_CheckPage != string.Empty) { this.ErrorMsgLabel.Text = s_CheckPage; return; } #endregion ErrorMsgLabel.Text = ""; DataTable dt = new DataTable(); VGRModel.VDS_VGR08_BCO bco = new VGRModel.VDS_VGR08_BCO(ConnectionDB); DateTime dateB, dateE; DateTime.TryParse(this.SLP_SLPDateRange1.StartDate.ToString(), out dateB); if (DateTime.TryParse(this.SLP_SLPDateRange1.EndDate.ToString(), out dateE) == false) dateE = Convert.ToDateTime("3000/01/01"); else DateTime.TryParse(this.SLP_SLPDateRange1.EndDate.ToString(), out dateE); if (this.TextBoxRowCountLimit.Text.Trim() == "") { this.TextBoxRowCountLimit.Text = "500"; } if (this.rdoTypeQ1.Checked == true) { hid_Query_Type.Value = "1"; } else if (this.rdoTypeQ2.Checked) { hid_Query_Type.Value = "2"; } else { hid_Query_Type.Value = "3"; } dt = bco.QueryOKByFind(hid_Query_Type.Value, GetValueSetParameter(this.txt_User.Text.Trim(), "string", false).ToString(), dateB, dateE, Convert.ToInt32(this.TextBoxRowCountLimit.Text.Trim())); #region 資料與GridView繫結 //抓取本頁初次登記的時間 if (dt.Rows.Count == 0) { ErrorMsgLabel.Text = "查無資料!"; } else { string SessionIDName = "VGR081_OK_" + PageTimeStamp.Value; this.gv_OKData.Visible = true; Session["SessionID"] = SessionIDName; Session[SessionIDName] = dt; this.gv_OKData.DataSource = dt; if (this.TextBoxPagesize.Text == "") this.gv_OKData.PageSize = 10; else this.gv_OKData.PageSize = Convert.ToInt32(this.TextBoxPagesize.Text); this.gv_OKData.PageIndex = 0; this.gv_OKData.DataBind(); } #endregion } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; } #endregion }
private void ClientFileToServerTemp() { #region try { this.ErrorMsgLabel.Text = ""; //設定頁面狀態 this.hid_FrmStatus.Value = "fmBroswe"; //LockPage(); string s_UploadPath = string.Empty; string s_BackPath = string.Empty; string s_LoginUser = string.Empty; ArrayList arl_FileUpload_Return = null; ArrayList arl_FileToTmp_Return = null; VGRModel.VDS_VGR08_BCO bco = new VGRModel.VDS_VGR08_BCO(ConnectionDB); #region 上傳檔案到AP端 //取得要上傳的路徑 if (this.FileUpload1.FileName == "") { this.ErrorMsgLabel.Text = "請點選要匯入的檔案"; return; } s_UploadPath = Server.MapPath("..\\") + System.Configuration.ConfigurationManager.AppSettings["UploadPath"] + "\\VGR\\"; s_LoginUser = Session["UID"].ToString(); arl_FileUpload_Return = bco.FileUpload(s_UploadPath, this.FileUpload1, s_LoginUser); #endregion if (arl_FileUpload_Return[0].ToString() == "FALSE")//檔案上傳至AP端錯誤 { #region this.ErrorMsgLabel.Text = "檔案上傳至AP端錯誤";//檔案上傳至AP端錯誤,後面直接不做了 #endregion } else if (arl_FileUpload_Return[0].ToString() == "TRUE")//檔案上傳至AP端正常 { #region #region 讀取 Excel 資料 OleDbConnection oleConnection = null; DataTable ds_Excel = new DataTable(); if (this.rdoType1.Checked == true) { ds_Excel.Columns.Add(new DataColumn("廠退日期", typeof(string))); ds_Excel.Columns.Add(new DataColumn("品號", typeof(string))); ds_Excel.Columns.Add(new DataColumn("期別", typeof(string))); ds_Excel.Columns.Add(new DataColumn("數量", typeof(string))); } else { ds_Excel.Columns.Add(new DataColumn("入帳日", typeof(string))); ds_Excel.Columns.Add(new DataColumn("簽收日", typeof(string))); ds_Excel.Columns.Add(new DataColumn("通路單號", typeof(string))); ds_Excel.Columns.Add(new DataColumn("店號", typeof(string))); ds_Excel.Columns.Add(new DataColumn("品號", typeof(string))); ds_Excel.Columns.Add(new DataColumn("期別", typeof(string))); ds_Excel.Columns.Add(new DataColumn("數量", typeof(string))); } try { String connString = "Provider=Microsoft.JET.OLEDB.4.0;Data Source =" + arl_FileUpload_Return[1].ToString() + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1';"; oleConnection = new OleDbConnection(connString); oleConnection.Open(); OleDbCommand oleCommand = new OleDbCommand("SELECT * FROM [Sheet1$]", oleConnection); OleDbDataAdapter oleAdapter = new OleDbDataAdapter(oleCommand); oleAdapter.Fill(ds_Excel); RemoveBlankDataRow(ref ds_Excel); #region 請注意如果EXCEL檔欄位有值,但到DB卻沒有資料 //請修改,機碼 HKEY_LOCAL_MACHINE\Software\Microsoft\Jet\4.0\Engines\Excel\TypeGuessRows 值 //預設是 8, 表示會先讀取前 8 列來決定每一個欄位的型態, 所以如果前 8 列的資料都是數字, 到了第 9 列以後出現的文字資料都會變成 null //如果要解決這個問題, 只要把 TypeGuessRows 機碼值改成 0 #endregion } catch (Exception ex) { this.Response.Write(ex.Message); } finally { if (oleConnection != null) { oleConnection.Close(); oleConnection.Dispose(); } } #endregion #region 將檔案匯入TmpTable int N_TMP_CNT = 0; int N_TAB_CNT = 0; int N_UPLOAD = ds_Excel.Rows.Count; string V_MSG = ""; if (this.rdoType1.Checked == true) { V_MSG = bco.FileToTmp("1", ds_Excel, null, arl_FileUpload_Return[4].ToString(), Session["UID"].ToString()); if (V_MSG == "") { bco.QueryImportStat("1", Session["UID"].ToString(), out N_TMP_CNT, out N_TAB_CNT); } else { this.ErrorMsgLabel.Text = V_MSG; } } else if (this.rdoType2.Checked == true) { V_MSG = bco.FileToTmp("2", ds_Excel, null, arl_FileUpload_Return[4].ToString(), Session["UID"].ToString()); if (V_MSG == "") { bco.QueryImportStat("2", Session["UID"].ToString(), out N_TMP_CNT, out N_TAB_CNT); } else { this.ErrorMsgLabel.Text = V_MSG; } } else { V_MSG = bco.FileToTmp("3", ds_Excel, null, arl_FileUpload_Return[4].ToString(), Session["UID"].ToString()); if (V_MSG == "") { bco.QueryImportStat("3", Session["UID"].ToString(), out N_TMP_CNT, out N_TAB_CNT); } else { this.ErrorMsgLabel.Text = V_MSG; } } #endregion string hexValue = "#A29E9E"; Color colour = System.Drawing.ColorTranslator.FromHtml(hexValue); //上傳結果 this.UploadStatusPanel1.UploadSum = N_UPLOAD; this.UploadStatusPanel1.UploadOK = N_UPLOAD-N_TMP_CNT; this.UploadStatusPanel1.UploadNG = N_TMP_CNT; if (N_TMP_CNT > 0) { ((TextBox)UploadStatusPanel1.FindControl("txtUP13")).ForeColor = System.Drawing.Color.Red; } else { ((TextBox)UploadStatusPanel1.FindControl("txtUP13")).ForeColor = colour; } //匯入結果 this.UploadStatusPanel1.ImportSum = (N_TMP_CNT==0)? N_UPLOAD : 0; this.UploadStatusPanel1.ImportOK = (N_TMP_CNT == 0) ? (N_UPLOAD - N_TAB_CNT) : 0; this.UploadStatusPanel1.ImportNG = (N_TMP_CNT == 0) ? N_TAB_CNT:0; if (N_TMP_CNT == 0 && N_TAB_CNT > 0) { ((TextBox)UploadStatusPanel1.FindControl("txtUP23")).ForeColor = System.Drawing.Color.Red; } else { ((TextBox)UploadStatusPanel1.FindControl("txtUP23")).ForeColor = colour; } #endregion } unLockPage(); this.hid_FrmStatus.Value = ""; } catch (Exception ex) { this.ErrorMsgLabel.Text = ex.Message; unLockPage(); this.hid_FrmStatus.Value = ""; } #endregion }