Thursday, May 31, 2012

Formatting Date column of WPF XamDataGrid


xmlns:igEditors="http://infragistics.com/Editors"
xmlns:sys="clr-namespace:System;assembly=mscorlib"

 <Style TargetType="{x:Type igEditors:XamTextEditor}" x:Key="TheDateStyle">
        <Setter Property="Format" Value="dd/MMMM/yyyy" />
 </Style>


 <igDP:Field Name="CaseDate" Label="Case Date"  Visibility="Visible" Width="*">
                            <igDP:Field.Settings>
                                <igDP:FieldSettings EditAsType="{x:Type sys:String}"
                            EditorType="{x:Type igEditors:XamTextEditor}"
                            EditorStyle="{StaticResource TheDateStyle}" />
                            </igDP:Field.Settings>
                        </igDP:Field>

Integration of Avay IP Office CTI Link in WPF C# Project and Interoperability Issues


In last I was assigned a task of Avay IP Office CTI Link integration in my WPF C# Project by my client. As Avaya provide SDKs in C++ and VB 6.0 only.  So we can use only Wrapper DLL of SDK in our C# or managed code project. As I have already integrated this Click and Dial functionally in my VB 6 project using   VB 6.0 SDK of Avay IP Office CTI Link. So in order to avoid hurdles using C++ code I decided to use my VB6 SDK code as DLLL.
After compiling the DLL in Visual Studio 6.0 on my XP (32 bit machine) , when I tried to add its reference in WPF project in Visual Studio 2010 installed on Window 7 64 bit operating system I faced following different interoperability issues.
  1.        While adding assemble reference directly in studio I faced " rence to '.dll' could not be added. Please make sure that the file is accessible and that it is a valid assembly or COM component.”
  2. While loading assemble by [ImportDlL()] method I faced “Unable to find an entry point named ...in DLL”
  3.  And once I added reference of DLL in project after processing it by TIBLIB utility  I faced "Retrieving the COM class factory for component with CLSID {F87D03A3-E4DB-4CA1-91D3-4B8254A90C03} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REG DB_E_CLASSNOTREG)).”

So in order to avoid all these hurdles and interoperability issues, I finally got the way of doing all this.

  1. Install Visual Studio 6.O on your 64 bit operating system and don’t forget to run studio as Administrator.
  2. Open the Avaya IP Office SDK project
  3. Make its DLL
  4. Open your Visual Studio 2010 run as Administrator
  5. Open your WPF  project in which you want to integrate the DLL
  6. Add reference of Avaya VB DLL  in the project and compile  it
  7. Make the setup of the project
  8. Don’t forget to run setup as run as administrator


All will be fine and no interoperability hurdles. I have even tested the setup on 32 bit machine build on 64biy machine.

Wednesday, May 23, 2012

How to make WPF Text Block under line and change its fore color programmatically in C#


 TextDecoration _textDecorationUderLine = new TextDecoration();
             Pen _pen = new Pen();
            _pen.Brush = new LinearGradientBrush(Colors.Blue, Colors.Blue, new Point(0, 0.5), new Point(1, 0.5));
            _pen.DashStyle = DashStyles.Solid;
            _textDecorationUderLine.Pen = _pen;
            _textDecorationUderLine.PenThicknessUnit = TextDecorationUnit.FontRecommended;
            TextDecorationCollection _textDecorationCollection = new TextDecorationCollection();
            _textDecorationCollection.Add(_textDecorationUderLine);
            tbPreferredPhoneWork.TextDecorations = _textDecorationCollection;
            tbPreferredPhoneWork.Foreground = Brushes.Blue;

Tuesday, May 22, 2012

Loading Assembly at Runtime through Reflection in C#



 private void CallLaodAssembly()
        {
            string path = @"";
            object[] param = { "1", "5" };
            LoadDllMethod("Project1.Class1", "AddTwoNumbers", path, param);
        }


static int LoadDllMethod(string title_class, string title_void, string path, object[] parameters)
        {
            int _result=0;
            Assembly _assembly = Assembly.LoadFile(path);
            Type _type = _assembly.GetType(title_class);
            if (_type != null)
            {
                MethodInfo _MethodInfo = _type.GetMethod(title_void);
                if (_MethodInfo != null)
                {
                    if (parameters.Length >= 1)
                    {
                        object[] myparam = new object[1];
                        myparam[0] = parameters;
                        _result = (int)_MethodInfo.Invoke(null, myparam);
                    }
                    else
                        _result = (int)_MethodInfo.Invoke(null, null);
                }
             
            }
            return _result;
        }

Retrieving the COM class factory for component with CLSID {F87D03A3-E4DB-4CA1-91D3-4B8254A90C03} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).


I was facing this issue while I want to utilize my VB6 Code as DLL in my WPF application in .NET framework 4.0 and Visual Studio 2010.
While adding VB6.0  DLL reference studio show me the error “A reference to '.dll' could not be added. Please make sure that the file is accessible and that it is a valid assembly or COM component.”
Solution:
Another cause of facing this issue is 32 bit and 64 bit compatibility issue. There is no error while importing DLL in VS2010 installed on a 32 bit machine.

A reference to '.dll' could not be added. Please make sure that the file is accessible and that it is a valid assembly or COM component.


