Monday, January 30, 2012

WPF Multiline Textbox

For Multiline  in TextBox we can use a TestBox Like this



We can make a TextBox Control that will support Multiline  by using 2 properties. TextWrapping="Wrap" and AcceptsReturn="True"

The XAML code for this TextBox




 <TextBox Height="131" HorizontalAlignment="Left" Margin="6,6,0,0"   
 Name="educationalInformationTextBox" VerticalAlignment="Top" Width="345" TextWrapping="Wrap" AcceptsReturn="True" />  


Sunday, January 29, 2012

WPF Tab Control Navigation

 Most of time in Tab Control we want navigate one tab to another tab without clicking the tab header.

Go to next tab.




Back to the previous tab.

it's easy, in your event just use tabname.selected= true.


 private void empInformationBackButton_Click(object sender, RoutedEventArgs e)  
     {  
       tabItemPersonalInfo.IsSelected = true;  
     }  

Monday, January 23, 2012

WPF DataGrid XAML Binding

DataGrid in one of the powerfull control in WPF. we can easily load our Datagrid if we bind the DataGrid with our Class property. consider the DataGrid.


To bind this DataGrid i have use this class & hare i also Implement INotifyPropertyChanged property for datagrids cell property change event. hare Apv from & Apv To Datepicker change event will change the value of Apv Days.




  

   public class ELeaveApprove : INotifyPropertyChanged  
   {  
     public long Appr_LeaveId { get; set; }  
     public string Appr_LeaveType { get; set; }  
     public int? Appr_RemainLeave { get; set; }  
     public DateTime Appr_FromDate { get; set; }  
     public DateTime Appr_ToDate { get; set; }  
     public string Appr_Action { get; set; }  
     public long Appr_EmpId { get; set; }  
     public int? Apply_Day { get; set; }  
     public string Appr_Status { get; set; }  
     private int apvNoOfdays;  
     public string Emp_Name { get; set; }  
     public string Emp_Department { get; set; }  
     public string Department_Name { get; set; }  
     public string Designation_Name { get; set; }  
     public long Apply_ID { get; set; }  
     public int Appr_TotalLeave  
     {  
       get  
       {  
         return this.apvNoOfdays;  
       }  
       set  
       {  
         if (value != this.apvNoOfdays)  
         {  
           this.apvNoOfdays = value;  
           NotifyPropertyChanged("Appr_TotalLeave");  
         }  
       }  
     }  
     private void NotifyPropertyChanged(string info)  
     {  
       if (PropertyChanged != null)  
       {  
         PropertyChanged(this, new PropertyChangedEventArgs(info));  
       }  
     }  
     public event PropertyChangedEventHandler PropertyChanged;  
   }  
