Пример #1
0
    protected void btDelete_Click(object sender, EventArgs e)
    {
        var clsDefault = new clsDefault();

        try
        {
            var fi = new FileInfo(Server.MapPath(hidFileName.Value));
            if (fi.Exists)
            {
                fi.Delete();
                BindDetail(Request.QueryString["id"].ToString());
                lblSQL.Text = clsDefault.AlertMessageFlat("ลบไฟล์เสร็จสมบูรณ์", clsDefault.AlertType.Success);
            }
            else
            {
                lblSQL.Text = clsDefault.AlertMessageFlat("ไม่พบไฟล์ : " + fi.FullName, clsDefault.AlertType.Fail);
            }
        }
        catch (Exception ex)
        {
            lblSQL.Text = clsDefault.AlertMessageFlat("เกิดข้อผิดพลาดขณะลบไฟล์ : " + ex.Message, clsDefault.AlertType.Fail);
        }
    }
    protected void btSubmit_Click(object sender, EventArgs e)
    {
        #region Variable

        #endregion
        #region Procedure
        if (fuPhoto.HasFile)
        {
            if (!Path.GetExtension(fuPhoto.FileName).Contains("jpg"))
            {
                lblSQL.Text = clsDefault.AlertMessageFlat("โปรดเลือกภาพ JPG เท่านั้น", clsDefault.AlertType.Warn);
                return;
            }
            try
            {
                fuPhoto.SaveAs(Server.MapPath("/Images/bgHome.jpg"));
                getDefault();
                lblSQL.Text = clsDefault.AlertMessageFlat("อัพโหลดรูปภาพเสร็จสิ้น * หากภาพไม่อัพเดท โปรดกดปุ่ม F5 เพื่อรีเฟรชหน้าเว็บ", clsDefault.AlertType.Success);
            }
            catch (Exception ex) { lblSQL.Text = clsDefault.AlertMessageFlat(ex.Message, clsDefault.AlertType.Fail); }
        }
        #endregion
    }
Пример #3
0
    protected void btSendMail_Click(object sender, EventArgs e)
    {
        #region Variable
        var strSQL     = new StringBuilder();
        var clsSQL     = new clsSQL(clsGlobal.dbType, clsGlobal.cs);
        var clsDefault = new clsDefault();
        #endregion
        #region Procedure
        if (hidFileName.Value != "")
        {
            #region SQLQuery
            strSQL.Append("INSERT INTO ");
            strSQL.Append("P5_Job");
            strSQL.Append("(FileName,Name,Detail,ContactName,ContactPhone,ContactEmail,Location,CWhen,MWhen)");
            strSQL.Append("VALUES(");
            strSQL.Append("'" + hidFileName.Value.Trim() + "',");
            strSQL.Append("'" + txtName.Text.SQLQueryFilter() + "',");
            strSQL.Append("'" + txtDetail.Text.SQLQueryFilter() + "',");
            strSQL.Append("'" + txtContactName.Text.SQLQueryFilter() + "',");
            strSQL.Append("'" + txtContactPhone.Text.SQLQueryFilter() + "',");
            strSQL.Append("'" + txtContactEmail.Text.SQLQueryFilter() + "',");
            strSQL.Append("'" + txtLocation.Text.SQLQueryFilter() + "',");
            strSQL.Append("GETDATE(),");
            strSQL.Append("GETDATE()");
            strSQL.Append(");");
            #endregion
            if (clsSQL.Execute(strSQL.ToString()))
            {
                #region MailSender
                var clsMail    = new clsMail();
                var outMessage = "";

                //Send to Admin
                try
                {
                    if (!clsMail.SendByGmail(
                            "*****@*****.**",
                            "G00des1gn",
                            System.Configuration.ConfigurationManager.AppSettings["mailTo"],
                            "P5GraphicDesign : มีใบงานใหม่ '" + txtName.Text.SQLQueryFilter() + "'",
                            string.Format("<h1>มีใบงานใหม่ : {0}</h1><div><b>จาก</b> : {1}</div><div><b>เบอร์โทร</b> : {2}</div><div><b>รายละเอียด</b> : {3}</div><hr/><a href='http://www.p5graphicdesign.com/Management/Job.aspx'>คลิกที่นี่เพื่อดูข้อมูล</a>",
                                          txtName.Text.SQLQueryFilter(),
                                          txtContactName.Text.SQLQueryFilter(),
                                          txtContactPhone.Text.SQLQueryFilter(),
                                          txtDetail.Text.SQLQueryFilter()),
                            out outMessage,
                            "P5GraphicDesign : มีใบงานใหม่ '" + txtName.Text.SQLQueryFilter() + "'",
                            "*****@*****.**", "", "", System.Net.Mail.MailPriority.High))
                    {
                        Response.Write("Send to Admin : " + outMessage);
                        //ucColorBox1.Alert("พบข้อผิดพลาดขณะส่งเมล์", outMessage, AlertImage: ucColorBox.Alerts.Fail);
                        return;
                    }
                }
                catch (Exception exMailToAdmin) { Response.Write(exMailToAdmin.Message); }
                if (txtContactEmail.Text.Trim() != "" && txtContactEmail.Text.Contains("@") && txtContactEmail.Text.Contains("."))
                {
                    //Send to Customer
                    try
                    {
                        if (!clsMail.SendByGmail(
                                "*****@*****.**",
                                "G00des1gn",
                                txtContactEmail.Text.Trim(),
                                "P5GraphicDesign : ได้รับใบงาน '" + txtName.Text.SQLQueryFilter() + "' ของคุณแล้ว",
                                string.Format("<h1>ได้รับใบงานใหม่เรียบร้อยแล้ว : {0}</h1><div><b>จาก</b> : {1}</div><div><b>เบอร์โทร</b> : {2}</div><div><b>รายละเอียด</b> : {3}</div>",
                                              txtName.Text.SQLQueryFilter(),
                                              txtContactName.Text.SQLQueryFilter(),
                                              txtContactPhone.Text.SQLQueryFilter(),
                                              txtDetail.Text.SQLQueryFilter()),
                                out outMessage,
                                "P5GraphicDesign : ได้รับใบงาน '" + txtName.Text.SQLQueryFilter() + "' ของคุณแล้ว",
                                "", "", "", System.Net.Mail.MailPriority.High))
                        {
                            Response.Write(outMessage);
                            //ucColorBox1.Alert("พบข้อผิดพลาดขณะส่งเมล์", outMessage, AlertImage: ucColorBox.Alerts.Fail);
                            return;
                        }
                    }
                    catch (Exception exMailToCustomer) { Response.Write("Send to Customer : " + exMailToCustomer.Message); }
                }
                #endregion
                txtName.Text          = ""; txtDetail.Text = ""; txtContactName.Text = ""; txtContactPhone.Text = ""; txtLocation.Text = ""; hidFileName.Value = "";
                lblSendMailAlert.Text = clsDefault.AlertMessageFlat("บันทึกข้อมูลเสร็จสมบูรณ์", clsDefault.AlertType.Success);
                lblSendMailAlert.Focus();
            }
            else
            {
                lblSendMailAlert.Text = clsDefault.AlertMessageFlat("เกิดข้อผิดพลาดขณะบันทึกข้อมูล<br/>" + strSQL.ToString(), clsDefault.AlertType.Fail);
                lblSendMailAlert.Focus();
            }
        }
        else
        {
            lblSendMailAlert.Text = clsDefault.AlertMessageFlat("โปรดเลือกอัพโหลดไฟล์ก่อนทำการส่งข้อมูล", clsDefault.AlertType.Fail);
            lblSendMailAlert.Focus();
        }
        #endregion
    }