protected void UpDate_Click(object sender, EventArgs e) { String id = (String)Session["fac_id"]; Facility f = new Facility(); f = FacilityManagementSystem.GetFacility(id); if (string.IsNullOrEmpty(txtName.Text)) { txtName.Text = f.facilityName; } if (string.IsNullOrEmpty(txtInfo.Text)) { txtInfo.Text = f.generalInfo; } if (string.IsNullOrEmpty(txtPhoneNumber.Text)) { txtPhoneNumber.Text = f.phoneNumber.ToString(); } if (string.IsNullOrEmpty(txtAddress.Text)) { txtAddress.Text = f.address; } if (string.IsNullOrEmpty(txtRegion.Text)) { txtRegion.Text = f.region; } String image = f.image; if (ImageUpload.HasFile) { string ext = System.IO.Path.GetExtension(ImageUpload.PostedFile.FileName); if (!Validation.ImageCheck(ext)) { lblImage.Text = "Invalid image type"; } else { image = Path.GetFileName(ImageUpload.PostedFile.FileName); ImageUpload.PostedFile.SaveAs(Server.MapPath("~/upload/facility/") + image); } } FacilityManagementSystem.UpdateFacility(txtName.Text, listFacility.SelectedItem.Text, txtInfo.Text, Convert.ToInt32(txtPhoneNumber.Text), UpdateOpeninghr.SelectedItem.Text + ":" + "00", UpdateClosinghr.SelectedItem.Text + ":" + "00", txtAddress.Text, txtRegion.Text, image, f.facilityID); //need to check whether there's any doctor with these department Department[] dp = new Department[12]; //selected Department[] ndp = new Department[12]; //not selected int index = 0; int nindex = 0; foreach (ListItem listItem in UpdateDepartmentList.Items) { if (listItem.Selected) { dp[index] = new Department(); dp[index].facilityId = f.facilityID; dp[index].departmentName = listItem.Value; index++; } else { ndp[nindex] = new Department(); ndp[nindex].facilityId = f.facilityID; ndp[nindex].departmentName = listItem.Value; nindex++; } } bool DepartmentCheckexist = false; //this is to check whether there's child dependency for facility_staff before deleting the uncheck facility to prevent database error String tempDeptName; foreach (Department d in ndp) { if (d != null) { tempDeptName = DepartmentManagementSystem.CheckDepartmentForStaff(d); if (tempDeptName != null) { lblImage.Text = "unable to remove department: " + tempDeptName + ", there are doctors working in that department"; DepartmentCheckexist = true;//don't allow the update } } } if (DepartmentCheckexist == false) { DepartmentManagementSystem.DeleteDepartment(ndp); DepartmentManagementSystem.AddDepartment(dp); Response.Write("<script type=\"text/javascript\">alert('Facility Updated!');location.href='AdminHomePage.aspx'</script>"); } }
protected void Create_Click(object sender, EventArgs e) { bool check = true; if (Validation.isEmpty(txtName.Text)) { lblName.Text = "Name cannot be empty"; check = false; } if (Validation.isEmpty(txtInfo.Text)) { lblInfo.Text = "Info cannot be empty"; check = false; } if (Validation.isEmpty(txtPhoneNumber.Text)) { lblPhoneNumber.Text = "PhoneNumber cannot be empty"; check = false; } if (Validation.isEmpty(txtOpeninghr.Text)) { lblOpening.Text = "Opening Hours cannot be empty"; check = false; } if (Validation.isEmpty(txtClosinghr.Text)) { lblClosing.Text = "Closing Hours cannot be empty"; check = false; } if (Validation.isEmpty(txtAddress.Text)) { lblAddress.Text = "Address cannot be empty"; check = false; } if (Validation.isEmpty(txtRegion.Text)) { lblRegion.Text = "Region cannot be empty"; check = false; } if (ImageUpload.HasFile) { string ext = System.IO.Path.GetExtension(ImageUpload.PostedFile.FileName); byte[] bytes = ImageUpload.FileBytes; int width; int height; using (Stream memStream = new MemoryStream(bytes)) { using (System.Drawing.Image img = System.Drawing.Image.FromStream(memStream)) { width = img.Width; height = img.Height; } } if (!Validation.ImageCheck(ext)) { check = false; lblImage.Text = "Invalid image type"; } else if (width > 720 || height > 480) { lblImage.Text = "Profile Picture size does not meet specified requirements 720x480 pixels"; check = false; } } if (CreateDepartmentList.Items.Cast <ListItem>().Count(li => li.Selected) == 0) { check = false; lblDepartmentList.Text = "Please select at least 1 department"; } if (check == true) { Facility f = new Facility(); f.facilityName = txtName.Text; f.facilityType = listFacility.SelectedItem.Text; f.generalInfo = txtInfo.Text; f.phoneNumber = Int32.Parse(txtPhoneNumber.Text); f.openingHrs = txtOpeninghr.SelectedItem.Text + ":" + "00"; f.closingHrs = txtClosinghr.SelectedItem.Text + ":" + "00"; f.address = txtAddress.Text; f.region = txtRegion.Text; f.x = Decimal.Parse(lblSelectedX.Text); f.y = Decimal.Parse(lblSelectedY.Text); if (ImageUpload.HasFile) { f.image = Path.GetFileName(ImageUpload.PostedFile.FileName); ImageUpload.PostedFile.SaveAs(Server.MapPath("~/upload/facility/") + f.image); } if (!FacilityManagementSystem.CheckFacilityName(f.facilityName)) { FacilityManagementSystem.CreateFacility(f); /////////////////////////To add data department table/////////////////////////// int facility_id = FacilityManagementSystem.GetFacilityId(f.facilityName); //only after facility is created will there be facility id Department[] dp = new Department[12]; int index = 0; foreach (ListItem listItem in CreateDepartmentList.Items) { if (listItem.Selected) { dp[index] = new Department(); dp[index].facilityId = facility_id; dp[index].departmentName = listItem.Value; index++; } } DepartmentManagementSystem.AddDepartment(dp); txtName.Text = txtInfo.Text = txtPhoneNumber.Text = txtOpeninghr.Text = txtClosinghr.Text = txtAddress.Text = txtRegion.Text = ""; lblName.Text = lblInfo.Text = lblPhoneNumber.Text = lblOpening.Text = lblClosing.Text = lblAddress.Text = lblRegion.Text = ""; foreach (ListItem listItem in CreateDepartmentList.Items) { if (listItem.Selected) { listItem.Selected = false; } } Response.Write("<script type=\"text/javascript\">alert('Facility Created!');location.href='AdminHomePage.aspx'</script>"); //Response.Redirect("AdminHomePage.aspx", false); } else { lblImage.Text = "This hospital already exist in the database"; } } }