private void Delete(string id)
 {
     pnDetail.Visible = false;
     #region Authorize
     if (!clsSecurity.LoginChecker("admin") && !clsSecurity.LoginChecker("hr"))
     {
         ucColorBox1.Redirect("/", "กรุณาล็อคอินด้วยสิทธิ์ Admin");
         return;
     }
     #endregion
     #region Variable
     var clsIO  = new clsIO();
     var strSQL = new StringBuilder();
     #endregion
     #region Procedure
     #region Delete Database
     #region SQL Query
     strSQL.Append("DELETE FROM ");
     strSQL.Append(tableDefault + " ");
     strSQL.Append("WHERE ");
     strSQL.Append("UID=" + id);
     #endregion
     if (clsSQL.Execute(strSQL.ToString(), dbType, cs))
     {
         ucColorBox1.Redirect(webDefault);
     }
     else
     {
         ucColorBox1.Redirect(webDefault, "เกิดข้อผิดพลาดขณะลบข้อมูล");
         return;
     }
     strSQL.Length = 0; strSQL.Capacity = 0;
     #endregion
     #endregion
 }
    private void Delete(string id)
    {
        pnDetail.Visible = false;
        #region Authorize
        if (!clsSecurity.LoginChecker("admin"))
        {
            ucColorBox1.Redirect("/", "กรุณาล็อคอินด้วยสิทธิ์ Admin");
            return;
        }
        #endregion
        #region Variable
        StringBuilder strSQL = new StringBuilder();
        DataTable     dt     = new DataTable();
        clsIO         clsIO  = new clsIO();
        #endregion

        #region Delete Photo
        #region SQL Query
        strSQL.Append("SELECT ");
        strSQL.Append("Icon ");
        strSQL.Append("FROM ");
        strSQL.Append("MedicalCenter ");
        strSQL.Append("WHERE ");
        strSQL.Append("MedicalCenterGroupUID=" + id);
        #endregion
        dt            = clsSQL.Bind(strSQL.ToString(), dbType, cs);
        strSQL.Length = 0; strSQL.Capacity = 0;
        if (dt != null && dt.Rows.Count > 0)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i]["Icon"] != DBNull.Value)
                {
                    clsIO.FileExist(dt.Rows[i]["Icon"].ToString(), true);
                }
            }
            dt = null;
        }
        strSQL.Length = 0; strSQL.Capacity = 0;
        #endregion
        #region Delete Database
        #region SQL Query
        strSQL.Append("DELETE FROM ");
        strSQL.Append(tableDefault + " ");
        strSQL.Append("WHERE ");
        strSQL.Append("UID=" + parameterChar + "UID");
        #endregion
        if (clsSQL.Execute(strSQL.ToString(), new string[, ] {
            { parameterChar + "UID", id }
        }, dbType, cs))
        {
            ucColorBox1.Redirect(webDefault);
        }
        else
        {
            ucColorBox1.Redirect(webDefault, "เกิดข้อผิดพลาดขณะลบข้อมูล");
        }
        strSQL.Length = 0; strSQL.Capacity = 0;
        #endregion
    }
    private void Delete(string id)
    {
        pnDetail.Visible = false;
        #region Authorize
        if (!clsSecurity.LoginChecker("admin"))
        {
            ucColorBox1.Redirect("/", "กรุณาล็อคอินด้วยสิทธิ์ Admin");
            return;
        }
        #endregion
        #region Variable
        var clsIO  = new clsIO();
        var strSQL = new StringBuilder();
        #endregion
        #region Procedure
        #region Delete Photo

        /*
         #region SQL Query
         * strSQL.Append("SELECT ");
         * strSQL.Append("Icon ");
         * strSQL.Append("FROM ");
         * strSQL.Append(tableDefault + " ");
         * strSQL.Append("WHERE ");
         * strSQL.Append("UID=" + id);
         #endregion
         * string photoDelete = clsSQL.Return(strSQL.ToString(), dbType, cs);
         * if (!string.IsNullOrEmpty(photoDelete))
         * {
         *  clsIO.FileExist(photoDelete, true);
         * }
         * strSQL.Length = 0; strSQL.Capacity = 0;
         */
        #endregion
        #region Delete Database
        #region SQL Query
        strSQL.Append("DELETE FROM ");
        strSQL.Append(tableDefault + " ");
        strSQL.Append("WHERE ");
        strSQL.Append("UID=" + id);
        #endregion
        if (clsSQL.Execute(strSQL.ToString(), dbType, cs))
        {
            ucColorBox1.Redirect(webDefault);
        }
        else
        {
            ucColorBox1.Redirect(webDefault, "เกิดข้อผิดพลาดขณะลบข้อมูล");
            return;
        }
        strSQL.Length = 0; strSQL.Capacity = 0;
        #endregion
        #endregion
    }
Ejemplo n.º 4
0
    protected void btUpload_Click(object sender, EventArgs e)
    {
        string strFileName;
        int    i;
        clsIO  clsIO = new clsIO();

        if (!fuUpload.HasFile)
        {
            lblUpload.Text = "โปรดเลือกรูปก่อน";
            return;
        }
        if (fuUpload.PostedFile.ContentLength > maxSize * 1000)
        {
            lblUpload.Text = "<div style='color:red;'>ขนาดของไฟล์ใหญ่เกินไป ซึ่งต้องไม่เกิน " + maxSize + " KB</div>";
            return;
        }

        for (i = 1; i < 10; i++)
        {
            strFileName = DateTime.Now.Year.ToString() +
                          DateTime.Now.Month.ToString() +
                          DateTime.Now.Day.ToString() +
                          DateTime.Now.Hour.ToString() +
                          DateTime.Now.Minute.ToString() +
                          DateTime.Now.Second.ToString() + "_" + i.ToString() +
                          System.IO.Path.GetExtension(fuUpload.FileName).ToLower();

            if (!clsIO.FileExist(pathUpload + strFileName, false))
            {
                try
                {
                    fuUpload.SaveAs(Server.MapPath(pathUpload + strFileName));
                }
                catch (Exception ex)
                {
                    lblUpload.Text = "<div style='color:red;'>เกิดข้อผิดพลาดขณะอัพโหลดไฟล์ : " + ex.Message + "</div>";
                    return;
                }
                clsIO.ImageResize(maxWidth, 0, pathUpload + strFileName, "", webname, 0);

                lblUpload.Text = "<div style='font-size:9pt;margin:5px 0px 5px 0px;'>อัพโหลดไฟล์เสร็จสิ้น : " +
                                 "<span style='' title='Copy ชื่อไฟล์นี้ วางในหน้าแทรกภาพ'>" +
                                 "<input id='txtInsertImages' type='text' value='" +
                                 pathUpload + strFileName.Trim() +
                                 "' style='border:1px solid #dddddd;background-color:#fafafa;width:300px;'/>" +
                                 "</span></div>";
                InsertTinyMCE("<img src=" + pathUpload + strFileName.Trim() + " />");
                break;
            }
        }
    }
