/// <summary> /// 寫出至文字檔 /// </summary> //private void WriteTXT(string VDSCGD411TXTFILE) //{ // string path = @"" + txtFilePath.Text.Trim(); // StreamWriter sw = new StreamWriter(path, true, System.Text.Encoding.Unicode); // sw.WriteLine(VDSCGD411TXTFILE); // sw.Close(); // sw = null; //} /// <summary> /// Query理貨批次 /// </summary> private void setPickBatch(string StAcceptDate) { CGDModel.VDS_CGD41_BCO BCO = new CGDModel.VDS_CGD41_BCO(ConntionDB); DataTable Dt; ParameterList.Clear(); ParameterList.Add(StAcceptDate); Dt = BCO.QuerySwitch(CGDModel.CGDCommon.QueryType.GetPickBatch, ParameterList); if (Dt.Rows.Count == 0) { txtPickBatch.Text = ""; } else { txtPickBatch.Text = Dt.Rows[0][0].ToString(); } if (Dt.Rows[0][0].ToString() == "") { txtPickBatch.Text = ""; } }
/// <summary> /// 標籤列印 /// </summary> protected void btnDownLoad_Click(object sender, EventArgs e) { if (VerifyFormData() == true) { try { CGDModel.VDS_CGD41_BCO BCO = new CGDModel.VDS_CGD41_BCO(ConntionDB); DataTable Dt; ParameterList.Clear(); ParameterList.Add(SLP_SLPDate1.Text.Trim()); ParameterList.Add(txtPickBatch.Text.Trim()); ParameterList.Add(ddlLineStart.SelectedValue); ParameterList.Add(ddlLineEnd.SelectedValue); ParameterList.Add(SLP_Route_Start.Text.Trim()); ParameterList.Add(SLP_Route_End.Text.Trim()); ParameterList.Add(txtBoxStart.Text.Trim()); ParameterList.Add(txtBoxEnd.Text.Trim()); Dt = BCO.QuerySwitch(CGDModel.CGDCommon.QueryType.Label, ParameterList); if (Dt.Rows.Count == 0) { ErrorMsgLabel.Text = "查無資料"; //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD411.aspx", "alert(' 查無資料 ');", true); return; } //string VDSCGD411TXTFILE = ""; //for (int i = 0; i <= Dt.Rows.Count - 1; i++) //{ // VDSCGD411TXTFILE = Dt.Rows[i][0].ToString().Trim(); // WriteTXT(VDSCGD411TXTFILE); //} //---輸出至文字檔 System.Text.StringBuilder sb_Out_String = new System.Text.StringBuilder(); Response.Clear(); Response.Buffer = true; Response.Charset = "BIG5"; Response.AppendHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode(Request[txtFilePath.UniqueID].ToString().Trim())); Response.ContentEncoding = System.Text.Encoding.GetEncoding("BIG5"); Response.ContentType = "application/ms-txt"; this.EnableViewState = false; System.IO.StringWriter oStringWriter = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter oHtmlTextWriter = new HtmlTextWriter(oStringWriter); foreach (DataRow dRow in Dt.Rows) { sb_Out_String.Remove(0, sb_Out_String.Length); sb_Out_String.Append(dRow["DATA"].ToString()); Response.Write(sb_Out_String.ToString()); Response.Write(oHtmlTextWriter.NewLine); } Response.End(); ErrorMsgLabel.Text = "儲存完畢"; //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD411.aspx", "alert(' 儲存完畢 ');", true); } catch (System.UnauthorizedAccessException a) { ErrorMsgLabel.Text = "儲存失敗,對該路徑無寫入權限"; //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD411.aspx", "alert(' 儲存失敗,對該路徑無寫入權限 ');", true); } catch (System.IO.DirectoryNotFoundException b) { ErrorMsgLabel.Text = "儲存失敗,請確認儲存路徑正確"; //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD011.aspx", "alert(' 儲存失敗,請確認儲存路徑正確 ');", true); } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; } } }