Jump to content
Xtreme .Net Talk

mike55

Avatar/Signature
  • Posts

    734
  • Joined

  • Last visited

Everything posted by mike55

  1. I am running into a problem with uploading the images into a web. I am using the following code to take an image and create a thumbnail of it: Private Function UploadThumbnail(ByVal myUpload As FileUpload, ByVal nameExtension As String, ByVal myNewHeight As Integer, ByVal myNewWidth As Integer, ByVal compression As Int16, ByVal leadName As String) As Boolean Dim myresult As Boolean = True 'Const bmpW = 300 'New image target width Dim bmpW = myNewWidth 'Const bmpH = 226 'New Image target height Dim bmpH = myNewHeight If (myUpload.HasFile) Then 'Clear the error label text lblError.Text = "" 'Check to make sure the file to upload has a picture file format extention and set the target width and height If (CheckFileType(myUpload.FileName)) Then Dim newWidth As Integer = bmpW Dim newHeight As Integer = bmpH 'Use the uploaded filename for saving without the '.' extension Dim upName As String = Mid(myUpload.FileName, 1, (InStr(myUpload.FileName, ".") - 1)) upName = nameExtension & leadName & lblLandRef.Text 'Set the save path of the resized image, you will need this directory already created in your web site Dim filePath As String = "" & upName & ".jpg" 'Create a new Bitmap using the uploaded picture as a Stream 'Set the new bitmap resolution to 72 pixels per inch Dim upBmp As Bitmap = Bitmap.FromStream(myUpload.PostedFile.InputStream) Dim newBmp As Bitmap = New Bitmap(newWidth, newHeight, Imaging.PixelFormat.Format24bppRgb) newBmp.SetResolution(72, 72) 'Get the uploaded image width and height Dim upWidth As Integer = upBmp.Width Dim upHeight As Integer = upBmp.Height Dim newX As Integer = 0 'Set the new top left drawing position on the image canvas Dim newY As Integer = 0 Dim reDuce As Decimal 'Keep the aspect ratio of image the same if not 4:3 and work out the newX and newY positions 'to ensure the image is always in the centre of the canvas vertically and horizontally If upWidth > upHeight Then 'Landscape picture reDuce = newWidth / upWidth 'calculate the width percentage reduction as decimal newHeight = Int(upHeight * reDuce) 'reduce the uploaded image height by the reduce amount newY = Int((bmpH - newHeight) / 2) 'Position the image centrally down the canvas newX = 0 'Picture will be full width ElseIf upWidth < upHeight Then 'Portrait picture reDuce = newHeight / upHeight 'calculate the height percentage reduction as decimal newWidth = Int(upWidth * reDuce) 'reduce the uploaded image height by the reduce amount newX = Int((bmpW - newWidth) / 2) 'Position the image centrally across the canvas newY = 0 'Picture will be full hieght ElseIf upWidth = upHeight Then 'square picture reDuce = newHeight / upHeight 'calculate the height percentage reduction as decimal newWidth = Int(upWidth * reDuce) 'reduce the uploaded image height by the reduce amount newX = Int((bmpW - newWidth) / 2) 'Position the image centrally across the canvas newY = Int((bmpH - newHeight) / 2) 'Position the image centrally down the canvas End If 'Create a new image from the uploaded picture using the Graphics class 'Clear the graphic and set the background colour to white 'Use Antialias and High Quality Bicubic to maintain a good quality picture 'Save the new bitmap image using 'Png' picture format and the calculated canvas positioning Dim newGraphic As Graphics = Graphics.FromImage(newBmp) Try newGraphic.Clear(Color.White) newGraphic.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias newGraphic.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic newGraphic.DrawImage(upBmp, newX, newY, newWidth, newHeight) 'Dim ep As EncoderParameters = CompressImageParameters(newBmp) Dim eps As EncoderParameters = New EncoderParameters(1) eps.Param(0) = New EncoderParameter(Encoder.Quality, _ compression) Dim ici As ImageCodecInfo = GetEncoderInfo("image/jpeg") 'newBmp.Save(MapPath(filePath), ici, eps) newBmp.Save(MapPath(filePath), Imaging.ImageFormat.Jpeg) Return myresult Catch ex As Exception myresult = False lblError.Text = ex.ToString Finally upBmp.Dispose() newBmp.Dispose() newGraphic.Dispose() End Try Else lblError.Text = "Please select a picture with a file format extension of either Bmp, Jpg, Jpeg, Gif or Png." myresult = False Return myresult End If End If End Function and I am also using the following code to simply upload an image: Private Function UploadStandardImage() As Boolean Dim result As Boolean = True Try If Me.FileUpload1.HasFile Then If CheckFileType(FileUpload1.FileName) = True Then Dim strName As String strName = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName) FileUpload1.PostedFile.SaveAs(Server.MapPath(lblLandRef.Text & ".jpg")) End If End If Return result Catch ex As Exception result = False End Try End Function The problem that I am having is that I need to supply a username and password, to allow the upload. How can I supply such data? Mike55.
  2. Found the solution, add the following line of code to the web.config file: <httpRuntime maxRequestLength="102400" /> in the system.web tag area. Mike55.
  3. hi all I have a FileUpload control on my page, and a button control called btnSave. I also have code that is responsible for uploading the images. The code also resizes and compresses the image. I have enclosed the code that responds to the btnSave handler in a try catch statement, with a stop statement with in the catch exception. I also have a number of break points within the btnSave handler code. The problem that occurs is that when I try and upload large images i.e. 12.7MB the btnSave handler code does not appear to run, and all I get is the page "Page cannot be display" as if I had no connection to the internet. Everything runs fine if the image size is low i.e. 108Kb. What I cannot understand is why the button code does not run and then thows an exception if the file size is too large. Mike55.
  4. Hi all I am doing up a quick site for an auctioneer's business. They want to be able to display details of upcoming and past sales. They want to be able to update the details or insert new details without having to come back to me. I have selected the repeater control to display all the data, and it works. I am providing the user with a number of text fields into which they can insert some data. However I think that the solution that I have is in appropriate, and instead, I should provide a faciliate whereby the user can upload a word document to the database and the repeater controls displays multiple word documents. Can anyone suggest if the way I am proceeding is the best option, or is there a better option? Mike55.
  5. I have tried using Umbraco over the last few days, but it doesn't seem to be as flexable as I first thought. Mike55.
  6. I have a javascript file which stores a number of functions. One of these functions is: function limitText(limitField, limitCount, msgCount){ //do something. } The values are passed to the function using the following: <textarea id="txtMessage" runat="server" language="javascript" name="txtMessage" onkeyup="limitText(this.form.txtMessage,this.form.hCount,this.form.MsgNo);" style="font-size: 10px; width: 230px; font-family: verdana; height: 88px"></textarea> Now I have the controls txtMEssage, hCount, and MsgNo all inside an ajax update panel. My problem is that some of the parameters are passed as undefined. must I changce the way I pass these since they are inside the ajax control? Mike55.
  7. Hi all I am in the middle of changing project to use master pages. On a number of my old style web pages I was calling a javascript function when the body loaded: <body onload="Test();" My query is how do you do the same with the content pane in that accompanies the master pages? Mike55.
  8. Solved the problem, caused by incorrect data being in the database. Mike55.
  9. Hi all I am getting the error: "Index was outside the bounds of the array" when updating database records using a dataset and the sqldataadapter.update command. Here is my database code: 'Provides a means of updating basic required data for all members. Public Function QuickUpdate(ByVal orgData As DataSet, ByVal organisation As String) As Boolean Dim sqlReturn As Boolean = True Try quickAddAdapter.InsertCommand = New SqlCommand quickAddAdapter.InsertCommand.Connection = cnConn quickAddAdapter.InsertCommand.CommandText = "QuickInsertMembers" quickAddAdapter.InsertCommand.CommandType = CommandType.StoredProcedure quickAddAdapter.DeleteCommand = New SqlCommand quickAddAdapter.DeleteCommand.Connection = cnConn quickAddAdapter.DeleteCommand.CommandText = "QuickDeleteMembers" quickAddAdapter.DeleteCommand.CommandType = CommandType.StoredProcedure quickAddAdapter.UpdateCommand = New SqlCommand quickAddAdapter.UpdateCommand.Connection = cnConn quickAddAdapter.UpdateCommand.CommandText = "QuickUpdateMember" quickAddAdapter.UpdateCommand.CommandType = CommandType.StoredProcedure quickAddAdapter.InsertCommand.Parameters.Add(New SqlParameter("@Forename", SqlDbType.NVarChar, 24)) quickAddAdapter.InsertCommand.Parameters("@Forename").Direction = ParameterDirection.Input quickAddAdapter.InsertCommand.Parameters("@Forename").SourceColumn = "Forename" quickAddAdapter.InsertCommand.Parameters.Add(New SqlParameter("@Surname", SqlDbType.NVarChar, 24)) quickAddAdapter.InsertCommand.Parameters("@Surname").Direction = ParameterDirection.Input quickAddAdapter.InsertCommand.Parameters("@Surname").SourceColumn = "Surname" quickAddAdapter.InsertCommand.Parameters.Add(New SqlParameter("@MobileNumb", SqlDbType.Char, 20)) quickAddAdapter.InsertCommand.Parameters("@MobileNumb").Direction = ParameterDirection.Input quickAddAdapter.InsertCommand.Parameters("@MobileNumb").SourceColumn = "MobileNumb" quickAddAdapter.InsertCommand.Parameters.Add(New SqlParameter("@Email", SqlDbType.NVarChar, 50)) quickAddAdapter.InsertCommand.Parameters("@Email").Direction = ParameterDirection.Input quickAddAdapter.InsertCommand.Parameters("@Email").SourceColumn = "Email" quickAddAdapter.InsertCommand.Parameters.Add(New SqlParameter("@Organisation", SqlDbType.NVarChar, 10)) quickAddAdapter.InsertCommand.Parameters("@Organisation").Direction = ParameterDirection.Input quickAddAdapter.InsertCommand.Parameters("@Organisation").Value = organisation quickAddAdapter.DeleteCommand.Parameters.Add(New SqlParameter("@Organisation", SqlDbType.NVarChar, 10)) quickAddAdapter.DeleteCommand.Parameters("@Organisation").Direction = ParameterDirection.Input quickAddAdapter.DeleteCommand.Parameters("@Organisation").Value = organisation quickAddAdapter.DeleteCommand.Parameters.Add(New SqlParameter("@MID", SqlDbType.BigInt)) quickAddAdapter.DeleteCommand.Parameters("@MID").Direction = ParameterDirection.Input quickAddAdapter.DeleteCommand.Parameters("@MID").SourceColumn = "Member_ID" quickAddAdapter.UpdateCommand.Parameters.Add(New SqlParameter("@MemberID", SqlDbType.BigInt)) quickAddAdapter.UpdateCommand.Parameters("@MemberID").Direction = ParameterDirection.Input quickAddAdapter.UpdateCommand.Parameters("@MemberID").SourceColumn = "Member_ID" quickAddAdapter.UpdateCommand.Parameters.Add(New SqlParameter("@Forename", SqlDbType.NVarChar, 24)) quickAddAdapter.UpdateCommand.Parameters("@Forename").Direction = ParameterDirection.Input quickAddAdapter.UpdateCommand.Parameters("@Forename").SourceColumn = "Forename" quickAddAdapter.UpdateCommand.Parameters.Add(New SqlParameter("@Surname", SqlDbType.NVarChar, 24)) quickAddAdapter.UpdateCommand.Parameters("@Surname").Direction = ParameterDirection.Input quickAddAdapter.UpdateCommand.Parameters("@Surname").SourceColumn = "Surname" quickAddAdapter.UpdateCommand.Parameters.Add(New SqlParameter("@MobileNumb", SqlDbType.Char, 20)) quickAddAdapter.UpdateCommand.Parameters("@MobileNumb").Direction = ParameterDirection.Input quickAddAdapter.UpdateCommand.Parameters("@MobileNumb").SourceColumn = "MobileNumb" quickAddAdapter.UpdateCommand.Parameters.Add(New SqlParameter("@Email", SqlDbType.NVarChar, 50)) quickAddAdapter.UpdateCommand.Parameters("@Email").Direction = ParameterDirection.Input quickAddAdapter.UpdateCommand.Parameters("@Email").SourceColumn = "Email" quickAddAdapter.UpdateCommand.Parameters.Add(New SqlParameter("@Organisation", SqlDbType.NVarChar, 10)) quickAddAdapter.UpdateCommand.Parameters("@Organisation").Direction = ParameterDirection.Input quickAddAdapter.UpdateCommand.Parameters("@Organisation").Value = organisation quickAddAdapter.Update(orgData, "Everybody") Return sqlReturn Catch ex As Exception sqlReturn = False Finally clsConnection.CloseConnection(cnConn) End Try End Function One posting that I saw suggested that the problem was due to the user using the "Select *" rather than selecting only the columns needed. I am not using the "Select *" so that is one thing ruled out. Mike55.
  10. I have a grid view that is binded to a dataset. I am trying to implement sorting on the grid. I have succeeded in allowing sort to occur, the only problem that I am having is to specify what sort option, i.e. ASC or DECS to tuser. Here is the code that I am using: Protected Sub gVGroups2_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles gVGroups2.Sorting Dim myView As DataView dsData = Session("GridData") myView = dsData.Tables("Groups").DefaultView Select Case e.SortDirection Case SortDirection.Ascending myView.Sort = "Group_Name DESC" e.SortDirection = SortDirection.Descending Case SortDirection.Descending myView.Sort = "Group_Name ASC" e.SortDirection = SortDirection.Ascending End Select Me.gVGroups2.DataSource = myView Me.gVGroups2.DataBind() End Sub Can anyone suggest a simple way of storing the sort order. I don't want to use an external textbox/label to store the current sort order. Mike55.
  11. Hi all I have an email template stored in my web project. When I want to send an email to all the users, I just populate the data that has to change, and then proceed with sending the email. I have now been told that instead of sending most of the data in the body of the email that I must attach it as an attachment. Here is a sample of one of the email as it is currently send: I then use the following code to replace the tags with the proper values: Dim templateVar As New Hashtable templateVar.Add("OrgName", dsOrg.Tables("Organization").Rows(0).Item("Org_Name").ToString) templateVar.Add("Oid", org_ID) templateVar.Add("Currency", drwData(0).Item("Currency").ToString) templateVar.Add("Amount", Math.Round(dsOrg.Tables("OrderDetails").Rows(0).Item("Total"), 2)) templateVar.Add("Order", dsOrg.Tables("OrderDetails").Rows(0).Item("Description").ToString) templateVar.Add("Net", Calculate(CType(dsOrg.Tables("OrderDetails").Rows(0).Item("Total"), Decimal), CType(drwData(0).Item("VAT"), Decimal), 2)) templateVar.Add("Rate", drwData(0).Item("VAT").ToString) templateVar.Add("Vat", Calculate(CType(dsOrg.Tables("OrderDetails").Rows(0).Item("Total"), Decimal), CType(drwData(0).Item("VAT"), Decimal), 1)) templateVar.Add("Total", Math.Round(dsOrg.Tables("OrderDetails").Rows(0).Item("Total"), 2)) templateVar.Add("Purchase", ActionLabel(action)) Dim emailBody As New Parser(ConfigurationManager.AppSettings("EmailTemplates") & _ "Registration.htm", templateVar) To send the template in the body, I simply supply emailBody.Parse for the body property. Any suggestions on how to adjust this so that I can access the template, modify it and attach it as a template? Mike55.
  12. Here is what I have finished up with, I would appreciate it if anyone could let me know if I have done it correctly, or if I have completely mis-read the documentation. The Component Class. using System; using System.Collections.Generic; using System.Text; namespace CompositePattern { abstract class AbstractEmployee : CompositePattern.IAbstractEmployee { public string name; public string title; public decimal salary; //This is a list of references for all my parents. See GoF pg166(Implementation pt1.) for reasoning. public List<AbstractEmployee> myParents = new List<AbstractEmployee>(); public AbstractEmployee(string name, string title, decimal salary) { this.name = name; this.title = title; this.salary = salary; } //Add a leaf to a parent, or add a parent to another parent. public abstract void Add(AbstractEmployee employee); //Remove a leaf from a parent. public abstract void Remove(AbstractEmployee employee); //Display all the leaves for a particular parent. public abstract void Display(int indent); //Get the name of the parent/leaf. public abstract string GetName(); //Get the salary of the parent/leaf. public abstract string GetTitle(); //Get the salary of the parent/leaf. public abstract decimal GetSalary(); //Add a new reference to the object for a new parent. public abstract void AddParentReference(AbstractEmployee myParentRef); //List all the references to parents that an object has. public abstract void ListParentReference(); public abstract void RemoveReferences(CompositeElement myParentRef); } } The Composite Class using System; using System.Collections.Generic; using System.Text; namespace CompositePattern { class CompositeElement: AbstractEmployee { List<AbstractEmployee> myElements = new List<AbstractEmployee>(); public CompositeElement(string name, string title, decimal salary): base(name, title, salary) { } //Add an employee to the manger. public override void Add(AbstractEmployee myEmployee) { myElements.Add(myEmployee); } //Remove an employee from the manger. public override void Remove(AbstractEmployee myEmployee) { myElements.Remove(myEmployee); } //1. Begin by printing the name of the parent, 2. followed by its children. public override void Display(int indent) { //1. Print the name of the parnet. Console.WriteLine(new string('-', indent) + "+ " + name); //2. Print all the children of the parent. foreach (AbstractEmployee myEmployee in myElements) { myEmployee.Display(indent + 1); } } //Return the name of a parent. public override string GetName() { return name; } //Return the title of the parent. public override string GetTitle() { return title; } //Return the salary of the parent. public override decimal GetSalary() { return salary; } //Add a reference to the parent. public override void AddParentReference(AbstractEmployee myParentRef) { myParents.Add(myParentRef); } //List all the references that the parent has to other parents. public override void ListParentReference() { if (myParents.Count == 0) { Console.WriteLine("No references exist."); } else { //1. Print the name of the parnet. Console.WriteLine(new string('-', 1) + "+ " + name); int counter = 0; //Print all the references that the object has to parents. foreach (AbstractEmployee myRef in myParents) { counter += 1; Console.WriteLine("Reference " + counter + ": " + myRef.GetName()); } } } //Remove a reference to a parent. public override void RemoveReferences(CompositeElement myParentRef) { myParents.Remove(myParentRef); } } } The Leaf Class using System; using System.Collections.Generic; using System.Text; namespace CompositePattern { class Employee: AbstractEmployee { public Employee(string name, string title, decimal salary):base(name, title, salary) { } public override void Add(AbstractEmployee myEmployee) { Console.WriteLine("Cannot ADD to an employee, operation can only be performed on an manager."); } public override void Remove(AbstractEmployee myEmployee) { Console.WriteLine("Cannot REMOVE from an employee, operation can only be performed on an manager."); } //Display the employee. public override void Display(int indent) { Console.WriteLine(new string('-', indent) + " " + name); } //Get the name of the employee. public override string GetName() { return name; } //Get the title of the employee. public override string GetTitle() { return title; } //Get the salary of the employee. public override decimal GetSalary() { return salary; } //Add a reference to the child. public override void AddParentReference(AbstractEmployee myParentRef) { //Console.WriteLine("Cannot ADD_PARENT_REFERENCE from an employee, operation can only be performed on an manager."); myParents.Add(myParentRef); } //List all the references that the child has to other parents. public override void ListParentReference() { if (myParents.Count == 0) { Console.WriteLine("No references exist."); } else { //1. Print the name of the parnet. Console.WriteLine(new string('-', 1) + "+ " + name); int counter = 0; //Print all the references that the object has to parents. foreach (AbstractEmployee myRef in myParents) { counter += 1; Console.WriteLine("Reference " + counter + ": " + myRef.GetName()); } } } //Remove a reference to a parent. public override void RemoveReferences(CompositeElement myParentRef) { myParents.Remove(myParentRef); } } } And finally, the code from my Main class //1. Create the primary parent. CompositeElement root = new CompositeElement("PJimmy", "Managing Director", 100000); CompositeElement comp = new CompositeElement("PMichael", "Developer", 17000); //2. Create an employee and add a reference. Employee emp = new Employee("Tom", "Quality Manager", 50000); emp.AddParentReference(root); emp.AddParentReference(comp); comp.AddParentReference(root); //Display the references. emp.ListParentReference(); Mike55.
  13. Is the flyweight pattern the way to go with this problem? I am after reading in http://www.research.ibm.com/designpatterns/pubs/ph-jun98.pdf in the last paragraph on page 4, that the composite pattern can generate a lot of overhead if you are applying it to too fine a granularity. The flyweight is appliciable if there is a lot of redundancy. Any suggestions? or am I going completely off track. Mike55
  14. Problem Solved, had already called the .Dispose method. Hi all I have a crystal report which I am displaying in my web page as a .pdf file. I am getting the error message: "Object reference not set to an instance of an object" when the Page_Unload method is fired. Not sure what could be going wrong, as I am using the same code in two other pages, and they work correctly. Is it that I should be using a garbage collector? Here is the code that I am using: 'Global Variable Dim oRpt As ReportDocument Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload oRpt.Dispose() End Sub Private Sub GenerateReport() Dim crystalServer As String = ConfigurationManager.ConnectionStrings("SERVER").ToString Dim count As Int16 = 0 start: oRpt = New ReportDocument Dim util As New Utility Dim requestedHostAddress As String requestedHostAddress = Request.UserHostAddress 'If util.GetReportCredentials(dbUser, dbPass, dbName) = False Then ' Response.Redirect("Error.aspx?fc=rpt&type=Msgrpt") 'End If Dim rptpath As String = Server.MapPath("rptMessages.rpt") If Len(rptpath) = 0 Then Exit Sub Else oRpt.Load(rptpath) End If oRpt.DataDefinition.FormulaFields("DFrom").Text = "'" + Request.QueryString("From") + "'" oRpt.DataDefinition.FormulaFields("DTo").Text = "'" + Request.QueryString("To") + "'" oRpt.DataDefinition.FormulaFields("Org").Text = "'" + Session("OrgID") + "'" oRpt.DataDefinition.FormulaFields("GID").Text = "'" + Request.QueryString("GID") + "'" oRpt.DataDefinition.FormulaFields("Group").Text = "'" + Request.QueryString("Group") + "'" oRpt.DataDefinition.FormulaFields("Type").Text = "'" + Request.QueryString("Type") + "'" oRpt.DataDefinition.FormulaFields("User").Text = "'" + Request.QueryString("by").Replace("'", "`") + "'" oRpt.DataDefinition.FormulaFields("OName").Text = "'" + Session("OrgName") + "'" Try 'The following try catch statement is responsible for generating the report in a .pdf format. Dim crLogonInfo As CrystalDecisions.Shared.TableLogOnInfo crLogonInfo = oRpt.Database.Tables(0).LogOnInfo crLogonInfo.ConnectionInfo.ServerName = crystalServer crLogonInfo.ConnectionInfo.DatabaseName = ConfigurationManager.ConnectionStrings("DBNAME").ToString crLogonInfo.ConnectionInfo.UserID = ConfigurationManager.ConnectionStrings("USER").ToString crLogonInfo.ConnectionInfo.Password = ConfigurationManager.ConnectionStrings("PASS").ToString oRpt.Database.Tables(0).ApplyLogOnInfo(crLogonInfo) Dim myExportOptions As CrystalDecisions.Shared.ExportOptions Dim myDiskFilesDestinationOptions As CrystalDecisions.Shared.DiskFileDestinationOptions Dim myExportFile As String myExportFile = "C:\temp\PDF " & Session.SessionID.ToString & ".pdf" myDiskFilesDestinationOptions = New CrystalDecisions.Shared.DiskFileDestinationOptions myDiskFilesDestinationOptions.DiskFileName = myExportFile myExportOptions = oRpt.ExportOptions With myExportOptions .DestinationOptions = myDiskFilesDestinationOptions .ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile .ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat End With oRpt.Export() Response.ClearContent() Response.ClearHeaders() Response.ContentType = "application/pdf" Response.WriteFile(myExportFile) Response.Flush() Response.Close() oRpt.Dispose() If Not oRpt Is Nothing Then oRpt = Nothing End If System.IO.File.Delete(myExportFile) Catch ex As Exception If count <= 1 Then crystalServer = ConfigurationManager.ConnectionStrings("SERVER_FAILOVER").ToString count = +1 End If GoTo start End Try End Sub Mike55.
  15. Hi all I have being looking through the book "Design Patterns" by the Gang of Four, I came across the composite pattern and implemented a sample app the demonstrates the pattern working (hopefully I did it correctly). After some further reading using the web other resources, I came across a statement that said that a child in the pattern could have multiple parents. I have being trying to figure out how to adjust my sample app to accomidate this; I considered adding an list to the child, which allowed it to store a reference to all its parents, and the same for the parent, so that it could store all its children. I am not sure if this is the best approach, can anyone suggest any alternative? Here is the code that I am using in my basic composite pattern: The Abstract child using System; using System.Collections.Generic; using System.Text; namespace CompositePattern { abstract class AbstractChild : CompositePattern.IAbstractChild { protected string name; public AbstractChild(string name) { this.name = name; } public abstract void Add(AbstractChild soldier); public abstract void Remove(AbstractChild soldier); public abstract void Display(int indent); } } The Child using System; using System.Collections.Generic; using System.Text; namespace CompositePattern { class Child: AbstractChild { public Child(string name):base(name) { } public override void Add(AbstractChild soldier) { Console.WriteLine("Cannot add to a child."); //(throw new Exception("The method or operation is not implemented."); } public override void Remove(AbstractChild soldier) { Console.WriteLine("Cannot remove from a child."); //throw new Exception("The method or operation is not implemented."); } public override void Display(int indent) { Console.WriteLine(new string('-', indent) + " " + name); //throw new Exception("The method or operation is not implemented."); } } } The parent using System; using System.Collections.Generic; using System.Text; namespace CompositePattern { class Parent: AbstractChild { //private ArrayList elements = new ArrayList(); private List<AbstractChild> elements = new List<AbstractChild>(); public Parent(string name): base(name) { } public override void Add(AbstractChild soldier) { elements.Add(soldier); //throw new Exception("The method or operation is not implemented."); } public override void Remove(AbstractChild soldier) { elements.Remove(soldier); //throw new Exception("The method or operation is not implemented."); } public override void Display(int indent) { Console.WriteLine(new string('-', indent) + " + " + name); foreach (AbstractChild aSoldier in elements) { aSoldier.Display(indent + 2); } //throw new Exception("The method or operation is not implemented."); } } } And finally the main using System; using System.Collections.Generic; using System.Text; using System.Data; namespace CompositePattern { class MainApp { public static void Main() { Parent myParent = new Parent("John Doe"); myParent.Add(new Child("Tom")); myParent.Add(new Child("Dick")); myParent.Add(new Child("Harry")); myParent.Display(0); Console.Read(); } } } Mike55.
  16. Hi Nate Here is what I do for the confirm dialog/messagebox using javascript: In my page load method I have the following line of code: btnSend.Attributes.Add("onclick", "if(confirm('Are you sure you want to do this?')){}else{return false}") I then have my normal btnSend_Click method that handles the button click. Just make sure that your btnSend is an asp.net button. When you click the button, you will get a javascript dialog asking you the above question, you will be give to two options, Ok or Cancel. I still haven't figured out how to changed this to Yes and No. You would probabily need to create your own javascript button. Now if you click on the OK button, the javascript will allow you to proceed to the btnSend_Click method. If you click on the Cancel button, then the javascript will simply act as if you never click the button. Hope this helps. Mike55.
  17. hi all I have a gridview on my page, I happen to be looping through the grid row by row, at certain times, it is necessary to go in and retrieve a certain value in a cell in the particular row. I know that I can using the following cmd to access a cell once I know what cell I need: gvMembers.Rows(gridRow).Cells(1).Text But is there anyway that I can replace the cell number with the name of the cell, or the underlying datatype? Mike55.
  18. Problem solved, wrong css file name supplied. mike55.
  19. Ok, I have used the AJAX web toolkit to do what I want. I am using the collapseable panel extender. I have followed all the steps outlined in the video: http://www.asp.net/learn/videos/view.aspx?tabid=63&id=89. Here is the the html code that I am using: <cc1:CollapsiblePanelExtender ID="CollapsiblePanelExtender1" runat="server" TargetControlID="pnlAdvanced" ExpandControlId="pnlHeader" CollapseControlID="pnlHeader" Collapsed="true" TextLabelID = "Label1" ExpandedText="Advanced Options" CollapsedText="Advanced Options" ImageControlID ="Image1" CollapsedImage="~/Suretxt_Images/collapse.jpg" ExpandedImage="~/Suretxt_Images/expand.jpg" SuppressPostBack="true" > </cc1:CollapsiblePanelExtender> <asp:Panel ID="pnlHeader" runat="server" BackColor="#336699" Font-Names="Tahoma" Font-Size="XX-Small" ForeColor="White" Height="19px" Width="243px" Font-Bold="True" HorizontalAlign="Left"> <asp:Image ID="Image1" runat="server" ImageUrl="~/Suretxt_Images/expand.jpg" /> <asp:Label ID="Label1" runat="server"></asp:Label></asp:Panel> <asp:Panel ID="pnlAdvanced" runat="server" CssClass="collapsePanel"> <asp:CheckBox ID="chkDelivery" runat="server" Width="125px" Text="Delivery Report." /><br /> <input id="chkSponsor" name="chkSponsor" title="chkSponsor" type="checkbox" runat="server" onclick="SponsorStatus();" value="" />Sponsors Message.<br /> <asp:CheckBox ID="chkName" runat="server" EnableTheming="True" Text="Replace mobile number with: " Width="163px" /> <asp:TextBox ID="txtSenderId" runat="server" Height="14px" Width="68px" MaxLength="8" Font-Names="Tahoma" Font-Size="XX-Small"></asp:TextBox></asp:Panel> Here is the entry for my css file: .collapsePanel { width:243px; height:0px; background-color:White; overflow:hidden; } The problem's that I am having are as follows: 1. The css file is not being used correct. 2. The panel is showing at the beginning, and the collapsing, according to the video tutorial by setting the height of the collapsing panel to 0 and the overflow to hidden, this problem would not occur. This problem I believe is due to the first problem. Any suggestions? Mike55.
  20. Come to Ireland, apparently there are 14,000 IT vacancies at the current time. Mike55.
  21. tFowler Many thanks for the link to the video, I had been using this ajax wrapper provided by a third party on the net. I followed the video and have the ajax working now. I am also in the process of downloading the other ajax related videos on the site, and will start going throught them. Again, many thanks for the help. Mike55.
  22. Is anyone in this forum a professional Technical Writer? Interested in hearing more about it, the skills needed, and the opportunities available. Mike55.
  23. Hi tfowler I have added my Ajax.dll to my bin, and added the following to the web.config file: <add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax" /> I have added the following command to the page load of my page: Ajax.Utility.RegisterTypeForAjax(GetType(SendMessage)) I have added the panel to my page, and placed the controls that I want inside the panel. I have also added the html button, and have set up the javascript. My method for hiding or viewing the panel is as follows: <Ajax.AjaxMethod()> _ Public Sub ShowPanel() Dim setValue As Boolean Try Select Case pnlAdvanced.Visible Case True setValue = False Case False setValue = True End Select Catch ex As Exception Stop End Try pnlAdvanced.Visible = setValue End Sub I am however getting the following error when I use the ajax code: This error relates to the panel. Any suggestions on how to overcome this problem? Mike55.
  24. Hi all I am trying to implement an example of the singleton pattern using the code at the following site: http://www.codeproject.com/cpp/singletonrvs.asp. I am getting the following error: The error is occuring in the main method when I try and call the method getInstance. Any suggestions on how to solve this problem? Mike55.
  25. Hi all I am creating an anchor tag on my page, and I am placing a div tag inside that. Inside the div tag I am placing various asp.net controls. When the page loads the visible property of the anchor tag should be false. <a id="dControls" runat="server" visible="false" > <div runat="server" style="width: 301px; height: 64px" id="test"> <asp:CheckBox ID="CheckBox1" runat="server" /> <input id="Button1" title="Close" type="button" value="Close" onclick="Hide();" /> </div> </a> I have a html button outside of the anchor tag that should set the visibilty of the anchor tag to true using javascript. I also have another html button inside the div tag that calls javascipt to set the visibility of the anchor tag to false. <input id="Button2" title="Advanced" type="button" value="Advanced" onclick="Show();" /> Here is the javascript code: <script language="jscript" type="text/jscript"> function Show() { document.getElementById("dControls").visible = true; } function Hide() { document.getElementById("dControls").visible = false; } </script> When I click the button to change the visibilty of the anchor tag to true, I get the following error: The javascript code cannot seem to find the anchor tag. Any suggestions on how to overcome this problem. I am using javascript and html buttons in an attempt to reduce post back. I am also going to have a look at ajax now to see if that can help. Mike55.
×
×
  • Create New...