Wednesday 30 May 2012

How to change silverlight toolkit chart x axis foreground color




use the following xaml code to change the  x  axis  color in the silverlight toolkit chart


   
     <toolkit:Chart Height="auto"  x:Name="ch2" Width="autoStyle="{StaticResource ChartStyle1}">


     <toolkit:Chart.Axes>


      <toolkit:LinearAxis Orientation="X"  Foreground="#FF0F98E0">
      </toolkit:LinearAxis>

      </toolkit:Chart.Axes>

     </toolkit:Chart>



How to change silverlight chart area background


                     
         use  the following style to change  the chart area background

              Style plotarea = new Style(typeof(Grid));
              plotarea.Setters.Add(new Setter(BackgroundProperty, "white"));

              chart.PlotAreaStyle = plotarea;



Dynamically setting Pie Chart DatapointStyle in Silverlight



         Required Namespaces
      
           using System.Windows.Controls.DataVisualization.Charting;
           using System.Windows.Controls.DataVisualization;
               
         first create a chart using the chart class and create the pie series 
              
            Chart  piechart = new Chart();
            PieSeries   ps  = new PieSeries();
                         
         Then map the pieseries to data,here i have used four records ,so  the pie chart
         will have four slices.                

            List<data> DAT = new List<data>();
            DAT.Add(new data() { project="project1",completed=50 });
            DAT.Add(new data() { project = " project2 ", completed = 100 });
            DAT.Add(new data() { project = " project3 ", completed = 20 });
            DAT.Add(new data() { project = " project4 ", completed = 10 });
             
            ps.IndependentValuePath = "project";
            ps.DependentValuePath  = "completed"; 
            ps.ItemsSource = DAT;

            public class data
                {
                     public string project{get;set;}
                     public int completed{get;set;}
                }

         Now u need to create multiple styles for the pie chart DataPoint,
         each style will be applied to each slice in the pie chart.

         Each  Style must be enclosed in ResourceDictionary class   

            ResourceDictionary rs1 = new ResourceDictionary();
            Style datapointstyle1 = new Style(typeof(DataPoint));
            datapointstyle1.Setters.Add(new Setter(BackgroundProperty, "#FF42B444"));
            datapointstyle1.Setters.Add(new Setter(OpacityProperty,"0.8"));
            rs1.Add("DataPointStyle",datapointstyle1);

            ResourceDictionary rs2 = new ResourceDictionary();
            Style datapointstyle2 = new Style(typeof(DataPoint));
            datapointstyle2.Setters.Add(new Setter(BackgroundProperty, "#FFF73110"));
            datapointstyle2.Setters.Add(new Setter(OpacityProperty, "0.8"));
            rs2.Add("DataPointStyle", datapointstyle2);

            ResourceDictionary rs3 = new ResourceDictionary();
            Style datapointstyle3 = new Style(typeof(DataPoint));
            datapointstyle3.Setters.Add(new Setter(BackgroundProperty, "Blue"));
            datapointstyle3.Setters.Add(new Setter(OpacityProperty, "0.8"));
            rs3.Add("DataPointStyle", datapointstyle3);

            ResourceDictionary rs4 = new ResourceDictionary();
            Style datapointstyle4 = new Style(typeof(DataPoint));
            datapointstyle4.Setters.Add(new Setter(BackgroundProperty, "Gray"));
            datapointstyle4.Setters.Add(new Setter(OpacityProperty, "0.8"));
            rs4.Add("DataPointStyle", datapointstyle4);

         Now we add all the resource dictionaries to a single collection,the
         ResourceDictionaryCollection

            ResourceDictionaryCollection coll = new ResourceDictionaryCollection();

            coll.Add(rs1);
            coll.Add(rs2);

            coll.Add(rs3);
            coll.Add(rs4);

         finally we are going to apply the styles to the piechart
                           
            piechart.Pallete = coll;
            
         Now add the Pie Series to the PieChart

             piechart.Series.Add(ps); 
            

Tuesday 29 May 2012

Changing ADS User Password Programatically



   First you need to include the reference

            using  System.DirectoryServices;


   then create an object  for the DirectoryEntry Class

        DirectoryEntry de = new DirectoryEntry ();


   Now set  the properties for the DirectoryEntry Object,you  need
   to provide administrative previleges such as UserName and Password.

        de.Path     =    ldap://dc=Name,dc=net/;

        de.Username =   "admin";

        de.Password =   "12345";

        de.AuthenticationType = AuthenticationTypes.Secure;

   Now using a directory searcher we will retrive all the users in the ADS
   the result from directory searcher is placed in a searchresultcollection.

        DirectorySearcher 
desearch = new DirectorySearcher(de); 

        desearch.SearchRoot = de;
        SearchResultCollection 
result;

        result = desearch.FindAll();


   From the SearchResultCollection,using for loop we find the appropriate user 
   that we  want to change the  password for, then we invoke  the setpassword 
   method of the particular Directory  Entry to change the password.
  

        foreach (SearchResult s in result)
         {
            DirectoryEntry 
d = s.GetDirectoryEntry();

            d.Username = "admin";
            d.Password = "12345";

            d.AuthenticationType =
 AuthenticationTypes.Secure;

            if (d.Properties["Name"].Value.ToString() == "username")
             {


                d.Invoke("SetPassword", new object[] { pass });
                d.CommitChanges();

             }


           }