protected void btSubmit_Click(object sender, EventArgs e) { #region Authorize if (!clsSecurity.LoginChecker("admin")) { ucColorBox1.Redirect("/", "กรุณาล็อคอินด้วยสิทธิ์ Admin"); return; } #endregion #region Variable var clsSQL = new clsSQL(clsGlobal.dbType, clsGlobal.cs); 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", "'" + clsSQL.CodeFilter(txtName.Text) + "'" }, { "Detail", "'" + clsSQL.CodeFilter(txtDetail.Text) + "'" }, { "NameEN", "'" + clsSQL.CodeFilter(txtNameEN.Text) + "'" }, { "DetailEN", "'" + clsSQL.CodeFilter(txtDetailEN.Text) + "'" }, { "MetaKeywords", "'" + clsSQL.CodeFilter(txtMetaKeyword.Text) + "'" }, { "MetaDescription", "'" + clsSQL.CodeFilter(txtMetaDescription.Text) + "'" }, { "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 Find New ID id = clsSQL.GetNewIDAutoIncrement(tableDefault); 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, 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", "'" + clsSQL.CodeFilter(txtName.Text) + "'" }, { "Detail", "'" + clsSQL.CodeFilter(txtDetail.Text) + "'" }, { "NameEN", "'" + clsSQL.CodeFilter(txtNameEN.Text) + "'" }, { "DetailEN", "'" + clsSQL.CodeFilter(txtDetailEN.Text) + "'" }, { "Type", "'Experiences'" }, { "MetaKeywords", "'" + clsSQL.CodeFilter(txtMetaKeyword.Text) + "'" }, { "MetaDescription", "'" + clsSQL.CodeFilter(txtMetaDescription.Text) + "'" }, { "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 #endregion }