Friday, 4 January 2013

Datagridview multiple select Checkbox


  dgvChangeUserName.DataSource = _objProducts.GetAllProductsinUserName(mam._objAdmin.CustomerID, mam._objAdmin.IsAdmin);
Rectangle rect = dgvChangeUserName.GetCellDisplayRectangle(0, -1, true);
                rect.Y = 3;
                rect.X = rect.Location.X + (rect.Width / 4)-2;
                CheckBox checkboxHeader = new CheckBox();
                checkboxHeader.Name = "checkboxHeader";
                //datagridview[0, 0].ToolTipText = "sdfsdf";
                checkboxHeader.Size = new Size(18, 18);
                checkboxHeader.Location = rect.Location;
                checkboxHeader.CheckedChanged += new EventHandler(checkboxHeader_CheckedChanged);
                dgvChangeUserName.Controls.Add(checkboxHeader);




  void checkboxHeader_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox cbx=(CheckBox) sender;

            if (dgvChangeUserName.Rows[0].Cells.Count > 2)
            {
                dgvChangeUserName.Rows[0].Cells[2].Selected = true;
                dgvChangeUserName.Rows[0].Cells[2].Selected = false;
            }
            for (int intLoop = 0; intLoop < dgvChangeUserName.Rows.Count; intLoop++)
            {
               
                dgvChangeUserName.Rows[intLoop].Cells[0].Value = cbx.Checked;
             
            }
           
        }

Wednesday, 2 January 2013

First Time Load Display Popup


 if (document.cookie == "")  //Checking Whether First time or not
{
            document.cookie = 1;
}

set time intrvel to display popup



syntax:
setTimeout("Function",time);

Example
setTimeout("jQuery('#dialog').hide();$('#mask').hide();", 20000);

Tuesday, 1 January 2013

Open Popup in html


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Simple JQuery Modal Window from Queness</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script>

<script type="text/javascript">
    $(document).ready(function () {

        var id = '#dialog';

        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        //Set heigth and width to mask to fill up the whole screen
        $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

        //transition effect
        $('#mask').fadeIn(1000);
        $('#mask').fadeTo("slow", 0.8);

        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();

        //Set the popup window to center
        $(id).css('top', winH / 2 - $(id).height() / 2);
        $(id).css('left', winW / 2 - $(id).width() / 2);

        //transition effect
        $(id).fadeIn(2000);

        //if close button is clicked
        $('.window .close').click(function (e) {
            //Cancel the link behavior
            e.preventDefault();

            $('#mask').hide();
            $('.window').hide();
        });

        //if mask is clicked
        $('#mask').click(function () {
            $(this).hide();
            $('.window').hide();
        });

    });

</script>

<style type="text/css">
body {
font-family:verdana;
font-size:15px;
}

a {color:#333; text-decoration:none}
a:hover {color:#ccc; text-decoration:none}

#mask {
  position:absolute;
  left:0;
  top:0;
  z-index:9000;
  background-color:#000;
  display:none;
}
#boxes .window {
  position:absolute;
  left:0;
  top:0;
  width:440px;
  height:400px;
  display:none;
  z-index:9999;
  padding:10px;
}

#boxes #dialog {
  width:375px;
  height:203px;
  padding:10px;
  background-color:#ffffff;
}

</style>
</head><body>
<h2><a href="http://www.queness.com/">Simple jQuery Modal Window Examples from Queness WebBlog</a></h2>
<div style="font-size: 10px; color: rgb(204, 204, 204);">Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution 3.0 License.</div>

<div id="boxes">
<div style="top: 10.5px; left: 50.5px; display: none;" id="dialog" class="window">

Simple Modal Window |
<a href="#" class="close">Close it</a>

<img src="sample.jpg"  alt="Sample" height="400px" width="500px"/>
</div>
<!-- Mask to cover the whole screen -->
<div style="width: 1478px; height: 602px; display: none; opacity: 0.8;" id="mask"></div>
</div>
</body>
</html>

Friday, 28 December 2012

