Example #1
0
    private void Data2Page(string v, string v2)
    {
        Class01 SBApp = new Class01();

        ConnectionStringSettings connectionString = ConfigurationManager.ConnectionStrings["SWCConnStr"];

        using (SqlConnection SwcConn = new SqlConnection(connectionString.ConnectionString))
        {
            SwcConn.Open();

            string strSQLRV = " select * from SWCCASE ";
            strSQLRV = strSQLRV + " where SWC000 = '" + v + "' ";

            SqlDataReader readeSwc;
            SqlCommand    objCmdSwc = new SqlCommand(strSQLRV, SwcConn);
            readeSwc = objCmdSwc.ExecuteReader();

            while (readeSwc.Read())
            {
                string tSWC005 = readeSwc["SWC005"] + "";

                LBSWC000.Text = v;
                LBSWC005.Text = tSWC005;
            }

            readeSwc.Close();
            objCmdSwc.Dispose();

            if (v2 == "AddNew")
            {
                string nIDA = GetDTLAID(v);

                LBDTL001.Text = nIDA;
            }
            else
            {
                string strSQLRV2 = " select * from SWCDTL02 ";
                strSQLRV2 = strSQLRV2 + " where SWC000 = '" + v + "' ";
                strSQLRV2 = strSQLRV2 + "   AND DTLB000 = '" + v2 + "' ";

                SqlDataReader readeDTL;
                SqlCommand    objCmdDTL = new SqlCommand(strSQLRV2, SwcConn);
                readeDTL = objCmdDTL.ExecuteReader();

                while (readeDTL.Read())
                {
                    string tDTLB001 = readeDTL["DTLB001"] + "";
                    string tDTLB002 = readeDTL["DTLB002"] + "";
                    string tDTLB003 = readeDTL["DTLB003"] + "";
                    string tDTLB004 = readeDTL["DTLB004"] + "";
                    string tDTLB006 = readeDTL["DTLB006"] + "";
                    string tDTLB007 = readeDTL["DTLB007"] + "";
                    string tDTLB008 = readeDTL["DTLB008"] + "";
                    string tDTLB009 = readeDTL["DTLB009"] + "";
                    string tDTLB010 = readeDTL["DTLB010"] + "";
                    string tDTLB011 = readeDTL["DTLB011"] + "";
                    string tDTLB012 = readeDTL["DTLB012"] + "";
                    string tDTLB013 = readeDTL["DTLB013"] + "";
                    string tDTLB014 = readeDTL["DTLB014"] + "";
                    string tDTLB015 = readeDTL["DTLB015"] + "";
                    string tDTLB016 = readeDTL["DTLB016"] + "";
                    string tDTLB017 = readeDTL["DTLB017"] + "";
                    string tDTLB018 = readeDTL["DTLB018"] + "";
                    string tDTLB019 = readeDTL["DTLB019"] + "";
                    string tDTLB020 = readeDTL["DTLB020"] + "";
                    string tDTLB021 = readeDTL["DTLB021"] + "";
                    string tDTLB022 = readeDTL["DTLB022"] + "";
                    string tDTLB023 = readeDTL["DTLB023"] + "";

                    string tDATALOCK = readeDTL["DATALOCK"] + "";

                    LBDTL001.Text  = tDTLB001;
                    TXTDTL002.Text = tDTLB002;
                    TXTDTL003.Text = tDTLB003;
                    TXTDTL004.Text = tDTLB004;
                    //TXTDTL006.Text = SBApp.DateView(tDTLB006, "00");
                    if (tDTLB007 == "1")
                    {
                        CHKDTL007.Checked = true;
                    }
                    if (tDTLB008 == "1")
                    {
                        CHKDTL008.Checked = true;
                    }
                    if (tDTLB009 == "1")
                    {
                        CHKDTL009.Checked = true;
                    }
                    TXTDTL010.Text            = tDTLB010;
                    DropList011.SelectedValue = tDTLB011;
                    DropList012.SelectedValue = tDTLB012;
                    DropList013.SelectedValue = tDTLB013;
                    TXTDTL014.Text            = tDTLB014;
                    if (tDTLB015 == "1")
                    {
                        CHKBOX015.Checked = true;
                    }
                    if (tDTLB016 == "1")
                    {
                        CHKBOX016.Checked = true;
                    }
                    if (tDTLB017 == "1")
                    {
                        CHKBOX017.Checked = true;
                    }
                    if (tDTLB018 == "1")
                    {
                        CHKBOX018.Checked = true;
                    }
                    TXTDTL019.Text = tDTLB019;
                    TXTDTL020.Text = tDTLB001;
                    TXTDTL021.Text = tDTLB021;
                    TXTDTL022.Text = tDTLB022;
                    TXTDTL023.Text = tDTLB023;

                    //檔案類處理
                    string[] arrayFileNameLink = new string[] { tDTLB023 };
                    System.Web.UI.WebControls.HyperLink[] arrayLinkAppobj = new System.Web.UI.WebControls.HyperLink[] { Link023 };

                    for (int i = 0; i < arrayFileNameLink.Length; i++)
                    {
                        string strFileName = arrayFileNameLink[i];
                        System.Web.UI.WebControls.HyperLink FileLinkObj = arrayLinkAppobj[i];

                        FileLinkObj.Visible = false;
                        if (strFileName == "")
                        {
                        }
                        else
                        {
                            string tempLinkPateh = SwcUpLoadFilePath + v + "/" + strFileName;
                            FileLinkObj.Text        = strFileName;
                            FileLinkObj.NavigateUrl = tempLinkPateh;
                            FileLinkObj.Visible     = true;
                        }
                    }

                    //圖片類處理
                    string[] arrayFileName = new string[] { tDTLB022 };
                    System.Web.UI.WebControls.Image[] arrayImgAppobj = new System.Web.UI.WebControls.Image[] { TXTDTL022_img };

                    for (int i = 0; i < arrayFileName.Length; i++)
                    {
                        string strFileName = arrayFileName[i];
                        System.Web.UI.WebControls.Image ImgFileObj = arrayImgAppobj[i];

                        if (strFileName == "")
                        {
                        }
                        else
                        {
                            string tempImgPateh = SwcUpLoadFilePath + v + "/" + strFileName;
                            ImgFileObj.Attributes.Add("src", tempImgPateh + "?ts=" + DateTime.Now.Millisecond);
                        }
                    }

                    //按鈕處理
                    if (tDATALOCK == "Y")
                    {
                        DataLock.Visible = false;
                        SaveCase.Visible = false;

                        error_msg.Text = SBApp.AlertMsg("資料已送出,目前僅供瀏覽。");
                    }
                }
            }
        }
    }