XAML:

      <DataGrid AutoGenerateColumns="False" Height="264" HorizontalAlignment="Left" Margin="2,1,0,0" Name="approveDataGrid" VerticalAlignment="Top" Width="1033" CanUserAddRows="False">  
           <DataGrid.Columns>  
             <DataGridTextColumn Header="Apply Id" Binding="{Binding Path=Apply_ID}" Width="70"/>  
             <DataGridTextColumn Header="Name" Binding="{Binding Path=Emp_Name}" Width="70"/>  
             <DataGridTextColumn Header="Department" Binding="{Binding Path=Department_Name}" Width="70"/>  
             <DataGridTextColumn Header="Designation" Binding="{Binding Path=Designation_Name}" Width="70"/>  
             <DataGridTextColumn Header="Leave For" Binding="{Binding Path=Appr_LeaveType}" Width="70"/>  
             <DataGridTextColumn Header="Apy Day's" Binding="{Binding Path=Apply_Day}" Width="70"/>  
             <DataGridTextColumn Header="Apy From " Binding="{Binding Path=Appr_FromDate,StringFormat={}{0:MM/dd/yyyy}}" Width="70"/>  
             <DataGridTextColumn Header="Apy To " Binding="{Binding Path=Appr_ToDate,StringFormat={}{0:MM/dd/yyyy}}" Width="70"/>  
             <DataGridTemplateColumn Header="Status" Width="70">  
               <DataGridTemplateColumn.CellTemplate>  
                 <DataTemplate>  
                   <Border x:Name="brdBroder" VerticalAlignment="Stretch" Margin="1">  
                     <TextBlock Text="{Binding Appr_Status}" Margin="3,1" x:Name="txtTextBlock"/>  
                   </Border>  
                   <DataTemplate.Triggers>  
                     <DataTrigger Binding="{Binding Appr_Status}" Value="Pending">  
                       <Setter TargetName="brdBroder" Property="Background" Value="Green"/>  
                       <Setter TargetName="txtTextBlock" Property="Foreground" Value="White"/>  
                     </DataTrigger>  
                   </DataTemplate.Triggers>  
                 </DataTemplate>  
               </DataGridTemplateColumn.CellTemplate>  
             </DataGridTemplateColumn>  
             <DataGridTemplateColumn Header="Apv From" Width="100">  
               <DataGridTemplateColumn.CellTemplate>  
                 <DataTemplate>  
                   <TextBlock Text="{Binding Path=Appr_FromDate, Mode=TwoWay,StringFormat={}{0:MM/dd/yyyy}}" />  
                 </DataTemplate>  
               </DataGridTemplateColumn.CellTemplate>  
               <DataGridTemplateColumn.CellEditingTemplate>  
                 <DataTemplate>  
                   <DatePicker Text="{Binding Path=Appr_FromDate,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"  
                 SelectedDate="{x:Static System:DateTime.Now}" SelectedDateChanged="DatePicker_SelectedDateChanged_1"/>  
                 </DataTemplate>  
               </DataGridTemplateColumn.CellEditingTemplate>  
             </DataGridTemplateColumn>  
             <DataGridTemplateColumn Header="Apv To " Width="100">  
               <DataGridTemplateColumn.CellTemplate>  
                 <DataTemplate>  
                   <TextBlock Text="{Binding Path=Appr_ToDate, Mode=TwoWay,StringFormat={}{0:MM/dd/yyyy}}" />  
                 </DataTemplate>  
               </DataGridTemplateColumn.CellTemplate>  
               <DataGridTemplateColumn.CellEditingTemplate>  
                 <DataTemplate>  
                   <DatePicker Text="{Binding Path=Appr_ToDate,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"  
                 SelectedDate="{x:Static System:DateTime.Now}" SelectedDateChanged="DatePicker_SelectedDateChanged"/>  
                 </DataTemplate>  
               </DataGridTemplateColumn.CellEditingTemplate>  
             </DataGridTemplateColumn>  
             <DataGridTextColumn Header="Apv Day" Binding="{Binding Path=Appr_TotalLeave}" Width="70"/>  
             <DataGridTemplateColumn Header="Action" Width="120">  
               <DataGridTemplateColumn.CellTemplate>  
                 <DataTemplate>  
                   <TextBlock Text="{Binding Path=Appr_Action}"/>  
                 </DataTemplate>  
               </DataGridTemplateColumn.CellTemplate>  
               <DataGridTemplateColumn.CellEditingTemplate>  
                 <DataTemplate>  
                   <ComboBox SelectedItem="{Binding Path=Appr_Action}" Name="cmbLeaveType" ItemsSource="{Binding Source={StaticResource ResourceKey=LeaveApproveActionList}}" Text="Appr_Action"/>  
                 </DataTemplate>  
               </DataGridTemplateColumn.CellEditingTemplate>  
             </DataGridTemplateColumn>  
           </DataGrid.Columns>  
         </DataGrid>  

        

Cast the DataGrid With Class for Get DataGrid Value :

 List<ELeaveApprove> leaveApvList = new List<ELeaveApprove>();  
       for (int i = 0; i < approveDataGrid.Items.Count; i++)  
       {  
         ELeaveApprove eLeaveApproveObj = (ELeaveApprove)approveDataGrid.Items[i];  
         if (eLeaveApproveObj.Appr_Action == "Approve")  
         {  
           leaveApvList.Add(eLeaveApproveObj);  
         }  
         if (eLeaveApproveObj.Appr_Action == "Reject")  
         {  
           leaveApvList.Add(eLeaveApproveObj);  
         }  
       }  


Using leaveApvList you can also filter you datagrid value.






Thursday, January 19, 2012

Get Number of Day from Two Datetime Picker Value

