for (i = 1; i < 8; i++)//我們只拉8個FileUpload出來
{
FileUpload fu = (FileUpload)Panel1.FindControl(string.Format("FileUpLoad{0}", i));
TextBox TextBoxa = (TextBox)Panel1.FindControl(string.Format("TextBox{0}", i));
if (fu.PostedFile.ContentLength < 2048000)
{
string path = HttpContext.Current.Request.MapPath("../picture/phone/");
//檢查是否有檔案
if (fu.HasFile)
{
// if (IsAllowedExtension(fu) == true)
// {
try
{
//儲存檔案到您指定的位子
fu.SaveAs(path + fu.FileName);
string wpath = "picture/phone/" + fu.FileName;
paras2[0].Value = strpid;
paras2[1].Value = Dropphonetype.SelectedValue;
paras2[2].Value = wpath;
paras2[3].Value = TextBoxa.Text;
string sqlb = sql2.ToString();
SqlHelper.ExecuteNonQuery(st, CommandType.Text, sqlb, paras2);//循环执行添加数据
}
'循环添加导师
For i As Integer = 1 To 3
Dim stra As String = "lblNamChn" & i.ToString
Dim strb As String = "txtEmpno" & i.ToString
Dim TextBoxa As TextBox = CType(Me.FindControl(stra), TextBox)
Dim TextBoxb As TextBox = CType(Me.FindControl(strb), TextBox)
If TextBoxa.Text.Trim <> "" Then
strSQL = "Insert Into TUTOR(tutor_type,tutor_emp_id,tutor_name,crs_num,cls_num,crt_user,crt_datetime) Values("
strSQL &= "'" & ReplaceString(SelTutorType.SelectedValue) & "',"
strSQL &= "'" & ReplaceString(TextBoxb.Text.Trim) & "',"
strSQL &= "'" & ReplaceString(TextBoxa.Text.Trim) & "',"
strSQL &= "'" & ReplaceString(lstCrsNum.SelectedValue) & "',"
strSQL &= "'" & ReplaceString(txtClsnum.Text.Trim) & "',"
strSQL &= "'" & Session("UserID") & "',"
strSQL &= "'" & Format(Now(), "yyyy/MM/dd HH:mm:ss") & "')"
clsDbProcess.ExecuteSQL(Session("Server"), Session("Database"), strSQL)
End If
Next
For i = 0 To count - 1 '循环修改删除
Dim rec(i) As String
If IsDBNull(ds.Tables(0).Rows(i)(0)) Then
rec(i) = ""
Else
rec(i) = ds.Tables(0).Rows(i)(0).ToString
End If
'rec(i) = IIf(ds.Tables(0).Rows(i)(0) Is DBNull.Value, "", ds.Tables(0).Rows(i)(0))
'msgbox.Text = rec(i) & " "& Request.QueryString("strClassNum")
Dim j As Integer = i + 1
Dim strx As String = "lblnamchn" & j.ToString
Dim stry As String = "txtempno" & j.ToString
Dim textboxx As TextBox = CType(Me.FindControl(strx), TextBox)
Dim textboxy As TextBox = CType(Me.FindControl(stry), TextBox)
If textboxx.Text.Trim <> "" Then
If rec(i) <> "" Then
'如果rec1原来有值的,则修改表
strSQL = "update tutor set "
strSQL &= "tutor_type='" & ReplaceString(SelTutorType.SelectedValue) & "',"
strSQL &= "tutor_emp_id='" & ReplaceString(textboxy.Text.Trim) & "',"
strSQL &= "tutor_name='" & ReplaceString(textboxx.Text.Trim) & "',"
strSQL &= "crs_num='" & ReplaceString(lstCrsNum.SelectedValue) & "',"
strSQL &= "chg_user='" & Session("UserID") & "' ,"
strSQL &= "chg_datetime='" & Format(Now(), "yyyy-MM-dd HH:mm:ss") & "' "
strSQL &= " where rec_id ='" & rec(i) & "'"
clsDbProcess.ExecuteSQL(Session("server"), Session("database"), strSQL)
End If
End If
If textboxx.Text.Trim = "" Then '如果班別有導師,但該textbox資料為空時就刪除該數據
If rec(i) <> "" Then
strSQL = "delete from tutor where rec_id='" & rec(i) & "' "
clsDbProcess.ExecuteSQL(Session("Server"), Session("Database"), strSQL)
End If
End If
Next
'循环添加导师 '例如:如果有一个导师,另外第二第三个lblNamChn不为空,则添加导师
For k As Integer = count + 1 To 3
Dim stra As String = "lblNamChn" & k.ToString
Dim strb As String = "txtEmpno" & k.ToString
Dim TextBoxa As TextBox = CType(Me.FindControl(stra), TextBox)
Dim TextBoxb As TextBox = CType(Me.FindControl(strb), TextBox)
If TextBoxa.Text.Trim <> "" Then
strSQL = "Insert Into TUTOR(tutor_type,tutor_emp_id,tutor_name,crs_num,cls_num,crt_user,crt_datetime) Values("
strSQL &= "'" & ReplaceString(SelTutorType.SelectedValue) & "',"
strSQL &= "'" & ReplaceString(TextBoxb.Text.Trim) & "',"
strSQL &= "'" & ReplaceString(TextBoxa.Text.Trim) & "',"
strSQL &= "'" & ReplaceString(lstCrsNum.SelectedValue) & "',"
strSQL &= "'" & ReplaceString(txtClsnum.Text.Trim) & "',"
strSQL &= "'" & Session("UserID") & "',"
strSQL &= "'" & Format(Now(), "yyyy/MM/dd HH:mm:ss") & "')"
clsDbProcess.ExecuteSQL(Session("Server"), Session("Database"), strSQL)
End If
Next
Alert("修改成功")
//循环添加导师
{
for (int i = 1; i <= 3; i++) {
string stra = "lblNamChn" + i.ToString;
string strb = "txtEmpno" + i.ToString;
TextBox TextBoxa = (TextBox)this.FindControl(stra);
TextBox TextBoxb = (TextBox)this.FindControl(strb);
if (!string.IsNullOrEmpty(TextBoxa.Text.Trim)) {
strSQL = "Insert Into TUTOR(tutor_type,tutor_emp_id,tutor_name,crs_num,cls_num,crt_user,crt_datetime) Values(";
strSQL += "'" + ReplaceString(SelTutorType.SelectedValue) + "',";
strSQL += "'" + ReplaceString(TextBoxb.Text.Trim) + "',";
strSQL += "'" + ReplaceString(TextBoxa.Text.Trim) + "',";
strSQL += "'" + ReplaceString(lstCrsNum.SelectedValue) + "',";
strSQL += "'" + ReplaceString(txtClsnum.Text.Trim) + "',";
strSQL += "'" + Session("UserID") + "',";
strSQL += "'" + Strings.Format(Now(), "yyyy/MM/dd HH:mm:ss") + "')";
clsDbProcess.ExecuteSQL(Session("Server"), Session("Database"), strSQL);
}
}
for (i = 0; i <= count - 1; i++) {
//循环修改删除
string[] rec = new string[i + 1];
if (ds.Tables(0).Rows(i)(0) == System.DBNull.Value) {
rec(i) = "";
}
else {
rec(i) = ds.Tables(0).Rows(i)(0).ToString;
}
//rec(i) = IIf(ds.Tables(0).Rows(i)(0) Is DBNull.Value, "", ds.Tables(0).Rows(i)(0))
//msgbox.Text = rec(i) & " "& Request.QueryString("strClassNum")
int j = i + 1;
string strx = "lblnamchn" + j.ToString;
string stry = "txtempno" + j.ToString;
TextBox textboxx = (TextBox)this.FindControl(strx);
TextBox textboxy = (TextBox)this.FindControl(stry);
if (!string.IsNullOrEmpty(textboxx.Text.Trim)) {
if (!string.IsNullOrEmpty(rec(i))) {
//如果rec1原来有值的,则修改表
strSQL = "update tutor set ";
strSQL += "tutor_type='" + ReplaceString(SelTutorType.SelectedValue) + "',";
strSQL += "tutor_emp_id='" + ReplaceString(textboxy.Text.Trim) + "',";
strSQL += "tutor_name='" + ReplaceString(textboxx.Text.Trim) + "',";
strSQL += "crs_num='" + ReplaceString(lstCrsNum.SelectedValue) + "',";
strSQL += "chg_user='" + Session("UserID") + "' ,";
strSQL += "chg_datetime='" + Strings.Format(Now(), "yyyy-MM-dd HH:mm:ss") + "' ";
strSQL += " where rec_id ='" + rec(i) + "'";
clsDbProcess.ExecuteSQL(Session("server"), Session("database"), strSQL);
}
}
if (string.IsNullOrEmpty(textboxx.Text.Trim)) {
//如果班別有導師,但該textbox資料為空時就刪除該數據
if (!string.IsNullOrEmpty(rec(i))) {
strSQL = "delete from tutor where rec_id='" + rec(i) + "' ";
clsDbProcess.ExecuteSQL(Session("Server"), Session("Database"), strSQL);
}
}
}
//循环添加导师 '例如:如果有一个导师,另外第二第三个lblNamChn不为空,则添加导师
for (int k = count + 1; k <= 3; k++) {
string stra = "lblNamChn" + k.ToString;
string strb = "txtEmpno" + k.ToString;
TextBox TextBoxa = (TextBox)this.FindControl(stra);
TextBox TextBoxb = (TextBox)this.FindControl(strb);
if (!string.IsNullOrEmpty(TextBoxa.Text.Trim)) {
strSQL = "Insert Into TUTOR(tutor_type,tutor_emp_id,tutor_name,crs_num,cls_num,crt_user,crt_datetime) Values(";
strSQL += "'" + ReplaceString(SelTutorType.SelectedValue) + "',";
strSQL += "'" + ReplaceString(TextBoxb.Text.Trim) + "',";
strSQL += "'" + ReplaceString(TextBoxa.Text.Trim) + "',";
strSQL += "'" + ReplaceString(lstCrsNum.SelectedValue) + "',";
strSQL += "'" + ReplaceString(txtClsnum.Text.Trim) + "',";
strSQL += "'" + Session("UserID") + "',";
strSQL += "'" + Strings.Format(Now(), "yyyy/MM/dd HH:mm:ss") + "')";
clsDbProcess.ExecuteSQL(Session("Server"), Session("Database"), strSQL);
}
}
Alert("修改成功");
}