Posts

Showing posts from 2015

TreeView Traversing in c#

To get tree view structure in C# language according to business logic

privateList<string> GetAllSubItems(string ItemId)  {     List<string> ItemIds = newList<string>();     List<ClassName> subItems = null;     var objController = new StorageManager();     subItems = objController.GetAllItemPreAssemblyPickupLocationItem();     System.Func<string, IEnumerable<ClassName>,                  IEnumerable<ClassName>> getItems = null;     getItems = (strItemId, Items) => Items.Where(x => x.ItemId == strItemId).     SelectMany(x => getItems(x.SubItemId, Items).Concat(new ClassName[] { x }));     var allItems = getItems(ItemId, subItems);     if (allItems != null && allItems.Count() > 0)         allItems.ToList().ForEach(x => { ItemIds.Add(x.ItemId); ItemIds.Add(x.SubItemId); });     return ItemIds.Distinct().ToList(); }

How to change the ForeColor of individual items in a ComboBox in C# Winforms

Image
//SET COMBOBOXBOX PROPERTY TO DRAWMODE =>Ownerdrawfixed or Ownerdravariable
 private void cmbColour_DrawItem(object sender, DrawItemEventArgs e)
        {
            try
            {    
               YourClassName  presenter =new YourClassName();    
                presenter.DrawColourCode(sender, e);
            }
            catch (Exception ex)
            {

                    throw ex;

            }
        }

   public void DrawColourCode(object sender, DrawItemEventArgs e)
        {

//HERR I AM USING DATABASE TO FETCH THE COLOURCODE, ,FOREGROUDCOLOUR //AND BACKGROUNDCOLOUR
            float size = 10;
            System.Drawing.Font myFont;
            string backgroundColorCode = Convert.ToString(((sender as ComboBox).Items[e.Index] as ClassEntityName).BackgroundColourCode);
            // Draw the background of the item.
            e.DrawBackground();
            Brush BrsFore = null;
            // Create a square filled with the item color. Vary the size
       …

Add New Column and Index in sql server

Image

Sibling number and get largest number in the family using C#

Image
Following code will illustrate to get largest number from given sibling numbers.

static void Main(string[] args)
        {
            int n2 = 3456789;
            var digits = new List<int>();
            int temp = 0;
            for (; n2 != 0; n2 /= 10)
            {
                digits.Add(n2 % 10);
            }
            var arr2 = digits;
            for (int num = 0; num < arr2.Count; num++)
            {
                for (int sort = 0; sort < arr2.Count - 1; sort++)
                {
                    if (arr2[sort] < arr2[sort + 1])
                    {
                        temp = arr2[sort + 1];
                        arr2[sort + 1] = arr2[sort];
                        arr2[sort] = temp;
                    }
                }
            }

            for (int i = 0; i < arr2.Count; i++)
                Console.Write(arr2[i] + "");
            Console.ReadKey();
        }

Temporarily avoid foreign key constraint in sql server

Image
We can avoid foreign key constraint temporarly by using following code

--ALTER TABLE Station NOCHECK CONSTRAINT MyConstraint

ALTER TABLE TABLE_NAME NOCHECK CONSTRAINT FK_CONSTRAINTNAME

select * from TABLE_NAME where COLUMN_NAME='UPDATEDVALUE'

update TABLE_NAME set COLUMN_NAME='UPDATEDVALUE' where COLUMN_NAME='WHERECONDITION_VALUE'

select * from TABLE_NAME where COLUMN_NAME='WHERECONDITION_VALUE'
-- Enable single constraint

ALTER TABLE TABLE_NAME CHECK CONSTRAINT FK_CONSTRAINTNAME