ช่วยแปลง code จาก VB.NET เป็น C# ให้หน่อย แนะนำการแปลง VB.NET เป็น C#
ขอบคุณสำหรับวิธีการ
Date :
2010-03-23 15:58:54
By :
eclipse
Code (C#)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlClient;
using System.Data.OleDb;
namespace GTHFormsApplication
{
public partial class gthmovie : Form
{
string movType;
string year;
string rating;
string selectStr;
string strConnString = " ";
// Data Source = ชื่อ server; Initial Catalog = ชื่อ DB;Integrated Security = การเข้ารหัสข้อมูล
bool isTypeSelect = false;
bool isRateSelect = false;
bool isYesrSelect = false;
public gthmovie()
{
InitializeComponent();
}
private void submitButton_Click(object sender, EventArgs e)
{
movType = movieTypeComboBox.Text;
year = yearComboBox.Text;
if (movType.Equals("Movie Type"))
{
isTypeSelect = false;
}
else
{
isTypeSelect = true;
}
if (year.Equals("Year"))
{
isYesrSelect = false;
}
else
{
isYesrSelect = true;
}
if (radioButton6.Checked)
{
rating = "allRate";
}
else if (radioButton1.Checked)
{
rating = "all";
isRateSelect = true;
}
else if (radioButton2.Checked)
{
rating = "13";
isRateSelect = true;
}
else if (radioButton3.Checked)
{
rating = "15";
isRateSelect = true;
}
else if (radioButton4.Checked)
{
rating = "18";
isRateSelect = true;
}
else if (radioButton5.Checked)
{
rating = "20";
isRateSelect = true;
}
else
{
rating = "no";
isRateSelect = false;
}
showDetails();
}
public void showDetails()
{
string tmp = null;
if (movieTypeComboBox.Text.Equals("Movie Type") && yearComboBox.Text.Equals("Year") && rating.Equals("no"))
{
tmp += "\n Please select at least 1 chioce.";
}
if (tmp != null)
{
MessageBox.Show(tmp);
}
else
{
if ((movType.Equals("All Movie Type") && isYesrSelect == false && isRateSelect == false) ||
(isTypeSelect == false && year.Equals("All Year") && isRateSelect == false) ||
(isTypeSelect == false && isYesrSelect == false && radioButton6.Checked) ||
(movType.Equals("All Movie Type") && year.Equals("All Year") && isRateSelect == false) ||
(movType.Equals("All Movie Type") && isYesrSelect == false && radioButton6.Checked) ||
(isTypeSelect == false && year.Equals("All Year") && radioButton6.Checked) ||
(movType.Equals("All Movie Type") && year.Equals("All Year") && radioButton6.Checked))
{
selectStr = "Select * FROM gth";
}
else if (movType.Equals("All Movie Type") && isYesrSelect == true && isRateSelect == true)
{
selectStr = "Select * FROM gth WHERE year = '" + year + "' AND rat = '" + rating + "'";
}
else if (isTypeSelect == true && year.Equals("All Year") && isRateSelect == true)
{
selectStr = "Select * FROM gth WHERE movie_type = '" + movType + "' AND rat = '" + rating + "'";
}
else if (isTypeSelect == true && isYesrSelect == true && radioButton6.Checked)
{
selectStr = "Select * FROM gth WHERE movie_type = '" + movType + "' AND year = '" + year + "'";
}
else if ((movType.Equals("All Movie Type") && isYesrSelect == false && isRateSelect == true) || (isTypeSelect == false && year.Equals("All Year") && isRateSelect == true) || (movType.Equals("All Movie Type") && year.Equals("All Year") && isRateSelect == true))
{
selectStr = "Select * FROM gth WHERE rat = '" + rating + "'";
}
else if ((isTypeSelect == true && year.Equals("All Year") && isRateSelect == false) || (isTypeSelect == true && isYesrSelect == false && radioButton6.Checked) || (isTypeSelect == true && year.Equals("All Year") && radioButton6.Checked))
{
selectStr = "Select * FROM gth WHERE movie_type = '" + movType + "'";
}
else if ((movType.Equals("All Movie Type") && isYesrSelect == true && isRateSelect == false) || (isTypeSelect == false && isYesrSelect == true && radioButton6.Checked) || (movType.Equals("All Movie Type") && isYesrSelect == true && radioButton6.Checked))
{
selectStr = "Select * FROM gth WHERE year = '" + year + "'";
}
else if (isTypeSelect == true && isYesrSelect == false && isRateSelect == false)
{
selectStr = "Select * FROM gth WHERE movie_type = '" + movType + "'";
}
else if (isTypeSelect == false && isYesrSelect == true && isRateSelect == false)
{
selectStr = "Select * FROM gth WHERE year = '" + year + "'";
}
else if (isTypeSelect == false && isYesrSelect == false && isRateSelect == true)
{
selectStr = "Select * FROM gth WHERE rat = '" + rating + "'";
}
else if (isTypeSelect == true && isYesrSelect == true && isRateSelect == false)
{
selectStr = "Select * FROM gth WHERE movie_type = '" + movType + "' AND year = '" + year + "'";
}
else if (isTypeSelect == true && isYesrSelect == false && isRateSelect == true)
{
selectStr = "Select * FROM gth WHERE movie_type = '" + movType + "' AND rat = '" + rating + "'";
}
else if (isTypeSelect == false && isYesrSelect == true && isRateSelect == true)
{
selectStr = "Select * FROM gth WHERE year = '" + year + "' AND rat = '" + rating + "'";
}
else if (isTypeSelect == true && isYesrSelect == true && isRateSelect == true)
{
selectStr = "Select * FROM gth WHERE movie_type = '" + movType + "' AND year = '" + year + "' AND rat = '" + rating + "'";
}
else
{
selectStr = "SELECT * FROM gth";
}
try
{
SqlDataAdapter sqlAdap = new SqlDataAdapter(selectStr, strConnString);
SqlCommandBuilder sqlBuild = new SqlCommandBuilder(sqlAdap);
DataTable t = new DataTable();
sqlAdap.Fill(t);
dataGridView1.DataSource = t;
dataGridView1.Visible = true;
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
}
private void yearComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void restButton_Click(object sender, EventArgs e)
{
dataGridView1.Visible = false;
yearComboBox.Text = "Year";
movieTypeComboBox.Text = "Movie Type";
radioButton1.Checked = false;
radioButton2.Checked = false;
radioButton3.Checked = false;
radioButton4.Checked = false;
radioButton5.Checked = false;
radioButton6.Checked = false;
movType = "";
year = "";
rating = "";
selectStr = "";
isTypeSelect = false;
isRateSelect = false;
isYesrSelect = false;
}
}
}
ช่วยแปลงโค้ดให้เป็น vb ด้วยค่ะ
ขอบคุณมากค่ะ
Date :
2011-02-04 23:52:09
By :
คนไม่รู้รื่อง
Code (VB.NET)
Sub Button1_Click(sender As Object, e As EventArgs)
Dim chkCusID As CheckBox
Dim lblID As Label
Dim i As Integer
lblText.Text = ""
For i = 0 To myGridView.Rows.Count - 1
chkCusID = myGridView.Rows(i).FindControl("chkCustomerID")
lblID = myGridView.Rows(i).FindControl("lblCustomerID")
IF chkCusID.Checked = True Then
'*** Have lblID.Text ***'
Me.lblText.Text = Me.lblText.Text & "<br>" & lblID.Text
End IF
Next
End Sub
Code (C#)
void Button1_Click(object sender,EventArgs e)
{
CheckBox chkCusID;
Label lblID;
int i;
lblText.Text = "";
for( i = 0; i <= myGridView.Rows.Count - 1; i++)
{
chkCusID = (CheckBox)myGridView.Rows[i].FindControl("chkCustomerID");
lblID = (Label)myGridView.Rows[i].FindControl("lblCustomerID");
if(chkCusID.Checked)
{
//*** Have lblID.Text ***//
this.lblText.Text = this.lblText.Text + "<br>" + lblID.Text;
}
}
}
Date :
2011-02-05 22:05:25
By :
webmaster
Load balance : Server 00