انتخاب واحد در پروژه سایت دانشگاه به زبان# asp.net ,c
سلام دوستان
خسته نباشید
اگه ممکنه میتونید بگید چه طوری صفحه انتخاب واحد رو کدنویسی کنم
من این برنامه رو به زبانc# دارم ولی حالا به زبان asp.net میخوام انجام بدم
لطفا راهنمایی کنید
کد:
public int nn=0,nnmax = 0,sum;
public int currow = -1;
public frm_selectedvahed()
{
InitializeComponent();
}
string strStId = "";
public frm_selectedvahed(string strStId)
{
InitializeComponent();
this.strStId = strStId;
}
private void frm_selectedvahed_Load(object sender, EventArgs e)
{
cmd.Connection = cn;
filldatagrid1();
}
void connction()
{
double nn = 0;
for (int i = 0;i< dataGridView1.Rows.Count; ++i)
{
nn += Convert.ToDouble(dataGridView1.Rows[i].Cells[2].Value);
}
txtnn.Text = nn.ToString();
}
void filldatagrid1()
{
float grade = 0;
cn.Open();
SqlCommand cmd = new SqlCommand("select average from student where id=@id" , cn);
cmd.Parameters.AddWithValue("@id", strStId);
SqlDataReader dr = cmd.ExecuteReader();
int i = 0;
while (dr.Read())
{
grade = Convert.ToInt32(dr[0].ToString());
}
dr.Close();
SqlCommand cmd2 = new SqlCommand("select * from vselect where stu_id=@id", cn);
cmd2.Parameters.AddWithValue("@id", strStId);
SqlDataReader dr2 = cmd2.ExecuteReader();
i = 0;
while (dr2.Read())
{
DataGridViewRow row = (DataGridViewRow)dataGridView1.Rows[0].Clone();
row.Cells[0].Value = dr2[1].ToString();
row.Cells[1].Value = dr2[2].ToString();
row.Cells[2].Value = dr2[3].ToString();
row.Cells[3].Value = dr2[4].ToString();
dataGridView1.Rows.Add(row);
i++;
}
dr2.Close();
connction();
if (grade <= 12)
nnmax = 14;
else if (grade < 18)
nnmax = 20;
else
nnmax = 24;
txtmax.Text = nnmax.ToString();
}
private void add_Click(object sender, EventArgs e)
{
int covahed = 0;
string coname, cote, coid;
SqlCommand cmd = new SqlCommand("select *from infocu where id_co=@id_co", cn);
cmd.Parameters.AddWithValue("@id_co", txtid_co.Text);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
coid = dr["id_co"].ToString();
covahed = Int32.Parse(dr["vahed"].ToString());
coname = dr["name_co"].ToString();
cote = dr["name_te"].ToString();
bool flag = false;
for (int k = 0; k < dataGridView1.Rows.Count; k++)
{
if (dataGridView1.Rows[k].Cells[0].Value != null && coid == dataGridView1.Rows[k].Cells[0].Value.ToString())
{
flag = true;
break;
}
}
if (flag)
MessageBox.Show("قبلا درس مورد نظر انتخاب شده است");
else if (covahed + sum > nnmax)
MessageBox.Show("نمی توانید واحدبیشتری بردارید");
else
{
int nToSelect = Convert.ToInt32(txtmax.Text);
int nSelected = Convert.ToInt32(txtnn.Text) + covahed;
if (nSelected <= nToSelect)
{
DataGridViewRow row = (DataGridViewRow)dataGridView1.Rows[0].Clone();
row.Cells[0].Value = coid;
row.Cells[2].Value = covahed.ToString();
row.Cells[1].Value = coname;
row.Cells[3].Value = cote;
dataGridView1.Rows.Add(row);
connction();
}
else
{
MessageBox.Show(" شما مجاز به برداشتن " + ((nToSelect + covahed) - nSelected).ToString() + " واحد دیگری هستید ","تعداد واحد مجاز",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
}
else
MessageBox.Show("کد درس یافت نشد","کددرس ");
dr.Close();
}
private void delete_Click(object sender, EventArgs e)
{
dataGridView1.Rows.RemoveAt(dataGridView1.CurrentRow.Index);
}
private void save_Click(object sender, EventArgs e)
{
DataGridViewRow row = (DataGridViewRow)dataGridView1.Rows[0].Clone();
SqlCommand cmd = new SqlCommand("delete stu_dars where stu_id=@id", cn);
cmd.Parameters.AddWithValue("@id", strStId);
cmd.ExecuteNonQuery();
for (int i = 0; i < dataGridView1.Rows.Count-1; i++)
{
SqlCommand ss = new SqlCommand("insert into stu_dars(vahed_id,stu_id) values(@vahed_id,@id)", cn);
ss.Parameters.AddWithValue("@vahed_id", dataGridView1.Rows[i].Cells[0].Value.ToString());
ss.Parameters.AddWithValue("@id", strStId);
ss.ExecuteNonQuery();
}
MessageBox.Show("اطلاعات با موفقیت ثبت شد","ثبت اطلاعات");
}
private void back_Click(object sender, EventArgs e)
{
this.Hide();
}
private void fillByToolStripButton_Click(object sender, EventArgs e)
{
try
{
this.infocuTableAdapter.FillBy(this.database1DataSet.infocu);
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
}
}