Example #2
0
    private void FileUpLoadApp(string ChkType, FileUpload UpLoadBar, TextBox UpLoadText, string UpLoadStr, string UpLoadType, System.Web.UI.WebControls.Image UpLoadView, HyperLink UpLoadLink)
    {
        Class01 MyBassAppPj = new Class01();
        string  SwcFileName = "";
        string  CaseId      = LBSWC000.Text + "";

        if (UpLoadBar.HasFile)
        {
            string filename = UpLoadBar.FileName;   // UpLoadBar.FileName 只有 "檔案名稱.附檔名",並沒有 Client 端的完整理路徑

            string extension = Path.GetExtension(filename).ToLowerInvariant();

            // 判斷是否為允許上傳的檔案附檔名

            switch (ChkType)
            {
            case "PIC":
                List <string> allowedExtextsion01 = new List <string> {
                    ".jpg", ".png"
                };

                if (allowedExtextsion01.IndexOf(extension) == -1)
                {
                    error_msg.Text = MyBassAppPj.AlertMsg("請選擇 JPG PNG 檔案格式上傳,謝謝!!");
                    return;
                }
                break;

            case "DOC":
                List <string> allowedExtextsion02 = new List <string> {
                    ".pdf"
                };

                if (allowedExtextsion02.IndexOf(extension) == -1)
                {
                    error_msg.Text = MyBassAppPj.AlertMsg("請選擇 PDF 檔案格式上傳,謝謝!!");
                    return;
                }
                break;
            }

            // 限制檔案大小,限制為 5MB
            int filesize = UpLoadBar.PostedFile.ContentLength;

            if (filesize > 10000000)
            {
                error_msg.Text = "請選擇 10 Mb 以下檔案上傳,謝謝!!";
                return;
            }

            // 檢查 Server 上該資料夾是否存在,不存在就自動建立
            string serverDir = ConfigurationManager.AppSettings["SwcFileTemp"] + CaseId;

            if (Directory.Exists(serverDir) == false)
            {
                Directory.CreateDirectory(serverDir);
            }

            Session[UpLoadStr] = "有檔案";
            //SwcFileName = CaseId + UpLoadType + System.IO.Path.GetExtension(UpLoadBar.FileName);
            SwcFileName     = Path.GetFileNameWithoutExtension(filename) + UpLoadType + System.IO.Path.GetExtension(UpLoadBar.FileName);
            UpLoadText.Text = SwcFileName;

            // 判斷 Server 上檔案名稱是否有重覆情況,有的話必須進行更名
            // 使用 Path.Combine 來集合路徑的優點
            //  以前發生過儲存 Table 內的是 \\ServerName\Dir(最後面沒有 \ 符號),
            //  直接跟 FileName 來進行結合,會變成 \\ServerName\DirFileName 的情況,
            //  資料夾路徑的最後面有沒有 \ 符號變成還需要判斷,但用 Path.Combine 來結合的話,
            //  資料夾路徑沒有 \ 符號,會自動補上,有的話,就直接結合

            string serverFilePath = Path.Combine(serverDir, SwcFileName);
            string fileNameOnly   = Path.GetFileNameWithoutExtension(SwcFileName);
            int    fileCount      = 1;

            //while (File.Exists(serverFilePath))
            //{
            //    // 重覆檔案的命名規則為 檔名_1、檔名_2 以此類推
            //    filename = string.Concat(fileNameOnly, "_", fileCount, extension);
            //    serverFilePath = Path.Combine(serverDir, filename);
            //    fileCount++;
            //}

            // 把檔案傳入指定的 Server 內路徑
            try
            {
                UpLoadBar.SaveAs(serverFilePath);
                //error_msg.Text = "檔案上傳成功";

                switch (ChkType)
                {
                case "PIC":
                    UpLoadView.Attributes.Add("src", "..\\UpLoadFiles\\temp\\" + CaseId + "\\" + SwcFileName + "?ts=" + System.DateTime.Now.Millisecond);
                    //UpLoadView.ImageUrl = "..\\UpLoadFiles\\temp\\" + CaseId +"\\"+ geohfilename;

                    imagestitch(UpLoadView, serverDir + "\\" + SwcFileName, 320, 180);
                    break;

                case "DOC":
                    UpLoadLink.Text        = SwcFileName;
                    UpLoadLink.NavigateUrl = "..\\UpLoadFiles\\temp\\" + CaseId + "\\" + SwcFileName + "?ts=" + System.DateTime.Now.Millisecond;
                    UpLoadLink.Visible     = true;
                    break;
                }
            }
            catch (Exception ex)
            {
                //error_msg.Text = "檔案上傳失敗";
            }
        }
        else
        {
            Session[UpLoadStr] = "";
        }
    }