protected void ButUpdate_Click(object sender, EventArgs e) { // Get the record from viewstate copy = (Copy)ViewState["copy"]; // Get values from controls DateTime renewD = DateTime.ParseExact(boxRenewal.Text, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture); copy.RenewalDate = renewD; DateTime purchaseD = DateTime.ParseExact(boxPurchase.Text, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture); copy.PurchaseDate = purchaseD; try { // Update and goes to copy list BCopy.deleteById(copy.CopyId); Response.Redirect("~/Book/Copies.aspx?bookId=" + copy.BookId); } catch (Exception generalException) { PanelDeleteCopy.Visible = true; LiteralDeleteCopy.Text = generalException.Message; } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // Get Index of the copy to update and save it in viewstate copyId = Convert.ToInt32(Request.QueryString["copyId"]); // Get the copy record and save it in viewstate copy = BCopy.getById(copyId); ViewState["copy"] = copy; // Fill controls boxBookId.Text = copy.BookId.ToString(); boxBookId.Enabled = false; boxCopyId.Text = copy.CopyId.ToString(); boxCopyId.Enabled = false; boxRenewal.Text = copy.RenewalDate.ToString("dd/MM/yyyy"); boxRenewal.Enabled = false; boxPurchase.Text = copy.PurchaseDate.ToString("dd/MM/yyyy"); boxPurchase.Enabled = false; } }
public void BCopy_Execute_CopyFiles() { var destinationFolder = "CopyFiles"; var originalFile = string.Format(@"TestFiles\{0}", filename); var destinationFile = string.Format(@"TestFiles\{0}\{1}", destinationFolder, filename); var directory = Path.GetDirectoryName(destinationFile); if (Directory.Exists(directory)) { var files = Directory.GetFiles(directory); foreach (var file in files) { File.Delete(file); } } BCopy.Copy(originalFile, destinationFile); BCopy.Copy(originalFile, destinationFile); BCopy.Copy(originalFile, destinationFile); int counter = 1; Assert.IsTrue(File.Exists(destinationFile)); Assert.IsTrue(File.Exists(GetCleanDestination(destinationFile, counter++))); Assert.IsTrue(File.Exists(GetCleanDestination(destinationFile, counter++))); //string.Format(@"{0}\{1}({2}){3}", Path.GetDirectoryName(destinationFile), Path.GetFileNameWithoutExtension(destinationFile), counter++, Path.GetExtension(destinationFile)))); }
protected void fillCopiesByBookID(int _bookId) { // Get all the copies List <Copy> listCopy = new List <Copy>(); listCopy = BCopy.getAllCopyByBookId(_bookId); GridCopyList.DataSource = listCopy; GridCopyList.DataBind(); }
public void BCopy_Execute_NoDuplicate() { var destinationFolder = "NoCopyFiles"; var originalFile = string.Format(@"TestFiles\{0}", filename); var destinationFile = string.Format(@"TestFiles\{0}\{1}", destinationFolder, filename); //var copyCheck = string.Format(@"{0}\{1}", destinationFile, filename); if (File.Exists(destinationFile)) { File.Delete(destinationFile); } BCopy.Copy(originalFile, destinationFile); Assert.IsTrue(File.Exists(destinationFile)); }
protected void ButUpdate_Click(object sender, EventArgs e) { // Get the record from viewstate copy = (Copy)ViewState["copy"]; // Get values from controls DateTime renewD = DateTime.ParseExact(boxRenewal.Text, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture); copy.RenewalDate = renewD; DateTime purchaseD = DateTime.ParseExact(boxPurchase.Text, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture); copy.PurchaseDate = purchaseD; // Update and goes to copy list BCopy.update(copy); Response.Redirect("~/Book/Copies.aspx?bookId=" + copy.BookId); }
protected void copyIdValidation_ServerValidate(object source, ServerValidateEventArgs args) { // Validate field for "is integer", int value; Boolean ret = true; LiteralCopyId.Text = ""; if (!Int32.TryParse(boxCopyId.Text, out value)) { ret = false; LiteralCopyId.Text = writeDigitsLabel(); } // Validate field for "require", if (string.IsNullOrEmpty(boxCopyId.Text)) { ret = false; LiteralCopyId.Text = writeRequireLabel(); } // Check if record exist in database if above validations are met if (ret) { // Get the copy record int copyId = Convert.ToInt32(boxCopyId.Text); copyDTO = BCopy.getCopyByCopyId(copyId); // If record does not exist, ret is set to false if (copyDTO.CopyId <= 0) { LiteralCopyId.Text = writeDBLabel(); ret = false; } } // IsValid is set to ret and return args.IsValid = ret; }