Posts

Showing posts from February, 2011

WPF ComboBox & ListView Load From Database

Combox load & Listview load for our application is one of the most important task in our Development.
For ComboBox:


 private void LoadVendorTYpeComboBox()
        {
            vendorTYpecomboBox.Items.Clear();
            ObjVendorTypeList = ObjBvendorType.GetAllVendirType();
            foreach (EVendorType obj in ObjVendorTypeList)
            {
                vendorTYpecomboBox.Items.Add(obj.VendorType);
            }


        }

For ListView:
 private void LoadVendorTypeListView()         {             vendorTypelistView.Items.Clear();             ObjVendorTypeList = ObjBvendorType.GetAllVendirType();             foreach (EVendorType obj in ObjVendorTypeList)             {                 vendorTypelistView.Items.Add(obj);             }         }
for listview you have to bind the object in list column.
<GridViewColumn DisplayMemberBinding="{Binding Path=VendorType}"  Header="Vendor Type" Width="100"/>
Enjoy...

WPF Message Box

Hay Guy's Sometime we are forgate how to write message box to perform operation. it's quite simple

MessageBox.Show("Are you sure want to Delete this?", "Confirmation", MessageBoxButton.YesNo) == MessageBoxResult.Yes

WPF Listview selection item change

List view selection change is one of interesting matter in WPF. When you will select the item from list view. It will automatically fill field of the corrosponding item. Consider the following Selection change Event:

 private void unitNamelistView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (unitNamelistView.SelectedIndex > -1)
            {
   /*====Setting Selected item in Entity=====*/
                EUnitMeasurement seletedUnit = (EUnitMeasurement)unitNamelistView.SelectedItem;
                /*==== Filling UI Field From entity======*/
    unitIDtextBox.Text = seletedUnit.Id;
                unitAbbrivationtextBox.Text = seletedUnit.UnitName;
                fullNameUnittextBox.Text = seletedUnit.FullNameOfUnit;
                unitCommenttextBox.Text = seletedUnit.UnitComment;
               }
        }

Enjoy....!!



WPF Text Change value will Auto select Listview item

if you want to select Listview item in Textfield value change you can do it by the code in text Change Event:


private void textBox1_TextChanged(object sender, TextChangedEventArgs e) { string typeID = textBox1.Text; for (int i = 0; i < unitNamelistView.Items.Count; i++) { EUnitMeasurement aWHType = (EUnitMeasurement)unitNamelistView.Items[i]; if (aWHType.UnitName == typeID) { unitNamelistView.SelectedIndex = i; break; } } }

WPF Get All Country in Combobox