I was facing this issue while I want to utilize my VB6 Code as DLL in my WPF application in .NET framework 4.0 and Visual Studio 2010.
While adding VB6.0  DLL reference studio show me the error “A reference to '.dll' could not be added. Please make sure that the file is accessible and that it is a valid assembly or COM component.”
Solution 1:
I get solved this issue by using “tlbimp” utility. You can find this utility in Installed .NET Bin directory.
tlbimp myCOM.tlb /out:d:\interopAssembly.dll
Solution 2:
Another cause of facing this issue is 32 bit and 64 bit compatibility issue. There is no error while importing DLL in VS2010 installed on a 32 bit machine.

Tuesday, April 24, 2012

Unable to read data from transport connection. The connection was closed


public static string SendHTTP( string webRequest)
        {
            try
            {
                string strPostData = "";

                // Create a request using a URL that can receive a post.
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(webRequest);
                // Set the Method property of the request to POST.
                request.Method = "POST";

                //request.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
               // request.KeepAlive = false;
                request.ProtocolVersion = HttpVersion.Version10;


                // Create POST data and convert it to a byte array.
                string postData = strPostData;
                byte[] byteArray = Encoding.UTF8.GetBytes(postData);
                // Set the ContentType property of the WebRequest.
                request.ContentType = "text/xml";
                // Set the ContentLength property of the WebRequest.
                request.ContentLength = byteArray.Length;
                // Get the request stream.
                Stream dataStream = request.GetRequestStream();
                // Write the data to the request stream.
                dataStream.Write(byteArray, 0, byteArray.Length);
                // Close the Stream object.
                dataStream.Close();
                // Get the response.
                WebResponse response = request.GetResponse();
                // Display the status.
                Console.WriteLine(((HttpWebResponse)response).StatusDescription);
                // Get the stream containing content returned by the server.
                dataStream = response.GetResponseStream();
                // Open the stream using a StreamReader for easy access.
                StreamReader reader = new StreamReader(dataStream);
                // Read the content.
                string responseFromServer = reader.ReadToEnd();

                // Clean up the streams.
                reader.Close();
                dataStream.Close();
                response.Close();
                // Display the content.
                return responseFromServer;

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
                return null;
            }

        }

Thursday, February 23, 2012

how to get the column index of WPF XamDataGrid selected cell?


private void xamOpenTasksDataGrid_CellActivating(object sender, Infragistics.Windows.DataPresenter.Events.CellActivatingEventArgs e)
        {
            //MessageBox.Show(e.Cell.Value.ToString());
            MessageBox.Show(e.Cell.Field.Index.ToString());
        }

How to display Icons and Text in WPF “XamDataGrid” Programmatically.


How to display icons in WPF “XamDataGrid”


 <igDP:XamDataGrid Grid.Row="1" Name="xamPostCloseDataGrid" VerticalAlignment="Stretch" Theme="Office2010Blue">
                                <igDP:XamDataGrid.FieldLayoutSettings>
                                    <igDP:FieldLayoutSettings AutoGenerateFields="False" />
                                </igDP:XamDataGrid.FieldLayoutSettings>
                                <igDP:XamDataGrid.FieldSettings>
                                    <igDP:FieldSettings AllowEdit="False" />
                                </igDP:XamDataGrid.FieldSettings>
                                <igDP:XamDataGrid.FieldLayouts>
                                    <igDP:FieldLayout>
                                        <igDP:Field Name="WorkPhone" Label="Work Phone" Width="*" />
                                        <igDP:UnboundField Label="!" DataType="Image" Width="*"/>
                                        <igDP:UnboundField Label="Status" DataType="Image" Width="*"/>
                                        <igDP:Field Name="MinutesToAppt" Label="Minutes To Appt" Width="*"  />
                                        <igDP:Field Name="LastName" Label="Borrower" Width="*" />
                                        <igDP:Field Name="ApptDateTime" Label="Appt Date/Time" Width="*" />
                                        <igDP:UnboundField Label="Zone"  Width="*"/>
                                        <igDP:Field Name="TimeZoneOffset" Label="Zone"  Visibility="Collapsed" />
                                        <igDP:Field Name="ContractId" Label="Order #" Width="*" />
                                        <igDP:UnboundField Label="Signed"  Width="*" />
                                        <igDP:UnboundField Label="Filed"  Width="*" />
                                        <igDP:Field Name="SignedFlag" Label="SignedFlag" Width="*" />
                                        <igDP:Field Name="FiledFlag" Label="FiledFlag" Width="*" />
                                        <igDP:Field Name="SignerNotes" Label="Notes" Width="*" />
                                    </igDP:FieldLayout>
                                </igDP:XamDataGrid.FieldLayouts>
                            </igDP:XamDataGrid>

-----------------------------------------------------------


 if (xamPostCloseDataGrid.Records.Count > 0)
  {
                    for (int i = 0; i < xamPostCloseDataGrid.Records.Count; i++)
                    {
                        Image iconImage1 = new Image();
                        iconImage1.Width = 20;
                        iconImage1.Height = 20;
                        iconImage1.Margin = new Thickness(5);

                        BitmapImage bi1 = new BitmapImage();
                        bi1.BeginInit();
                        bi1.UriSource = new Uri(@"/Assets/Icons/imgTelephone.png", UriKind.RelativeOrAbsolute);
                        bi1.EndInit();

                        iconImage1.Source = bi1;
                        (xamPostCloseDataGrid.Records[i] as DataRecord).Cells[1].Value = iconImage1;
}
}