We can easily find out the Total number of day from Two Datetime Picker value using TimeSpan

  int totalDay=0;  
  TimeSpan ts = new TimeSpan(Convert.ToDateTime(objApplyLeave.Apply_ToDate).Ticks - Convert.ToDateTime(objApplyLeave.Apply_FromDate).Ticks);  
   totalDay = ts.TotalDays + 1 ;  

Thursday, January 12, 2012

Google style Searching in WPF

Hi,
       In your WPF application you can use search style like as google. Like the images when you are type in a Textbox  for search.


and your matching data will load in Employee list:


this can be done on Textchange event. hare i use textbox for type, listbox for load type matches data & the Listview for displaying the final data.

Text Change Event:


   private void searchEmployeeCodeTextBox_TextChanged(object sender, TextChangedEventArgs e)  
     {  
       employesLstView.Items.Clear();  
       if (searchEmployeeCodeTextBox.Text != "")  
       {  
         empObj.EmployeeCode = searchEmployeeCodeTextBox.Text.Trim();  
         List<EEmployeeInfo> employeeInfos = new List<EEmployeeInfo>();  
         employeeInfos = bEmployeeObj.listshowEmployeeCodeWise(empObj);  
         if (employeeInfos.Count > 0)  
         {  
           if (employeeInfos.Count != 1)  
           {  
             employeeCodeListBox.Visibility = Visibility.Visible;  
             foreach (var obj in employeeInfos)  
             {  
               employeeCodeListBox.Items.Add(obj.EmployeeCode + "(" + obj.EmployeeName + ")");  
             }  
           }  
           else  
           {  
             GetSingleEmployeeInfo();  
             employeeCodeListBox.Visibility = Visibility.Hidden;  
           }  
         }  
         else  
         {  
           employeeCodeListBox.Visibility = Visibility.Hidden;  
         }  
       }  
       else  
       {  
         PopulateEmployeeList();  
         employeeCodeListBox.Visibility = Visibility.Hidden;  
       }  
     }  

Implement GetSingleEmployee() Method

     private void GetSingleEmployeeInfo()  
     {  
       List<EEmployeeInfo> employeeInfosList = new List<EEmployeeInfo>();  
       try  
       {  
         empObj.EmployeeCode = searchEmployeeCodeTextBox.Text.Trim();  
         employeeInfosList = (List<EEmployeeInfo>)bEmployeeObj.GetSelectedEmployeesCodeInfo(empObj);  
       }  
       catch (Exception ex)  
       {  
        MessageBox.Show(ex.Message, "Single Employee Info.", MessageBoxButton.OK, MessageBoxImage.Information);  
       }  
       if (employeeInfosList.Count > 0)  
       {  
         foreach (EEmployeeInfo employeeInfo in employeeInfosList)  
         {  
           employesLstView.Items.Add(employeeInfo);  
         }  
       }  
     }  

Listbox Event 1

   private void employeeCodeListBox_PreviewKeyDown(object sender, KeyEventArgs e)  
     {  
       if (employeeCodeListBox.SelectedIndex == 0 && e.Key == Key.Up)  
       {  
         searchEmployeeCodeTextBox.Focus();  
       }  
       if (employeeCodeListBox.SelectedIndex > -1)  
       {  
         if (e.Key == Key.Enter)  
         {  
           string[] id = (employeeCodeListBox.SelectedItem.ToString()).Split('(');  
           searchEmployeeCodeTextBox.Text = id[0];  
         }  
       }  
     }  

Listbox Event

   private void employeeCodeListBox_MouseDoubleClick(object sender, MouseButtonEventArgs e)  
     {  
       if (employeeCodeListBox.SelectedIndex > -1)  
       {  
         string[] id = (employeeCodeListBox.SelectedItem.ToString()).Split('(');  
         searchEmployeeCodeTextBox.Text = id[0];  
       }  
     }  

Listbox Event 3

  private void searchEmployeeCodeTextBox_PreviewKeyUp(object sender, KeyEventArgs e)  
     {  
       if(employeeCodeListBox.Items.Count>0 && e.Key==Key.Down)  
       {  
         employeeCodeListBox.Focus();  
       }  
     }  

