Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Saturday, March 22, 2014

Class Library Toolbox Icon

Step 1: 

Create bmp file (16x16) and save as like below.

   ProjectNameSpace.ControlName.bmp

  e.g. Project Name : CustomGrid
        Control Name : MyGridControl

Bmp File Name :  CustomGrid.MyGridControl.bmp

Step 2: Add in Project and Change Build Action Properties to "Embedded Resources".

Stpe 3: Add ToolboxBitmap line in your class file as per screenshot.




Step 4 : Compile your Project as "Class Library".

Step 5:  Add this control in Different Solution Project Toolbox using choose items and icon will display like below ( In Same Project icon can not display).


Download Complete Source : CustomGrid.Zip



Wednesday, January 2, 2013

Capture Screen with Menu

This Application will capture screen with Open Menu. (e.g. File Menu, Windows Start Menu)

It will works with Windows 7 Basic Themes & Aero Themes.

Tuesday, August 9, 2011

RunTime Sum & GroupBy of DataTable using LINQ



            DataTable dt = new DataTable();
            
            dt.Columns.Add("ItemName", typeof(String));
            dt.Columns.Add("SalebyEmployee", typeof(String));
            dt.Columns.Add("ItemRate", typeof(Double));
            dt.Columns.Add("Qty", typeof(Int32));
            dt.Columns.Add("Amount", typeof(Double));

            DataRow oRow = dt.Rows.Add();
            oRow["ItemName"] = "Item No. 1 ";
            oRow["SalebyEmployee"] = "Kalpesh";
            oRow["ItemRate"] = 10;
            oRow["Qty"] = 5;
            oRow["Amount"] = 50;

            oRow = dt.Rows.Add();
            oRow["ItemName"] = "Item No. 2 ";
            oRow["SalebyEmployee"] = "Kalpesh";
            oRow["ItemRate"] = 15;
            oRow["Qty"] = 3;
            oRow["Amount"] = 45;

            oRow = dt.Rows.Add();
            oRow["ItemName"] = "Item No. 3 ";
            oRow["SalebyEmployee"] = "Kalpesh";
            oRow["ItemRate"] = 4;
            oRow["Qty"] = 20;
            oRow["Amount"] = 80;

            oRow = dt.Rows.Add();
            oRow["ItemName"] = "Item No. 1 ";
            oRow["SalebyEmployee"] = "Chirag";
            oRow["ItemRate"] = 10;
            oRow["Qty"] = 20;
            oRow["Amount"] = 200;

            oRow = dt.Rows.Add();
            oRow["ItemName"] = "Item No. 2 ";
            oRow["SalebyEmployee"] = "Chirag";
            oRow["ItemRate"] = 15;
            oRow["Qty"] = 30;
            oRow["Amount"] = 450;

            oRow = dt.Rows.Add();
            oRow["ItemName"] = "Item No. 3 ";
            oRow["SalebyEmployee"] = "Kalpesh";
            oRow["ItemRate"] = 10;
            oRow["Qty"] = 15;
            oRow["Amount"] = 150;

            oRow = dt.Rows.Add();
            oRow["ItemName"] = "Item No. 1 ";
            oRow["SalebyEmployee"] = "Rohit";
            oRow["ItemRate"] = 11;
            oRow["Qty"] = 50;
            oRow["Amount"] = 550;

            oRow = dt.Rows.Add();
            oRow["ItemName"] = "Item No. 2 ";
            oRow["SalebyEmployee"] = "Rohit";
            oRow["ItemRate"] = 10;
            oRow["Qty"] = 20;
            oRow["Amount"] = 200;

            oRow = dt.Rows.Add();
            oRow["ItemName"] = "Item No. 3 ";
            oRow["SalebyEmployee"] = "Rohit";
            oRow["ItemRate"] = 10;
            oRow["Qty"] = 4;
            oRow["Amount"] = 40;

            oRow = dt.Rows.Add();
            oRow["ItemName"] = "Item No. 4 ";
            oRow["SalebyEmployee"] = "Rohit";
            oRow["ItemRate"] = 100;
            oRow["Qty"] = 50;
            oRow["Amount"] = 5000;


var queryResult = from item in dt.AsEnumerable()
                              group item by new { ItemSale = item.Field<String>("ItemName") + "_" + item.Field<String>("SaleByEmployee") } into grp
                              orderby grp.Key.ItemSale
                              select new
                              {
                                  ItemSaleByEmp = grp.Key.ItemSale,
                                  TotalAmount = grp.Sum(i => i.Field<Double>("Amount"))
                              };

                   DataTable dtNew  = queryResult.ToList().ToDataTable();


        public static DataTable ToDataTable(this IList data)
        {
            PropertyDescriptorCollection props =
                TypeDescriptor.GetProperties(typeof(T));
            DataTable table = new DataTable();
            for (int i = 0; i < props.Count; i++)
            {
                PropertyDescriptor prop = props[i];
                table.Columns.Add(prop.Name, prop.PropertyType);
            }
            object[] values = new object[props.Count];
            foreach (T item in data)
            {
                for (int i = 0; i < values.Length; i++)
                {
                    values[i] = props[i].GetValue(item);
                }
                table.Rows.Add(values);
            }
            return table;
        }