Ejemplo n.º 5
0
 private void Delete(string id)
 {
     pnDetail.Visible = false;
     #region Authorize
     if (!clsSecurity.LoginChecker("admin"))
     {
         ucColorBox1.Redirect(webDefault, "กรุณาล็อคอินด้วยสิทธิ์ Admin");
         return;
     }
     #endregion
     #region Variable
     StringBuilder strSQL = new StringBuilder();
     DataTable     dt     = new DataTable();
     clsIO         clsIO  = new clsIO();
     string        photoName;
     #endregion
     #region Delete Photo
     photoName = clsSQL.Return(
         "SELECT Photo FROM " + tableDefault + " WHERE UID=" + parameterChar + "UID",
         new string[, ] {
         { parameterChar + "UID", id }
     },
         dbType,
         cs);
     if (photoName != "")
     {
         clsIO.FileExist(photoName, true);
     }
     #endregion
     #region Delete Database
     #region SQL Query
     strSQL.Append("DELETE FROM ");
     strSQL.Append(tableDefault + " ");
     strSQL.Append("WHERE ");
     strSQL.Append("UID=" + parameterChar + "UID");
     #endregion
     if (clsSQL.Execute(strSQL.ToString(), new string[, ] {
         { parameterChar + "UID", id }
     }, dbType, cs))
     {
         ucColorBox1.Redirect(webDefault);
     }
     else
     {
         ucColorBox1.Redirect(webDefault, "เกิดข้อผิดพลาดขณะลบข้อมูล");
     }
     strSQL.Length = 0; strSQL.Capacity = 0;
     #endregion
 }
    protected void btInsertImages_Click(object sender, EventArgs e)
    {
        string strFileName;
        int i;
        clsIO clsIO = new clsIO();

        if (fuInsertImages.PostedFile.ContentLength > maxSize * 1000)
        {
            lblInsertImages.Text = "<div style='color:red;'>ขนาดของไฟล์ใหญ่เกินไป ซึ่งต้องไม่เกิน " + maxSize + " KB</div>";
            return;
        }

        for (i = 1; i < 10; i++)
        {
            strFileName = DateTime.Now.Year.ToString() +
                DateTime.Now.Month.ToString() +
                DateTime.Now.Day.ToString() +
                DateTime.Now.Hour.ToString() +
                DateTime.Now.Minute.ToString() +
                DateTime.Now.Second.ToString() + "_" + i.ToString() +
                System.IO.Path.GetExtension(fuInsertImages.FileName).ToLower();

            if (!clsIO.FileExist(pathUpload + strFileName, false))
            {
                try
                {
                    fuInsertImages.SaveAs(Server.MapPath(pathUpload + strFileName));
                }
                catch (Exception ex)
                {
                    lblInsertImages.Text = "<div style='color:red;'>เกิดข้อผิดพลาดขณะอัพโหลดไฟล์ : " + ex.Message + "</div>";
                    return;
                }
                clsIO.ImageResize(maxWidth, 0, pathUpload + strFileName, "", webname, 0);

                lblInsertImages.Text = "<div style='font-size:9pt;margin:5px 0px 5px 0px;'>อัพโหลดไฟล์เสร็จสิ้น : " +
                    "<span style='' title='Copy ชื่อไฟล์นี้ วางในหน้าแทรกภาพ'>" +
                    "<input id='txtInsertImages' type='text' value='" +
                    pathUpload + strFileName.Trim() +
                    "' style='border:1px solid #dddddd;background-color:#fafafa;width:300px;'/>" +
                    "</span></div>";
                InsertTinyMCE("<img src=" + pathUpload + strFileName.Trim() + " />");
                ChangeIFrameHeight(70);
                break;
            }
        }
    }
    private void Delete(string id)
    {
        pnDetail.Visible = false;
        #region Authorize
        if (!clsSecurity.LoginChecker("admin"))
        {
            ucColorBox1.Redirect("/", "กรุณาล็อคอินด้วยสิทธิ์ Admin");
            return;
        }
        #endregion
        #region Variable
        StringBuilder strSQL = new StringBuilder();
        DataTable dt = new DataTable();
        clsIO clsIO = new clsIO();
        #endregion

        #region Delete Database
        #region SQL Query
        strSQL.Append("DELETE FROM ");
        strSQL.Append(tableDefault + " ");
        strSQL.Append("WHERE ");
        strSQL.Append("UID=" + parameterChar + "UID");
        #endregion
        if (clsSQL.Execute(strSQL.ToString(), new string[,] { { parameterChar + "UID", id } }, dbType, cs))
        {
            ucColorBox1.Redirect(webDefault);
        }
        else
        {
            ucColorBox1.Redirect(webDefault, "เกิดข้อผิดพลาดขณะลบข้อมูล");
        }
        strSQL.Length = 0; strSQL.Capacity = 0;
        #endregion
    }
    protected void btSubmit_Click(object sender, EventArgs e)
    {
        #region Authorize
        if (!clsSecurity.LoginChecker("admin"))
        {
            ucColorBox1.Redirect(webDefault, "กรุณาล็อคอินด้วยสิทธิ์ Admin");
            return;
        }
        #endregion
        #region Variable
        clsIO         clsIO  = new clsIO();
        StringBuilder strSQL = new StringBuilder();
        int           id     = 0;
        string        outSQL;
        string        outErrorMessage;
        string        outFilename;
        string        photoName = "";
        #endregion

        #region Update
        if (clsDefault.URLRouting("id") != "" && clsDefault.URLRouting("command") == "Edit")
        {
            id = int.Parse(clsDefault.URLRouting("id"));
            #region Photo Upload
            if (fuPhoto.HasFile)
            {
                if (clsIO.UploadPhoto(
                        fuPhoto, pathUpload,
                        "Group" + id.ToString(),
                        out outErrorMessage,
                        out outFilename,
                        maxWidth: photoWidth,
                        maxHeight: photoHeight,
                        resizeMode: clsIO.ResizeMode.crop))
                {
                    photoName = outFilename;
                }
                else
                {
                    ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะอัพโหลดไฟล์รูปภาพ<br/>" + outErrorMessage, AlertImage: ucColorBox.Alerts.Fail);
                    return;
                }
            }
            #endregion
            if (clsSQL.Update(tableDefault,
                              new string[, ] {
                { "WebboardTypeUID", ddlWebboardType.SelectedItem.Value },
                { "GlobalUID", "'" + clsSQL.CodeFilter(txtGlobalUID.Text) + "'" },
                { "Icon", (photoName != ""?"'" + pathUpload + photoName + "'":"Icon") },
                { "Name", "'" + clsSQL.CodeFilter(txtName.Text) + "'" },
                { "Detail", "'" + clsSQL.CodeFilter(txtDetail.Text) + "'" },
                { "MetaKeywords", "'" + clsSQL.CodeFilter(txtMetaKeywords.Text) + "'" },
                { "MetaDescription", "'" + clsSQL.CodeFilter(txtMetaDescription.Text) + "'" },
                { "MUser", "'" + clsSecurity.LoginUID + "'" },
                { "MWhen", "GETDATE()" },
                { "Sort", clsSQL.CodeFilter(txtSort.Text) },
                { "Active", "'" + (cbActive.Checked ? "1" : "0") + "'" }
            }, new string[, ] {
                { parameterChar + "UID", id.ToString() }
            },
                              "UID=" + parameterChar + "UID",
                              dbType, cs, out outSQL))
            {
                ucColorBox1.ReloadParent();
            }
            else
            {
                ucColorBox1.Alert("เกิดข้อผิดพลาดขณะบันทึกข้อมูล<br/>", outSQL, AlertImage: ucColorBox.Alerts.Fail);
            }
        }
        #endregion
        #region Insert
        else
        {
            #region Find New ID
            id = clsSQL.GetNewID("UID", tableDefault, "", dbType, cs);
            if (id == 0)
            {
                ucColorBox1.Alert("เกิดข้อผิดพลาดขณะบันทึกข้อมูล", "ไม่สามารถหา UID ใหม่ได้", AlertImage: ucColorBox.Alerts.Fail);
                return;
            }
            #endregion
            #region Photo Upload
            if (fuPhoto.HasFile)
            {
                if (clsIO.UploadPhoto(
                        fuPhoto, pathUpload,
                        "Group" + id.ToString(),
                        out outErrorMessage,
                        out outFilename,
                        maxWidth: photoWidth,
                        maxHeight: photoHeight,
                        resizeMode: clsIO.ResizeMode.crop))
                {
                    photoName = outFilename;
                }
                else
                {
                    ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะอัพโหลดไฟล์รูปภาพ<br/>" + outErrorMessage, AlertImage: ucColorBox.Alerts.Fail);
                    return;
                }
            }
            #endregion
            if (clsSQL.Insert(tableDefault,
                              new string[, ] {
                { "UID", id.ToString() },
                { "WebboardTypeUID", clsDefault.URLRouting("type") },
                { "GlobalUID", "'" + clsSQL.CodeFilter(txtGlobalUID.Text) + "'" },
                { "Icon", "'" + pathUpload + photoName + "'" },
                { "Name", "'" + clsSQL.CodeFilter(txtName.Text) + "'" },
                { "Detail", "'" + clsSQL.CodeFilter(txtDetail.Text) + "'" },
                { "MetaKeywords", "'" + clsSQL.CodeFilter(txtMetaKeywords.Text) + "'" },
                { "MetaDescription", "'" + clsSQL.CodeFilter(txtMetaDescription.Text) + "'" },
                { "Views", "0" },
                { "CUser", "'" + clsSecurity.LoginUID + "'" },
                { "CWhen", "GETDATE()" },
                { "MUser", "'" + clsSecurity.LoginUID + "'" },
                { "MWhen", "GETDATE()" },
                { "Sort", clsSQL.CodeFilter(txtSort.Text) },
                { "Active", "'" + (cbActive.Checked ? "1" : "0") + "'" }
            }, new string[, ] {
                { }
            },
                              dbType, cs, out outSQL))
            {
                ucColorBox1.ReloadParent();
            }
            else
            {
                ucColorBox1.Alert("เกิดข้อผิดพลาดขณะบันทึกข้อมูล<br/>", outSQL, AlertImage: ucColorBox.Alerts.Fail);
            }
        }
        #endregion
    }
    protected void btSubmit_Click(object sender, EventArgs e)
    {
        #region Authorize
        if (!clsSecurity.LoginChecker("admin"))
        {
            ucColorBox1.Redirect("/", "กรุณาล็อคอินด้วยสิทธิ์ Admin");
            return;
        }
        #endregion
        #region Variable
        var strSQL        = new StringBuilder();
        var id            = 0;
        var outSQL        = "";
        var photoName     = "";
        var photoFullName = "";
        #endregion

        #region Update
        if (Request.QueryString["id"] != null && clsDefault.QueryStringChecker("command") == "edit")
        {
            id = int.Parse(Request.QueryString["id"].ToString());
            clsIO  clsIO = new clsIO();
            string outErrorMessage; string outFilename;
            #region Photo Upload
            if (fuPhoto.HasFile)
            {
                if (clsIO.UploadPhoto(
                        fuPhoto, pathUpload,
                        "HealthPackage" + id.ToString() + "_T",
                        out outErrorMessage,
                        out outFilename,
                        maxWidth: photoWidth,
                        maxHeight: photoHeight))
                {
                    photoName = outFilename;
                }
                else
                {
                    ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะอัพโหลดไฟล์รูปภาพ<br/>" + outErrorMessage, AlertImage: ucColorBox.Alerts.Fail);
                    return;
                }
            }
            #endregion
            #region PhotoFull Upload
            if (fuPhotoFull.HasFile)
            {
                if (clsIO.UploadPhoto(
                        fuPhotoFull, pathUpload,
                        "HealthPackage" + id.ToString(),
                        out outErrorMessage,
                        out outFilename))
                {
                    photoFullName = outFilename;
                }
                else
                {
                    ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะอัพโหลดไฟล์รูปภาพ<br/>" + outErrorMessage, AlertImage: ucColorBox.Alerts.Fail);
                    return;
                }
            }
            #endregion
            if (clsSQL.Update(tableDefault,
                              new string[, ] {
                { "LanguageUID", rbLanguage.SelectedItem.Value },
                { "DepartmentUID", (txtDepartmentUID.Text != ""?clsSQL.CodeFilter(txtDepartmentUID.Text):"null") },
                { "PicThumbnail", (!string.IsNullOrEmpty(photoName)?"'" + pathUpload + photoName + "'":"PicThumbnail") },
                { "PicFull", (!string.IsNullOrEmpty(photoFullName)?"'" + pathUpload + photoFullName + "'":"PicFull") },
                { "Name", "'" + clsSQL.CodeFilter(txtName.Text) + "'" },
                { "Detail", "'" + ucContent.Text.SQLQueryFilter() + "'" },
                { "DetailSub", "'" + clsSQL.CodeFilter(txtDetail.Text) + "'" },
                { "ActiveDateFrom", (ucDateStart.Text != ""?"'" + ucDateStart.Text.SQLQueryFilter() + "'":"null") },
                { "ActiveDateTo", (ucDateEnd.Text != ""?"'" + ucDateEnd.Text.SQLQueryFilter() + "'":"null") },
                { "UnitPrice", "'" + txtPrice.Text.SQLQueryFilter() + "'" },
                { "MetaKeywords", "'" + clsSQL.CodeFilter(txtMetaKeyword.Text) + "'" },
                { "MetaDescription", "'" + clsSQL.CodeFilter(txtMetaDescription.Text) + "'" },
                { "MUser", "'" + clsSecurity.LoginUID + "'" },
                { "MWhen", "GETDATE()" },
                { "StatusFlag", "'" + (cbActive.Checked ? "A" : "D") + "'" }
            }, new string[, ] {
                { parameterChar + "UID", id.ToString() }
            },
                              "UID=" + parameterChar + "UID",
                              dbType, cs, out outSQL))
            {
                ucColorBox1.ReloadParent();
            }
            else
            {
                ucColorBox1.Alert("เกิดข้อผิดพลาดขณะบันทึกข้อมูล<br/>", outSQL, AlertImage: ucColorBox.Alerts.Fail);
            }
        }
        #endregion
        #region Insert
        else
        {
            #region Find New ID
            id = clsSQL.GetNewID("UID", tableDefault, "", dbType, cs);
            if (id == 0)
            {
                ucColorBox1.Alert("เกิดข้อผิดพลาดขณะบันทึกข้อมูล", "ไม่สามารถหา UID ใหม่ได้", AlertImage: ucColorBox.Alerts.Fail);
                return;
            }
            #endregion

            clsIO  clsIO = new clsIO();
            string outErrorMessage; string outFilename;
            #region Photo Upload
            if (fuPhoto.HasFile)
            {
                if (clsIO.UploadPhoto(
                        fuPhoto, pathUpload,
                        "HealthPackage" + id.ToString() + "_T",
                        out outErrorMessage,
                        out outFilename,
                        maxWidth: photoWidth,
                        maxHeight: photoHeight))
                {
                    photoName = outFilename;
                }
                else
                {
                    ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะอัพโหลดไฟล์รูปภาพ<br/>" + outErrorMessage, AlertImage: ucColorBox.Alerts.Fail);
                    return;
                }
            }
            #endregion
            #region PhotoFull Upload
            if (fuPhotoFull.HasFile)
            {
                if (clsIO.UploadPhoto(
                        fuPhotoFull, pathUpload,
                        "HealthPackage" + id.ToString(),
                        out outErrorMessage,
                        out outFilename))
                {
                    photoFullName = outFilename;
                }
                else
                {
                    ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะอัพโหลดไฟล์รูปภาพ<br/>" + outErrorMessage, AlertImage: ucColorBox.Alerts.Fail);
                    return;
                }
            }
            #endregion
            if (clsSQL.Insert(tableDefault,
                              new string[, ] {
                { "LanguageUID", rbLanguage.SelectedItem.Value },
                { "DepartmentUID", (txtDepartmentUID.Text != ""?clsSQL.CodeFilter(txtDepartmentUID.Text):"null") },
                { "PicThumbnail", (!string.IsNullOrEmpty(photoName)?"'" + pathUpload + photoName + "'":"null") },
                { "PicFull", (!string.IsNullOrEmpty(photoFullName)?"'" + pathUpload + photoFullName + "'":"null") },
                { "Name", "'" + clsSQL.CodeFilter(txtName.Text) + "'" },
                { "Detail", "'" + ucContent.Text.SQLQueryFilter() + "'" },
                { "DetailSub", "'" + clsSQL.CodeFilter(txtDetail.Text) + "'" },
                { "ActiveDateFrom", (ucDateStart.Text != ""?"'" + ucDateStart.Text.SQLQueryFilter() + "'":"null") },
                { "ActiveDateTo", (ucDateEnd.Text != ""?"'" + ucDateEnd.Text.SQLQueryFilter() + "'":"null") },
                { "UnitPrice", "'" + txtPrice.Text.SQLQueryFilter() + "'" },
                { "MetaKeywords", "'" + clsSQL.CodeFilter(txtMetaKeyword.Text) + "'" },
                { "MetaDescription", "'" + clsSQL.CodeFilter(txtMetaDescription.Text) + "'" },
                { "CUser", "'" + clsSecurity.LoginUID + "'" },
                { "CWhen", "GETDATE()" },
                { "MUser", "'" + clsSecurity.LoginUID + "'" },
                { "MWhen", "GETDATE()" },
                { "StatusFlag", "'" + (cbActive.Checked ? "A" : "D") + "'" }
            }, new string[, ] {
                { }
            },
                              dbType, cs, out outSQL))
            {
                ucColorBox1.ReloadParent();
            }
            else
            {
                ucColorBox1.Alert("เกิดข้อผิดพลาดขณะบันทึกข้อมูล<br/>", outSQL, AlertImage: ucColorBox.Alerts.Fail);
            }
        }
        #endregion
    }
    private void Delete(string id)
    {
        pnDetail.Visible = false;
        #region Authorize
        if (!clsSecurity.LoginChecker("admin"))
        {
            ucColorBox1.Redirect("/", "กรุณาล็อคอินด้วยสิทธิ์ Admin");
            return;
        }
        #endregion
        #region Variable
        clsIO clsIO = new clsIO();
        StringBuilder strSQL = new StringBuilder();
        #endregion

        #region Delete Photo
        #region SQL Query
        strSQL.Append("SELECT ");
        strSQL.Append("Icon ");
        strSQL.Append("FROM ");
        strSQL.Append(tableDefault+" ");
        strSQL.Append("WHERE ");
        strSQL.Append("UID=" + id);
        #endregion
        string photoDelete=clsSQL.Return(strSQL.ToString(), dbType, cs);
        if (!string.IsNullOrEmpty(photoDelete))
        {
            clsIO.FileExist(photoDelete, true);
        }
        strSQL.Length = 0; strSQL.Capacity = 0;
        #endregion
        #region Delete Database
        #region SQL Query
        strSQL.Append("DELETE FROM ");
        strSQL.Append(tableDefault + " ");
        strSQL.Append("WHERE ");
        strSQL.Append("UID=" + id);
        #endregion
        if (clsSQL.Execute(strSQL.ToString(), dbType, cs))
        {
            ucColorBox1.Redirect(webDefault + "?group=" + clsDefault.QueryStringChecker("group"));
        }
        else
        {
            ucColorBox1.Redirect(webDefault + "?group=" + clsDefault.QueryStringChecker("group"), "เกิดข้อผิดพลาดขณะลบข้อมูล");
            return;
        }
        strSQL.Length = 0; strSQL.Capacity = 0;
        #endregion
    }
    protected void btSubmit_Click(object sender, EventArgs e)
    {
        #region Authorize
        if (!clsSecurity.LoginChecker("admin"))
        {
            ucColorBox1.Redirect("/", "กรุณาล็อคอินด้วยสิทธิ์ Admin");
            return;
        }
        #endregion
        #region Variable
        StringBuilder strSQL = new StringBuilder();
        int           id     = 0;
        string        outSQL;
        string        photoName        = "";
        string        photoPreviewName = "";
        #endregion

        #region Update
        if (Request.QueryString["id"] != null && clsDefault.QueryStringChecker("command") == "edit")
        {
            id = int.Parse(Request.QueryString["id"].ToString());
            #region Photo Upload
            if (fuPhoto.HasFile)
            {
                clsIO  clsIO = new clsIO();
                string outErrorMessage;
                string outFilename;
                string outFilenamePreview;

                #region Photo
                if (clsIO.UploadPhoto(
                        fuPhoto, pathUpload,
                        tableDefault + id.ToString(),
                        out outErrorMessage,
                        out outFilename,
                        maxWidth: photoWidth,
                        maxHeight: photoHeight))
                {
                    photoName = outFilename;
                }
                else
                {
                    ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะอัพโหลดไฟล์รูปภาพ<br/>" + outErrorMessage, AlertImage: ucColorBox.Alerts.Fail);
                    return;
                }
                #endregion
                #region Photo Preview
                if (clsIO.UploadPhoto(
                        fuPhoto, pathUpload,
                        tableDefault + id.ToString() + "Preview",
                        out outErrorMessage,
                        out outFilenamePreview,
                        maxWidth: photoPreviewWidth,
                        maxHeight: photoPreviewHeight))
                {
                    photoPreviewName = outFilenamePreview;
                }
                else
                {
                    ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะอัพโหลดไฟล์รูปภาพ<br/>" + outErrorMessage, AlertImage: ucColorBox.Alerts.Fail);
                    return;
                }
                #endregion
            }
            #endregion
            if (clsSQL.Update(tableDefault,
                              new string[, ] {
                { "UID", id.ToString() },
                { "PhotoPreview", (!string.IsNullOrEmpty(photoPreviewName)?"'" + pathUpload + photoPreviewName + "'":"PhotoPreview") },
                { "Photo", (!string.IsNullOrEmpty(photoName)?"'" + pathUpload + photoName + "'":"Photo") },
                { "Name", "'" + clsSQL.CodeFilter(txtName.Text) + "'" },
                { "Detail", "'" + clsSQL.CodeFilter(txtDetail.Text) + "'" },
                { "MUser", "'" + clsSecurity.LoginUID + "'" },
                { "MWhen", "GETDATE()" },
                { "Sort", clsSQL.CodeFilter(txtSort.Text) },
                { "Active", "'" + (cbActive.Checked ? "1" : "0") + "'" }
            }, new string[, ] {
                { parameterChar + "UID", id.ToString() }
            },
                              "UID=" + parameterChar + "UID",
                              dbType, cs, out outSQL))
            {
                ucColorBox1.ReloadParent();
            }
            else
            {
                ucColorBox1.Alert("เกิดข้อผิดพลาดขณะบันทึกข้อมูล<br/>", outSQL, AlertImage: ucColorBox.Alerts.Fail);
            }
        }
        #endregion
        #region Insert
        else
        {
            #region Find New ID
            id = clsSQL.GetNewID("UID", tableDefault, "", dbType, cs);
            if (id == 0)
            {
                ucColorBox1.Alert("เกิดข้อผิดพลาดขณะบันทึกข้อมูล", "ไม่สามารถหา UID ใหม่ได้", AlertImage: ucColorBox.Alerts.Fail);
                return;
            }
            #endregion
            #region Photo Upload
            if (fuPhoto.HasFile)
            {
                clsIO  clsIO = new clsIO();
                string outErrorMessage;
                string outFilename;
                string outFilenamePreview;

                #region Photo
                if (clsIO.UploadPhoto(
                        fuPhoto, pathUpload,
                        tableDefault + id.ToString(),
                        out outErrorMessage,
                        out outFilename,
                        maxWidth: photoWidth,
                        maxHeight: photoHeight))
                {
                    photoName = outFilename;
                }
                else
                {
                    ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะอัพโหลดไฟล์รูปภาพ<br/>" + outErrorMessage, AlertImage: ucColorBox.Alerts.Fail);
                    return;
                }
                #endregion
                #region PhotoPreview
                if (clsIO.UploadPhoto(
                        fuPhoto, pathUpload,
                        tableDefault + id.ToString() + "Preview",
                        out outErrorMessage,
                        out outFilenamePreview,
                        maxWidth: photoPreviewWidth,
                        maxHeight: photoPreviewHeight))
                {
                    photoPreviewName = outFilenamePreview;
                }
                else
                {
                    ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะอัพโหลดไฟล์รูปภาพ<br/>" + outErrorMessage, AlertImage: ucColorBox.Alerts.Fail);
                    return;
                }
                #endregion
            }
            #endregion
            if (clsSQL.Insert(tableDefault,
                              new string[, ] {
                { "UID", id.ToString() },
                { "GlobalUID", clsDefault.QueryStringChecker("globalid") },
                { "GlobalName", "'" + clsDefault.QueryStringChecker("globalname") + "'" },
                { "PhotoPreview", (!string.IsNullOrEmpty(photoPreviewName)?"'" + pathUpload + photoPreviewName + "'":"null") },
                { "Photo", (!string.IsNullOrEmpty(photoName)?"'" + pathUpload + photoName + "'":"null") },
                { "Name", "'" + clsSQL.CodeFilter(txtName.Text) + "'" },
                { "Detail", "'" + clsSQL.CodeFilter(txtDetail.Text) + "'" },
                { "[View]", "0" },
                { "CUser", "'" + clsSecurity.LoginUID + "'" },
                { "CWhen", "GETDATE()" },
                { "MUser", "'" + clsSecurity.LoginUID + "'" },
                { "MWhen", "GETDATE()" },
                { "Sort", clsSQL.CodeFilter(txtSort.Text) },
                { "Active", "'" + (cbActive.Checked ? "1" : "0") + "'" }
            }, new string[, ] {
                { }
            },
                              dbType, cs, out outSQL))
            {
                ucColorBox1.ReloadParent();
            }
            else
            {
                ucColorBox1.Alert("เกิดข้อผิดพลาดขณะบันทึกข้อมูล<br/>", outSQL, AlertImage: ucColorBox.Alerts.Fail);
            }
        }
        #endregion
    }
    protected void btSave_Click(object sender, EventArgs e)
    {
        System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

        clsSecurity security = new clsSecurity();
        clsIO       IO       = new clsIO();

        string strDetailSub = string.Empty;
        string strDetail    = txtDetail.Text.Replace("<p>", "");

        strDetail = strDetail.Replace("</p>", "");
        string PicFull    = "null";
        string PicThumb   = "null";
        string pathPhoto  = "/Images/Event/";
        string pathImages = @"\Images\Event\";
        string outError;

        //upload Photo to server
        if (txtImgFull.HasFile)
        {
            //Full Images
            if (IO.UploadPhoto(txtImgFull, pathPhoto, "f_pic" + DateTime.Now.ToString("yyyyMMddHHmmss"), 5120, 0, 0, "", 0, out outError, out PicFull) == false)
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "Information", "alert('" + outError.ToString() + "')", true);
                return;
            }
            else
            {
                PicFull = pathImages + "" + PicFull;
            }
        }
        else
        {
            PicFull = lblImagesFull.Text.Trim();
        }
        if (txtImgThum.HasFile)
        {
            //Thumb Images
            if (IO.UploadPhoto(txtImgThum, pathPhoto, "t_pic" + DateTime.Now.ToString("yyyyMMddHHmmss"), 2048, 0, 0, "", 0, out outError, out PicThumb) == false)
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "Information", "alert('" + outError.ToString() + "')", true);
                return;
            }
            else
            {
                PicThumb = pathImages + "" + PicThumb;
            }
        }
        else
        {
            PicThumb = lblImagesThumb.Text.Trim();
        }

        //insert data to database
        try
        {
            if (txtDetail.Text.Length >= 200)
            {
                strDetailSub = "<p>" + strDetail.Substring(0, 200) + ".....</p>";
            }
            else
            {
                strDetailSub = "<p>" + strDetail + ".....</p>";
            }

            //Insert new Event
            if (string.IsNullOrEmpty(lblUID.Text) == true)
            {
                Event tbevent = new Event();

                //Assign values for insert into database
                tbevent.Subject         = txtSubject.Text.Trim();
                tbevent.Detail          = txtDetail.Text;
                tbevent.PicFull         = PicFull;
                tbevent.PicThumbnail    = PicThumb;
                tbevent.DepartmentUID   = 1;
                tbevent.ActiveDateFrom  = Convert.ToDateTime(txtDateFrom.Text);
                tbevent.ActiveDateTo    = Convert.ToDateTime(txtDateTo.Text);
                tbevent.Remark          = txtRemark.Text.Trim();
                tbevent.CWhen           = DateTime.Now;
                tbevent.CUser           = Convert.ToInt32(security.LoginUID);
                tbevent.MWhen           = DateTime.Now;
                tbevent.MUser           = Convert.ToInt32(security.LoginUID);
                tbevent.StatusFlag      = rdbActive.Checked == true ? "A" : "D";
                tbevent.LanguageUID     = Convert.ToInt32(ddlLanguage.SelectedValue);
                tbevent.DetailSub       = strDetailSub;
                tbevent.MetaKeywords    = txtMetaKeywords.Text.Trim();
                tbevent.MetaDescription = txtMetaDescription.Text.Trim();

                //Insert data of Event to database
                db.Events.InsertOnSubmit(tbevent);
            }
            else //Update existing Event
            {
                var tbEvent = from ev in db.Events
                              where ev.UID == Convert.ToInt32(lblUID.Text.Trim())
                              select ev;
                foreach (Event ev in tbEvent)
                {
                    ev.Subject         = txtSubject.Text.Trim();
                    ev.Detail          = txtDetail.Text;
                    ev.PicFull         = PicFull;
                    ev.PicThumbnail    = PicThumb;
                    ev.DepartmentUID   = 1;
                    ev.ActiveDateFrom  = Convert.ToDateTime(txtDateFrom.Text);
                    ev.ActiveDateTo    = Convert.ToDateTime(txtDateTo.Text);
                    ev.Remark          = txtRemark.Text.Trim();
                    ev.MWhen           = DateTime.Now;
                    ev.MUser           = Convert.ToInt32(security.LoginUID);
                    ev.StatusFlag      = rdbActive.Checked == true ? "A" : "D";
                    ev.MetaKeywords    = txtMetaKeywords.Text.Trim();
                    ev.MetaDescription = txtMetaDescription.Text.Trim();
                    try
                    {
                        ev.LanguageUID = Convert.ToInt32(ddlLanguage.SelectedValue);
                    }
                    catch (Exception ex)
                    {
                        ex.ToString();
                    }
                    ev.DetailSub = strDetailSub;
                }
            }
            db.SubmitChanges();
            clsColorBox clsColorBox = new clsColorBox();
            clsColorBox.Refresh();
            //Page.ClientScript.RegisterStartupScript(Page.GetType(), "closeWindow", "<script language='javascript'>parent.$.colorbox.close();</script>");
        }
        catch (Exception ex)
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Information", "alert('" + ex.ToString() + "')", true);
        }
    }
