protected void dsSelectedEmployee_Updating(object sender, SqlDataSourceCommandEventArgs e) { //to update existing employee image: //locate the control and assign it to a new variable FileUpload eeImageUpload = (FileUpload)dvSelectedEmployee.FindControl("FileUpload1"); //...then see if there is anything there if (eeImageUpload.HasFile) { //if there is, get the name of the file then grab the extension string img = eeImageUpload.FileName; string ext = img.Substring(img.LastIndexOf(".")); //create a new, unique filename with a guid and add ack the ext string imgNewname = Guid.NewGuid().ToString(); imgNewname += ext; //save the file to the webserver and the url path to the database eeImageUpload.SaveAs(Server.MapPath("~/EmployeeImages/" + imgNewname)); e.Command.Parameters["@EmployeeImage"].Value = imgNewname; } //if there wasn't anything there, we'll use the current image else { TSTEntities ctx = new TSTEntities(); string img = (from i in ctx.TSTEmployees where i.EmployeeID == (int)gvEmployees.SelectedValue select i.EmployeeImage).Single(); e.Command.Parameters["@EmployeeImage"].Value = img; } }
protected void dsEmployeeDetails_Updating(object sender, SqlDataSourceCommandEventArgs e) { //find the upload contrul FileUpload fuEmp = (FileUpload)dvEmployees.FindControl("fuEmp"); if (fuEmp.HasFile) { //get the filename string fileName = fuEmp.FileName; //get the extension string ext = fileName.Substring(fileName.LastIndexOf(".")); //generate a new file name string newImageName = Guid.NewGuid().ToString(); //plug the extension back in newImageName += ext; //save the photo to the images folder fuEmp.SaveAs(Server.MapPath("~/screenImages/" + newImageName)); //save the photo name to the DB e.Command.Parameters["@EmpPhotoUrl"].Value = newImageName; } else { TSTEntities ctx = new TSTEntities(); string currentImage = (from x in ctx.C3TEmployees where x.EmployeeId == (int)gvEmployees.SelectedValue select x.EmpPhotoUrl).Single(); } }
protected void dsSelectedTicket_Updating(object sender, SqlDataSourceCommandEventArgs e) { //if the status was closed when editing began TSTEntities ctx = new TSTEntities(); int status = (from i in ctx.TSTRequests where i.RequestID == (int)gvTickets.SelectedValue select i.RequestStatusID).Single(); DropDownList newStatus = (DropDownList)dvTicketDetails.FindControl("DropDownList1"); if (newStatus.SelectedIndex < 3) { e.Command.Parameters["@ClosedDate"].Value = null; } else { if (status == 4) { e.Command.Parameters["@ClosedDate"].Value = (from i in ctx.TSTRequests where i.RequestID == (int)gvTickets.SelectedValue select i.ClosedDate).Single(); } else { e.Command.Parameters["@ClosedDate"].Value = DateTime.Now; } } //get existing notes from the database string techNotes = (from i in ctx.TSTRequests where i.RequestID == (int)gvTickets.SelectedValue select i.TechNotes).Single(); //get the textbox control and the notes inside of it TextBox notesAdded = (TextBox)dvTicketDetails.FindControl("TextBox3"); string newNotes = notesAdded.Text; //see if there were existing notes if (techNotes != null) { //if there are existing notes, append newly added notes with tech's username and datetimestamp e.Command.Parameters["@TechNotes"].Value = DateTime.Now.ToString() + " - " + User.Identity.Name + "</br>" + newNotes + "</br></br>" + techNotes; } else { //populate the field with the notes added by the tech e.Command.Parameters["@TechNotes"].Value = DateTime.Now.ToString() + " - " + User.Identity.Name + newNotes; } }