Listbox xaml

  <ListBox Height="100" HorizontalAlignment="Left" Margin="180,61,0,0" Name="employeeCodeListBox" VerticalAlignment="Top" Width="218" PreviewKeyDown="employeeCodeListBox_PreviewKeyDown" MouseDoubleClick="employeeCodeListBox_MouseDoubleClick" />  



Two Global Class

  private BEmployeeInfo bEmployeeObj = new BEmployeeInfo();  
     private EEmployeeInfo empObj = new EEmployeeInfo();  

Employee Class

   public class EEmployeeInfo  
   {  
     public long EmployeeId { get; set; }  
     public string EmployeeCode { get; set; }  
     public string EmployeeName { get; set; }  
     public DateTime DateOfBirth { get; set; }  
     public string PresentAddress { get; set; }  
     public string PermanentAddress { get; set; }  
     public string Email { get; set; }  
     public string Phone { get; set; }  
     public string Mobile { get; set; }  
     public byte[] Photo { get; set; }  
     public byte[] CV { get; set; }  
     public string DepartmentName { set; get; }  
     public string DesignationName { set; get; }  
     public string Location { get; set; }  
     public string SuperiourName { get; set; }  
    }  



For any query please write your comment.

Tuesday, January 10, 2012

Auto Custome ID Generation from SQL Table

Hi, if you have a table which contain a Id field. Such like "10001" If you want to Custom the ID like "EM00001" you can easily manage it using store procedure.

Consider the store Procedure:
 USE [HRMDB]  
 GO  
 /****** Object: StoredProcedure [dbo].[NEW_EMP_CODE_CREATION]  Script Date: 01/10/2012 19:09:58 ******/  
 SET ANSI_NULLS ON  
 GO  
 SET QUOTED_IDENTIFIER ON  
 GO  
 ALTER PROCEDURE [dbo].[NEW_EMP_CODE_CREATION]  
 AS  
 BEGIN  
      SET NOCOUNT ON  
      DECLARE  
           @empID_ID VARCHAR(20),  
           @countRow INT       
      SELECT @countRow=COUNT(*)   
      FROM EMPLOYEE_INFORMATION        
      IF(@countRow<>0)            
           BEGIN  
                DECLARE @num int  
                SELECT @num=(max(CONVERT(int, SUBSTRING( EMP_CODE,3,8)))+1)   
                FROM EMPLOYEE_INFORMATION  
                SET @empID_ID=(SELECT Distinct('EM'+RIGHT ('000000'+ CAST(@num as varchar), 6)) FROM EMPLOYEE_INFORMATION)  
           END  
      ELSE  
           SET     @empID_ID='EM000001'  
      SELECT @empID_ID AS EMP_CODE       
 END  

WPF Popup Window

Hi,

     we can use a WPF Popup window using show dialogBox. Hope code will be clear to you.

  // Main window any event  
  private void LoadListOfEmployee()  
     {  
             // Pop Up window open  
       PopUpEmployeeInfoList objPopupEmployeeList = new PopUpEmployeeInfoList();  
       if (objPopupEmployeeList.ShowDialog() == true)  
       {  
                  EEmployeeInfo eEmoloyeeInfoObj = new EEmployeeInfo();  
                  // Casting Popup window data   
         eEmoloyeeInfoObj = objPopupEmployeeList.employesLstView.SelectedItem as EEmployeeInfo;  
                     // Setting popupwindow data to main window control  
         textEmployeeCode.Text = eEmoloyeeInfoObj.EmployeeCode;  
         tenureEmployeeCodeTextBox.Text = eEmoloyeeInfoObj.EmployeeCode;  
         releaseEmployeeCodeTextBox.Text = eEmoloyeeInfoObj.EmployeeCode;  
       }  
     }  

 // Pop Up window Event  
           // using this.DialogResult = true; popup window replace the control to main window  
            private void employesLstView_KeyDown(object sender, KeyEventArgs e)  
     {  
       if (employesLstView.SelectedIndex > -1)  
       {  
         if (e.Key == Key.Enter)  
         {  
           this.DialogResult = true;  
         }  
       }  
     }  

Tuesday, January 3, 2012

SQL Get all Index create script from Database

To get all script from database as a create new index into another database you can use the following --Get all Index Script SELECT...