Ejemplo n.º 13
0
    private void PreLoading()
    {
        StringBuilder strScript         = new StringBuilder();
        clsIO         clsIO             = new clsIO();
        string        loaderImage       = "Images/" + _loaderImage.ToString() + ".gif";
        string        loaderImageWidth  = (clsIO.ImageWidth(ResolveClientUrl(loaderImage)) / 2).ToString();
        string        loaderImageHeight = (clsIO.ImageHeight(ResolveClientUrl(loaderImage)) / 2).ToString();

        #region Create Display
        if (!Page.ClientScript.IsStartupScriptRegistered(Page.GetType(), "PreLoading_BindDiv"))
        {
            StringBuilder strDIV = new StringBuilder();

            strDIV.Append("<div id='" + _displayDiv + "' style='text-align:center;position:fixed;left:0;right:0;top:0;bottom:0;width:100%;height:100%;z-index: 99999;overflow:auto;");
            #region Style
            strDIV.Append("background-color:" + _backgroundColor + ";");
            strDIV.Append("filter:alpha(opacity=" + (_opacity * 100).ToString() + ");");
            strDIV.Append("opacity:" + _opacity.ToString() + ";");
            #endregion
            strDIV.Append("'>");
            strDIV.Append("<div style='position:absolute;top: 50%;left: 50%;margin-top:-" + loaderImageHeight + "px;margin-left:-" + loaderImageWidth + "px;'>");
            strDIV.Append("<img src='" + this.ResolveClientUrl(loaderImage) + "' alt=''/>");
            strDIV.Append("</div>");
            strDIV.Append("</div>");

            Page.ClientScript.RegisterClientScriptBlock(
                Page.GetType(),
                "PreLoading_BindDiv",
                strDIV.ToString()
                );
        }
        #endregion

        #region Create JavaScript
        strScript.Append("<script type='text/javascript'>");
        strScript.Append("window.onload = function PreLoading() {");
        strScript.Append("if (document.getElementById)");
        strScript.Append("{");
        strScript.Append("document.getElementById('" + _displayDiv + "').style.visibility='hidden';");
        strScript.Append("}");
        strScript.Append("else");
        strScript.Append("{");
        strScript.Append("if (document.layers)");
        strScript.Append("{");
        strScript.Append("document." + _displayDiv + ".visibility = 'hidden';");
        strScript.Append("}");
        strScript.Append("else");
        strScript.Append("{");
        strScript.Append("document.all." + _displayDiv + ".style.visibility = 'hidden';");
        strScript.Append("}");
        strScript.Append("}");
        strScript.Append("}");
        strScript.Append("</script>");

        if (!Page.ClientScript.IsStartupScriptRegistered(Page.GetType(), "PreLoading_Onload"))
        {
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "PreLoading_Onload", strScript.ToString());
            strScript = null;
        }
        #endregion
    }
    protected void btSave_Click(object sender, EventArgs e)
    {
        clsSecurity security = new clsSecurity();
        clsIO IO = new clsIO();

        string strDetailSub = string.Empty;
        string strDetail = txtDetail.Text.Replace("<p>", "");
        strDetail = strDetail.Replace("</p>", "");
        string PicFull = "null";
        string PicThumb = "null";
        string pathPhoto = "/Images/Article/";
        string pathImages = @"\Images\Article\";
        string outError;

        //upload Photo to server
        if (txtImanges.HasFile)
        {
            //Full Images
            if (IO.UploadPhoto(txtImanges, pathPhoto, "f_pic" + DateTime.Now.ToString("yyyyMMddHHmmss"), 5120, 0, 0, "", 0, out outError, out PicFull) == false)
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "Information", "alert('" + outError.ToString() + "')", true);
                return;
            }
            else
            {
                PicFull = pathImages + "" + PicFull;
            }
            //Thumb Images
            if (IO.UploadPhoto(txtImanges, pathPhoto, "t_pic" + DateTime.Now.ToString("yyyyMMddHHmmss"), 1024, 100, 100, "", 0, out outError, out PicThumb) == false)
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "Information", "alert('" + outError.ToString() + "')", true);
                return;
            }
            else
            {
                PicThumb = pathImages + "" + PicThumb;
            }

        }
        else
        {
            PicFull = lblImagesFull.Text.Trim();
            PicThumb = lblImagesThumb.Text.Trim();
        }

        //insert data to database
        try
        {
            if (txtDetail.Text.Length >= 200)
            {
                strDetailSub = "<p>" + strDetail.Substring(0, 200) + ".....</p>";
            }
            else
            {
                strDetailSub = "<p>" + strDetail + ".....</p>";
            }

            //Insert new Article
            if (string.IsNullOrEmpty(lblUID.Text) == true)
            {
                Article tbarticle = new Article();

                //Assign values for insert into database
                tbarticle.Subject = txtSubject.Text.Trim();
                tbarticle.Detail = txtDetail.Text;
                tbarticle.PicFull = PicFull;
                tbarticle.PicThumbnail = PicThumb;
                tbarticle.ActiveDateFrom = Convert.ToDateTime(txtDateFrom.Text);
                tbarticle.ActiveDateTo = Convert.ToDateTime(txtDateTo.Text);
                tbarticle.Remark = txtRemark.Text.Trim();
                tbarticle.CWhen = DateTime.Now;
                tbarticle.CUser = Convert.ToInt32(security.LoginUID);
                tbarticle.MWhen = DateTime.Now;
                tbarticle.MUser = Convert.ToInt32(security.LoginUID);
                tbarticle.StatusFlag = rdbActive.Checked == true ? "A" : "D";
                tbarticle.LanguageUID = Convert.ToInt32(ddlLanguage.SelectedValue);
                tbarticle.DetailSub = strDetailSub;
                tbarticle.NumberDislike = 0;
                tbarticle.NumberLike = 0;
                tbarticle.NumberView = 0;
                tbarticle.Score = 0;
                tbarticle.SampleSize = 0;
                tbarticle.MetaKeywords = txtMetaKeywords.Text.Trim();
                tbarticle.MetaDescription = txtMetaDescription.Text.Trim();

                //Insert data of Event to database
                db.Articles.InsertOnSubmit(tbarticle);
            }
            else //Update existing Event
            {
                var tbarticle = from a in db.Articles
                              where a.UID == Convert.ToInt32(lblUID.Text.Trim())
                              select a;
                foreach (Article a in tbarticle)
                {
                    a.Subject = txtSubject.Text.Trim();
                    a.Detail = txtDetail.Text;
                    a.PicFull = PicFull;
                    a.PicThumbnail = PicThumb;
                    a.ActiveDateFrom = Convert.ToDateTime(txtDateFrom.Text);
                    a.ActiveDateTo = Convert.ToDateTime(txtDateTo.Text);
                    a.Remark = txtRemark.Text.Trim();
                    a.MWhen = DateTime.Now;
                    a.MUser = Convert.ToInt32(security.LoginUID);
                    a.StatusFlag = rdbActive.Checked == true ? "A" : "D";
                    a.MetaKeywords = txtMetaKeywords.Text.Trim();
                    a.MetaDescription = txtMetaDescription.Text.Trim();
                    try
                    {
                        a.LanguageUID = Convert.ToInt32(ddlLanguage.SelectedValue);
                    }
                    catch (Exception ex)
                    {
                        ex.ToString();
                    }
                    a.DetailSub = strDetailSub;
                }
            }
            db.SubmitChanges();
            clsColorBox clsColorBox = new clsColorBox();
            clsColorBox.Refresh();
            //Page.ClientScript.RegisterStartupScript(Page.GetType(), "closeWindow", "<script language='javascript'>parent.$.colorbox.close();</script>");
        }
        catch (Exception ex)
        {
            clsColorBox clsColorBox = new clsColorBox();
            clsColorBox.Refresh();
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Information", "alert('" + ex.ToString() + "')", true);
        }
    }
    protected void btSubmit_Click(object sender, EventArgs e)
    {
        #region Variable
        var outSQL = "";
        var clsIO = new clsIO();
        var outError="";
        var outPhoto="";
        var outMail = "";
        #endregion
        #region Procedure
        if (fuPhoto.HasFile)
        {
            if(!clsIO.UploadPhoto(
                fuPhoto,
                "/Upload/Jobs/",
                clsSQL.GetNewID("UID","JobsHistory","",dbType,cs).ToString(),
                out outError,
                out outPhoto,
                512, 200, 200))
            {
                ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะอัพโหลดภาพ : " + outError);
                return;
            }
        }
        #region InsertData
        if (!clsSQL.Insert(
            "JobsHistory",
            new string[,]{
                {"JobsUID",ddlJobs.SelectedItem.Value},
                {"JobsName","'"+txtJobsName.Text.SQLQueryFilter()+"'"},
                {"Salary","'"+txtSalary.Text.SQLQueryFilter()+"'"},
                {"Start","'"+txtStart.Text.SQLQueryFilter()+"'"},
                {"ProvinceChange","'"+rbProvinceChange.SelectedItem.Value+"'"},
                {"PrenameTH","'"+ddlPrenameTH.SelectedItem.Value+"'"},
                {"ForenameTH","'"+txtForenameTH.Text.SQLQueryFilter()+"'"},
                {"SurnameTH","'"+txtSurnameTH.Text.SQLQueryFilter()+"'"},
                {"PrenameEN","'"+ddlPrenameEN.SelectedItem.Value+"'"},
                {"ForenameEN","'"+txtForenameEN.Text.SQLQueryFilter()+"'"},
                {"SurnameEN","'"+txtSurnameEN.Text.SQLQueryFilter()+"'"},
                {"MarriageStatus","'"+rbMarriageStatus.SelectedItem.Value+"'"},
                {"Gender","'"+rbGender.SelectedItem.Value+"'"},
                {"Birthdate","'"+(ucBirthdate.Text.Trim()!=""?ucBirthdate.DateTime.ToString("yyyy-MM-dd"):"1900-01-01 00:00")+"'"},
                {"Birthplace","'"+txtBirthplace.Text.SQLQueryFilter()+"'"},
                {"Nationality","'"+txtNationality.Text.SQLQueryFilter()+"'"},
                {"Race","'"+txtRace.Text.SQLQueryFilter()+"'"},
                {"Religion","'"+txtReligion.Text.SQLQueryFilter()+"'"},
                {"Weight","'"+txtWeight.Text.SQLQueryFilter()+"'"},
                {"Height","'"+txtHeight.Text.SQLQueryFilter()+"'"},
                {"NID","'"+txtNID.Text.SQLQueryFilter()+"'"},
                {"NIDCreateBy","'"+txtNIDCreateBy.Text.SQLQueryFilter()+"'"},
                {"NIDExpire","'"+(ucNIDExpire.Text!=""?ucNIDExpire.DateTime.ToString("yyyy-MM-dd"):"")+"'"},
                {"Phone","'"+txtPhone.Text.SQLQueryFilter()+"'"},
                {"Email","'"+txtEmail.Text.SQLQueryFilter()+"'"},
                {"Address","'"+txtAddress.Text.SQLQueryFilter()+"'"},
                {"EmergencyName","'"+txtEmergencyName.Text.SQLQueryFilter()+"'"},
                {"EmergencyPhone","'"+txtEmergencyPhone.Text.SQLQueryFilter()+"'"},
                {"EmergencyEmail","'"+txtEmergencyEmail.Text.SQLQueryFilter()+"'"},
                {"EmergencyAddress","'"+txtEmergencyAddress.Text.SQLQueryFilter()+"'"},
                {"EmergencyRelationship","'"+txtEmergencyRelationship.Text.SQLQueryFilter()+"'"},
                {"Photo",(outPhoto!=""?"'"+outPhoto+"'":"null")},
                {"Education","'"+ucEducation.Text.SQLQueryFilter()+"'"},
                {"Experience","'"+ucExperience.Text.SQLQueryFilter()+"'"},
                {"Resume","null"},
                {"CWhen","GETDATE()"},
                {"CUser","0"},
                {"MWhen","GETDATE()"},
                {"MUser","0"},
                {"Sort","0"},
                {"StatusFlag","'A'"}
            },
            new string[,] { { } },
            dbType,
            cs,
            out outSQL))
        {
            ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะรันคำสั่ง : " + Server.HtmlEncode(outSQL));
            return;
        }
        else
        {
            #region MailSender
            string JobsUID = clsSQL.Return("SELECT MAX(UID) FROM JobsHistory", dbType, cs);

            if (!clsMail.SendTemplate(
                "JobsApply",
                clsMail.GetEmailList("AutoSystemFrom"),
                clsMail.GetEmailList("JobsTo"),
                new string[,] 
                { 
                    {"[Photo]","<img src='"+System.Configuration.ConfigurationManager.AppSettings["website"]+"/Upload/Jobs/"+outPhoto+"'/>"},
                    {"[UID]", JobsUID},
                    {"[JobsName]", ddlJobs.SelectedItem.Text+(txtJobsName.Text.Trim()!=""?" ("+txtJobsName.Text.SQLQueryFilter()+")":"") },
                    {"[PrenameTH]",ddlPrenameTH.SelectedItem.Text},
                    {"[ForenameTH]",txtForenameTH.Text},
                    {"[SurnameTH]",txtSurnameTH.Text},
                    {"[Birthdate]",ucBirthdate.DateTime.ToString("dd/MM/yyyy")},
                    {"[Birthplace]",txtBirthplace.Text},
                    {"[Gender]",rbGender.SelectedItem.Text},
                    {"[Phone]",txtPhone.Text},
                    {"[Email]",txtEmail.Text},
                    {"[Start]",txtStart.Text.SQLQueryFilter()},
                    {"[Education]",ucEducation.Text.SQLQueryFilter()},
                    {"[Experience]",ucExperience.Text.SQLQueryFilter()},
                    {"[CWhen]",DateTime.Now.ToString("dd/MM/yyyy HH:mm")}
                },
                out outMail))
            {
                lblMessage.Text = clsDefault.AlertMessageColor("เกิดข้อผิดพลาดขณะพยายามส่งอีเมล์<br/>" + outMail, clsDefault.AlertType.Fail);
                lblMessage.Focus();
                return;
            }
            #endregion
            ucColorBox1.Redirect("/Jobs/");
        }
        #endregion
        #endregion
    }
Ejemplo n.º 16
0
    private void PreLoading()
    {
        StringBuilder strScript = new StringBuilder();
        clsIO clsIO = new clsIO();
        string loaderImage = "Images/" + _loaderImage.ToString() + ".gif";
        string loaderImageWidth = (clsIO.ImageWidth(ResolveClientUrl(loaderImage)) / 2).ToString();
        string loaderImageHeight = (clsIO.ImageHeight(ResolveClientUrl(loaderImage)) / 2).ToString();

        #region Create Display
        if (!Page.ClientScript.IsStartupScriptRegistered(Page.GetType(), "PreLoading_BindDiv"))
        {
            StringBuilder strDIV = new StringBuilder();

            strDIV.Append("<div id='" + _displayDiv + "' style='text-align:center;position:fixed;left:0;right:0;top:0;bottom:0;width:100%;height:100%;z-index: 99999;overflow:auto;");
            #region Style
            strDIV.Append("background-color:" + _backgroundColor + ";");
            strDIV.Append("filter:alpha(opacity=" + (_opacity * 100).ToString() + ");");
            strDIV.Append("opacity:" + _opacity.ToString() + ";");
            #endregion
            strDIV.Append("'>");
            strDIV.Append("<div style='position:absolute;top: 50%;left: 50%;margin-top:-" + loaderImageHeight + "px;margin-left:-" + loaderImageWidth + "px;'>");
            strDIV.Append("<img src='" + this.ResolveClientUrl(loaderImage) + "' alt=''/>");
            strDIV.Append("</div>");
            strDIV.Append("</div>");

            Page.ClientScript.RegisterClientScriptBlock(
                Page.GetType(),
                "PreLoading_BindDiv",
                strDIV.ToString()
                );
        }
        #endregion

        #region Create JavaScript
        strScript.Append("<script type='text/javascript'>");
        strScript.Append("window.onload = function PreLoading() {");
        strScript.Append("if (document.getElementById)");
        strScript.Append("{");
        strScript.Append("document.getElementById('" + _displayDiv + "').style.visibility='hidden';");
        strScript.Append("}");
        strScript.Append("else");
        strScript.Append("{");
        strScript.Append("if (document.layers)");
        strScript.Append("{");
        strScript.Append("document." + _displayDiv + ".visibility = 'hidden';");
        strScript.Append("}");
        strScript.Append("else");
        strScript.Append("{");
        strScript.Append("document.all." + _displayDiv + ".style.visibility = 'hidden';");
        strScript.Append("}");
        strScript.Append("}");
        strScript.Append("}");
        strScript.Append("</script>");

        if (!Page.ClientScript.IsStartupScriptRegistered(Page.GetType(), "PreLoading_Onload"))
        {
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "PreLoading_Onload", strScript.ToString());
            strScript = null;
        }
        #endregion
    }
