protected void btnUpdateProject_Click(object sender, EventArgs e) { if (Request.QueryString["id"] != null) { string[] validFileTypes = { "pdf" }; string ext = System.IO.Path.GetExtension(FUdocument.PostedFile.FileName); bool isValidFile = false; for (int i = 0; i < validFileTypes.Length; i++) { if (ext == "." + validFileTypes[i]) { isValidFile = true; break; } } if (!isValidFile) { ScriptManager.GetCurrent(this.Page).SetFocus(this.FUdocument); ChangeNotification("danger", "กรุณาแนบไฟล์นามสกุล " + string.Join(",", validFileTypes) + " เท่านั้น"); return; } else if (FUdocument.PostedFile.ContentLength > 26214400) { ScriptManager.GetCurrent(this.Page).SetFocus(this.FUdocument); ChangeNotification("danger", "กรุณาแนบไฟล์ไม่เกิน 25 MB"); return; } else { ChangeNotification("", ""); } if (tbStartDate.Text != "" && tbEndDate.Text != "") { DateTime dtEndDate = DateTime.Parse(tbEndDate.Text); DateTime dtStartDate = DateTime.Parse(tbStartDate.Text); int totalDay = (int)(dtEndDate - dtStartDate).TotalDays + 1; if (totalDay <= 0) { notification.Attributes["class"] = "alert alert_danger"; notification.InnerHtml = ""; notification.InnerHtml += "<div> <img src='Image/Small/red_alert.png' /> วันที่เริ่มโครงการ - วันที่สิ้นสุดโครงการ : วันที่ไม่ถูกต้อง !</div>"; ScriptManager.GetCurrent(this.Page).SetFocus(this.tbStartDate); return; } else { notification.Attributes["class"] = "none"; notification.InnerHtml = ""; } } PersonnelSystem ps = PersonnelSystem.GetPersonnelSystem(this); UOC_STAFF loginPerson = ps.LoginPerson; PROJECT p = new PROJECT(); p.Load(int.Parse(MyCrypto.GetDecryptedQueryString(Request.QueryString["id"].ToString()))); p.CATEGORY_ID = Convert.ToInt32(ddlCategory.SelectedValue); p.PROJECT_NAME = tbProjectName.Text; p.ADDRESS_PROJECT = tbAddressProject.Text; p.START_DATE = DateTime.Parse(tbStartDate.Text); p.END_DATE = DateTime.Parse(tbEndDate.Text); p.EXPENSES = Convert.ToInt32(tbExpenses.Text); p.FUNDING = tbFunding.Text; p.CERTIFICATE = tbCertificate.Text; p.SUMMARIZE_PROJECT = tbSummarizeProject.Text; p.RESULT_TEACHING = tbResultTeaching.Text; p.RESULT_ACADEMIC = tbResultAcademic.Text; p.DIFFICULTY_PROJECT = tbDifficultyProject.Text; p.RESULT_PROJECT = tbResultProject.Text; p.RESULT_RESEARCHING = tbResultResearching.Text; p.RESULT_OTHER = tbResultOther.Text; p.COUNSEL = tbCounsel.Text; p.COUNTRY_ID = Convert.ToInt32(ddlCountry.SelectedValue); p.SUB_COUNTRY_ID = Convert.ToInt32(ddlSubCountry.SelectedValue); if (FUdocument.HasFile) { string CountBase = DatabaseManager.ExecuteString("select count(*) from tb_project where pro_id = '" + int.Parse(MyCrypto.GetDecryptedQueryString(Request.QueryString["id"].ToString())) + "'"); FileInfo fi = new FileInfo(FUdocument.FileName); string imgFile = "UID=" + p.UOC_ID + "&count=" + CountBase + fi.Extension; FUdocument.SaveAs(Server.MapPath("Upload/Project/PDF/" + imgFile)); p.IMG_FILE = imgFile; } p.PRO_ID = int.Parse(MyCrypto.GetDecryptedQueryString(Request.QueryString["id"].ToString())); p.UPDATE_PROJECT(); Notsuccess.Visible = false; success.Visible = true; } }
protected void btnAddProject_Click(object sender, EventArgs e) { OracleConnection.ClearAllPools(); using (OracleConnection con = new OracleConnection(DatabaseManager.CONNECTION_STRING)) { con.Open(); using (OracleCommand com = new OracleCommand("SELECT PRO_ID FROM TB_PROJECT WHERE START_DATE BETWEEN " + Util.DatabaseToDateSearch(tbStartDate.Text) + " AND " + Util.DatabaseToDateSearch(tbEndDate.Text) + " AND CITIZEN_ID = '" + loginPerson.PS_CITIZEN_ID + "'", con)) { using (OracleDataReader reader = com.ExecuteReader()) { while (reader.Read()) { if (!reader.IsDBNull(0)) { Project ProjectData = new Project(); ProjectData.Load(reader.GetInt32(0)); ChangeNotification("danger", "ไม่สามารถเพิ่มข้อมูลได้ พบวันซ้อนทับกัน (รหัสโครงการ " + ProjectData.PRO_ID + ", " + ProjectData.START_DATE.Value.ToLongDateString() + " ถึง " + ProjectData.END_DATE.Value.ToLongDateString() + ")"); return; } } } } } /*string[] validFileTypes = { "pdf" }; * string ext = System.IO.Path.GetExtension(FUdocument.PostedFile.FileName); * //bool isValidFile = false; * * for (int i = 0; i < validFileTypes.Length; i++) * { * if (ext == "." + validFileTypes[i]) * { * isValidFile = true; * break; * } * } * if (!isValidFile) * { * ScriptManager.GetCurrent(this.Page).SetFocus(this.FUdocument); * ChangeNotification("danger", "กรุณาแนบไฟล์นามสกุล " + string.Join(",", validFileTypes) + " เท่านั้น"); * return; * } * * else if (FUdocument.PostedFile.ContentLength > 26214400) * { * ScriptManager.GetCurrent(this.Page).SetFocus(this.FUdocument); * ChangeNotification("danger", "กรุณาแนบไฟล์ไม่เกิน 25 MB"); * return; * } * else * { * ChangeNotification("", ""); * }*/ if (tbStartDate.Text != "" && tbEndDate.Text != "") { DateTime dtEndDate = DateTime.Parse(tbEndDate.Text); DateTime dtStartDate = DateTime.Parse(tbStartDate.Text); int totalDay = (int)(dtEndDate - dtStartDate).TotalDays + 1; if (totalDay <= 0) { notification.Attributes["class"] = "alert alert_danger"; notification.InnerHtml = ""; notification.InnerHtml += "<div> <img src='Image/Small/red_alert.png' /> วันที่เริ่มโครงการ - วันที่สิ้นสุดโครงการ : วันที่ไม่ถูกต้อง !</div>"; ScriptManager.GetCurrent(this.Page).SetFocus(this.tbStartDate); return; } else { notification.Attributes["class"] = "none"; notification.InnerHtml = ""; } } if (Util.ToDateTimeOracle(tbStartDate.Text) > DateTime.Now) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('วันที่ไม่สามารถมากกว่าวันปัจจุบัน')", true); return; } if (Util.ToDateTimeOracle(tbEndDate.Text) > DateTime.Now) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('วันที่ไม่สามารถมากกว่าวันปัจจุบัน')", true); return; } OracleConnection.ClearAllPools(); using (OracleConnection con = new OracleConnection(DatabaseManager.CONNECTION_STRING)) { con.Open(); using (OracleCommand com = new OracleCommand("INSERT INTO TB_PROJECT (CITIZEN_ID,CATEGORY_ID,COUNTRY_ID,SUB_COUNTRY_ID,PROJECT_NAME,ADDRESS_PROJECT,START_DATE,END_DATE,EXPENSES,FUNDING,CERTIFICATE,SUMMARIZE_PROJECT,RESULT_TEACHING,RESULT_ACADEMIC,DIFFICULTY_PROJECT,RESULT_PROJECT,RESULT_RESEARCHING,RESULT_OTHER,COUNSEL,PDF_FILE) VALUES (:CITIZEN_ID,:CATEGORY_ID,:COUNTRY_ID,:SUB_COUNTRY_ID,:PROJECT_NAME,:ADDRESS_PROJECT,:START_DATE,:END_DATE,:EXPENSES,:FUNDING,:CERTIFICATE,:SUMMARIZE_PROJECT,:RESULT_TEACHING,:RESULT_ACADEMIC,:DIFFICULTY_PROJECT,:RESULT_PROJECT,:RESULT_RESEARCHING,:RESULT_OTHER,:COUNSEL,:PDF_FILE)", con)) { com.Parameters.Add(new OracleParameter("CITIZEN_ID", loginPerson.PS_CITIZEN_ID)); com.Parameters.Add(new OracleParameter("CATEGORY_ID", Convert.ToInt32(ddlCategory.SelectedValue))); com.Parameters.Add(new OracleParameter("COUNTRY_ID", Convert.ToInt32(ddlCountry.SelectedValue))); com.Parameters.Add(new OracleParameter("SUB_COUNTRY_ID", Convert.ToInt32(ddlSubCountry.SelectedValue))); com.Parameters.Add(new OracleParameter("PROJECT_NAME", tbProjectName.Text)); com.Parameters.Add(new OracleParameter("ADDRESS_PROJECT", tbAddressProject.Text)); com.Parameters.Add(new OracleParameter("START_DATE", DateTime.Parse(tbStartDate.Text))); com.Parameters.Add(new OracleParameter("END_DATE", DateTime.Parse(tbEndDate.Text))); com.Parameters.Add(new OracleParameter("EXPENSES", Convert.ToInt32(tbExpenses.Text))); com.Parameters.Add(new OracleParameter("FUNDING", tbFunding.Text)); com.Parameters.Add(new OracleParameter("CERTIFICATE", tbCertificate.Text)); com.Parameters.Add(new OracleParameter("SUMMARIZE_PROJECT", tbSummarizeProject.Text)); com.Parameters.Add(new OracleParameter("RESULT_TEACHING", tbResultTeaching.Text)); com.Parameters.Add(new OracleParameter("RESULT_ACADEMIC", tbResultAcademic.Text)); com.Parameters.Add(new OracleParameter("DIFFICULTY_PROJECT", tbDifficultyProject.Text)); com.Parameters.Add(new OracleParameter("RESULT_PROJECT", tbResultProject.Text)); com.Parameters.Add(new OracleParameter("RESULT_RESEARCHING", tbResultResearching.Text)); com.Parameters.Add(new OracleParameter("RESULT_OTHER", tbResultOther.Text)); com.Parameters.Add(new OracleParameter("COUNSEL", tbCounsel.Text)); if (FUdocument.HasFile) { string CountBase = DatabaseManager.ExecuteString("SELECT COUNT(*) FROM TB_PROJECT WHERE CITIZEN_ID = '" + loginPerson.PS_CITIZEN_ID + "'"); FileInfo fi = new FileInfo(FUdocument.FileName); string imgFile = "CID=" + loginPerson.PS_CITIZEN_ID + "&count=" + CountBase + fi.Extension; FUdocument.SaveAs(Server.MapPath("Upload/Project/PDF/" + imgFile)); com.Parameters.Add(new OracleParameter("PDF_FILE", imgFile)); } else { com.Parameters.Add(new OracleParameter("PDF_FILE", DBNull.Value)); } com.ExecuteNonQuery(); } } ChangeNotification("", ""); Notsuccess.Visible = false; success.Visible = true; }