Dotnetinfo’s Weblog

Just another WordPress.com weblog

Silverlight – “Loading Please wait”

Posted by dotnetinfo on November 17, 2009

Silverlight – “Loading Please wait” was my search in google i was not able to find any useful information. I thought how come nobody thought about the loading wait time and started to code using my little knowledge , then came across a great post by dan – http://www.davidpoll.com/2009/09/14/update-2-displaying-background-activity-in-a-silverlight-ria-application/ i added the activity to my DomainDataSource that calls a sybase database not Entity framework. Remember to use the new acitivy dll from dan’s blog not in RIA template.

Posted in RIA, Silverlight | Leave a Comment »

Silverlight – RIA – Sybase without Entity Framework

Posted by dotnetinfo on November 13, 2009

I am in the process of learning RIA with Silverlight. I like the Entity Framework but it wont work for my sybase. At last i found an article  http://msmvps.com/blogs/deborahk/archive/2009/11/05/silverlight-ria-services-and-your-business-objects.aspx

that helped me to create domain objects and connect directly to database. The change i made mainly in domain layer

public static List<SomeData> GetData()
        {
            DataSet dsSome;
            List<SomeData> SomeList = new List<SomeData>();
            try
            {
  //using Entlib you can use any database
                DAL.Database db = DAL.DatabaseFactory.CreateDatabase(“Use Connection String”);              
                dsSome= db.ExecuteDataSet(CommandType.StoredProcedure, “Query’”);
                foreach (DataRow SomeRow in dsSome.[1].Rows)
                {
                    SomeData s = new SomeData ();
                    s.Name = SomeRow ["Name"].ToString();
                    s.Age = SomeRow ["Age"].ToString();
                    SomeList.Add(SomeData);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

         
            return SomeList;
        }

public class SomeData
    {
        [System.ComponentModel.DataAnnotations.Key()]
        public string Name{ get; set; }    
        public string Age{ get; set; }               
    }

In Service Layer
public IEnumerable<SomeData> GetSomeData()
        {
            return Customers.GetData();
        }

In Main.XAML add another grid to display the value

Posted in RIA, Silverlight | Leave a Comment »

Dynamically adding events in Javascript

Posted by dotnetinfo on March 12, 2009

I was working on a small project to create some buttons dynmicaly using javascript .

 var oCel2 = newRow.insertCell(4);
var button = document.createElement(‘input’);
button.setAttribute(‘type’,'button’);
button.setAttribute(‘name’,'button1′)
button.setAttribute(‘id’,'button1′)    
button.setAttribute(‘value’,'Delete’);     
// button.onclick= ‘removeRow(this)’; // wrong way – adding  text not a function

button.onclick= new Function(‘removeRow(this)’); // correct way – adding a function
oCel2.appendChild(button);

Hope it helps someone. Thanks

Posted in Javascript | Leave a Comment »

Update – Saving Blob more than 32K using gzip

Posted by dotnetinfo on March 12, 2009

I thought split and save blob is a great idea until i found the link

http://blogs.microsoft.co.il/blogs/gilf/archive/2009/02/05/back-to-basics-zip-in-net.aspx

Like my grandfather said : Better answer is available if you search for it.

Posted in C#, Database | Leave a Comment »

IE Developer ToolBar

Posted by dotnetinfo on March 12, 2009

In one of projects we use extensive amounts of javascripts to modify HTML on runtime. It is very difficult to troubleshoot ex: when an user says we see a small white color shade on the right side of the screen whatever code we check in visual studio will not provide an answer.

Now comes a tool that helps it is call IE Developer ToolBar from Microsoft- http://www.microsoft.com/downloadS/details.aspx?familyid=E59C3964-672D-4511-BB3E-2D5E1DB91038&displaylang=en

good tool to help and increase your productivity.  Thanks

Posted in C#, Tools | Leave a Comment »

Installation issue with ASP.NET MVC Release candidate 2

Posted by dotnetinfo on March 12, 2009

I had tried to install MVC RC 2.0 process failed because of unknown errors. I got frustrated, lucky me  Phil Haack article explanined the issue http://haacked.com/archive/2009/03/06/hotfix-for-installing-aspnetmvc.aspx

I uninstalled clone detective MVC installed ok and i am able to create a project.

Thanks

Posted in C#, MVC | Leave a Comment »

c# Evaluate string expression

Posted by dotnetinfo on February 10, 2009

I was assigned to write a code to evaluate some rule and role based data from database and create entitlements.

I thought it will be easy process to eval the string expressions, then i came to know c# (2.0) does not have eval .. Do i need to write my own compiler..

Noooo google is your friend i came across the code that matches my requirement:

http://www.egilh.com/blog/archive/2006/10/02/3062.aspx thanks eglih.

I modified 2 lines of code as mentioned in the document

//compiler = new JScriptCodeProvider().CreateCompiler();

 

 CodeDomProvider provider = CodeDomProvider.CreateProvider(“JScript”);

….. 

 CompilerResults results;  

 //results = compiler.CompileAssemblyFromSource(parameters, _jscriptSource);

results = provider.CompileAssemblyFromSource(parameters, _jscriptSource);

Posted in C# | Leave a Comment »

Saving BLOB more than 32K

Posted by dotnetinfo on October 29, 2008

What method to follow to save a BLOB from .NET to Oracle if the content is more than 32K?

If the content is a string convert the string the Bytes System.Text.

Encoding.ASCII.GetBytes(stringValue)  and Split the Binary to 32k chunks using append logic to add or update

ex: First time calling the chunk insert then update

Posted in C#, Database | Leave a Comment »

c# Reflection or Verbs or Design Time help document

Posted by dotnetinfo on October 29, 2008

The article explains how to use reflection to view resource data or how to use verbs to display design time help documents

As always thousand ways to implement something so use the document as a path not as a pattern

Step 1 : Create a HTML/XML/ …. file and Set Build Action to Embedded Resources

 

Step 2 :  Create a windows form with the example code to read the data from assembly

 

private void LoadData(string ResourcePath)

        {                                   

            try

            {

                

                if (!String.IsNullOrEmpty(ResourcePath))

                {

                   

                    Assembly assembly = Assembly.GetExecutingAssembly();

                    StreamReader sr = new StreamReader(assembly.GetManifestResourceStream(ResourcePath));

                    if (sr == null)

                        MessageBox.Show(“Resource is null for “ + ResourcePath);

                    string partialContent = sr.ReadToEnd();                   

                    DataDetails.Text = partialContent;                   

                    GenericHelp.ActiveForm.Activate();

                }

                else

                {

                    MessageBox.Show(“ResourcePath not assigned for display”);

                }

               

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message.ToString());

            }

           

           

        }

 

Step 3: In VersionControlDesigner in Designers add a new control desginer

 

public class SomeControlDesigner : ControlDesigner

      {

        public override System.ComponentModel.Design.DesignerVerbCollection Verbs

        {

            get

            {

                DesignerVerbCollection v = new DesignerVerbCollection();

                v.Add(new DesignerVerb(“Help link”, new EventHandler(HelpVerbHandler)));

                return v;

            }

        }

 

        private void HelpVerbHandler(object sender, System.EventArgs e)

        {

 

            OpenForm();

 

        }

 

        // write process to open web form

        private void OpenForm()

        {

            // Resource Path need to be passed with intialization

            GenericHelp gh = new GenericHelp(“Full file name – Case Sensitive”);                                        

            gh.ShowDialog();

        }

 

 

Step 4 :  In SomeControl.cs add a attribute –

[Designer(typeof(NameSpace.SomeControlDesigner))]

 

Step 5 : In Designer mode , view property window you will see a link and Click on the link will open window form

Posted in C#, Design Time, Reflection | Leave a Comment »

Creating Help Links for Custom Controls using Verbs

Posted by dotnetinfo on September 10, 2008

.NET 2.0 provided an attribute to add to custom control. The Attribute used for the Help Link is Designer. The Designer is used in calendar control to create custom links. The idea can be used in multiple ways. The code explains an idea how to create help links on your custom controls.

 

Note: Code is not a complete code; the code provides an idea how to achieve the functionality. I might have renamed some objects to hide proprietary company names.

 

 

 

[Designer(typeof(CustomLabelDesigner))]   

[HelpAttribute("http://internalsite.company.com/CustomLabel")]

public class CustomLabel : System.Web.UI.WebControls.Label

 

In CustomLabelDesigner.cs Inherited from ControlDesigner

 

public class CustomLabelDesigner: ControlDesigner

{

 

……………

…………..

………….

public override System.ComponentModel.Design.DesignerVerbCollection Verbs

{

get

{

DesignerVerbCollection v = new DesignerVerbCollection();               

v.Add(new DesignerVerb(“Help link”, new EventHandler(HelpVerbHandler)));                   

                return v;

}

}

 

private void HelpVerbHandler(object sender, System.EventArgs e)

{

 

// Creates a new form.

            CustomLabel myLabel = new CustomLabel ();

 

// Gets the attributes for the collection.

System.ComponentModel.AttributeCollection attributes = TypeDescriptor.GetAttributes(myLabel);

 

//retrieve HelpAttribute

HelpAttribute attrib = (HelpAttribute)Attribute.GetCustomAttribute(typeof(CustomLabel), typeof(HelpAttribute));           

           

//Display Data                                              

System.Diagnostics.Process.Start(attrib.Url.ToString());

           

}

 

………………

 

Add a new HelpAttribute.cs

 

using System;

using System.Collections.Generic;

using System.Text;

 

namespace SomeName.Company.Code

{

    [AttributeUsage(AttributeTargets.Class)]

    class HelpAttribute : System.Attribute

    {

        public readonly string Url;

      

        public HelpAttribute(string url)  // url is a positional parameter

        {

            this.Url = url;

        }

 

       

    }

}

 

Pictures :

 

Posted in C# | Tagged: , , | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.