Ejemplo n.º 17
0
    protected void btSave_Click(object sender, EventArgs e)
    {
        clsSecurity security = new clsSecurity();
        clsIO       IO       = new clsIO();

        string strDetailSub = string.Empty;
        string strDetail    = txtDetail.Text.Replace("<p>", "");

        strDetail = strDetail.Replace("</p>", "");
        string PicFull    = "null";
        string PicThumb   = "null";
        string pathPhoto  = "/Images/Package/";
        string pathImages = @"\Images\Package\";
        string outError;

        //upload Photo to server
        if (txtImgFull.HasFile)
        {
            //Full Images
            if (IO.UploadPhoto(txtImgFull, pathPhoto, "f_pic" + DateTime.Now.ToString("yyyyMMddHHmmss"), 4096, 0, 0, "", 0, out outError, out PicFull) == false)
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "Information", "alert('" + outError.ToString() + "')", true);
                return;
            }
            else
            {
                PicFull = pathImages + "" + PicFull;
            }
        }
        else
        {
            PicFull = lblImagesFull.Text.Trim();
        }

        if (txtImgThum.HasFile)
        {
            //Thumb Images
            if (IO.UploadPhoto(txtImgThum, pathPhoto, "t_pic" + DateTime.Now.ToString("yyyyMMddHHmmss"), 2048, 0, 0, "", 0, out outError, out PicThumb) == false)
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "Information", "alert('" + outError.ToString() + "')", true);
                return;
            }
            else
            {
                PicThumb = pathImages + "" + PicThumb;
            }
        }
        else
        {
            PicThumb = lblImagesThumb.Text.Trim();
        }

        //insert data to database
        try
        {
            if (txtDetail.Text.Length >= 200)
            {
                strDetailSub = "<p>" + strDetail.Substring(0, 200) + ".....</p>";
            }
            else
            {
                strDetailSub = "<p>" + strDetail + ".....</p>";
            }

            //Insert new Package
            if (string.IsNullOrEmpty(lblUID.Text) == true)
            {
                Package tbpackage = new Package();

                //Assign values for insert into database
                tbpackage.PackageName    = txtSubject.Text.Trim();
                tbpackage.Detail         = txtDetail.Text;
                tbpackage.PicFull        = PicFull;
                tbpackage.PicThumbnail   = PicThumb;
                tbpackage.ActiveDateFrom = Convert.ToDateTime(txtDateFrom.Text);
                if (!string.IsNullOrEmpty(txtDateTo.Text))
                {
                    tbpackage.ActiveDateTo = Convert.ToDateTime(txtDateTo.Text);
                }
                else
                {
                    tbpackage.ActiveDateTo = null;
                }
                tbpackage.Remark          = txtRemark.Text.Trim();
                tbpackage.CWhen           = DateTime.Now;
                tbpackage.CUser           = Convert.ToInt32(security.LoginUID);
                tbpackage.MWhen           = DateTime.Now;
                tbpackage.MUser           = Convert.ToInt32(security.LoginUID);
                tbpackage.StatusFlag      = rdbActive.Checked == true ? "A" : "D";
                tbpackage.LanguageUID     = Convert.ToInt32(ddlLanguage.SelectedValue);
                tbpackage.DepartmentUID   = Convert.ToInt32(ddlDepartment.SelectedValue);
                tbpackage.DetailSub       = strDetailSub;
                tbpackage.MetaKeywords    = txtMetaKeywords.Text.Trim();
                tbpackage.MetaDescription = txtMetaDescription.Text.Trim();
                tbpackage.PackageCode     = txtPackagecode.Text.Trim();
                if (!string.IsNullOrEmpty(txtUnitPrice.Text))
                {
                    tbpackage.UnitPrice = Convert.ToDouble(txtUnitPrice.Text.Trim());
                }
                else
                {
                    tbpackage.UnitPrice = 0;
                }

                //Insert data of Event to database
                db.Packages.InsertOnSubmit(tbpackage);
            }
            else //Update existing Event
            {
                var tbpackage = from p in db.Packages
                                where p.UID == Convert.ToInt32(lblUID.Text.Trim())
                                select p;
                foreach (Package p in tbpackage)
                {
                    p.PackageName    = txtSubject.Text.Trim();
                    p.Detail         = txtDetail.Text;
                    p.PicFull        = PicFull;
                    p.PicThumbnail   = PicThumb;
                    p.ActiveDateFrom = Convert.ToDateTime(txtDateFrom.Text);
                    if (!string.IsNullOrEmpty(txtDateTo.Text))
                    {
                        p.ActiveDateTo = Convert.ToDateTime(txtDateTo.Text);
                    }
                    else
                    {
                        p.ActiveDateTo = null;
                    }
                    p.Remark     = txtRemark.Text.Trim();
                    p.MWhen      = DateTime.Now;
                    p.MUser      = Convert.ToInt32(security.LoginUID);
                    p.StatusFlag = rdbActive.Checked == true ? "A" : "D";
                    try
                    {
                        p.LanguageUID   = Convert.ToInt32(ddlLanguage.SelectedValue);
                        p.DepartmentUID = Convert.ToInt32(ddlDepartment.SelectedValue);
                    }
                    catch (Exception ex)
                    {
                        ex.ToString();
                    }
                    p.DetailSub       = strDetailSub;
                    p.MetaKeywords    = txtMetaKeywords.Text.Trim();
                    p.MetaDescription = txtMetaDescription.Text.Trim();
                    p.PackageCode     = txtPackagecode.Text.Trim();
                    if (!string.IsNullOrEmpty(txtUnitPrice.Text))
                    {
                        p.UnitPrice = Convert.ToDouble(txtUnitPrice.Text.Trim());
                    }
                    else
                    {
                        p.UnitPrice = 0;
                    }
                }
            }
            db.SubmitChanges();
            clsColorBox clsColorBox = new clsColorBox();
            clsColorBox.Refresh();
            //Page.ClientScript.RegisterStartupScript(Page.GetType(), "closeWindow", "<script language='javascript'>parent.$.colorbox.close();</script>");
        }
        catch (Exception ex)
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Information", "alert('" + ex.ToString() + "')", true);
        }
    }
    protected void btInsertImages_Click(object sender, EventArgs e)
    {
        #region Variable
        string strFileName;
        clsIO  clsIO           = new clsIO();
        string outErrorMessage = "";
        string outFileName     = "";
        #endregion

        #region Data Checker
        if (fuInsertImages.PostedFile.ContentLength > maxSize * 1000)
        {
            lblInsertImages.Text = "<div class='fontWarn'>ขนาดไฟล์ใหญ่เกิน " + maxSize + " KB</div>";
            lblInsertImages.Focus();
            return;
        }
        #endregion

        for (int i = 1; i < 10; i++)
        {
            #region FileName Builder
            strFileName = prefixName +
                          DateTime.Now.Year.ToString() +
                          DateTime.Now.Month.ToString() +
                          DateTime.Now.Day.ToString() +
                          DateTime.Now.Hour.ToString() +
                          DateTime.Now.Minute.ToString() +
                          DateTime.Now.Second.ToString() + "_" + i.ToString();
            #endregion
            #region Upload
            if (!clsIO.FileExist(
                    pathUpload + strFileName + fuInsertImages + Path.GetExtension(fuInsertImages.FileName).ToLower(),
                    false))
            {
                if (!clsIO.UploadPhoto(
                        fuInsertImages,
                        pathUpload,
                        strFileName,
                        out outErrorMessage,
                        out outFileName,
                        maxSize,
                        maxWidth,
                        maxHeight,
                        clsIO.ResizeAnchor.middlecenter,
                        clsIO.ResizeMode.max))
                {
                    lblInsertImages.Text = "<div class='fontWarn'>เกิดข้อผิดพลาดขณะอัพโหลดไฟล์ : " + outErrorMessage + "</div>";
                    return;
                }

                #region Show Detail

                /*
                 * lblInsertImages.Text = "<div style='font-size:9pt;margin:5px 0px 5px 0px;'>อัพโหลดไฟล์เสร็จสิ้น : " +
                 *  "<span style='' title='Copy ชื่อไฟล์นี้ วางในหน้าแทรกภาพ'>" +
                 *  "<input id='txtInsertImages' type='text' value='" +
                 *  pathUpload + strFileName.Trim() +
                 *  "' style='border:1px solid #dddddd;background-color:#fafafa;width:300px;'/>" +
                 *  "</span></div>";
                 * ChangeIFrameHeight(70);
                 */
                #endregion

                InsertTinyMCE("<img src=" + pathUpload + outFileName + " />");
                break;
            }
            #endregion
        }
    }
    private void Delete(string id)
    {
        pnDetail.Visible = false;
        #region Authorize
        if (!clsSecurity.LoginChecker("admin"))
        {
            ucColorBox1.Redirect("/", "กรุณาล็อคอินด้วยสิทธิ์ Admin");
            return;
        }
        #endregion
        #region Variable
        StringBuilder strSQL = new StringBuilder();
        DataTable dt = new DataTable();
        clsIO clsIO = new clsIO();
        #endregion

        #region Delete Photo
        #region SQL Query
        strSQL.Append("SELECT ");
        strSQL.Append("Icon ");
        strSQL.Append("FROM ");
        strSQL.Append("Service ");
        strSQL.Append("WHERE ");
        strSQL.Append("ServiceGroupUID=" + id);
        #endregion
        dt = clsSQL.Bind(strSQL.ToString(), dbType, cs);
        strSQL.Length = 0; strSQL.Capacity = 0;
        if (dt != null && dt.Rows.Count > 0)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i]["Icon"] != DBNull.Value)
                {
                    clsIO.FileExist(dt.Rows[i]["Icon"].ToString(), true);
                }
            }
            dt = null;
        }
        strSQL.Length = 0; strSQL.Capacity = 0;
        #endregion
        #region Delete Database
        #region SQL Query
        strSQL.Append("DELETE FROM ");
        strSQL.Append(tableDefault + " ");
        strSQL.Append("WHERE ");
        strSQL.Append("UID=" + id);
        #endregion
        if (clsSQL.Execute(strSQL.ToString(), dbType, cs))
        {
            ucColorBox1.Redirect(webDefault);
        }
        else
        {
            ucColorBox1.Redirect(webDefault, "เกิดข้อผิดพลาดขณะลบข้อมูล");
        }
        strSQL.Length = 0; strSQL.Capacity = 0;
        #endregion
    }
