protected void redoVersion_Click(object sender, EventArgs e) { if (!checkUser()) { Response.Write("<script>alert('please login.');window.location.href='login.aspx';</script>"); return; } Version v2 = new Version(); v2.version_id = int.Parse(hidValue.Value); vd.SelectByID(ref v2); Branch b2 = new Branch(); b2.branch_id = v2.branch_id; if (!bd.SelectByID(ref b2)) { Response.Write("<script>alert('invalid argument.')</script>"); return; } Warehouse w2 = new Warehouse(); w2.warehouse_id = v2.warehouse_id; if (!wd.SelectedByID(ref w2)) { Response.Write("<script>alert('invalid argument.')</script>"); return; } if (b2.branch_name == "master") { deleteFrom(v2.version_id); w2.master_version_id = v2.version_id; wd.Update(ref w2); } else { deleteFrom(v2.version_id); } Response.Write("<script>alert('success.');window.location.href='warehouse_page.aspx?wid=" + w2.warehouse_id.ToString() + "&vid=" + w2.master_version_id.ToString() + "';</script>"); }
protected void Page_Load(object sender, EventArgs e) { wd = new WarehouseDAL(); vd = new VersionDAL(); bd = new BranchDAL(); if (int.TryParse(Request.QueryString["wid"], out wid) == false) { //error } if (int.TryParse(Request.QueryString["vid"], out vid) == false) { //error } if (wid == 0 || vid == 0) { //error } //debug!!!!!!!!!!!!!!!!!!!!!!! //wid = 1; //vid = 1; //User u = new User(); //u.user_id = 1; //UserDAL ud = new UserDAL(); //ud.SelectByID(ref u); //Session["user"] = u; w = new Warehouse(); w.warehouse_id = wid; if (!wd.SelectedByID(ref w)) { //error } v = new Version(); v.version_id = vid; if (!vd.SelectByID(ref v)) { //error } b = new Branch(); b.branch_id = v.branch_id; if (!bd.SelectByID(ref b)) { //error } //head headName.InnerText = w.warehouse_name; headDesc.InnerText = w.warehouse_description; //current version curBran.InnerText = "当前分支:" + b.branch_name; curVer.InnerText = "当前版本:" + v.version_id.ToString(); curTime.InnerText = "修改时间:" + v.timestamp; curDesc.InnerText = "当前版本描述:" + v.description; //draw if (!DrawGraph()) { } //file fileInit(); }
protected void createButton_Click(object sender, EventArgs e) { User u = (User)Session["user"]; if (u == null) { Response.Write("<script>alert('invalid user 1.');window.opener=null;window.close();</script>"); return; } if (v == null) { Response.Write("<script>alert('invalid vid in create.');window.opener=null;window.close();</script>"); return; } if (u.user_id != v.user_id) { Response.Write("<script>alert('invalid user.');window.opener=null;window.close();</script>"); return; } if (name.Value.Length == 0 || desc.Value.Length == 0) { //error Response.Write("<script>alert('invalid name or desc.');</script>"); return; } //new version Version v2 = new Version(); v2.version_name = name.Value; v2.description = desc.Value; v2.prev_id = v.version_id; //! v2.next_id = v.next_id; //! v2.warehouse_id = v.warehouse_id; v2.user_id = v.user_id; v2.branch_id = v.branch_id; if (!vd.Insert(ref v2)) { Response.Write("<script>alert('insert error 1.');</script>"); return; } Version v3 = new Version(); v3.branch_id = v.branch_id; v3.description = v.description; v3.next_id = v2.version_id; //warning v3.prev_id = v.prev_id; //warning v3.timestamp = v.timestamp; v3.user_id = v.user_id; v3.version_id = v.version_id; v3.version_name = v.version_name; v3.warehouse_id = v.warehouse_id; if (!vd.Update(ref v3)) { Response.Write("<script>alert('error 3.');</script>"); vd.Delete(ref v2); vd.Update(ref v); return; } //create files if (!FileSystem.CopyFolder(Server.MapPath("~/") + @"data\" + v.warehouse_id.ToString() + @"\" + v.version_id.ToString(), Server.MapPath("~/") + @"data\" + v.warehouse_id.ToString() + @"\" + v2.version_id.ToString())) { vd.Delete(ref v2); vd.Update(ref v); Response.Write("<script>alert('file error.');</script>"); return; } //warnning ; bug here Branch b = new Branch(); b.branch_id = v.branch_id; bd = new BranchDAL(); bd.SelectByID(ref b); if (b.branch_name == "master") { Warehouse w = new Warehouse(); w.warehouse_id = v.warehouse_id; wd = new WarehouseDAL(); wd.SelectedByID(ref w); if (w.master_version_id == v.version_id) { w.master_version_id = v2.version_id; wd.Update(ref w); } } Response.Write("<script>alert('create success.');window.location.href='warehouse_page.aspx?wid=" + v.warehouse_id + "&vid=" + v2.version_id + "';</script>"); }