Since I can afford anymore my blog I will be posting here again. I Blog because I know that once you write something is not easy to forget or at least you can remember where you can find something.
Maybe this is not specific technology but while I was reading a WPF and SilverLight book I found the meaning of the Image format. Yeah I know that if you go to Wikipedia you can find them though I think that one way to not forget something that you read or learn is writing it. Therefore this is what I found:
  • BMP : Bitmap
  • JPEG: Joint Photographics Expert Group
  • GIF: Graphics Interchange Format
  • PNG: Portable Network Graphics

That was unknown for me, now I can understand more the purposes of each format.

 I decided to post this because I have tried to update my dbml file (LINQ2SQL) several times and I have forgotten the steps.

If I write this I should not forget it again. :)

For some reason LINQ2SQL has a bug in VS2008 (hope it will be fixed in VS2010) when you modify the dbml file and you have a partial class of the DataContext LINQ class with using statements the Custom tool that generates the code for LINQ class has a problem and  it doesn't generate the designer.cs file that contains the generated classes that you will be using in your pages or code.

Therefore these are the steps that I have followed with success

 1.- Modify the dbml with your changes.

2.- Comment the using statements in the partial class of the LINQ class

3.- Delete the designer.cs file

4.- Right Click the dbml file and select Run Custom Tool

5.- designer.cs is generated with the last changes in the dbml, make sure that designer.cs has a Build Action compile and not content.

6.- Rebuild your solution it should be compiled with new changes and ready to run the application.

 

Hope it helps, Happy Programming!!!

 Since I have been reading the book "The Pragmatic Programmer", I see the importance of using the available tools that you can find online. I have a requirement to add to a installer a zipped folder of the GlassFish (Java App Server) and then unzip it to process some files there and have GF running as a server. My first approach was use the GZipStream class from System.IO in my merge module. So I decided to do a Unit before include that code in my installer Merge Module. I found that C# class has not functionality to zip a folder with nested folders and I was thinking on create a recursive method to that job for me to accomplish that but I got a better "Pragmatic" idea, I googled it then I found a wonderful tool to do that, that fortunately is free to use on any project. It is SharpZipLib from ICSharpCode you can find it on http://www.icsharpcode.net/OpenSource/SharpZipLib/Default.aspx.

 This is the code of the Unit Testing so I can sure this works great and it's too easy you only need to provide de Path of your folder as parameter

 
using NUnit.Framework;
using ICSharpCode.SharpZipLib.Zip;

namespace InstalllerTest
{
    [TestFixture]
    public class InstallJavaTest
    {
        private string zipName;
        private string zipPath;
        private string unzipPath;

        [TestFixtureSetUp]
        public void InitTest()
        {
            zipName = @"C:\Tests\GFJava.zip";
            zipPath = @"C:\Sun\AppServer9U1";
            unzipPath = @"C:\Tests";
        }

        [Test]
        public void ZipFolderTest()
        {
            FastZip fZip = new FastZip();
            fZip.CreateZip(zipName, zipPath, true, "");
            Assert.IsTrue(File.Exists(zipName));
        }

        [Test]
        public void UnZipFolderTest()
        {
            FastZip fZip = new FastZip();
            fZip.ExtractZip(zipName, unzipPath, "");
            Assert.IsTrue(Directory.GetFiles(unzipPath).Length > 1); 

       }

   }

}

 Recently I found this solution hope can help to others. I have a report that is created with GridViews and the client ask for functionality to export it to Excel. In some cases the report was giving different sum results in Excel as in the page. That is because when you export to Excel from ASP.NET you don't have control of the format and some values were not recognized as numbers. I didn't know that you can specify that with CSS. This was the solution

protected void Button1_ServerClick(object sender, EventArgs e)
        {


            Response.Clear();

            Response.AddHeader("content-disposition", "attachment;filename=" + Request.QueryString[2].ToString() + "_"          +       DateTime.Now.ToString("dd-MMM-yy").ToString() + ".xls");

            Response.Charset = "";

            Response.ContentEncoding = Encoding.UTF7;

            Response.ContentType = "application/vnd.xls";

            System.IO.StringWriter stringWrite = new System.IO.StringWriter();

            System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

 

            htmlWrite.WriteLine(@"<style>.number {mso-number-format:0\.00; } </style>");

            Panel p1 = (Panel)frmResults.FindControl("pnlForm");

            p1.RenderControl(htmlWrite);

           

            Response.Write(stringWrite.ToString());

            Response.End();

 

        }