Ejemplo n.º 20
0
    protected void btSubmit_Click(object sender, EventArgs e)
    {
        #region Validation
        if (!ucCaptchaEncrypt1.Checker())
        {
            lblCaptcha.Text = clsDefault.AlertMessageColor("คำตอบไม่ถูกต้อง", clsDefault.AlertType.Fail);
            lblCaptcha.Focus();
            return;
        }
        #endregion
        #region Authorize
        if (!clsSecurity.LoginChecker() && (txtCName.Text.Trim() == "" || txtCEmail.Text.Trim() == ""))
        {
            //ucColorBox1.Redirect("/Webboard/", "กรุณาล็อคอิน หรือ ระบุชื่อและอีเมล์ก่อนส่งข้อมูล");
            ucColorBox1.Alert("เกิดข้อผิดพลาด", "กรุณาล็อคอิน หรือ กรอกชื่อและอีเมล์ก่อน", AlertImage: ucColorBox.Alerts.Fail);
            return;
        }
        #endregion
        #region Variable
        clsIO         clsIO  = new clsIO();
        StringBuilder strSQL = new StringBuilder();
        int           id     = 0;
        string        outSQL;
        string        outErrorMessage;
        string        outFilename;
        string        photoName = "";
        #endregion

        #region Update
        if (clsDefault.URLRouting("id") != "" && clsDefault.URLRouting("command") == "Edit")
        {
            id = int.Parse(clsDefault.URLRouting("id"));
            #region Photo Upload
            if (fuPhoto.HasFile)
            {
                if (clsIO.UploadPhoto(
                        fuPhoto, pathUpload,
                        "Q" + id.ToString(),
                        out outErrorMessage,
                        out outFilename,
                        maxWidth: photoWidth,
                        maxHeight: photoHeight))
                {
                    photoName = outFilename;
                }
                else
                {
                    ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะอัพโหลดไฟล์รูปภาพ<br/>" + outErrorMessage, AlertImage: ucColorBox.Alerts.Fail);
                    return;
                }
            }
            #endregion
            if (clsSQL.Update(tableDefault,
                              new string[, ] {
                { "WebboardGroupUID", ddlWebboardGroup.SelectedItem.Value },
                { "Photo", (photoName == ""?"Photo":"'" + pathUpload + photoName + "'") },
                { "Name", "'" + clsSQL.CodeFilter(ReservedWords(txtName.Text)) + "'" },
                { "Detail", "'" + clsSQL.CodeFilter(ReservedWords(ucDetail.Text)) + "'" },
                { "MetaKeywords", "'" + clsSQL.CodeFilter(txtMetaKeywords.Text) + "'" },
                { "MetaDescription", "'" + clsSQL.CodeFilter(txtMetaDescription.Text) + "'" },
                { "Status", (ddlStatus.SelectedItem.Value != "N"?"'" + ddlStatus.SelectedItem.Value + "'":"null") },
                { "MUser", (clsSecurity.LoginChecker()?clsSecurity.LoginUID:"0") },
                { "MWhen", "GETDATE()" },
                { "MIPAddress", "'" + clsNet.IPGet() + "'" },
                { "MComputername", "'" + clsNet.ComNameGet() + "'" },
                { "Sort", clsSQL.CodeFilter(txtSort.Text) },
                { "Active", "'" + (cbActive.Checked ? "1" : "0") + "'" }
            }, new string[, ] {
                { parameterChar + "UID", id.ToString() }
            },
                              "UID=" + parameterChar + "UID",
                              dbType, cs, out outSQL))
            {
                ucColorBox1.ReloadParent();
            }
            else
            {
                ucColorBox1.Alert("เกิดข้อผิดพลาดขณะบันทึกข้อมูล<br/>", outSQL, AlertImage: ucColorBox.Alerts.Fail);
            }
        }
        #endregion
        #region Insert
        else
        {
            #region Find New ID
            id = clsSQL.GetNewID("UID", tableDefault, "", dbType, cs);
            if (id == 0)
            {
                ucColorBox1.Alert("เกิดข้อผิดพลาดขณะบันทึกข้อมูล", "ไม่สามารถหา UID ใหม่ได้", AlertImage: ucColorBox.Alerts.Fail);
                return;
            }
            #endregion
            #region Photo Upload
            if (fuPhoto.HasFile)
            {
                if (clsIO.UploadPhoto(
                        fuPhoto, pathUpload,
                        "Q" + id.ToString(),
                        out outErrorMessage,
                        out outFilename,
                        maxWidth: photoWidth,
                        maxHeight: photoHeight))
                {
                    photoName = outFilename;
                }
                else
                {
                    ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะอัพโหลดไฟล์รูปภาพ<br/>" + outErrorMessage, AlertImage: ucColorBox.Alerts.Fail);
                    return;
                }
            }
            #endregion
            if (clsSQL.Insert(tableDefault,
                              new string[, ] {
                { "UID", id.ToString() },
                { "WebboardGroupUID", ddlWebboardGroup.SelectedItem.Value },
                { "Photo", (photoName == ""?"''":"'" + pathUpload + photoName + "'") },
                { "Name", "'" + clsSQL.CodeFilter(ReservedWords(txtName.Text)) + "'" },
                { "Detail", "'" + clsSQL.CodeFilter(ReservedWords(ucDetail.Text)) + "'" },
                { "MetaKeywords", "'" + clsSQL.CodeFilter(txtMetaKeywords.Text) + "'" },
                { "MetaDescription", "'" + clsSQL.CodeFilter(txtMetaDescription.Text) + "'" },
                { "Status", (ddlStatus.SelectedItem.Value != "N"?"'" + ddlStatus.SelectedItem.Value + "'":"null") },
                { "Views", "0" },
                { "CName", (txtCName.Text.Trim() == ""?"null":"'" + clsSQL.CodeFilter(txtCName.Text) + "'") },
                { "CEmail", (txtCEmail.Text.Trim() == ""?"null":"'" + clsSQL.CodeFilter(txtCEmail.Text) + "'") },
                { "CUser", (clsSecurity.LoginChecker()?clsSecurity.LoginUID:"0") },
                { "CWhen", "GETDATE()" },
                { "CIPAddress", "'" + clsNet.IPGet() + "'" },
                { "CComputername", "'" + clsNet.ComNameGet() + "'" },
                { "MUser", (clsSecurity.LoginChecker()?clsSecurity.LoginUID:"0") },
                { "MWhen", "GETDATE()" },
                { "MIPAddress", "'" + clsNet.IPGet() + "'" },
                { "MComputername", "'" + clsNet.ComNameGet() + "'" },
                { "Sort", clsSQL.CodeFilter(txtSort.Text) },
                { "Active", "'" + (approveEnable != "1"?"1":"0") + "'" }
            }, new string[, ] {
                { }
            },
                              dbType, cs, out outSQL))
            {
                string  outMessage;
                clsMail clsMail = new clsMail();

                if (approveEnable != "1")
                {
                    clsMail.SendTemplate(
                        "WebboardTopicAlert",
                        clsMail.GetEmailList("GlobalFrom"),
                        clsMail.GetEmailList("WebboardTo"),
                        new string[, ] {
                        { "[Username]", clsSecurity.LoginUsername },
                        { "[CName]", clsSQL.CodeFilter(txtCName.Text) },
                        { "[CEmail]", clsSQL.CodeFilter(txtCName.Text) },
                        { "[IPAddress]", clsNet.IPGet() },
                        { "[ComputerName]", clsNet.ComNameGet() },
                        { "[Name]", clsDefault.URLRoutingFilter(txtName.Text) },
                        { "[Detail]", clsSQL.CodeFilter(ucDetail.Text) },
                        { "[CWhen]", DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") },
                        { "[WebboardGroupUID]", ddlWebboardGroup.SelectedItem.Value },
                        { "[UID]", id.ToString() }
                    }, out outMessage);

                    ucColorBox1.ReloadParent();
                }
                else
                {
                    clsMail.SendTemplate(
                        "WebboardTopicApprove",
                        clsMail.GetEmailList("GlobalFrom"),
                        clsMail.GetEmailList("WebboardTo"),
                        new string[, ] {
                        { "[Username]", clsSecurity.LoginUsername },
                        { "[CName]", clsSQL.CodeFilter(txtCName.Text) },
                        { "[CEmail]", clsSQL.CodeFilter(txtCName.Text) },
                        { "[IPAddress]", clsNet.IPGet() },
                        { "[ComputerName]", clsNet.ComNameGet() },
                        { "[Name]", clsDefault.URLRoutingFilter(txtName.Text) },
                        { "[Detail]", clsSQL.CodeFilter(ucDetail.Text) },
                        { "[CWhen]", DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") },
                        { "[WebboardGroupUID]", ddlWebboardGroup.SelectedItem.Value },
                        { "[UID]", id.ToString() }
                    }, out outMessage);

                    ucColorBox1.Redirect(webDefault + clsDefault.URLRouting("group") + "/",
                                         "ดำเนินการเสร็จสิ้น",
                                         "เมื่อเจ้าหน้าที่ทำการตรวจสอบข้อมูลคำถามของคุณเรียบร้อยแล้ว จะทำการเผยแพร่โดยเร็ว");
                }
            }
            else
            {
                ucColorBox1.Alert("เกิดข้อผิดพลาดขณะบันทึกข้อมูล<br/>", outSQL, AlertImage: ucColorBox.Alerts.Fail);
            }
        }
        #endregion
    }
    protected void btSave_Click(object sender, EventArgs e)
    {
        clsSecurity security = new clsSecurity();
        clsIO       IO       = new clsIO();

        string strDetailSub = string.Empty;
        string strDetail    = txtDetail.Text.Replace("<p>", "");

        strDetail = strDetail.Replace("</p>", "");
        string PicFull    = "null";
        string PicThumb   = "null";
        string pathPhoto  = "/Images/Article/";
        string pathImages = @"\Images\Article\";
        string outError;

        //upload Photo to server
        if (txtImanges.HasFile)
        {
            //Full Images
            if (IO.UploadPhoto(txtImanges, pathPhoto, "f_pic" + DateTime.Now.ToString("yyyyMMddHHmmss"), 5120, 0, 0, "", 0, out outError, out PicFull) == false)
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "Information", "alert('" + outError.ToString() + "')", true);
                return;
            }
            else
            {
                PicFull = pathImages + "" + PicFull;
            }
            //Thumb Images
            if (IO.UploadPhoto(txtImanges, pathPhoto, "t_pic" + DateTime.Now.ToString("yyyyMMddHHmmss"), 1024, 100, 100, "", 0, out outError, out PicThumb) == false)
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "Information", "alert('" + outError.ToString() + "')", true);
                return;
            }
            else
            {
                PicThumb = pathImages + "" + PicThumb;
            }
        }
        else
        {
            PicFull  = lblImagesFull.Text.Trim();
            PicThumb = lblImagesThumb.Text.Trim();
        }

        //insert data to database
        try
        {
            if (txtDetail.Text.Length >= 200)
            {
                strDetailSub = "<p>" + strDetail.Substring(0, 200) + ".....</p>";
            }
            else
            {
                strDetailSub = "<p>" + strDetail + ".....</p>";
            }

            //Insert new Article
            if (string.IsNullOrEmpty(lblUID.Text) == true)
            {
                Article tbarticle = new Article();

                //Assign values for insert into database
                tbarticle.Subject         = txtSubject.Text.Trim();
                tbarticle.Detail          = txtDetail.Text;
                tbarticle.PicFull         = PicFull;
                tbarticle.PicThumbnail    = PicThumb;
                tbarticle.ActiveDateFrom  = Convert.ToDateTime(txtDateFrom.Text);
                tbarticle.ActiveDateTo    = Convert.ToDateTime(txtDateTo.Text);
                tbarticle.Remark          = txtRemark.Text.Trim();
                tbarticle.CWhen           = DateTime.Now;
                tbarticle.CUser           = Convert.ToInt32(security.LoginUID);
                tbarticle.MWhen           = DateTime.Now;
                tbarticle.MUser           = Convert.ToInt32(security.LoginUID);
                tbarticle.StatusFlag      = rdbActive.Checked == true ? "A" : "D";
                tbarticle.LanguageUID     = Convert.ToInt32(ddlLanguage.SelectedValue);
                tbarticle.DetailSub       = strDetailSub;
                tbarticle.NumberDislike   = 0;
                tbarticle.NumberLike      = 0;
                tbarticle.NumberView      = 0;
                tbarticle.Score           = 0;
                tbarticle.SampleSize      = 0;
                tbarticle.MetaKeywords    = txtMetaKeywords.Text.Trim();
                tbarticle.MetaDescription = txtMetaDescription.Text.Trim();

                //Insert data of Event to database
                db.Articles.InsertOnSubmit(tbarticle);
            }
            else //Update existing Event
            {
                var tbarticle = from a in db.Articles
                                where a.UID == Convert.ToInt32(lblUID.Text.Trim())
                                select a;
                foreach (Article a in tbarticle)
                {
                    a.Subject         = txtSubject.Text.Trim();
                    a.Detail          = txtDetail.Text;
                    a.PicFull         = PicFull;
                    a.PicThumbnail    = PicThumb;
                    a.ActiveDateFrom  = Convert.ToDateTime(txtDateFrom.Text);
                    a.ActiveDateTo    = Convert.ToDateTime(txtDateTo.Text);
                    a.Remark          = txtRemark.Text.Trim();
                    a.MWhen           = DateTime.Now;
                    a.MUser           = Convert.ToInt32(security.LoginUID);
                    a.StatusFlag      = rdbActive.Checked == true ? "A" : "D";
                    a.MetaKeywords    = txtMetaKeywords.Text.Trim();
                    a.MetaDescription = txtMetaDescription.Text.Trim();
                    try
                    {
                        a.LanguageUID = Convert.ToInt32(ddlLanguage.SelectedValue);
                    }
                    catch (Exception ex)
                    {
                        ex.ToString();
                    }
                    a.DetailSub = strDetailSub;
                }
            }
            db.SubmitChanges();
            clsColorBox clsColorBox = new clsColorBox();
            clsColorBox.Refresh();
            //Page.ClientScript.RegisterStartupScript(Page.GetType(), "closeWindow", "<script language='javascript'>parent.$.colorbox.close();</script>");
        }
        catch (Exception ex)
        {
            clsColorBox clsColorBox = new clsColorBox();
            clsColorBox.Refresh();
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Information", "alert('" + ex.ToString() + "')", true);
        }
    }
    private void Delete(string id)
    {
        pnDetail.Visible = false;
        #region Authorize
        if (!clsSecurity.LoginChecker("admin"))
        {
            ucColorBox1.Redirect("/", "กรุณาล็อคอินด้วยสิทธิ์ Admin");
            return;
        }
        #endregion
        #region Variable
        clsIO         clsIO  = new clsIO();
        StringBuilder strSQL = new StringBuilder();
        #endregion

        #region Delete Photo
        #region SQL Query
        strSQL.Append("SELECT ");
        strSQL.Append("Photo ");
        strSQL.Append("FROM ");
        strSQL.Append(tableDefault + " ");
        strSQL.Append("WHERE ");
        strSQL.Append("UID=" + id);
        #endregion
        string photoDelete = clsSQL.Return(strSQL.ToString(), dbType, cs);
        if (!string.IsNullOrEmpty(photoDelete))
        {
            clsIO.FileExist(photoDelete, true);
        }
        strSQL.Length = 0; strSQL.Capacity = 0;
        #endregion
        #region Delete PhotoPreview
        #region SQL Query
        strSQL.Append("SELECT ");
        strSQL.Append("PhotoPreview ");
        strSQL.Append("FROM ");
        strSQL.Append(tableDefault + " ");
        strSQL.Append("WHERE ");
        strSQL.Append("UID=" + id);
        #endregion
        string photoPreviewDelete = clsSQL.Return(strSQL.ToString(), dbType, cs);
        if (!string.IsNullOrEmpty(photoPreviewDelete))
        {
            clsIO.FileExist(photoPreviewDelete, true);
        }
        strSQL.Length = 0; strSQL.Capacity = 0;
        #endregion
        #region Delete Database
        #region SQL Query
        strSQL.Append("DELETE FROM ");
        strSQL.Append(tableDefault + " ");
        strSQL.Append("WHERE ");
        strSQL.Append("UID=" + id);
        #endregion
        if (clsSQL.Execute(strSQL.ToString(), dbType, cs))
        {
            ucColorBox1.Redirect(webDefault + clsDefault.QueryStringRemover(new string[] { "id", "command" }));
        }
        else
        {
            ucColorBox1.Redirect(webDefault, "เกิดข้อผิดพลาดขณะลบข้อมูล");
            return;
        }
        strSQL.Length = 0; strSQL.Capacity = 0;
        #endregion
    }
    protected void btSubmit_Click(object sender, EventArgs e)
    {
        #region Validation
        if (!ucCaptchaEncrypt1.Checker())
        {
            lblCaptcha.Text = clsDefault.AlertMessageColor("คำตอบไม่ถูกต้อง", clsDefault.AlertType.Fail);
            lblCaptcha.Focus();
            return;
        }
        #endregion
        #region Authorize
        if (!clsSecurity.LoginChecker() && (txtCName.Text.Trim()=="" || txtCEmail.Text.Trim()==""))
        {
            //ucColorBox1.Redirect("/Webboard/", "กรุณาล็อคอิน หรือ ระบุชื่อและอีเมล์ก่อนส่งข้อมูล");
            ucColorBox1.Alert("เกิดข้อผิดพลาด", "กรุณาล็อคอิน หรือ กรอกชื่อและอีเมล์ก่อน", AlertImage: ucColorBox.Alerts.Fail);
            return;
        }
        #endregion
        #region Variable
        clsIO clsIO = new clsIO();
        StringBuilder strSQL = new StringBuilder();
        int id = 0;
        string outSQL;
        string outErrorMessage;
        string outFilename;
        string photoName = "";
        #endregion

        #region Update
        if (clsDefault.URLRouting("id")!="" && clsDefault.URLRouting("command") == "Edit")
        {
            id = int.Parse(clsDefault.URLRouting("id"));
            #region Photo Upload
            if (fuPhoto.HasFile)
            {
                if (clsIO.UploadPhoto(
                    fuPhoto, pathUpload,
                    "Q" + id.ToString(),
                    out outErrorMessage,
                    out outFilename,
                    maxWidth: photoWidth,
                    maxHeight: photoHeight))
                {
                    photoName = outFilename;
                }
                else
                {
                    ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะอัพโหลดไฟล์รูปภาพ<br/>" + outErrorMessage, AlertImage: ucColorBox.Alerts.Fail);
                    return;
                }
            }
            #endregion
            if (clsSQL.Update(tableDefault,
                new string[,]{
                    {"WebboardGroupUID",ddlWebboardGroup.SelectedItem.Value},
                    {"Photo",(photoName==""?"Photo":"'"+pathUpload+photoName+"'")},
                    {"Name","'"+clsSQL.CodeFilter(ReservedWords(txtName.Text))+"'"},
                    {"Detail","'"+clsSQL.CodeFilter(ReservedWords(ucDetail.Text))+"'"},
                    {"MetaKeywords","'"+clsSQL.CodeFilter(txtMetaKeywords.Text)+"'"},
                    {"MetaDescription","'"+clsSQL.CodeFilter(txtMetaDescription.Text)+"'"},
                    {"Status",(ddlStatus.SelectedItem.Value!="N"?"'"+ddlStatus.SelectedItem.Value+"'":"null")},
                    {"MUser",(clsSecurity.LoginChecker()?clsSecurity.LoginUID:"0")},
                    {"MWhen","GETDATE()"},
                    {"MIPAddress","'"+clsNet.IPGet()+"'"},
                    {"MComputername","'"+clsNet.ComNameGet()+"'"},
                    {"Sort",clsSQL.CodeFilter(txtSort.Text)},
                    {"Active","'" + (cbActive.Checked ? "1" : "0") + "'"}
                }, new string[,] { { parameterChar + "UID", id.ToString() } },
                "UID=" + parameterChar + "UID",
                dbType, cs, out outSQL))
            {
                ucColorBox1.ReloadParent();
            }
            else
            {
                ucColorBox1.Alert("เกิดข้อผิดพลาดขณะบันทึกข้อมูล<br/>", outSQL, AlertImage: ucColorBox.Alerts.Fail);
            }
        }
        #endregion
        #region Insert
        else
        {
            #region Find New ID
            id = clsSQL.GetNewID("UID", tableDefault, "", dbType, cs);
            if (id == 0)
            {
                ucColorBox1.Alert("เกิดข้อผิดพลาดขณะบันทึกข้อมูล", "ไม่สามารถหา UID ใหม่ได้", AlertImage: ucColorBox.Alerts.Fail);
                return;
            }
            #endregion
            #region Photo Upload
            if (fuPhoto.HasFile)
            {
                if (clsIO.UploadPhoto(
                    fuPhoto, pathUpload,
                    "Q" + id.ToString(),
                    out outErrorMessage,
                    out outFilename,
                    maxWidth: photoWidth,
                    maxHeight: photoHeight))
                {
                    photoName = outFilename;
                }
                else
                {
                    ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะอัพโหลดไฟล์รูปภาพ<br/>" + outErrorMessage, AlertImage: ucColorBox.Alerts.Fail);
                    return;
                }
            }
            #endregion
            if (clsSQL.Insert(tableDefault,
                new string[,]{
                    {"UID",id.ToString()},
                    {"WebboardGroupUID",ddlWebboardGroup.SelectedItem.Value},
                    {"Photo",(photoName==""?"''":"'"+pathUpload+photoName+"'")},
                    {"Name","'"+clsSQL.CodeFilter(ReservedWords(txtName.Text))+"'"},
                    {"Detail","'"+clsSQL.CodeFilter(ReservedWords(ucDetail.Text))+"'"},
                    {"MetaKeywords","'"+clsSQL.CodeFilter(txtMetaKeywords.Text)+"'"},
                    {"MetaDescription","'"+clsSQL.CodeFilter(txtMetaDescription.Text)+"'"},
                    {"Status",(ddlStatus.SelectedItem.Value!="N"?"'"+ddlStatus.SelectedItem.Value+"'":"null")},
                    {"Views","0"},
                    {"CName",(txtCName.Text.Trim()==""?"null":"'"+clsSQL.CodeFilter(txtCName.Text)+"'")},
                    {"CEmail",(txtCEmail.Text.Trim()==""?"null":"'"+clsSQL.CodeFilter(txtCEmail.Text)+"'")},
                    {"CUser",(clsSecurity.LoginChecker()?clsSecurity.LoginUID:"0")},
                    {"CWhen","GETDATE()"},
                    {"CIPAddress","'"+clsNet.IPGet()+"'"},
                    {"CComputername","'"+clsNet.ComNameGet()+"'"},
                    {"MUser",(clsSecurity.LoginChecker()?clsSecurity.LoginUID:"0")},
                    {"MWhen","GETDATE()"},
                    {"MIPAddress","'"+clsNet.IPGet()+"'"},
                    {"MComputername","'"+clsNet.ComNameGet()+"'"},
                    {"Sort",clsSQL.CodeFilter(txtSort.Text)},
                    {"Active","'" + (approveEnable!="1"?"1":"0") + "'"}
                }, new string[,] { { } },
                dbType, cs, out outSQL))
            {
                string outMessage;
                clsMail clsMail = new clsMail();

                if (approveEnable != "1")
                {
                    clsMail.SendTemplate(
                        "WebboardTopicAlert",
                        clsMail.GetEmailList("GlobalFrom"),
                        clsMail.GetEmailList("WebboardTo"),
                        new string[,]{
                        {"[Username]",clsSecurity.LoginUsername},
                        {"[CName]",clsSQL.CodeFilter(txtCName.Text)},
                        {"[CEmail]",clsSQL.CodeFilter(txtCName.Text)},
                        {"[IPAddress]",clsNet.IPGet()},
                        {"[ComputerName]",clsNet.ComNameGet()},
                        {"[Name]",clsDefault.URLRoutingFilter(txtName.Text)},
                        {"[Detail]",clsSQL.CodeFilter(ucDetail.Text)},
                        {"[CWhen]",DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss")},
                        {"[WebboardGroupUID]",ddlWebboardGroup.SelectedItem.Value},
                        {"[UID]",id.ToString()}
                    }, out outMessage);

                    ucColorBox1.ReloadParent();
                }
                else
                {
                    clsMail.SendTemplate(
                            "WebboardTopicApprove",
                            clsMail.GetEmailList("GlobalFrom"),
                            clsMail.GetEmailList("WebboardTo"),
                            new string[,]{
                        {"[Username]",clsSecurity.LoginUsername},
                        {"[CName]",clsSQL.CodeFilter(txtCName.Text)},
                        {"[CEmail]",clsSQL.CodeFilter(txtCName.Text)},
                        {"[IPAddress]",clsNet.IPGet()},
                        {"[ComputerName]",clsNet.ComNameGet()},
                        {"[Name]",clsDefault.URLRoutingFilter(txtName.Text)},
                        {"[Detail]",clsSQL.CodeFilter(ucDetail.Text)},
                        {"[CWhen]",DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss")},
                        {"[WebboardGroupUID]",ddlWebboardGroup.SelectedItem.Value},
                        {"[UID]",id.ToString()}
                    }, out outMessage);

                    ucColorBox1.Redirect(webDefault + clsDefault.URLRouting("group") + "/",
                        "ดำเนินการเสร็จสิ้น",
                        "เมื่อเจ้าหน้าที่ทำการตรวจสอบข้อมูลคำถามของคุณเรียบร้อยแล้ว จะทำการเผยแพร่โดยเร็ว");
                }
            }
            else
            {
                ucColorBox1.Alert("เกิดข้อผิดพลาดขณะบันทึกข้อมูล<br/>", outSQL, AlertImage: ucColorBox.Alerts.Fail);
            }
        }
        #endregion
    }
    protected void btSubmit_Click(object sender, EventArgs e)
    {
        #region Authorize
        if (!clsSecurity.LoginChecker("admin"))
        {
            ucColorBox1.Redirect(webDefault, "กรุณาล็อคอินด้วยสิทธิ์ Admin");
            return;
        }
        #endregion
        #region Variable
        clsIO clsIO = new clsIO();
        StringBuilder strSQL = new StringBuilder();
        int id = 0;
        string outSQL;
        string outErrorMessage;
        string outFilename;
        string photoName = "";
        #endregion

        #region Update
        if (clsDefault.URLRouting("id") != "" && clsDefault.URLRouting("command") == "Edit")
        {
            id = int.Parse(clsDefault.URLRouting("id"));
            #region Photo Upload
            if (fuPhoto.HasFile)
            {
                if (clsIO.UploadPhoto(
                    fuPhoto, pathUpload,
                    "Group" + id.ToString(),
                    out outErrorMessage,
                    out outFilename,
                    maxWidth: photoWidth,
                    maxHeight: photoHeight,
                    resizeMode: clsIO.ResizeMode.crop))
                {
                    photoName = outFilename;
                }
                else
                {
                    ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะอัพโหลดไฟล์รูปภาพ<br/>" + outErrorMessage, AlertImage: ucColorBox.Alerts.Fail);
                    return;
                }
            }
            #endregion
            if (clsSQL.Update(tableDefault,
                new string[,]{
                    {"WebboardTypeUID",ddlWebboardType.SelectedItem.Value},
                    {"GlobalUID","'"+clsSQL.CodeFilter(txtGlobalUID.Text)+"'"},
                    {"Icon",(photoName!=""?"'"+pathUpload+photoName+"'":"Icon")},
                    {"Name","'"+clsSQL.CodeFilter(txtName.Text)+"'"},
                    {"Detail","'"+clsSQL.CodeFilter(txtDetail.Text)+"'"},
                    {"MetaKeywords","'"+clsSQL.CodeFilter(txtMetaKeywords.Text)+"'"},
                    {"MetaDescription","'"+clsSQL.CodeFilter(txtMetaDescription.Text)+"'"},
                    {"MUser","'" + clsSecurity.LoginUID + "'"},
                    {"MWhen","GETDATE()"},
                    {"Sort",clsSQL.CodeFilter(txtSort.Text)},
                    {"Active","'" + (cbActive.Checked ? "1" : "0") + "'"}
                }, new string[,] { { parameterChar + "UID", id.ToString() } },
                "UID=" + parameterChar + "UID",
                dbType, cs, out outSQL))
            {
                ucColorBox1.ReloadParent();
            }
            else
            {
                ucColorBox1.Alert("เกิดข้อผิดพลาดขณะบันทึกข้อมูล<br/>", outSQL, AlertImage: ucColorBox.Alerts.Fail);
            }
        }
        #endregion
        #region Insert
        else
        {
            #region Find New ID
            id = clsSQL.GetNewID("UID", tableDefault, "", dbType, cs);
            if (id == 0)
            {
                ucColorBox1.Alert("เกิดข้อผิดพลาดขณะบันทึกข้อมูล", "ไม่สามารถหา UID ใหม่ได้", AlertImage: ucColorBox.Alerts.Fail);
                return;
            }
            #endregion
            #region Photo Upload
            if (fuPhoto.HasFile)
            {
                if (clsIO.UploadPhoto(
                    fuPhoto, pathUpload,
                    "Group" + id.ToString(),
                    out outErrorMessage,
                    out outFilename,
                    maxWidth: photoWidth,
                    maxHeight: photoHeight,
                    resizeMode: clsIO.ResizeMode.crop))
                {
                    photoName = outFilename;
                }
                else
                {
                    ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะอัพโหลดไฟล์รูปภาพ<br/>" + outErrorMessage, AlertImage: ucColorBox.Alerts.Fail);
                    return;
                }
            }
            #endregion
            if (clsSQL.Insert(tableDefault,
                new string[,]{
                    {"UID",id.ToString()},
                    {"WebboardTypeUID",clsDefault.URLRouting("type")},
                    {"GlobalUID","'"+clsSQL.CodeFilter(txtGlobalUID.Text)+"'"},
                    {"Icon","'"+pathUpload+photoName+"'"},
                    {"Name","'"+clsSQL.CodeFilter(txtName.Text)+"'"},
                    {"Detail","'"+clsSQL.CodeFilter(txtDetail.Text)+"'"},
                    {"MetaKeywords","'"+clsSQL.CodeFilter(txtMetaKeywords.Text)+"'"},
                    {"MetaDescription","'"+clsSQL.CodeFilter(txtMetaDescription.Text)+"'"},
                    {"Views","0"},
                    {"CUser","'" + clsSecurity.LoginUID + "'"},
                    {"CWhen","GETDATE()"},
                    {"MUser","'" + clsSecurity.LoginUID + "'"},
                    {"MWhen","GETDATE()"},
                    {"Sort",clsSQL.CodeFilter(txtSort.Text)},
                    {"Active","'" + (cbActive.Checked ? "1" : "0") + "'"}
                }, new string[,] { { } },
                dbType, cs, out outSQL))
            {
                ucColorBox1.ReloadParent();
            }
            else
            {
                ucColorBox1.Alert("เกิดข้อผิดพลาดขณะบันทึกข้อมูล<br/>", outSQL, AlertImage: ucColorBox.Alerts.Fail);
            }
        }
        #endregion
    }
    protected void btSubmit_Click(object sender, EventArgs e)
    {
        #region Variable
        var outSQL   = "";
        var clsIO    = new clsIO();
        var outError = "";
        var outPhoto = "";
        var outMail  = "";
        #endregion
        #region Procedure
        if (fuPhoto.HasFile)
        {
            if (!clsIO.UploadPhoto(
                    fuPhoto,
                    "/Upload/Jobs/",
                    clsSQL.GetNewID("UID", "JobsHistory", "", dbType, cs).ToString(),
                    out outError,
                    out outPhoto,
                    512, 200, 200))
            {
                ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะอัพโหลดภาพ : " + outError);
                return;
            }
        }
        #region InsertData
        if (!clsSQL.Insert(
                "JobsHistory",
                new string[, ] {
            { "JobsUID", ddlJobs.SelectedItem.Value },
            { "JobsName", "'" + txtJobsName.Text.SQLQueryFilter() + "'" },
            { "Salary", "'" + txtSalary.Text.SQLQueryFilter() + "'" },
            { "Start", "'" + txtStart.Text.SQLQueryFilter() + "'" },
            { "ProvinceChange", "'" + rbProvinceChange.SelectedItem.Value + "'" },
            { "PrenameTH", "'" + ddlPrenameTH.SelectedItem.Value + "'" },
            { "ForenameTH", "'" + txtForenameTH.Text.SQLQueryFilter() + "'" },
            { "SurnameTH", "'" + txtSurnameTH.Text.SQLQueryFilter() + "'" },
            { "PrenameEN", "'" + ddlPrenameEN.SelectedItem.Value + "'" },
            { "ForenameEN", "'" + txtForenameEN.Text.SQLQueryFilter() + "'" },
            { "SurnameEN", "'" + txtSurnameEN.Text.SQLQueryFilter() + "'" },
            { "MarriageStatus", "'" + rbMarriageStatus.SelectedItem.Value + "'" },
            { "Gender", "'" + rbGender.SelectedItem.Value + "'" },
            { "Birthdate", "'" + (ucBirthdate.Text.Trim() != ""?ucBirthdate.DateTime.ToString("yyyy-MM-dd"):"1900-01-01 00:00") + "'" },
            { "Birthplace", "'" + txtBirthplace.Text.SQLQueryFilter() + "'" },
            { "Nationality", "'" + txtNationality.Text.SQLQueryFilter() + "'" },
            { "Race", "'" + txtRace.Text.SQLQueryFilter() + "'" },
            { "Religion", "'" + txtReligion.Text.SQLQueryFilter() + "'" },
            { "Weight", "'" + txtWeight.Text.SQLQueryFilter() + "'" },
            { "Height", "'" + txtHeight.Text.SQLQueryFilter() + "'" },
            { "NID", "'" + txtNID.Text.SQLQueryFilter() + "'" },
            { "NIDCreateBy", "'" + txtNIDCreateBy.Text.SQLQueryFilter() + "'" },
            { "NIDExpire", "'" + (ucNIDExpire.Text != ""?ucNIDExpire.DateTime.ToString("yyyy-MM-dd"):"") + "'" },
            { "Phone", "'" + txtPhone.Text.SQLQueryFilter() + "'" },
            { "Email", "'" + txtEmail.Text.SQLQueryFilter() + "'" },
            { "Address", "'" + txtAddress.Text.SQLQueryFilter() + "'" },
            { "EmergencyName", "'" + txtEmergencyName.Text.SQLQueryFilter() + "'" },
            { "EmergencyPhone", "'" + txtEmergencyPhone.Text.SQLQueryFilter() + "'" },
            { "EmergencyEmail", "'" + txtEmergencyEmail.Text.SQLQueryFilter() + "'" },
            { "EmergencyAddress", "'" + txtEmergencyAddress.Text.SQLQueryFilter() + "'" },
            { "EmergencyRelationship", "'" + txtEmergencyRelationship.Text.SQLQueryFilter() + "'" },
            { "Photo", (outPhoto != ""?"'" + outPhoto + "'":"null") },
            { "Education", "'" + ucEducation.Text.SQLQueryFilter() + "'" },
            { "Experience", "'" + ucExperience.Text.SQLQueryFilter() + "'" },
            { "Resume", "null" },
            { "CWhen", "GETDATE()" },
            { "CUser", "0" },
            { "MWhen", "GETDATE()" },
            { "MUser", "0" },
            { "Sort", "0" },
            { "StatusFlag", "'A'" }
        },
                new string[, ] {
            { }
        },
                dbType,
                cs,
                out outSQL))
        {
            ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะรันคำสั่ง : " + Server.HtmlEncode(outSQL));
            return;
        }
        else
        {
            #region MailSender
            string JobsUID = clsSQL.Return("SELECT MAX(UID) FROM JobsHistory", dbType, cs);

            if (!clsMail.SendTemplate(
                    "JobsApply",
                    clsMail.GetEmailList("AutoSystemFrom"),
                    clsMail.GetEmailList("JobsTo"),
                    new string[, ]
            {
                { "[Photo]", "<img src='" + System.Configuration.ConfigurationManager.AppSettings["website"] + "/Upload/Jobs/" + outPhoto + "'/>" },
                { "[UID]", JobsUID },
                { "[JobsName]", ddlJobs.SelectedItem.Text + (txtJobsName.Text.Trim() != ""?" (" + txtJobsName.Text.SQLQueryFilter() + ")":"") },
                { "[PrenameTH]", ddlPrenameTH.SelectedItem.Text },
                { "[ForenameTH]", txtForenameTH.Text },
                { "[SurnameTH]", txtSurnameTH.Text },
                { "[Birthdate]", ucBirthdate.DateTime.ToString("dd/MM/yyyy") },
                { "[Birthplace]", txtBirthplace.Text },
                { "[Gender]", rbGender.SelectedItem.Text },
                { "[Phone]", txtPhone.Text },
                { "[Email]", txtEmail.Text },
                { "[Start]", txtStart.Text.SQLQueryFilter() },
                { "[Education]", ucEducation.Text.SQLQueryFilter() },
                { "[Experience]", ucExperience.Text.SQLQueryFilter() },
                { "[CWhen]", DateTime.Now.ToString("dd/MM/yyyy HH:mm") }
            },
                    out outMail))
            {
                lblMessage.Text = clsDefault.AlertMessageColor("เกิดข้อผิดพลาดขณะพยายามส่งอีเมล์<br/>" + outMail, clsDefault.AlertType.Fail);
                lblMessage.Focus();
                return;
            }
            #endregion
            ucColorBox1.Redirect("/Jobs/");
        }
        #endregion
        #endregion
    }
Ejemplo n.º 26
0
    protected void btSubmit_Click(object sender, EventArgs e)
    {
        #region Authorize
        if (!clsSecurity.LoginChecker("admin"))
        {
            ucColorBox1.Redirect("/", "กรุณาล็อคอินด้วยสิทธิ์ Admin");
            return;
        }
        #endregion
        #region Variable
        StringBuilder strSQL = new StringBuilder();
        int           id     = 0;
        string        outSQL;
        string        photoName = "";
        #endregion

        #region Update
        if (Request.QueryString["id"] != null && clsDefault.QueryStringChecker("command") == "edit")
        {
            id = int.Parse(Request.QueryString["id"].ToString());
            #region Photo Upload
            if (fuPhoto.HasFile)
            {
                clsIO  clsIO = new clsIO();
                string outErrorMessage; string outFilename;
                if (clsIO.UploadPhoto(
                        fuPhoto, pathUpload,
                        "Service" + id.ToString(),
                        out outErrorMessage,
                        out outFilename,
                        maxWidth: photoWidth,
                        maxHeight: photoHeight))
                {
                    photoName = outFilename;
                }
                else
                {
                    ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะอัพโหลดไฟล์รูปภาพ<br/>" + outErrorMessage, AlertImage: ucColorBox.Alerts.Fail);
                    return;
                }
            }
            #endregion
            if (clsSQL.Update(tableDefault,
                              new string[, ] {
                { "UID", id.ToString() },
                { "LanguageUID", rbLanguage.SelectedItem.Value },
                { "ServiceGroupUID", clsDefault.QueryStringChecker("group") },
                { "DepartmentUID", (txtDepartmentUID.Text != ""?"'" + clsSQL.CodeFilter(txtDepartmentUID.Text) + "'":"null") },
                { "Icon", (!string.IsNullOrEmpty(photoName)?"'" + pathUpload + photoName + "'":"Icon") },
                { "Name", "'" + clsSQL.CodeFilter(txtName.Text) + "'" },
                { "Detail", "'" + clsSQL.CodeFilter(txtDetail.Text) + "'" },
                { "[Content]", "'" + clsSQL.CodeFilter(ucContent.Text) + "'" },
                { "Price", "'" + clsSQL.CodeFilter(ucPrice.Text) + "'" },
                { "Location", "'" + clsSQL.CodeFilter(txtLocation.Text) + "'" },
                { "OfficeHours", "'" + clsSQL.CodeFilter(txtOfficeHours.Text) + "'" },
                { "Phone", "'" + clsSQL.CodeFilter(txtPhone.Text) + "'" },
                { "EMail", "'" + clsSQL.CodeFilter(txtEMail.Text) + "'" },
                { "MetaKeywords", "'" + clsSQL.CodeFilter(txtMetaKeyword.Text) + "'" },
                { "MetaDescription", "'" + clsSQL.CodeFilter(txtMetaDescription.Text) + "'" },
                { "MUser", "'" + clsSecurity.LoginUID + "'" },
                { "MWhen", "GETDATE()" },
                { "Sort", clsSQL.CodeFilter(txtSort.Text) },
                { "Active", "'" + (cbActive.Checked ? "1" : "0") + "'" }
            }, new string[, ] {
                { parameterChar + "UID", id.ToString() }
            },
                              "UID=" + parameterChar + "UID",
                              dbType, cs, out outSQL))
            {
                ucColorBox1.ReloadParent();
            }
            else
            {
                ucColorBox1.Alert("เกิดข้อผิดพลาดขณะบันทึกข้อมูล<br/>", outSQL, AlertImage: ucColorBox.Alerts.Fail);
            }
        }
        #endregion
        #region Insert
        else
        {
            #region Find New ID
            id = clsSQL.GetNewID("UID", tableDefault, "", dbType, cs);
            if (id == 0)
            {
                ucColorBox1.Alert("เกิดข้อผิดพลาดขณะบันทึกข้อมูล", "ไม่สามารถหา UID ใหม่ได้", AlertImage: ucColorBox.Alerts.Fail);
                return;
            }
            #endregion
            #region Photo Upload
            if (fuPhoto.HasFile)
            {
                clsIO  clsIO = new clsIO();
                string outErrorMessage; string outFilename;
                if (clsIO.UploadPhoto(
                        fuPhoto, pathUpload,
                        "Service" + id.ToString(),
                        out outErrorMessage,
                        out outFilename,
                        maxWidth: photoWidth,
                        maxHeight: photoHeight))
                {
                    photoName = outFilename;
                }
                else
                {
                    ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะอัพโหลดไฟล์รูปภาพ<br/>" + outErrorMessage, AlertImage: ucColorBox.Alerts.Fail);
                    return;
                }
            }
            #endregion
            if (clsSQL.Insert(tableDefault,
                              new string[, ] {
                { "UID", id.ToString() },
                { "LanguageUID", rbLanguage.SelectedItem.Value },
                { "ServiceGroupUID", clsDefault.QueryStringChecker("group") },
                { "DepartmentUID", (txtDepartmentUID.Text.Trim() != ""?"'" + clsSQL.CodeFilter(txtDepartmentUID.Text) + "'":"null") },
                { "Icon", (!string.IsNullOrEmpty(photoName)?"'" + pathUpload + photoName + "'":"null") },
                { "Name", "'" + clsSQL.CodeFilter(txtName.Text) + "'" },
                { "Detail", "'" + clsSQL.CodeFilter(txtDetail.Text) + "'" },
                { "[Content]", "'" + clsSQL.CodeFilter(ucContent.Text) + "'" },
                { "Price", "'" + clsSQL.CodeFilter(ucPrice.Text) + "'" },
                { "Location", "'" + clsSQL.CodeFilter(txtLocation.Text) + "'" },
                { "OfficeHours", "'" + clsSQL.CodeFilter(txtOfficeHours.Text) + "'" },
                { "Phone", "'" + clsSQL.CodeFilter(txtPhone.Text) + "'" },
                { "EMail", "'" + clsSQL.CodeFilter(txtEMail.Text) + "'" },
                { "MetaKeywords", "'" + clsSQL.CodeFilter(txtMetaKeyword.Text) + "'" },
                { "MetaDescription", "'" + clsSQL.CodeFilter(txtMetaDescription.Text) + "'" },
                { "CUser", "'" + clsSecurity.LoginUID + "'" },
                { "CWhen", "GETDATE()" },
                { "MUser", "'" + clsSecurity.LoginUID + "'" },
                { "MWhen", "GETDATE()" },
                { "Sort", clsSQL.CodeFilter(txtSort.Text) },
                { "Active", "'" + (cbActive.Checked ? "1" : "0") + "'" }
            }, new string[, ] {
                { }
            },
                              dbType, cs, out outSQL))
            {
                ucColorBox1.ReloadParent();
            }
            else
            {
                ucColorBox1.Alert("เกิดข้อผิดพลาดขณะบันทึกข้อมูล<br/>", outSQL, AlertImage: ucColorBox.Alerts.Fail);
            }
        }
        #endregion
    }
Ejemplo n.º 27
0
 protected void btSubmit_Click(object sender, EventArgs e)
 {
     #region Authorize
     if (!clsSecurity.LoginChecker("admin"))
     {
         ucColorBox1.Redirect("/", "กรุณาล็อคอินด้วยสิทธิ์ Admin");
         return;
     }
     #endregion
     #region Variable
     var strSQL    = new StringBuilder();
     var id        = 0;
     var outSQL    = "";
     var photoName = "";
     #endregion
     #region Procedure
     try
     {
         #region Update
         if (Request.QueryString["id"] != null && clsDefault.QueryStringChecker("command") == "edit")
         {
             id = int.Parse(Request.QueryString["id"].ToString());
             #region Photo Upload
             if (fuPhoto.HasFile)
             {
                 var    clsIO = new clsIO();
                 string outErrorMessage;
                 string outFilename;
                 #region Photo
                 if (clsIO.UploadPhoto(
                         fuPhoto, pathUpload,
                         tableDefault + id.ToString(),
                         out outErrorMessage,
                         out outFilename,
                         maxWidth: photoWidth,
                         maxHeight: photoHeight))
                 {
                     photoName = outFilename;
                 }
                 else
                 {
                     ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะอัพโหลดไฟล์รูปภาพ<br/>" + outErrorMessage, AlertImage: ucColorBox.Alerts.Fail);
                     return;
                 }
                 #endregion
             }
             #endregion
             if (clsSQL.Update(tableDefault,
                               new string[, ] {
                 { "Photo", (!string.IsNullOrEmpty(photoName)?"'" + pathUpload + photoName + "'":"Photo") },
                 { "UserGroupUID", ddlUserGroup.SelectedItem.Value },
                 { "PName", "'" + ddlPName.SelectedItem.Value + "'" },
                 { "FName", "'" + txtFName.Text.SQLQueryFilter() + "'" },
                 { "LName", "'" + txtLName.Text.SQLQueryFilter() + "'" },
                 { "BirthDate", (ucBirthdate.Text != ""?"'" + ucBirthdate.DateTime.ToString("yyyy-MM-dd") + "'":"null") },
                 { "Gender", "'" + rbGender.SelectedItem.Value + "'" },
                 { "NID", "'" + txtNID.Text.SQLQueryFilter() + "'" },
                 { "Phone", "'" + txtPhone.Text.SQLQueryFilter() + "'" },
                 { "Mobile", "'" + txtMobile.Text.SQLQueryFilter() + "'" },
                 { "Email", "'" + txtEmail.Text.SQLQueryFilter() + "'" },
                 { "Address", "'" + txtAddress.Text.SQLQueryFilter() + "'" },
                 { "AddressDistrict", "'" + txtAddressDistrict.Text.SQLQueryFilter() + "'" },
                 { "AddressPrefecture", "'" + txtAddressPrefecture.Text.SQLQueryFilter() + "'" },
                 { "AddressProvince", "'" + txtAddressProvince.Text.SQLQueryFilter() + "'" },
                 { "AddressPostal", "'" + txtAddressPostal.Text.SQLQueryFilter() + "'" },
                 { "Profile", "'" + ucProfile.Text.SQLQueryFilter() + "'" },
                 { "Signature", "'" + ucSignature.Text.SQLQueryFilter() + "'" },
                 { "MUser", "'" + clsSecurity.LoginUID + "'" },
                 { "MWhen", functionGetDate },
                 { "Sort", clsSQL.CodeFilter(txtSort.Text) },
                 { "StatusFlag", "'" + (cbActive.Checked ? "A" : "I") + "'" }
             }, new string[, ] {
                 { parameterChar + "UID", id.ToString() }
             },
                               "UID=" + parameterChar + "UID",
                               out outSQL))
             {
                 ucColorBox1.ReloadParent();
             }
             else
             {
                 ucColorBox1.Alert("เกิดข้อผิดพลาดขณะบันทึกข้อมูล<br/>", outSQL, AlertImage: ucColorBox.Alerts.Fail);
             }
         }
         #endregion
         #region Insert
         else
         {
             #region Photo Upload
             if (fuPhoto.HasFile)
             {
                 var    clsIO = new clsIO();
                 string outErrorMessage;
                 string outFilename;
                 #region Photo
                 if (clsIO.UploadPhoto(
                         fuPhoto, pathUpload,
                         tableDefault + id.ToString(),
                         out outErrorMessage,
                         out outFilename,
                         maxWidth: photoWidth,
                         maxHeight: photoHeight))
                 {
                     photoName = outFilename;
                 }
                 else
                 {
                     ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะอัพโหลดไฟล์รูปภาพ<br/>" + outErrorMessage, AlertImage: ucColorBox.Alerts.Fail);
                     return;
                 }
                 #endregion
             }
             #endregion
             if (clsSQL.Insert(tableDefault,
                               new string[, ] {
                 { "UserGroupUID", ddlUserGroup.SelectedItem.Value },
                 { "[Username]", "'" + txtUsername.Text.SQLQueryFilter() + "'" },
                 { "Password", "'" + clsSecurity.Encrypt(txtPassword.Text) + "'" },
                 { "PName", "'" + ddlPName.SelectedItem.Value + "'" },
                 { "FName", "'" + txtFName.Text.SQLQueryFilter() + "'" },
                 { "LName", "'" + txtLName.Text.SQLQueryFilter() + "'" },
                 { "BirthDate", (ucBirthdate.Text != ""?"'" + ucBirthdate.DateTime.ToString("yyyy-MM-dd") + "'":"null") },
                 { "Gender", "'" + rbGender.SelectedItem.Value + "'" },
                 { "NID", "'" + txtNID.Text.SQLQueryFilter() + "'" },
                 { "Phone", "'" + txtPhone.Text.SQLQueryFilter() + "'" },
                 { "Mobile", "'" + txtMobile.Text.SQLQueryFilter() + "'" },
                 { "Email", "'" + txtEmail.Text.SQLQueryFilter() + "'" },
                 { "[Address]", "'" + txtAddress.Text.SQLQueryFilter() + "'" },
                 { "AddressDistrict", "'" + txtAddressDistrict.Text.SQLQueryFilter() + "'" },
                 { "AddressPrefecture", "'" + txtAddressPrefecture.Text.SQLQueryFilter() + "'" },
                 { "AddressProvince", "'" + txtAddressProvince.Text.SQLQueryFilter() + "'" },
                 { "AddressPostal", "'" + txtAddressPostal.Text.SQLQueryFilter() + "'" },
                 { "Profile", "'" + ucProfile.Text.SQLQueryFilter() + "'" },
                 { "Signature", "'" + ucSignature.Text.SQLQueryFilter() + "'" },
                 { "CUser", "'" + clsSecurity.LoginUID + "'" },
                 { "CWhen", functionGetDate },
                 { "MUser", "'" + clsSecurity.LoginUID + "'" },
                 { "MWhen", functionGetDate },
                 { "Sort", clsSQL.CodeFilter(txtSort.Text) },
                 { "StatusFlag", "'" + (cbActive.Checked ? "A" : "I") + "'" }
             }, new string[, ] {
                 { }
             },
                               out outSQL))
             {
                 ucColorBox1.ReloadParent();
             }
             else
             {
                 ucColorBox1.Alert("เกิดข้อผิดพลาดขณะบันทึกข้อมูล<br/>", outSQL, AlertImage: ucColorBox.Alerts.Fail);
             }
         }
         #endregion
     }
     catch (Exception ex)
     {
         lblSQL.Text = "<div style='color:red;'>เกิดข้อผิดพลาด : " + ex.Message + "</div>";
         lblSQL.Focus();
     }
     #endregion
 }
    protected void btSubmit_Click(object sender, EventArgs e)
    {
        #region Authorize
        if (!clsSecurity.LoginChecker("admin"))
        {
            ucColorBox1.Redirect("/", "กรุณาล็อคอินด้วยสิทธิ์ Admin");
            return;
        }
        #endregion
        #region Variable
        var strSQL = new StringBuilder();
        var id = 0;
        var outSQL = "";
        var photoName = "";
        var photoFullName = "";
        #endregion

        #region Update
        if (Request.QueryString["id"] != null && clsDefault.QueryStringChecker("command") == "edit")
        {
            id = int.Parse(Request.QueryString["id"].ToString());
            clsIO clsIO = new clsIO();
            string outErrorMessage; string outFilename;
            #region Photo Upload
            if (fuPhoto.HasFile)
            {
                if (clsIO.UploadPhoto(
                    fuPhoto, pathUpload,
                    tableDefault + id.ToString() + "_T",
                    out outErrorMessage,
                    out outFilename,
                    maxWidth: photoWidth,
                    maxHeight: photoHeight))
                {
                    photoName = outFilename;
                }
                else
                {
                    ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะอัพโหลดไฟล์รูปภาพ<br/>" + outErrorMessage, AlertImage: ucColorBox.Alerts.Fail);
                    return;
                }
            }
            #endregion
            #region PhotoFull Upload
            if (fuPhotoFull.HasFile)
            {
                if (clsIO.UploadPhoto(
                    fuPhotoFull, pathUpload,
                    tableDefault + id.ToString(),
                    out outErrorMessage,
                    out outFilename))
                {
                    photoFullName = outFilename;
                }
                else
                {
                    ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะอัพโหลดไฟล์รูปภาพ<br/>" + outErrorMessage, AlertImage: ucColorBox.Alerts.Fail);
                    return;
                }
            }
            #endregion
            if (clsSQL.Update(tableDefault,
                new string[,]{
                    {"LanguageUID",rbLanguage.SelectedItem.Value},
                    {"DepartmentUID",(ddlDepartment.SelectedItem.Value!="null"?"'"+ddlDepartment.SelectedItem.Value+"'":"null")},
                    {"PicThumbnail",(!string.IsNullOrEmpty(photoName)?"'"+pathUpload+photoName+"'":"PicThumbnail")},
                    {"PicFull",(!string.IsNullOrEmpty(photoFullName)?"'"+pathUpload+photoFullName+"'":"PicFull")},
                    {"PromotionName","'"+clsSQL.CodeFilter(txtName.Text)+"'"},
                    {"Detail","'"+ucContent.Text.SQLQueryFilter()+"'"},
                    {"DetailSub","'"+clsSQL.CodeFilter(txtDetail.Text)+"'"},
                    {"ActiveDateFrom",(ucDateStart.Text!=""?"'"+ucDateStart.Text.SQLQueryFilter()+"'":"null")},
                    {"ActiveDateTo",(ucDateEnd.Text!=""?"'"+ucDateEnd.Text.SQLQueryFilter()+"'":"null")},
                    {"MetaKeywords","'"+clsSQL.CodeFilter(txtMetaKeyword.Text)+"'"},
                    {"MetaDescription","'"+clsSQL.CodeFilter(txtMetaDescription.Text)+"'"},
                    {"MUser","'" + clsSecurity.LoginUID + "'"},
                    {"MWhen","GETDATE()"},
                    {"StatusFlag","'" + (cbActive.Checked ? "A" : "D") + "'"}
                }, new string[,] { { parameterChar + "UID", id.ToString() } },
                "UID=" + parameterChar + "UID",
                dbType, cs, out outSQL))
            {
                ucColorBox1.ReloadParent();
            }
            else
            {
                ucColorBox1.Alert("เกิดข้อผิดพลาดขณะบันทึกข้อมูล<br/>", outSQL, AlertImage: ucColorBox.Alerts.Fail);
            }
        }
        #endregion
        #region Insert
        else
        {
            #region Find New ID
            id = clsSQL.GetNewID("UID", tableDefault, "", dbType, cs);
            if (id == 0)
            {
                ucColorBox1.Alert("เกิดข้อผิดพลาดขณะบันทึกข้อมูล", "ไม่สามารถหา UID ใหม่ได้", AlertImage: ucColorBox.Alerts.Fail);
                return;
            }
            #endregion

            clsIO clsIO = new clsIO();
            string outErrorMessage; string outFilename;
            #region Photo Upload
            if (fuPhoto.HasFile)
            {
                if (clsIO.UploadPhoto(
                    fuPhoto, pathUpload,
                    tableDefault + id.ToString() + "_T",
                    out outErrorMessage,
                    out outFilename,
                    maxWidth: photoWidth,
                    maxHeight: photoHeight))
                {
                    photoName = outFilename;
                }
                else
                {
                    ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะอัพโหลดไฟล์รูปภาพ<br/>" + outErrorMessage, AlertImage: ucColorBox.Alerts.Fail);
                    return;
                }
            }
            #endregion
            #region PhotoFull Upload
            if (fuPhotoFull.HasFile)
            {
                if (clsIO.UploadPhoto(
                    fuPhotoFull, pathUpload,
                    tableDefault + id.ToString(),
                    out outErrorMessage,
                    out outFilename))
                {
                    photoFullName = outFilename;
                }
                else
                {
                    ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะอัพโหลดไฟล์รูปภาพ<br/>" + outErrorMessage, AlertImage: ucColorBox.Alerts.Fail);
                    return;
                }
            }
            #endregion
            if (clsSQL.Insert(tableDefault,
                new string[,]{
                    {"LanguageUID",rbLanguage.SelectedItem.Value},
                    {"DepartmentUID",(ddlDepartment.SelectedItem.Value!="null"?"'"+ddlDepartment.SelectedItem.Value+"'":"null")},
                    {"PicThumbnail",(!string.IsNullOrEmpty(photoName)?"'"+pathUpload+photoName+"'":"null")},
                    {"PicFull",(!string.IsNullOrEmpty(photoFullName)?"'"+pathUpload+photoFullName+"'":"null")},
                    {"PromotionName","'"+clsSQL.CodeFilter(txtName.Text)+"'"},
                    {"Detail","'"+ucContent.Text.SQLQueryFilter()+"'"},
                    {"DetailSub","'"+clsSQL.CodeFilter(txtDetail.Text)+"'"},
                    {"ActiveDateFrom",(ucDateStart.Text!=""?"'"+ucDateStart.Text.SQLQueryFilter()+"'":"null")},
                    {"ActiveDateTo",(ucDateEnd.Text!=""?"'"+ucDateEnd.Text.SQLQueryFilter()+"'":"null")},
                    {"MetaKeywords","'"+clsSQL.CodeFilter(txtMetaKeyword.Text)+"'"},
                    {"MetaDescription","'"+clsSQL.CodeFilter(txtMetaDescription.Text)+"'"},
                    {"CUser","'" + clsSecurity.LoginUID + "'"},
                    {"CWhen","GETDATE()"},
                    {"MUser","'" + clsSecurity.LoginUID + "'"},
                    {"MWhen","GETDATE()"},
                    {"StatusFlag","'" + (cbActive.Checked ? "A" : "D") + "'"}
                }, new string[,] { { } },
                dbType, cs, out outSQL))
            {
                ucColorBox1.ReloadParent();
            }
            else
            {
                ucColorBox1.Alert("เกิดข้อผิดพลาดขณะบันทึกข้อมูล<br/>", outSQL, AlertImage: ucColorBox.Alerts.Fail);
            }
        }
        #endregion
    }
    protected void btSave_Click(object sender, EventArgs e)
    {
        System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

        clsSecurity security = new clsSecurity();
        clsIO IO = new clsIO();

        string strDetailSub = string.Empty;
        string strDetail = txtDetail.Text.Replace("<p>", "");
        strDetail = strDetail.Replace("</p>", "");
        string PicFull = "null";
        string PicThumb = "null";
        string pathPhoto = "/Images/Event/";
        string pathImages = @"\Images\Event\";
        string outError;

        //upload Photo to server
        if(txtImgFull.HasFile)
        {
            //Full Images
            if (IO.UploadPhoto(txtImgFull, pathPhoto, "f_pic" + DateTime.Now.ToString("yyyyMMddHHmmss"), 5120, 0, 0, "", 0, out outError, out PicFull) == false)
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "Information", "alert('" + outError.ToString() + "')", true);
                return;
            }
            else
            {
                PicFull = pathImages + "" + PicFull;
            }
        }
        else
        {
            PicFull = lblImagesFull.Text.Trim();
        }
        if (txtImgThum.HasFile)
        {
            //Thumb Images
            if (IO.UploadPhoto(txtImgThum, pathPhoto, "t_pic" + DateTime.Now.ToString("yyyyMMddHHmmss"), 2048, 0, 0, "", 0, out outError, out PicThumb) == false)
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "Information", "alert('" + outError.ToString() + "')", true);
                return;
            }
            else
            {
                PicThumb = pathImages + "" + PicThumb;
            }
        }
        else
        {
            PicThumb = lblImagesThumb.Text.Trim();
        }

        //insert data to database
        try
        {
            if (txtDetail.Text.Length >= 200)
            {
                strDetailSub = "<p>" + strDetail.Substring(0, 200) + ".....</p>";
            }
            else
            {
                strDetailSub = "<p>" + strDetail + ".....</p>";
            }

            //Insert new Event
            if (string.IsNullOrEmpty(lblUID.Text) == true)
            {
                Event tbevent = new Event();

                //Assign values for insert into database
                tbevent.Subject = txtSubject.Text.Trim();
                tbevent.Detail = txtDetail.Text;
                tbevent.PicFull = PicFull;
                tbevent.PicThumbnail = PicThumb;
                tbevent.DepartmentUID = 1;
                tbevent.ActiveDateFrom = Convert.ToDateTime(txtDateFrom.Text);
                tbevent.ActiveDateTo = Convert.ToDateTime(txtDateTo.Text);
                tbevent.Remark = txtRemark.Text.Trim();
                tbevent.CWhen = DateTime.Now;
                tbevent.CUser = Convert.ToInt32(security.LoginUID);
                tbevent.MWhen = DateTime.Now;
                tbevent.MUser = Convert.ToInt32(security.LoginUID);
                tbevent.StatusFlag = rdbActive.Checked == true ? "A" : "D";
                tbevent.LanguageUID = Convert.ToInt32(ddlLanguage.SelectedValue);
                tbevent.DetailSub = strDetailSub;
                tbevent.MetaKeywords = txtMetaKeywords.Text.Trim();
                tbevent.MetaDescription = txtMetaDescription.Text.Trim();

                //Insert data of Event to database
                db.Events.InsertOnSubmit(tbevent);
            }
            else //Update existing Event
            {
                var tbEvent = from ev in db.Events
                              where ev.UID == Convert.ToInt32(lblUID.Text.Trim())
                              select ev;
                foreach (Event ev in tbEvent)
                {
                    ev.Subject = txtSubject.Text.Trim();
                    ev.Detail = txtDetail.Text;
                    ev.PicFull = PicFull;
                    ev.PicThumbnail = PicThumb;
                    ev.DepartmentUID = 1;
                    ev.ActiveDateFrom = Convert.ToDateTime(txtDateFrom.Text);
                    ev.ActiveDateTo = Convert.ToDateTime(txtDateTo.Text);
                    ev.Remark = txtRemark.Text.Trim();
                    ev.MWhen = DateTime.Now;
                    ev.MUser = Convert.ToInt32(security.LoginUID);
                    ev.StatusFlag = rdbActive.Checked == true ? "A" : "D";
                    ev.MetaKeywords = txtMetaKeywords.Text.Trim();
                    ev.MetaDescription = txtMetaDescription.Text.Trim();
                    try
                    {
                       ev.LanguageUID = Convert.ToInt32(ddlLanguage.SelectedValue); 
                    }
                    catch(Exception ex)
                    {
                        ex.ToString();
                    }
                    ev.DetailSub = strDetailSub;
                }
            }
            db.SubmitChanges();
            clsColorBox clsColorBox = new clsColorBox();
            clsColorBox.Refresh();
            //Page.ClientScript.RegisterStartupScript(Page.GetType(), "closeWindow", "<script language='javascript'>parent.$.colorbox.close();</script>");
        }
        catch (Exception ex)
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Information", "alert('" + ex.ToString() + "')", true);
        }
        
    }
    protected void btSubmit_Click(object sender, EventArgs e)
    {
        #region Authorize
        if (!clsSecurity.LoginChecker("admin"))
        {
            ucColorBox1.Redirect("/", "กรุณาล็อคอินด้วยสิทธิ์ Admin");
            return;
        }
        #endregion
        #region Variable
        StringBuilder strSQL = new StringBuilder();
        int id = 0;
        string outSQL;
        string photoName = "";
        #endregion

        #region Update
        if (Request.QueryString["id"] != null && clsDefault.QueryStringChecker("command") == "edit")
        {
            id = int.Parse(Request.QueryString["id"].ToString());
            #region Photo Upload
            if (fuPhoto.HasFile)
            {
                clsIO clsIO = new clsIO();
                string outErrorMessage; string outFilename;
                if (clsIO.UploadPhoto(
                    fuPhoto, pathUpload,
                    "MedicalCenter" + id.ToString(),
                    out outErrorMessage,
                    out outFilename,
                    maxWidth: photoWidth,
                    maxHeight: photoHeight))
                {
                    photoName = outFilename;
                }
                else
                {
                    ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะอัพโหลดไฟล์รูปภาพ<br/>" + outErrorMessage, AlertImage: ucColorBox.Alerts.Fail);
                    return;
                }
            }
            #endregion
            if (clsSQL.Update(tableDefault,
                new string[,]{
                    {"UID",id.ToString()},
                    {"LanguageUID",rbLanguage.SelectedItem.Value},
                    {"MedicalCenterGroupUID",clsDefault.QueryStringChecker("group")},
                    {"DepartmentUID",(txtDepartmentUID.Text!=""?"'"+clsSQL.CodeFilter(txtDepartmentUID.Text)+"'":"null")},
                    {"Icon",(!string.IsNullOrEmpty(photoName)?"'"+pathUpload+photoName+"'":"Icon")},
                    {"Name","'"+clsSQL.CodeFilter(txtName.Text)+"'"},
                    {"Detail","'"+clsSQL.CodeFilter(txtDetail.Text)+"'"},
                    {"[Content]","'"+clsSQL.CodeFilter(ucContent.Text)+"'"},
                    {"Location","'"+clsSQL.CodeFilter(txtLocation.Text)+"'"},
                    {"OfficeHours","'"+clsSQL.CodeFilter(txtOfficeHours.Text)+"'"},
                    {"Phone","'"+clsSQL.CodeFilter(txtPhone.Text)+"'"},
                    {"EMail","'"+clsSQL.CodeFilter(txtEMail.Text)+"'"},
                    {"MetaKeywords","'"+clsSQL.CodeFilter(txtMetaKeyword.Text)+"'"},
                    {"MetaDescription","'"+clsSQL.CodeFilter(txtMetaDescription.Text)+"'"},
                    {"MUser","'" + clsSecurity.LoginUID + "'"},
                    {"MWhen","GETDATE()"},
                    {"Sort",clsSQL.CodeFilter(txtSort.Text)},
                    {"Active","'" + (cbActive.Checked ? "1" : "0") + "'"}
                }, new string[,] { { parameterChar + "UID", id.ToString() } },
                "UID=" + parameterChar + "UID",
                dbType, cs, out outSQL))
            {
                ucColorBox1.ReloadParent();
            }
            else
            {
                ucColorBox1.Alert("เกิดข้อผิดพลาดขณะบันทึกข้อมูล<br/>", outSQL, AlertImage: ucColorBox.Alerts.Fail);
            }
        }
        #endregion
        #region Insert
        else
        {
            #region Find New ID
            id = clsSQL.GetNewID("UID", tableDefault, "", dbType, cs);
            if (id == 0)
            {
                ucColorBox1.Alert("เกิดข้อผิดพลาดขณะบันทึกข้อมูล", "ไม่สามารถหา UID ใหม่ได้", AlertImage: ucColorBox.Alerts.Fail);
                return;
            }
            #endregion
            #region Photo Upload
            if (fuPhoto.HasFile)
            {
                clsIO clsIO = new clsIO();
                string outErrorMessage;string outFilename;
                if(clsIO.UploadPhoto(
                    fuPhoto, pathUpload,
                    "MedicalCenter" + id.ToString(),
                    out outErrorMessage,
                    out outFilename,
                    maxWidth: photoWidth,
                    maxHeight: photoHeight))
                {
                    photoName = outFilename;
                }
                else
                {
                    ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะอัพโหลดไฟล์รูปภาพ<br/>" + outErrorMessage, AlertImage: ucColorBox.Alerts.Fail);
                    return;
                }
            }
            #endregion
            if (clsSQL.Insert(tableDefault,
                new string[,]{
                    {"UID",id.ToString()},
                    {"LanguageUID",rbLanguage.SelectedItem.Value},
                    {"MedicalCenterGroupUID",clsDefault.QueryStringChecker("group")},
                    {"DepartmentUID",(txtDepartmentUID.Text.Trim()!=""?clsSQL.CodeFilter(txtDepartmentUID.Text):"null")},
                    {"Icon",(!string.IsNullOrEmpty(photoName)?"'"+pathUpload+photoName+"'":"null")},
                    {"Name","'"+clsSQL.CodeFilter(txtName.Text)+"'"},
                    {"Detail","'"+clsSQL.CodeFilter(txtDetail.Text)+"'"},
                    {"[Content]","'"+clsSQL.CodeFilter(ucContent.Text)+"'"},
                    {"Location","'"+clsSQL.CodeFilter(txtLocation.Text)+"'"},
                    {"OfficeHours","'"+clsSQL.CodeFilter(txtOfficeHours.Text)+"'"},
                    {"Phone","'"+clsSQL.CodeFilter(txtPhone.Text)+"'"},
                    {"EMail","'"+clsSQL.CodeFilter(txtEMail.Text)+"'"},
                    {"MetaKeywords","'"+clsSQL.CodeFilter(txtMetaKeyword.Text)+"'"},
                    {"MetaDescription","'"+clsSQL.CodeFilter(txtMetaDescription.Text)+"'"},
                    {"CUser","'" + clsSecurity.LoginUID + "'"},
                    {"CWhen","GETDATE()"},
                    {"MUser","'" + clsSecurity.LoginUID + "'"},
                    {"MWhen","GETDATE()"},
                    {"Sort",clsSQL.CodeFilter(txtSort.Text)},
                    {"Active","'" + (cbActive.Checked ? "1" : "0") + "'"}
                }, new string[,] { { } },
                dbType, cs, out outSQL))
            {
                ucColorBox1.ReloadParent();
            }
            else
            {
                ucColorBox1.Alert("เกิดข้อผิดพลาดขณะบันทึกข้อมูล<br/>", outSQL, AlertImage: ucColorBox.Alerts.Fail);
            }
        }
        #endregion
    }
    protected void btSubmit_Click(object sender, EventArgs e)
    {
        #region Authorize
        if (!clsSecurity.LoginChecker("admin"))
        {
            ucColorBox1.Redirect("/", "กรุณาล็อคอินด้วยสิทธิ์ Admin");
            return;
        }
        #endregion
        #region Variable
        StringBuilder strSQL = new StringBuilder();
        int id = 0;
        string outSQL;
        string photoName = "";
        string photoPreviewName = "";
        #endregion

        #region Update
        if (Request.QueryString["id"] != null && clsDefault.QueryStringChecker("command") == "edit")
        {
            id = int.Parse(Request.QueryString["id"].ToString());
            #region Photo Upload
            if (fuPhoto.HasFile)
            {
                clsIO clsIO = new clsIO();
                string outErrorMessage;
                string outFilename;
                string outFilenamePreview;

                #region Photo
                if (clsIO.UploadPhoto(
                    fuPhoto, pathUpload,
                    tableDefault + id.ToString(),
                    out outErrorMessage,
                    out outFilename,
                    maxWidth: photoWidth,
                    maxHeight: photoHeight))
                {
                    photoName = outFilename;
                }
                else
                {
                    ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะอัพโหลดไฟล์รูปภาพ<br/>" + outErrorMessage, AlertImage: ucColorBox.Alerts.Fail);
                    return;
                }
                #endregion
                #region Photo Preview
                if (clsIO.UploadPhoto(
                    fuPhoto, pathUpload,
                    tableDefault + id.ToString() + "Preview",
                    out outErrorMessage,
                    out outFilenamePreview,
                    maxWidth: photoPreviewWidth,
                    maxHeight: photoPreviewHeight))
                {
                    photoPreviewName = outFilenamePreview;
                }
                else
                {
                    ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะอัพโหลดไฟล์รูปภาพ<br/>" + outErrorMessage, AlertImage: ucColorBox.Alerts.Fail);
                    return;
                }
                #endregion
            }
            #endregion
            if (clsSQL.Update(tableDefault,
                new string[,]{
                    {"UID",id.ToString()},
                    {"PhotoPreview",(!string.IsNullOrEmpty(photoPreviewName)?"'"+pathUpload+photoPreviewName+"'":"PhotoPreview")},
                    {"Photo",(!string.IsNullOrEmpty(photoName)?"'"+pathUpload+photoName+"'":"Photo")},
                    {"Name","'"+clsSQL.CodeFilter(txtName.Text)+"'"},
                    {"Detail","'"+clsSQL.CodeFilter(txtDetail.Text)+"'"},
                    {"MUser","'" + clsSecurity.LoginUID + "'"},
                    {"MWhen","GETDATE()"},
                    {"Sort",clsSQL.CodeFilter(txtSort.Text)},
                    {"Active","'" + (cbActive.Checked ? "1" : "0") + "'"}
                }, new string[,] { { parameterChar + "UID", id.ToString() } },
                "UID=" + parameterChar + "UID",
                dbType, cs, out outSQL))
            {
                ucColorBox1.ReloadParent();
            }
            else
            {
                ucColorBox1.Alert("เกิดข้อผิดพลาดขณะบันทึกข้อมูล<br/>", outSQL, AlertImage: ucColorBox.Alerts.Fail);
            }
        }
        #endregion
        #region Insert
        else
        {
            #region Find New ID
            id = clsSQL.GetNewID("UID", tableDefault, "", dbType, cs);
            if (id == 0)
            {
                ucColorBox1.Alert("เกิดข้อผิดพลาดขณะบันทึกข้อมูล", "ไม่สามารถหา UID ใหม่ได้", AlertImage: ucColorBox.Alerts.Fail);
                return;
            }
            #endregion
            #region Photo Upload
            if (fuPhoto.HasFile)
            {
                clsIO clsIO = new clsIO();
                string outErrorMessage; 
                string outFilename;
                string outFilenamePreview;

                #region Photo
                if (clsIO.UploadPhoto(
                    fuPhoto, pathUpload,
                    tableDefault + id.ToString(),
                    out outErrorMessage,
                    out outFilename,
                    maxWidth: photoWidth,
                    maxHeight: photoHeight))
                {
                    photoName = outFilename;
                }
                else
                {
                    ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะอัพโหลดไฟล์รูปภาพ<br/>" + outErrorMessage, AlertImage: ucColorBox.Alerts.Fail);
                    return;
                }
                #endregion
                #region PhotoPreview
                if (clsIO.UploadPhoto(
                    fuPhoto, pathUpload,
                    tableDefault + id.ToString() + "Preview",
                    out outErrorMessage,
                    out outFilenamePreview,
                    maxWidth: photoPreviewWidth,
                    maxHeight: photoPreviewHeight))
                {
                    photoPreviewName = outFilenamePreview;
                }
                else
                {
                    ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะอัพโหลดไฟล์รูปภาพ<br/>" + outErrorMessage, AlertImage: ucColorBox.Alerts.Fail);
                    return;
                }
                #endregion
            }
            #endregion
            if (clsSQL.Insert(tableDefault,
                new string[,]{
                    {"UID",id.ToString()},
                    {"GlobalUID",clsDefault.QueryStringChecker("globalid")},
                    {"GlobalName","'"+clsDefault.QueryStringChecker("globalname")+"'"},
                    {"PhotoPreview",(!string.IsNullOrEmpty(photoPreviewName)?"'"+pathUpload+photoPreviewName+"'":"null")},
                    {"Photo",(!string.IsNullOrEmpty(photoName)?"'"+pathUpload+photoName+"'":"null")},
                    {"Name","'"+clsSQL.CodeFilter(txtName.Text)+"'"},
                    {"Detail","'"+clsSQL.CodeFilter(txtDetail.Text)+"'"},
                    {"[View]","0"},
                    {"CUser","'" + clsSecurity.LoginUID + "'"},
                    {"CWhen","GETDATE()"},
                    {"MUser","'" + clsSecurity.LoginUID + "'"},
                    {"MWhen","GETDATE()"},
                    {"Sort",clsSQL.CodeFilter(txtSort.Text)},
                    {"Active","'" + (cbActive.Checked ? "1" : "0") + "'"}
                }, new string[,] { { } },
                dbType, cs, out outSQL))
            {
                ucColorBox1.ReloadParent();
            }
            else
            {
                ucColorBox1.Alert("เกิดข้อผิดพลาดขณะบันทึกข้อมูล<br/>", outSQL, AlertImage: ucColorBox.Alerts.Fail);
            }
        }
        #endregion
    }