To Get all Country Name in your program now you no need to use Enum or load from Database. Microsoft .NET give All Country Name using this code.
** You need to use namesapce: using System.Globalization;
Create a Method in Load event of your UI and Implement it as Following:

    private void PopulateCountryComboBox()
        {
            RegionInfo country = new RegionInfo(new CultureInfo("en-US", false).LCID);
            List<string> countryNames = new List<string>();
            foreach (CultureInfo cul in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
            {
                country = new RegionInfo(new CultureInfo(cul.Name, false).LCID);

                countryNames.Add(country.DisplayName.ToString());
            }

            IEnumerable<string> nameAdded = countryNames.OrderBy(names => names).Distinct();

            foreach (string item in nameAdded)
            {
                supplierCountryComboBox.Items.Add(item);

            …

WPF Google Sample project

This link contain some WPF sample project
http://sites.google.com/site/wpfprojects/

WPF Crystal Report Viewer Using SAP

Image
There is no doubt that we fall a great problem that the VS2010 is not intregated crystal report. Initially it seems to be a big problem. Hare is some step for SAP crystal report that we can use in our WPF application.

1.Download  Crystal report from this Link:
http://scn.sap.com/docs/DOC-7824
2. Remove Crystal report if any exist.
3. Close your VS-2010 and install the new downloaded CRforVS_13_0 .
4. Take a new WPF project




5. Right click on the project click on Properties


6. Change the target framework .NET Framework 4 Client Profile to  .NET Framework 4.


7. Click on main window then click on Toolbox.  Right Click on the General Tab then click on Choose Item.


8. It will appear this window click on WPF Component.


9.  Select CrystalReportsViewer  click on ok  Button.



10. Now you will see the report viewer control.



11. Your Crystal Report Environment is ready. Now we will add Crystal report. Maximum time we use dataset for report source But I Strongly recommend to use your Class as repor…

WPF set Image in UI

byte[] ImgGet ;
  /*image setUp*/
            ImgGet = (byte[])objEVendorInformation.SupplierLogo;
            string strfn = Convert.ToString(DateTime.Now.ToFileTime());
            FileStream fs1 = new FileStream(strfn, FileMode.CreateNew, FileAccess.Write);
            fs1.Write(ImgGet, 0, ImgGet.Length);
            fs1.Flush();
            fs1.Close();
            ImageSourceConverter imgs = new ImageSourceConverter();
            SupplierLogoimage.SetValue(Image.SourceProperty, imgs.ConvertFromString(strfn));
            /*End Image Setup*/

WPF Pop Up List View

Pop up List view is needed when we want to search from database.

/=============== Button Event==================/

    private void VendorItemListSearchListBoxSelectionChanged_Click(object sender, RoutedEventArgs e)
        {
            vendorItemListPopup.IsOpen = true;
            vendorItemListSearchListBox.Items.Clear();
            try
            {
                List<EVendorItem> listVendorItem = ObjBvendorItem.GetAllVendorList();
                foreach (EVendorItem aEJournalMaster in listVendorItem)
                {
                    vendorItemListSearchListBox.Items.Add(aEJournalMaster);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message, "Vendor List ID Search", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

  /============= Pop up List view Change Event=============/


    private void VendorItemListSearchListBoxSelectionChanged(object sender…

WPF Validator as ajax/ Jquery

You can use wpf validator more smooth as ajax/ jquery. Just complete the following with me.

 Step 1.

       Open A new Window in WPF

Step 2. Add a class Which will provide the Validation

          /************ StringAtikStringValidationRule ************/

using System.Globalization;
using System.Windows.Controls;

namespace WpfApplication4
{
    public class StringAtikStringValidationRule : ValidationRule
    {
        private int _minimumLength = -1;
        private int _maximumLength = -1;
        private string _errorMessage;

        public int MinimumLength
        {
            get { return _minimumLength; }
            set { _minimumLength = value; }
        }

        public int MaximumLength
        {
            get { return _maximumLength; }
            set { _maximumLength = value; }
        }

        public string ErrorMessage
        {
            get { return _errorMessage; }
            set { _errorMessage = value; }
        }

        public override ValidationResult Valida…

UI Field Validation in WPF

UI field validation in WPF is a one of most important. Because when the field can't get the Specific class then it will get Error. So it better to create a CheckField()  for specific Button Event & there you can implement the method as:

/******************* A Button Event *****************/
         private void appointAddButton_Click(object sender, RoutedEventArgs e)
        {
            AddAppointmentInListView();


        }
     /************** Implement AddAppointmentInListView Method*****************/
        private void AddAppointmentInListView()
        {
            try
            {
                if (CheckField())
                {
                    EAppointment objAppointment = new EAppointment();
                    objAppointment.TrackNo = Convert.ToInt64(employeeTrackNoTextBox.Text);
                    objAppointment.InterviewId = Convert.ToInt64(employeeIdTextBox.Text);
                    objAppointment.AppointmentDate =  appointDateDateTimePicker.SelectedDate.Value;
    …

Upload a Picture in WPF UI

Uploading Picture in UI is very Important It is Quite Easy. On upload button Event Write down The following code:

 OpenFileDialog dlg;
                FileStream fs;
               byte[] data;

              dlg = new Microsoft.Win32.OpenFileDialog();

              dlg.ShowDialog();
               if (dlg.FileName == "")
            {
                MessageBox.Show("Picture is not selected......");
            }
            else
            {
                fs = new FileStream(dlg.FileName, FileMode.Open, FileAccess.Read);


                data = new byte[fs.Length];
                fs.Read(data, 0, System.Convert.ToInt32(fs.Length));


                fs.Close();
                ImageSourceConverter imgs = new ImageSourceConverter();
                SupplierLogoimage.SetValue(Image.SourceProperty, imgs.ConvertFromString(dlg.FileName.ToString()));


EnJoy....... !!

Generate Random Number

The Random class defined in the .NET Framework class library provides functionality to generate random numbers.

The Random class constructors have two overloaded forms. It takes either no value or it takes a seed value.

The Random class has three public methods - Next, NextBytes, and NextDouble. The Next method returns a random number, NextBytes returns an array of bytes filled with random numbers, and NextDouble returns a random number between 0.0 and 1.0. The Next method has three overloaded forms and allows you to set the minimum and maximum range of the random number.



                int newTicketNumber;
                int ticketnumber = Convert.ToInt32(lastTicNotextBox.Text);
                Random random =new Random();
                newTicketNumber = random.Next(ticketnumber);
                newticnomtextBox.Text = newTicketNumber.ToString();

MSDN WPF

Windows Presentation Foundation (WPF) is a next-generation presentation system for building Windows client applications with visually stunning user experiences. With WPF, you can create a wide range of both standalone and browser-hosted applications


http://msdn.microsoft.com/en-us/library/aa970268.aspx

WPF Developer Tools

in wpf there are many tools are not support as we do win/Web form. this project is very usefull for WPF control tool.

http://wpfdevelopertools.codeplex.com/