Thursday, October 27, 2011

WPF ComboBox Last item should be selected

If we want that our comboBox will select the last item, in combobox loading time then you can use


  private void LoadComboBo()
        {
            comboBox1.Items.Add("Atik");
            comboBox1.Items.Add("Amin");
            comboBox1.Items.Add("Nabab");
            comboBox1.Items.Add("Refat");
            comboBox1.SelectedIndex = comboBox1.Items.Count - 1;
        }

Tuesday, October 25, 2011

C# LINQ INSERT,UPDATE, DELETE, DOES EXIST statement

There is no doubt "LINQ" is much more smart that other. In our development we face complex transaction or logical query for our application. Hare is some common LINQ opration. It is important that your all table should be present in dbml file.  Hare PRODUCT_NAME is the table name, In which i will perform All LINQ operation. Product is the class name which will contain data.  table should contain a Primary Key.

LINQ INSERT:


  public void SaveNewProductName(Product aProduct)  
     {  
       var newProductName = new PRODUCT_NAME  
                    {  
                      NAME = aProduct.ProductName  
                    };  
       dataContexObj.PRODUCT_NAMEs.InsertOnSubmit(newProductName);  
       dataContexObj.SubmitChanges();  
     }  


LINQ DOESEXIST:


  public bool DoesExistProductName(Product aProduct)  
     {  
       return (dataContexObj.PRODUCT_NAMEs.Any(o => o.NAME.Contains(aProduct.ProductName)));  
     }  


LINQ UPDATE:


 public void UpdateProductName(Product aProduct)  
     {  
       var product = dataContexObj.PRODUCT_NAMEs.First(c => c.ID == aProduct.Id);  
       product.NAME = aProduct.ProductName;  
       dataContexObj.SubmitChanges();  
     }  


LINQ DELETE:



 public void DeleteProductName(Product aProduct)  
     {  
       PRODUCT_NAME productName = dataContexObj.PRODUCT_NAMEs.First(c => c.ID == aProduct.Id);  
       dataContexObj.PRODUCT_NAMEs.DeleteOnSubmit(productName);  
       dataContexObj.SubmitChanges();  
     }  



LINQ GETALL FROM TABLE:



 public List<Product> GetAllProductName()  
     {  
       List<Product> products = new List<Product>();  
       foreach (var p in (from j in dataContexObj.PRODUCT_NAMEs select new { j.ID, j.NAME }).Distinct())  
       {  
         Product aProduct = new Product();  
         aProduct.ProductName = p.NAME;  
         aProduct.Id = (int)p.ID;  
         products.Add(aProduct);  
       }  
       return products;  
     }  


Enjoy...




Saturday, October 22, 2011

How to use code in blogspot

 You can easily use your code spinet in your blog. Follow the link:

http://codeformatter.blogspot.com/2009/06/about-code-formatter.html#comment-form

Hare it is important You have paste your formatted code on your  Blog in  edit HTML view.

Enjoy...

Friday, October 21, 2011

WPF DataGrid Cell Color Change

DataGrid's ROW & CELL color Changing is one of most important part in our development. if you want to change Data grid specific cell Background just like:


use the xaml code for "Remaining Day" column in your Datagrid.

 <DataGridTemplateColumn Header="Remaining Day" Width="150">  
           <DataGridTemplateColumn.CellTemplate>  
                <DataTemplate>  
                     <Border x:Name="brdBroder" VerticalAlignment="Stretch" Margin="1">  
                          <TextBlock Text="{Binding RemainLeave}" Margin="3,1" x:Name="txtTextBlock"/>  
                     </Border>  
                     <DataTemplate.Triggers>  
                          <DataTrigger Binding="{Binding RemainLeave}" Value="0">  
                               <Setter TargetName="brdBroder" Property="Background" Value="Green"/>  
                               <Setter TargetName="txtTextBlock" Property="Foreground" Value="White"/>  
                          </DataTrigger>  
                     </DataTemplate.Triggers>  
                </DataTemplate>  
           </DataGridTemplateColumn.CellTemplate>  
      </DataGridTemplateColumn>  

Enjoy...

C# LINQ Search between date

The SQL BETWEEN operator we can use in C# code. Before your query you have to use
System.Globalization.CultureInfo culInfo = new System.Globalization.CultureInfo("en-US");  


Consider the Example:
internal List<ECalendarSetup> GetCalenderInfoOnSelectedDate(ECalendarSetup calendarSetup)
        {
            ieclHrmDataContext = new IECL_HRMDataContext();
            List<ECalendarSetup> calendarSetupsList = new List<ECalendarSetup>();
            var query = from j in ieclHrmDataContext.HR_CALENDAR_INFOs
                        where j.CAL_DAY_DATE >= calendarSetup.FromDate && j.CAL_DAY_DATE <= calendarSetup.ToDate
                        select j;
            foreach (var calendarInfo in query)
            {
                ECalendarSetup eCalendarSetup = new ECalendarSetup();
                eCalendarSetup.Date = (DateTime) calendarInfo.CAL_DAY_DATE;
                eCalendarSetup.DayStatus = calendarInfo.CAL_DAY_STATUS;
                eCalendarSetup.StartTime = calendarInfo.CAL_START_TIME.ToString();
                eCalendarSetup.EndTime = calendarInfo.CAL_END_TIME.ToString();
                eCalendarSetup.Remarks = calendarInfo.CAL_REMARKS;
                calendarSetupsList.Add(eCalendarSetup);
            }  
            return calendarSetupsList;
        }