In the code above is to do the export. Look at this code
htmlWrite.WriteLine(@"<style>.number {mso-number-format:0\.00; } </style>");

here I'm adding to the writer for render a css class that specifies mso-number-format that is format for numbers in Microsoft Office Applications

Then in the Databound event handler I linked the class to the cells I need to format

protected void grdValues_DataBound(object sender, EventArgs e)

        {

            foreach(GridViewRow gvr in grdAward.Rows)

            {

                if (gvr.RowType == DataControlRowType.DataRow)

                {

                    gvr.Cells[10].Attributes.Add("class", "number");

                    gvr.Cells[11].Attributes.Add("class", "number");

                    gvr.Cells[12].Attributes.Add("class", "number");

                    gvr.Cells[13].Attributes.Add("class", "number");

                }

            }

        }

 First of all this is my first blog post and I´m not sure if it can be interesting for some of you. I was trying for some days in differents ways to have a GridView with Textbox to edit information created dinamically. I googled and looked to blog like this for some that could help me and most people says that they were having problems with dynamic GridView in UserControls. The reason  I had to use a UserControl is that my requirement was to show the same kind of information but depending on a value (lets say state or country)  the gridview shows 1 to n rows in the gridview and also on each row should contain some textboxes to entry information and validate them according to different rules per entity (state or country). Also the info in the GridView should collapsed and expanded that was with JavaScript of course.

 My solution was to use the HTMLTable ASP Net Control and there I had some other issues and I needed to learn more about the pages Events and Loading UserControls from my page.

First of all in order to mantain the state of the TextBoxes in the UserControl I used (I will take some details from my code because it is from a Production Software I developed in my company).

Override the PreInit Event of the page 

        protected override void OnPreInit(EventArgs e)
        {
                base.OnPreInit(e);
          

                FillControls();
         }

In the page I have a PlaceHolder and in the FillControls do the following. Get the List of states and I add the UserControl for each of them. Since the UserControl contains a HTMLTable I included some methods in the UserControls class to add all the empty rows for items, a row for Summaryze values and a footer row that contains Buttons to Process the information. The ActiveToggle is the method to add attributes to the Image for collapse and expand the UserControl.

        protected void FillControls()
        {
            lstSt = MyDLL.EntityTempGetStates(param1,param2,param3);
            int id = 1;

            foreach (BEState beSt in lstSt)
            {
                EntityCredit EntityCtrl = (EntityPoints)Page.LoadControl("UserControls/EntityPoints.ascx");
                plhControls.Controls.Add(EntityCtrl);
                EntityCtrl.ID = "EntityCtrl" + id;
                EntityCtrl.StateID = beSt.StateID;
                EntityCtrl.param2 = param2;
                EntityCtrl.EventID = param1;
                EntityCtrl.StateName = beSt.StateCode;
                EntityCtrl.param3 = param3;
                id++;

                lstbeEntitys = MyDLL.EntityTempGetValues(param1, beSt.StateID,param2,param3);

                if (lstbeEntitys != null)
                    if (lstbeEntitys.Count > 0)
                    {
                        foreach (BEObjectDetailValues beObjValues in lstbeEntitys)
                        {
                            EntityCtrl.AddRow();
                        }
                    }
                EntityCtrl.AddSumsRow();
                EntityCtrl.AddFooterRow();
                EntityCtrl.ActiveToggle();
                EntityCtrl.AddRules();
            }
        }

In the codebehind of the UserControl are the methods called on the page class custom method FillControls. The source of the UserControls is included so you can consult it just to view the approach maybe could have errors cause I modified to use other variables name.

Once the UserControls is prepared in the Load Event of the page call the FillGrid method for each UserControl where the bind is done

                foreach (BEState beSt in lstSt)
                {
                    EntityCredit EntityCtrl = (EntityCredit)Page.FindControl("EntityCtrl" + id);
                    id++;
                    EntityCtrl.FillGrid();
                }

 

the JavaScript to collapse and expand the user control is the following

//Function to collapse or Expand the panel with Entity Grid
    function ToggleEntity(ctrlId,panelId)
    {
        var pnl = document.getElementById(panelId);
        var img = document.getElementById(ctrlId);
       
        if(pnl.style.display == "block")
        {
            pnl.style.display = "none";
            img.src="Closed.gif";
        }
        else
        {
            pnl.style.display = "block";
            img.src="Open.gif";
        }
    
    }

 

That´s the way I solved my problem and I hope it could be helpful for someone else. I didn´t include it the JavaScript to complete all the functionality but you can contact me for further info.
 

 


 

 

 


 

 

 

 

More Posts