Beispiel #1
0
    private void Export_Excel()
    {
        try
        {
            this.ErrorMsgLabel.Text = "";
            ParameterList.Clear();
            ParameterList.Add(SLP_VENDOR.Text.Trim());
            BCO.VAM21_BCO bco = new BCO.VAM21_BCO(ConntionDB);
            DataTable dt = bco.QueryData(ParameterList);

            if (dt.Rows.Count == 0)
            {
                this.ErrorMsgLabel.Text = "查無資料";
                return;
            }


            ExcelXmlWorkbook book = new ExcelXmlWorkbook();

            Worksheet sheet0 = book[0];

            AddSheetData(ref sheet0, "Sheet1", dt);

            //設定輸出檔名
            string s_FileName =
            s_FileName = HttpUtility.UrlEncode("折讓單自動排除廠商.XLS", System.Text.Encoding.UTF8);

            //File download
            Response.Charset = "big5";
            Response.ContentType = "application/x-excel;charset='utf-8'";
            Response.AddHeader("content-disposition", "attachment; filename=" + s_FileName);//excel檔名
            System.IO.MemoryStream stream = new System.IO.MemoryStream();
            book.Export(stream);
            string producedExcel = GetStringFromMemoryStream(stream);
            stream.Close();
            Response.Write(producedExcel);
            Response.Flush();
            Response.End();
        }
        catch (Exception ex)
        {
            this.ErrorMsgLabel.Text = ex.ToString();
        }
        finally { }
    }
Beispiel #2
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        ErrorMsgLabel.Text = "";
        WriteToCache();

        BCO.VAM21_BCO bco = new BCO.VAM21_BCO(ConntionDB);

        DataTable dt = (DataTable)Session["VAM211_" + PageTimeStamp.Value];

        #region 檢查是否有輸入廠商資料
        int iEmptyRows = 0;
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            if ((dt.Rows[i]["CREATEUID"].ToString() == "") && (dt.Rows[i]["VENDOR"].ToString() == ""))
            {
                iEmptyRows++;
            }
        }
        if (dt.Rows.Count == iEmptyRows)
        {
            ErrorMsgLabel.Text = "尚未輸入廠商資料,不可儲存.";
            return;
        }
        #endregion

        #region 檢查是否有重複設定
        string strErr = string.Empty;
        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            string strVENDOR = ((ASP.vdm_slp_slp_vendorbase_ascx)GridView1.Rows[i].FindControl("SLP_VENDOR")).Text;
            if (strVENDOR != "")
            {
                DataRow[] FindRows = dt.Select("VENDOR='" + strVENDOR + "' And ENABLE=1");
                if (FindRows.Length > 1)
                {
                    int iRow = i + 1;
                    strErr += "第 " + iRow.ToString() + " 行 廠商編號重複設定<BR/>";
                }
            }
        }
        if (strErr != "")
        {
            ErrorMsgLabel.Text = strErr;
            return;
        }
        #endregion

        #region 檢查DB裡面是否已經存在,並且不是在這次的編輯之中的
        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            string strVENDOR = ((ASP.vdm_slp_slp_vendorbase_ascx)GridView1.Rows[i].FindControl("SLP_VENDOR")).Text;
            if (strVENDOR != "")
            {
                ParameterList.Clear();
                ParameterList.Add(strVENDOR);
                DataTable dtCheck = bco.QueryData(ParameterList);
                if (dtCheck.Rows.Count != 0)
                {
                    DataRow[] FindRows = dt.Select("ID=" + dtCheck.Rows[0]["ID"].ToString() + " And CREATEUID is not null"); //是否是在本次編輯的範圍內
                    if (FindRows.Length == 0)
                    {
                        int iRow = i + 1;
                        strErr += "第 " + iRow.ToString() + " 行 廠商編號已經存在資料庫中<BR/>";
                    }
                }

            }
        }
        if (strErr != "")
        {
            ErrorMsgLabel.Text = strErr;
            return;
        }

        #endregion

        #region 儲存資料
        ParameterList.Clear();
        ParameterList.Add(DateTime.Now);
        ParameterList.Add(Session["UID"].ToString());
        bco.SaveData(ParameterList, dt);
        #endregion

        #region 重新顯示所有資料
        ParameterList.Clear();
        ParameterList.Add(DBNull.Value);
        dt = bco.QueryData(ParameterList);

        if (dt.Rows.Count == 0)
        {
            this.ErrorMsgLabel.Text = "廠商資料已全部刪除";
            btnNewRow.Visible = false;
            btnSave.Visible = false;
        }
        else
        {
            this.ErrorMsgLabel.Text = "儲存完成";
            btnNewRow.Visible = true;
            btnSave.Visible = true;
        }
        Session["VAM211_" + PageTimeStamp.Value] = dt;

        Build_GridView1();
        #endregion

    }
Beispiel #3
0
    private void LoadData()
    {
        try
        {
            ParameterList.Clear();
            ParameterList.Add(SLP_VENDOR.Text.Trim());
            BCO.VAM21_BCO bco = new BCO.VAM21_BCO(ConntionDB);
            DataTable dt = bco.QueryData(ParameterList);

            if (dt.Rows.Count == 0)
            {
                this.ErrorMsgLabel.Text = "查無資料";
                btnNewRow.Visible = false;
                btnSave.Visible = false;
            }
            else
            {
                btnNewRow.Visible = true;
                btnSave.Visible = true;
            }
            Session["VAM211_" + PageTimeStamp.Value] = dt;

            Build_GridView1();
        }
        catch (Exception ex)
        {
            ErrorMsgLabel.Text = ex.Message;
        }
    }
Beispiel #4
0
    protected void btnNew_Click(object sender, EventArgs e)
    {
        this.ErrorMsgLabel.Text = "";
        ParameterList.Clear();
        ParameterList.Add("XXXXXXXXXX"); //只讀取Table Schema
        BCO.VAM21_BCO bco = new BCO.VAM21_BCO(ConntionDB);
        DataTable dt = bco.QueryData(ParameterList);
        Session["VAM211_" + PageTimeStamp.Value] = dt;
        for (int i = 0; i < 5; i++)
            AddRow();
        btnNewRow.Visible = true;
        btnSave.Visible = true;

        Build_GridView1();

        string strClientID = ((ASP.vdm_slp_slp_vendorbase_ascx)GridView1.Rows[0].FindControl("SLP_VENDOR")).TextBox_Code.ClientID;
        ScriptManager.RegisterStartupScript(Page, this.GetType(), "SetToFocus", "SetToFocus('" + strClientID + "');", true);
    }