C# VB.NET Code Translator

by Erik Lane 1. July 2005 09:22

Just like Neal said, The CodeTranslator is very cool. 

This service will translate the code for you, just start typing the code or upload a file to translate it.
For now it only supports from VB.NET to C# and from C# to VB.NET.
To use it you can either:

  1. Start typing your code.
  2. Copy and Paste the code in the Code Text Box.
  3. Translate an entire file using the file upload.
Tags:

Comments

AHMED
AHMED on 10/7/2005 4:18:00 AM

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace DataGridTest
{
  /// <summary>
  /// Summary description for Option 3.
  /// </summary>
  public class Option3 : System.Web.UI.Page
  {
    protected System.Web.UI.WebControls.DataGrid DataGrid1;
  
    private void Page_Load(object sender, System.EventArgs e)
    {
      
      System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();
      //conn.ConnectionString = @"Data Source=""C:\datagridgrouping.mdb"";Password=;Provider=""Microsoft.Jet.OLEDB.4.0"";User ID=Admin;";
      conn.ConnectionString = String.Format(@"Data Source=""{0}"";Password=;Provider=""Microsoft.Jet.OLEDB.4.0"";User ID=Admin;", Server.MapPath("~/datagridgrouping.mdb"));
      
      
      System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand();
      cmd.CommandType = CommandType.Text;
      cmd.Connection = conn;
      cmd.CommandText = "SELECT Switch([Status]='Done','Done',[Status]<>'Done','In Progress') AS SubHeading, ProgRequests.ProgReqID, ProgRequests.Title, ProgRequests.Status FROM ProgRequests WHERE (((ProgRequests.Status)<>'Submitted')) ORDER BY Switch([Status]='Done','Done',[Status]<>'Done','In Progress') DESC , ProgRequests.ProgReqID;";
      
      DataSet ds = new DataSet();

      System.Data.OleDb.OleDbDataAdapter da = new System.Data.OleDb.OleDbDataAdapter();
      da.SelectCommand = cmd;
      da.Fill(ds);
      conn.Close();
      da.Dispose();
      conn.Dispose();
      cmd.Dispose();

      DataGrid1.DataSource = ds.Tables[0];
      DataGrid1.DataBind();
    }

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
      //
      // CODEGEN: This call is required by the ASP.NET Web Form Designer.
      //
      InitializeComponent();
      base.OnInit(e);
    }
    
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {    
      this.DataGrid1.ItemCreated += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DataGrid1_ItemCreated);
      this.DataGrid1.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DataGrid1_ItemDataBound);
      this.Load += new System.EventHandler(this.Page_Load);

    }
    #endregion

    private string subheading = "";
    private bool createsub = false;

    private void DataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
      switch (e.Item.ItemType)
      {
        case ListItemType.AlternatingItem:
        case ListItemType.Item:
          if (createsub)
          {
            DataGrid dg = (DataGrid)sender;
            TableCell tc = new TableCell();
            tc.Controls.Add(new LiteralControl(subheading));
            tc.ColumnSpan = e.Item.Cells.Count;
            tc.Attributes.Add("align", "left");
            tc.Font.Bold = true;
            tc.BackColor = Color.FromArgb(204, 204, 255);
            DataGridItem di = new DataGridItem(e.Item.ItemIndex+1,0,ListItemType.Item);
            di.Cells.Add(tc);
            Table t = (Table)dg.Controls[0];
            t.Rows.Add(di);
          }
          break;
        default:
          break;
      }      
    }

    private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
      switch (e.Item.ItemType)
      {
        case ListItemType.Header:
        case ListItemType.AlternatingItem:
        case ListItemType.Item:
          DataTable dt = (DataTable)((DataGrid)sender).DataSource;
          // header or Subheading column value will change
          if ((e.Item.ItemIndex == -1) ||
            (e.Item.ItemIndex+1 < dt.Rows.Count &&
            dt.Rows[e.Item.ItemIndex+1]["SubHeading"].ToString() != dt.Rows[e.Item.ItemIndex]["SubHeading"].ToString()))
          {
            subheading = dt.Rows[e.Item.ItemIndex+1]["SubHeading"].ToString();
            createsub = true;
          }
          else
            createsub = false;
          break;
      }
    }
  }
}

Comments are closed