Enjoy....

Thursday, October 20, 2011

C# string split & LINQ operation

Spliting string in C# is one of the most interesting part. you can also perform your business logic operation on spliting part.
Hare is a list of serial no comes from database, i split the Serial no then just increment id no +1 on maximum serial no, and return to UI.
i also check hare is the serial no is in current year.



 internal string GetNewSerialNo()  
     {  
       string refence = "";  
       DateTime dt = DateTime.Now;  
       List<RFQ> _listAllRef =new List<RFQ>();  
       foreach (var objrfq in rfqDalObj.GetNewSerialNo())  
       {  
         string[] splitedRef = (objrfq.SerialNO).Split('-');  
         if(DateTime.Now.Year.ToString()==splitedRef[1])  
         {  
           _listAllRef.Add(objrfq);  
         }  
       }  
       List<int> rfqSerials = new List<int>();  
       if (_listAllRef.Count > 0)  
       {  
         foreach (var obj in _listAllRef)  
         {  
           string[] splitedRef = (obj.SerialNO).Split('-');  
           string[] splitedMainId = splitedRef[0].Split('Q');  
           rfqSerials.Add(Convert.ToInt32(splitedMainId[1]));  
         }  
         refence = "RFQ"+ (rfqSerials.Max() + 1) + "-" + dt.Year;  
       }  
       else  
       {  
         refence = "RFQ10001" + "-" + dt.Year;  
       }  
       return refence;  
     }  

Enjoy...

Monday, October 17, 2011

WPF Common Programming

ListView Binding:

 <ListView Height="182" HorizontalAlignment="Left"  
  Name="foodSaleslistView" VerticalAlignment="Top"  
 Width="503" BorderBrush="#00981010" Margin="2,1,0,0">  
  <ListView.View>  
        <GridView>  
           <GridViewColumn DisplayMemberBinding="{Binding Path=FoodName}" Header="Food name" Width="250" />  
               <GridViewColumn DisplayMemberBinding="{Binding Path=Qty}" Header="Quantity" Width="100" />  
               <GridViewColumn DisplayMemberBinding="{Binding Path=TotalPrice}" Header="Total price" Width="150" />  
             </GridView>  
        </ListView.View>  
      </ListView>  

Get Data From ListView:


  for (int i = 0; i < headlistView.Items.Count; i++)  
       {  
         EStock anStock = headlistView.Items[i] as EStock;  
         if (i==0)  
         {  
           anStock.Qty = Convert.ToInt32(textBox1.Text);  
         }  
         else if (i == 1)  
         {  
           anStock.Qty = Convert.ToInt32(textBox2.Text);  
         }  
         else  
         {  
           anStock.Qty = Convert.ToInt32(textBox3.Text);  
         }  
         stockManagerObj.MoveToBranch(anStock);  
       }  

Load ListView:


 headlistView.Items.Clear();  
       foreach (EStock stock in stockManagerObj.GetAllHeadofficeStock())  
       {  
         headlistView.Items.Add(stock);  
       }  


LINQ GetAll From Table:


  List<EStock> headList = new List<EStock>();  
       var queery = from head in dataContex.HeadStocks  
             select new {head.TrNo, head.ItemCode, head.ItemName, head.Qty};  
       foreach (var hOffice in queery)  
       {  
         EStock eStock = new EStock();  
         eStock.Tr_No = hOffice.TrNo;  
         eStock.ItemCode = hOffice.ItemCode;  
         eStock.ItemName = hOffice.ItemName;  
         eStock.Qty = (int) hOffice.Qty;  
         headList.Add(eStock);  
       }  
       return headList;  


LINQ Does Exist:


  internal bool DoesExist(EStock anStock)  
     {  
       return (dataContex.BranchStocks.Any(o => o.ItemCode.Contains(anStock.ItemCode) && o.TrNo.Contains(anStock.Tr_No)));  
     }  

Sunday, October 9, 2011

Convert TEXT file in to CSV file using Excel

It's really great that you can convert text file in CSV file using Excel. Thn you can save this data in SQL Database. Hare is the link:

Enjoy...

Wednesday, October 5, 2011

WPF 4 Updated Information

There is many new functionality added in WPF 4 Like Visual tree,State Manager,VSM, Touch & manioulation, Graphics & Animation and much more.
 By the following Link You can get idea:

http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/d3d6b7ec-71f9-4011-afc5-0bf3956e6d78#x__Toc265507378

Enjoy.

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...