示例#1
0
 protected void Button2_Click(object sender, EventArgs e)
 {
     if (DropDownList2.SelectedValue == "Insert")
     {
         if (DropDownList1.SelectedValue == "Users")
         {
             string[]      insertcol  = { "License", "Privilege", "CreateDate", "WhoCreate" };
             string[]      insertcolp = { "@License", "@Privilege", "@CreateDate", "@WhoCreate" };
             List <string> userinsert = new List <string>();
             userinsert.Add(Text1.Text);
             userinsert.Add(Text2.Text);
             userinsert.Add(Text3.Text);
             userinsert.Add(Text4.Text);
             DBTool.InsertTable("Users", insertcol, insertcolp, userinsert);
             Label7.Text = "插入資料完成";
             string[] readcol = { "UserID", "Account", "Name", "Phone", "Mail", "LineID", "License", "Privilege", "CreateDate", "WhoCreate" };
             this.Repeater1.DataSource = DBTool.readTable("Users", readcol);
             this.Repeater1.DataBind();
         }
         else if (DropDownList1.SelectedValue == "Projects")
         {
             string[]      insertcol  = { "ProjectName", "TeamID", "TeamName", "DeadLine", "CreateDate", "WhoCreate" };
             string[]      insertcolp = { "@ProjectName", "@TeamID", "@TeamName", "@DeadLine", "@CreateDate", "@WhoCreate" };
             List <string> userinsert = new List <string>();
             userinsert.Add(Text1.Text);
             userinsert.Add(Text2.Text);
             userinsert.Add(Text3.Text);
             userinsert.Add(Text4.Text);
             userinsert.Add(Text5.Text);
             userinsert.Add(Text6.Text);
             DBTool.InsertTable("Projects", insertcol, insertcolp, userinsert);
             Label7.Text = "插入資料完成";
             string[] readcol = { "ProjectID", "ProjectName", "TeamID", "TeamName", "DeadLine", "CreateDate", "WhoCreate" };
             this.Repeater1.DataSource = DBTool.readTable("Projects", readcol);
             this.Repeater1.DataBind();
         }
     }
     else if (DropDownList2.SelectedValue == "Update")
     {
         if (DropDownList1.SelectedValue == "Users")
         {
             string[]      updatecol  = { "Account=@Account", "Name=@Name", "Phone=@Phone", "Mail=@Mail", "LineID=@LineID" };
             string        wherep     = "License=@License";
             string[]      updatecolp = { "@Account", "@Name", "@Phone", "@Mail", "@LineID", "@License" };
             List <string> userupdate = new List <string>();
             userupdate.Add(Text1.Text);
             userupdate.Add(Text2.Text);
             userupdate.Add(Text3.Text);
             userupdate.Add(Text4.Text);
             userupdate.Add(Text5.Text);
             userupdate.Add(Text6.Text);
             DBTool.UpdateTable("Users", updatecol, wherep, updatecolp, userupdate);
             Label7.Text = "更新資料完成";
             string[] readcol = { "UserID", "Account", "Name", "Phone", "Mail", "LineID", "License", "Privilege", "CreateDate", "WhoCreate" };
             this.Repeater1.DataSource = DBTool.readTable("Users", readcol);
             this.Repeater1.DataBind();
         }
         else if (DropDownList1.SelectedValue == "Projects")
         {
             string[]      updatecol  = { "ProjectName=@ProjectName", "TeamID=@TeamID", "TeamName=@TeamName", "DeadLine=@DeadLine" };
             string        wherep     = "ProjectID=@ProjectID";
             string[]      updatecolp = { "@ProjectName", "@TeamID", "@TeamName", "@DeadLine", "@ProjectID" };
             List <string> userupdate = new List <string>();
             userupdate.Add(Text1.Text);
             userupdate.Add(Text2.Text);
             userupdate.Add(Text3.Text);
             userupdate.Add(Text4.Text);
             userupdate.Add(Text5.Text);
             DBTool.UpdateTable("Projects", updatecol, wherep, updatecolp, userupdate);
             Label7.Text = "更新資料完成";
             string[] readcol = { "ProjectID", "ProjectName", "TeamID", "TeamName", "DeadLine", "CreateDate", "WhoCreate" };
             this.Repeater1.DataSource = DBTool.readTable("Projects", readcol);
             this.Repeater1.DataBind();
         }
     }
     else if (DropDownList2.SelectedValue == "Delete")
     {
         if (DropDownList1.SelectedValue == "Users")
         {
             string rdbVal = this.RadioButtonList1.SelectedValue;
             DBTool.DeleteTable("Users", "UserID", "@UserID", rdbVal);
             string[] readcol = { "UserID", "Account", "Name", "Phone", "Mail", "LineID", "License", "Privilege", "CreateDate", "WhoCreate" };
             this.Repeater1.DataSource = DBTool.readTable("Users", readcol);
             this.Repeater1.DataBind();
             this.RadioButtonList1.Items.Clear();
             string[] readcol2   = { "UserID", "Account", "Name" };
             string   wantdelete = "";
             foreach (DataRow item in DBTool.readTable("Users", readcol).Rows)
             {
                 wantdelete = $"ID:{item[0]}   帳號:{item[1]}    姓名:{item[2]}";
                 RadioButtonList1.Items.Add(new ListItem($"{wantdelete}", $"{item[0]}"));
             }
         }
         else if (DropDownList1.SelectedValue == "Projects")
         {
             string rdbVal = this.RadioButtonList1.SelectedValue;
             DBTool.DeleteTable("Projects", "ProjectID", "@ProjectID", rdbVal);
             string[] readcol = { "ProjectID", "ProjectName", "TeamID", "TeamName", "DeadLine", "CreateDate", "WhoCreate" };
             this.Repeater1.DataSource = DBTool.readTable("Projects", readcol);
             this.Repeater1.DataBind();
             this.RadioButtonList1.Items.Clear();
             string[] readcol2   = { "ProjectID", "ProjectName", "TeamName" };
             string   wantdelete = "";
             foreach (DataRow item in DBTool.readTable("Projects", readcol).Rows)
             {
                 wantdelete = $"ID:{item[0]}   專案:{item[1]}   負責組:{item[2]}";
                 RadioButtonList1.Items.Add(new ListItem($"{wantdelete}", $"{item[0]}"));
             }
         }
     }
 }