protected void btn_login_Click(object sender, EventArgs e) { bool isRegisted = false; DataBase.DBOperator db = new DataBase.DBOperator(); string sql = "select * from user where UserName=@name and UserPass=@pass"; db.NewSQL(sql); db.SetString("@name", tb_Name.Text); db.SetString("@pass", tb_Pwd.Text); using (SQLiteDataReader dr = db.ExecuteReader()) { if (dr.Read()) { isRegisted = true; Session["login"] = "******"; Session["loginUserID"] = dr["UserID"].ToString(); } } if (true == isRegisted) { ClientScript.RegisterClientScriptBlock(Page.GetType(), "", "<script>window.location.href='default.aspx';</script>"); } else { ClientScript.RegisterClientScriptBlock(Page.GetType(), "", "<script>window.alert('用户名或密码错误!')</script>"); } }
protected void btn_new_Click(object sender, EventArgs e) { DataBase.DBOperator db = new DataBase.DBOperator(); string sql = "insert into project (UserID,ProjectName,ProjectIntro,isPrivate,Path) values(@userid,@name,@info,@isPrivate,@path)"; db.NewSQL(sql); db.SetString("@userid", Session["loginUserID"].ToString()); db.SetString("@name", tb_newName.Text); db.SetString("@info", tb_newInfo.Text); db.SetInt("@isPrivate", int.Parse(drop_statue.SelectedValue)); string path = tool.getRandomStr(); db.SetString("@path", path); if (1 == db.ExecuteNonQuery()) { ClientScript.RegisterClientScriptBlock(Page.GetType(), "add", "<script>window.alert('添加成功!');window.location='default.aspx';</script>"); SVNOperation.create(path); } else { ClientScript.RegisterClientScriptBlock(Page.GetType(), "", "<script>window.alert('添加失败!');</script>"); } }
protected void btn_CreateUser_Click(object sender, EventArgs e) { bool isRegisted = false; DataBase.DBOperator db = new DataBase.DBOperator(); string sql = "select * from user where UserName=@name"; db.NewSQL(sql); db.SetString("@name", tb_CreateName.Text); using (SQLiteDataReader dr = db.ExecuteReader()) { if (dr.Read()) { isRegisted = true; } } if (true == isRegisted) { ClientScript.RegisterClientScriptBlock(Page.GetType(), "success1", "<script>window.alert('用户名已存在!')</script>"); } else { sql = "insert into user (UserName,UserPass,TrueName,Year) values(@name,@pass,@trueName,@year)"; db.NewSQL(sql); db.SetString("@name", tb_CreateName.Text); db.SetString("@pass", tb_CreatePwd.Text); db.SetString("@trueName", tb_CreatTrueName.Text); db.SetString("@year", tb_CreateYear.Text); db.ExecuteNonQuery(); ClientScript.RegisterClientScriptBlock(Page.GetType(), "success1", "<script>window.alert('注册成功!');window.location.href='default.aspx';</script>"); } }
protected void setBind(string sql, DataGrid dg) { DataBase.DBOperator db = new DataBase.DBOperator(); db.NewSQL(sql); using (DataSet ds = db.ExecuteDataSet()) { if (ds.Tables.Count == 0) { return; } using (DataTable dt = ds.Tables[0]) { dg.DataSource = dt; dg.DataBind(); } } }
protected void dg_ItemCommand(object source, DataGridCommandEventArgs e) { DataGridItem i = e.Item; DataBase.DBOperator db = new DataBase.DBOperator(); if (e.CommandName == "del") { string sql = "delete from project where projectID=@id"; db.NewSQL(sql); int Cid = int.Parse(i.Cells[0].Text); db.SetInt("@id", Cid); if (1 == db.ExecuteNonQuery()) { ClientScript.RegisterClientScriptBlock(Page.GetType(), "success1", "<script>window.alert('删除成功!')</script>"); setBind(); string path = (i.FindControl("hidden_path") as HiddenField).Value; SVNOperation.delete(path); } else { ClientScript.RegisterClientScriptBlock(Page.GetType(), "alert1", "<script>window.alert('删除失败,请重试!')</script>"); } } if (e.CommandName == "refresh") { int old_isPrivate = -1; string sql = "select * from project where ProjectID=@projectid"; db.NewSQL(sql); db.SetInt("@projectid", int.Parse(e.Item.Cells[0].Text)); using (SQLiteDataReader dr = db.ExecuteReader()) { if (dr.Read()) { old_isPrivate = int.Parse(dr["isPrivate"].ToString()); } } sql = "update project set ProjectName=@name, ProjectIntro=@intro, isprivate=@isPrivate, path=@path where projectID=@projectid"; db.NewSQL(sql); db.SetInt("@projectid", int.Parse(e.Item.Cells[0].Text)); string projectName = (i.FindControl("tb_name") as TextBox).Text; db.SetString("@name", projectName); string projectIntro = (i.FindControl("tb_intro") as TextBox).Text; db.SetString("@intro", projectIntro); int isPrivate = (i.FindControl("cb_statue") as CheckBox).Checked?1:2; db.SetInt("@isPrivate", isPrivate); string oldPath = (i.FindControl("hidden_path") as HiddenField).Value; string newPath = tool.getRandomStr(); if (old_isPrivate != isPrivate) { db.SetString("@path", newPath); } else { db.SetString("@path", oldPath); } if (1 == db.ExecuteNonQuery()) { ClientScript.RegisterClientScriptBlock(Page.GetType(), "", "<script>window.alert('更新成功!');window.location='default.aspx';</script>"); if (old_isPrivate != isPrivate) { SVNOperation.modify(oldPath, newPath); } } else { ClientScript.RegisterClientScriptBlock(Page.GetType(), "", "<script>window.alert('更新失败!');</script>"); } } }