Ejemplo n.º 32
0
 protected void btSubmit_Click(object sender, EventArgs e)
 {
     #region Authorize
     if (!clsSecurity.LoginChecker("admin"))
     {
         ucColorBox1.Redirect("/", "กรุณาล็อคอินด้วยสิทธิ์ Admin");
         return;
     }
     #endregion
     #region Variable
     var strSQL    = new StringBuilder();
     var id        = 0;
     var outSQL    = "";
     var photoName = "";
     #endregion
     #region Procedure
     #region Update
     if (Request.QueryString["id"] != null && clsDefault.QueryStringChecker("command") == "edit")
     {
         id = int.Parse(Request.QueryString["id"].ToString());
         #region Photo Upload
         if (fuPhoto.HasFile)
         {
             var    clsIO = new clsIO();
             string outErrorMessage; string outFilename;
             if (clsIO.UploadPhoto(
                     fuPhoto, pathUpload,
                     tableDefault + id.ToString(),
                     out outErrorMessage,
                     out outFilename,
                     maxWidth: photoWidth,
                     maxHeight: photoHeight))
             {
                 photoName = outFilename;
             }
             else
             {
                 ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะอัพโหลดไฟล์รูปภาพ<br/>" + outErrorMessage, AlertImage: ucColorBox.Alerts.Fail);
                 return;
             }
         }
         #endregion
         if (clsSQL.Update(tableDefault,
                           new string[, ] {
             { "Photo", (!string.IsNullOrEmpty(photoName)?"'" + pathUpload + photoName + "'":"Photo") },
             { "Name", "'" + txtName.Text.SQLQueryFilter() + "'" },
             { "Detail", "'" + txtDetail.Text.SQLQueryFilter() + "'" },
             { "MUser", clsSecurity.LoginUID },
             { "MWhen", functionGetDate },
             { "Sort", clsSQL.CodeFilter(txtSort.Text) },
             { "StatusFlag", "'" + (cbActive.Checked ? "A" : "I") + "'" }
         }, new string[, ] {
             { parameterChar + "UID", id.ToString() }
         },
                           "UID=" + parameterChar + "UID",
                           out outSQL))
         {
             ucColorBox1.ReloadParent();
         }
         else
         {
             ucColorBox1.Alert("เกิดข้อผิดพลาดขณะบันทึกข้อมูล<br/>", outSQL, AlertImage: ucColorBox.Alerts.Fail);
         }
     }
     #endregion
     #region Insert
     else
     {
         #region Photo Upload
         if (fuPhoto.HasFile)
         {
             clsIO  clsIO = new clsIO();
             string outErrorMessage; string outFilename;
             if (clsIO.UploadPhoto(
                     fuPhoto, pathUpload,
                     tableDefault + id.ToString(),
                     out outErrorMessage,
                     out outFilename,
                     maxWidth: photoWidth,
                     maxHeight: photoHeight))
             {
                 photoName = outFilename;
             }
             else
             {
                 ucColorBox1.Alert("เกิดข้อผิดพลาด", "เกิดข้อผิดพลาดขณะอัพโหลดไฟล์รูปภาพ<br/>" + outErrorMessage, AlertImage: ucColorBox.Alerts.Fail);
                 return;
             }
         }
         #endregion
         if (clsSQL.Insert(tableDefault,
                           new string[, ] {
             { "Photo", (!string.IsNullOrEmpty(photoName)?"'" + pathUpload + photoName + "'":"null") },
             { "Name", "'" + txtName.Text.SQLQueryFilter() + "'" },
             { "Detail", "'" + txtDetail.Text.SQLQueryFilter() + "'" },
             { "CUser", clsSecurity.LoginUID },
             { "CWhen", functionGetDate },
             { "MUser", clsSecurity.LoginUID },
             { "MWhen", functionGetDate },
             { "Sort", txtSort.Text.SQLQueryFilter() },
             { "StatusFlag", "'" + (cbActive.Checked ? "A" : "I") + "'" }
         }, new string[, ] {
             { }
         },
                           out outSQL))
         {
             ucColorBox1.ReloadParent();
         }
         else
         {
             ucColorBox1.Alert("เกิดข้อผิดพลาดขณะบันทึกข้อมูล<br/>", outSQL, AlertImage: ucColorBox.Alerts.Fail);
         }
     }
     #endregion
     #endregion
 }
    protected void btSave_Click(object sender, EventArgs e)
    {
        clsSecurity security = new clsSecurity();
        clsIO IO = new clsIO();

        string strDetailSub = string.Empty;
        string strDetail = txtDetail.Text.Replace("<p>", "");
        strDetail = strDetail.Replace("</p>", "");
        string PicFull = "null";
        string PicThumb = "null";
        string pathPhoto = "/Images/Package/";
        string pathImages = @"\Images\Package\";
        string outError;
        
        //upload Photo to server
        if (txtImgFull.HasFile)
        {
            //Full Images
            if (IO.UploadPhoto(txtImgFull, pathPhoto, "f_pic" + DateTime.Now.ToString("yyyyMMddHHmmss"), 4096, 0, 0, "", 0, out outError, out PicFull) == false)
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "Information", "alert('" + outError.ToString() + "')", true);
                return;
            }
            else
            {
                PicFull = pathImages + "" + PicFull;
            }
        }
        else
        {
            PicFull = lblImagesFull.Text.Trim();
        }

        if (txtImgThum.HasFile)
        {
            //Thumb Images
            if (IO.UploadPhoto(txtImgThum, pathPhoto, "t_pic" + DateTime.Now.ToString("yyyyMMddHHmmss"), 2048, 0, 0, "", 0, out outError, out PicThumb) == false)
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "Information", "alert('" + outError.ToString() + "')", true);
                return;
            }
            else
            {
                PicThumb = pathImages + "" + PicThumb;
            }

        }
        else
        {
            PicThumb = lblImagesThumb.Text.Trim();
        }

        //insert data to database
        try
        {
            if (txtDetail.Text.Length >= 200)
            {
                strDetailSub = "<p>" + strDetail.Substring(0, 200) + ".....</p>";
            }
            else
            {
                strDetailSub = "<p>" + strDetail + ".....</p>";
            }

            //Insert new Package
            if (string.IsNullOrEmpty(lblUID.Text) == true)
            {
                Package tbpackage = new Package();

                //Assign values for insert into database
                tbpackage.PackageName = txtSubject.Text.Trim();
                tbpackage.Detail = txtDetail.Text;
                tbpackage.PicFull = PicFull;
                tbpackage.PicThumbnail = PicThumb;
                tbpackage.ActiveDateFrom = Convert.ToDateTime(txtDateFrom.Text);
                if (!string.IsNullOrEmpty(txtDateTo.Text))
                {
                    tbpackage.ActiveDateTo = Convert.ToDateTime(txtDateTo.Text);
                }
                else
                {
                    tbpackage.ActiveDateTo = null;
                }
                tbpackage.Remark = txtRemark.Text.Trim();
                tbpackage.CWhen = DateTime.Now;
                tbpackage.CUser = Convert.ToInt32(security.LoginUID);
                tbpackage.MWhen = DateTime.Now;
                tbpackage.MUser = Convert.ToInt32(security.LoginUID);
                tbpackage.StatusFlag = rdbActive.Checked == true ? "A" : "D";
                tbpackage.LanguageUID = Convert.ToInt32(ddlLanguage.SelectedValue);
                tbpackage.DepartmentUID = Convert.ToInt32(ddlDepartment.SelectedValue);
                tbpackage.DetailSub = strDetailSub;
                tbpackage.MetaKeywords = txtMetaKeywords.Text.Trim();
                tbpackage.MetaDescription = txtMetaDescription.Text.Trim();
                tbpackage.PackageCode = txtPackagecode.Text.Trim();
                if (!string.IsNullOrEmpty(txtUnitPrice.Text))
                {
                    tbpackage.UnitPrice = Convert.ToDouble(txtUnitPrice.Text.Trim());
                }
                else
                {
                    tbpackage.UnitPrice = 0;
                }

                //Insert data of Event to database
                db.Packages.InsertOnSubmit(tbpackage);
            }
            else //Update existing Event
            {
                var tbpackage = from p in db.Packages
                              where p.UID == Convert.ToInt32(lblUID.Text.Trim())
                              select p;
                foreach (Package p in tbpackage)
                {
                    p.PackageName = txtSubject.Text.Trim();
                    p.Detail = txtDetail.Text;
                    p.PicFull = PicFull;
                    p.PicThumbnail = PicThumb;
                    p.ActiveDateFrom = Convert.ToDateTime(txtDateFrom.Text);
                    if (!string.IsNullOrEmpty(txtDateTo.Text))
                    {
                        p.ActiveDateTo = Convert.ToDateTime(txtDateTo.Text);
                    }
                    else
                    {
                        p.ActiveDateTo = null;
                    }
                    p.Remark = txtRemark.Text.Trim();
                    p.MWhen = DateTime.Now;
                    p.MUser = Convert.ToInt32(security.LoginUID);
                    p.StatusFlag = rdbActive.Checked == true ? "A" : "D";
                    try
                    {
                        p.LanguageUID = Convert.ToInt32(ddlLanguage.SelectedValue);
                        p.DepartmentUID = Convert.ToInt32(ddlDepartment.SelectedValue);
                    }
                    catch (Exception ex)
                    {
                        ex.ToString();
                    }
                    p.DetailSub = strDetailSub;
                    p.MetaKeywords = txtMetaKeywords.Text.Trim();
                    p.MetaDescription = txtMetaDescription.Text.Trim();
                    p.PackageCode = txtPackagecode.Text.Trim();
                    if (!string.IsNullOrEmpty(txtUnitPrice.Text))
                    {
                        p.UnitPrice = Convert.ToDouble(txtUnitPrice.Text.Trim());
                    }
                    else
                    {
                        p.UnitPrice = 0;
                    }
                }
            }
            db.SubmitChanges();
            clsColorBox clsColorBox = new clsColorBox();
            clsColorBox.Refresh();
            //Page.ClientScript.RegisterStartupScript(Page.GetType(), "closeWindow", "<script language='javascript'>parent.$.colorbox.close();</script>");
        }
        catch (Exception ex)
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Information", "alert('" + ex.ToString() + "')", true);
        }
    }