get excel sheet data


     private void btnCompare_Click(object sender, EventArgs e)
        {
            string filename1 = FileTxt1.Text;
            string filename2 = FileTxt2.Text;

            string file1_sheet = GetExcelSheets(filename1);
            string file2_sheet = GetExcelSheets(filename2);

            //String sConnectionString1 = "Provider=Microsoft.Jet.OLEDB.4.0;" +
            //"Data Source=" + filename1 + ";" +
            //"Extended Properties=Excel 8.0;";

            //String sConnectionString2 = "Provider=Microsoft.Jet.OLEDB.4.0;" +
            //"Data Source=" + filename2 + ";" +
            //"Extended Properties=Excel 8.0;";
            String sConnectionString1 = "Provider=Microsoft.ACE.OLEDB.12.0;" +
            "Data Source=" + filename1 + ";" +
            "Extended Properties=Excel 12.0;";

            String sConnectionString2 = "Provider=Microsoft.ACE.OLEDB.12.0;" +
            "Data Source=" + filename2 + ";" +
            "Extended Properties=Excel 12.0;";
            OleDbConnection objConn = new OleDbConnection(sConnectionString1);

            objConn.Open();
            OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM [" + file1_sheet + "$]", objConn);
            OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
            objAdapter1.SelectCommand = objCmdSelect;
            DataSet objDataset1 = new DataSet();
            objAdapter1.Fill(objDataset1, "XLData");
            DataTable dt1 = objDataset1.Tables[0];
            objConn.Close();


            objConn = new OleDbConnection(sConnectionString2);
            objConn.Open();
            objCmdSelect = new OleDbCommand("SELECT * FROM [" + file2_sheet + "$]", objConn);
            objAdapter1 = new OleDbDataAdapter();
            objAdapter1.SelectCommand = objCmdSelect;
            objDataset1 = new DataSet();
            objAdapter1.Fill(objDataset1, "XLData");
            DataTable dt2 = objDataset1.Tables[0];
            objConn.Close();
            compareDataTables(dt1, dt2);

        }



   public string GetExcelSheets(string excelFileName)
        {
            Microsoft.Office.Interop.Excel.Application excelFileObject = new Microsoft.Office.Interop.Excel.Application();
            Microsoft.Office.Interop.Excel.Workbook workBookObject = null;
            workBookObject = excelFileObject.Workbooks.Open(excelFileName, 0, true, 5, "", "", false,
            Microsoft.Office.Interop.Excel.XlPlatform.xlWindows,
            "",
            true,
            false,
            0,
            true,
            false,
            false);
            Excel.Sheets sheets = workBookObject.Worksheets;

            // get the first and only worksheet from the collection of worksheets
            Excel.Worksheet worksheet = (Excel.Worksheet)sheets.get_Item(1);
            //MessageBox.Show(worksheet.Name);
            return worksheet.Name;
        }

compare two datatables

 public DataTable CompareDataTables(DataTable first, DataTable second)
        {
            first.TableName = "FirstTable";
            second.TableName = "SecondTable";
            //Create Empty Table
            DataTable table = new DataTable("Difference");
            try
            {
                //Must use a Dataset to make use of a DataRelation object
                using (DataSet ds = new DataSet())
                {
                    //Add tables
                    ds.Tables.AddRange(new DataTable[] { first.Copy(), second.Copy() });
                    //Get Columns for DataRelation
                    DataColumn[] firstcolumns = new DataColumn[ds.Tables[0].Columns.Count];
                    for (int i = 0; i < firstcolumns.Length; i++)
                    {
                        firstcolumns[i] = ds.Tables[0].Columns[i];
                    }
                    DataColumn[] secondcolumns = new DataColumn[ds.Tables[1].Columns.Count];
                    for (int i = 0; i < secondcolumns.Length; i++)
                    {
                        secondcolumns[i] = ds.Tables[1].Columns[i];
                    }
                    //Create DataRelation
                    DataRelation r = new DataRelation(string.Empty, firstcolumns, secondcolumns, false);
                    ds.Relations.Add(r);
                    //Create columns for return table
                    for (int i = 0; i < first.Columns.Count; i++)
                    {
                        table.Columns.Add(first.Columns[i].ColumnName, first.Columns[i].DataType);
                    }
                    //If First Row not in Second, Add to return table.
                    table.BeginLoadData();
                    foreach (DataRow parentrow in ds.Tables[0].Rows)
                    {
                        DataRow[] childrows = parentrow.GetChildRows(r);
                        if (childrows == null || childrows.Length == 0)
                            table.LoadDataRow(parentrow.ItemArray, true);
                    }
                    table.EndLoadData();
                }
            }

        return table;
        }

Saturday, 15 December 2012

dynamic ip change in c#



                 ManagementBaseObject inPar = null;
                 ManagementBaseObject outPar = null;
                 ManagementClass mc = new
                 ManagementClass("Win32_NetworkAdapterConfiguration");
                 ManagementObjectCollection moc = mc.GetInstances();
                 try
                 {
                     foreach (ManagementObject mo in moc)
                     {
                         if (!(bool)mo["IPEnabled"])
                             continue;

                         inPar = mo.GetMethodParameters("EnableStatic");
                         inPar["IPAddress"] = new string[] {"10.57.245.184" };
                         inPar["SubnetMask"] = new string[] {"255.255.0.0" };
                         outPar = mo.InvokeMethod("EnableStatic", inPar,null);
                         //MonIP.Text = "10.59.245.186";
                     }
                 }
                 catch (Exception ex)
                 {
                     MessageBox.Show("Problème au changement d'IP (" +
                     ex.Message + ")", "erreur", MessageBoxButtons.OK,
                     MessageBoxIcon.Error);
                     return;
                 }