protected void btn_add_Click(object sender, EventArgs e) { AdminBooktypeTableAdapter ta_booktype = new AdminBooktypeTableAdapter(); //查询选择的节点,得到选择节点的id if (this.tree.SelectedNode == null) { lab_tip.Text = "没有选中目录"; } else { DataTable dt_booktype = ta_booktype.GetAdminBooktypeByName(this.tree.SelectedNode.Value); int parent_id = Convert.ToInt32(dt_booktype.Rows[0]["id"]); dt_booktype = ta_booktype.GetAdminBooktypeByName(txt_name.Text); if (dt_booktype.Rows.Count != 0) { lab_tip.Text = "账户名已存在"; } else { if (txt_name.Text == "") { lab_tip.Text = "输入不能为空"; } else { ta_booktype.InsertAdminSBooktype(txt_name.Text, 0, parent_id); lab_tip.Text = "添加成功"; } } } }
protected void btn_add_Click(object sender, EventArgs e) { AdminBooktypeTableAdapter ta_fabooktype = new AdminBooktypeTableAdapter(); DataTable dt_fabooktype = ta_fabooktype.GetAdminBooktypeByName(txt_name.Text); if (dt_fabooktype.Rows.Count != 0) { lab_tip.Text = "目录名已存在"; } else { ta_fabooktype.InsertAdminFBooktype(txt_name.Text, Convert.ToDouble(txt_price.Text), 0); lab_tip.Text = "添加成功"; } }
protected void btn_allmoney_click(object sender, EventArgs e) { string name; int price; if (rbl_menu.SelectedItem != null) { name = rbl_menu.SelectedItem.Text.ToString(); AdminBooktypeTableAdapter ta_book = new AdminBooktypeTableAdapter(); DataTable dt_book = ta_book.GetAdminBooktypeByName(name); price = Convert.ToInt32(dt_book.Rows[0]["price"]); int buycount = Convert.ToInt32(txtBuycount.Value); int allprice = price * buycount; lbl_allprice.Text = allprice.ToString(); } }
protected void MoveMenu(int parent_id) { AdminBooktypeTableAdapter ta_booktype = new AdminBooktypeTableAdapter(); DataTable dt_booktype = ta_booktype.GetTypeByParentId(parent_id); int j = 0; while (dt_booktype.Rows.Count > j) { ++i; a[i] = Convert.ToInt32(dt_booktype.Rows[j]["id"]); ++j; MoveMenu(a[i]); } }
private void AddTree(int Pid, TreeNode PNode) { AdminBooktypeTableAdapter ta_fatype = new AdminBooktypeTableAdapter(); AdminBookTableAdapter ta_book = new AdminBookTableAdapter(); DataTable dt_fa = ta_fatype.GetAdminMenuBooktype(); DataTable dt_book = ta_book.GetMenuBook(); dt_fa.Merge(dt_book); if (dt_fa.Rows.Count > 0) { DataView dv = new DataView(dt_fa); //过滤ParentID,得到当前的所有子节点 ParentID为父节点ID dv.RowFilter = "[parent_id] = " + Pid; //循环递归 foreach (DataRowView Row in dv) { //声明节点 TreeNode Node = new TreeNode(); //绑定超级链接 //Node.NavigateUrl = String.Format("javascript:show('{0}')", Row["name"].ToString()); //开始递归 if (PNode == null) { //添加根节点 Node.Text = Row["name"].ToString(); Node.Value = Row["id"].ToString(); name = Node.Text; tree.Nodes.Add(Node); Node.Expanded = false; //节点状态收缩 AddTree(Int32.Parse(Row["id"].ToString()), Node); //再次递归 } else { //添加当前节点的子节点 Node.Text = Row["name"].ToString(); Node.Value = Row["id"].ToString(); name = Node.Text; PNode.ChildNodes.Add(Node); Node.Expanded = false; //节点状态收缩 AddTree(Int32.Parse(Row["id"].ToString()), Node); //再次递归 } } } }
protected void Page_Load(object sender, EventArgs e) { Corporation corporation = (Corporation)Session["corporation"]; if (Session["corporation"] == null) { Response.Redirect("../corporation_login.aspx"); } else { url = "upload/" + corporation.name + "/"; if (!IsPostBack) { AddTree(0, null); content.Visible = false; selectbook.Visible = true; addinfo.Visible = false; btn_view.Visible = false; } if (this.tree.SelectedNode != null) { lbl_selectednode.Text = this.tree.SelectedNode.Text; Boolean b1 = lbl_selectednode.Text.EndsWith(".doc"); Boolean b2 = lbl_selectednode.Text.EndsWith(".pdf"); Boolean b3 = lbl_selectednode.Text.EndsWith(".txt"); Boolean b4 = lbl_selectednode.Text.EndsWith(".ppt"); Boolean b5 = lbl_selectednode.Text.EndsWith(".dwg"); if (b1 || b2 || b3 || b4 || b5) { } else { content.Visible = false; selectbook.Visible = true; addinfo.Visible = false; btn_view.Visible = false; DataTable dt_allbook = null; DataTable dt_branchbook = null; //开始控制selectbook中的显示 int tree_id = Convert.ToInt32(this.tree.SelectedNode.Value); AdminBooktypeTableAdapter ta_admin = new AdminBooktypeTableAdapter(); DataTable dt_corpo = ta_admin.GetBooktypeById(tree_id); int tree_parentid = Convert.ToInt32(dt_corpo.Rows[0]["parent_id"]); if (tree_parentid > 0) { //由此在book_parent[]中获得选定的目录下面有书籍的目录id getson(Convert.ToInt32(dt_corpo.Rows[0]["id"])); Connect connect = new Connect(); for (int m = 0; m < parent_num; m++) { string sql_temp = "SELECT dbo.AdminBook.id, dbo.AdminBook.name, dbo.AdminBT.abooktype_id AS parent_id,dbo.AdminBook.star,dbo.AdminBook.url," + "dbo.AdminBook.author,dbo.AdminBook.keyword,dbo.AdminBook.score,dbo.AdminBook.filetype " + "FROM AdminBook INNER JOIN AdminBT ON AdminBT.abook_id = AdminBook.id " + "INNER JOIN AdminBooktype ON AdminBT.abooktype_id = AdminBooktype.id " + "WHERE (AdminBT.abooktype_id = " + book_parent[m] + ")"; if (m == 0) { dt_allbook = connect.GetDataTable(sql_temp); } else { dt_branchbook = connect.GetDataTable(sql_temp); dt_allbook.Merge(dt_branchbook); } } if (rbl_score.SelectedItem == null) { dt_allbook.DefaultView.Sort = "name Asc"; } else { if (Convert.ToInt32(rbl_score.SelectedItem.Value) == 0) { dt_allbook.DefaultView.Sort = "star Desc"; } if (Convert.ToInt32(rbl_score.SelectedItem.Value) == 1) { dt_allbook.DefaultView.Sort = "score Asc"; } if (Convert.ToInt32(rbl_score.SelectedItem.Value) == 2) { dt_allbook.DefaultView.Sort = "name Asc"; } } lab_count.Text = dt_allbook.Rows.Count.ToString(); rep_booklist.DataSource = dt_allbook; rep_booklist.DataBind(); } } } } }
protected void btn_confirm_click(object sender, EventArgs e) { Connect connect = new Connect(); string sql; //为了将bookpath完整的表现出来,目前差一个后缀 string[] book = new string[200]; string[] cbook = new string[200]; Corporation corporation = (Corporation)Session["corporation"]; int corporationid = corporation.id; CorpoBooktypeTableAdapter ta_corpo = new CorpoBooktypeTableAdapter(); DataTable dt_corpo = ta_corpo.GetCBookTypeByTwo(Convert.ToInt32(rbl_menu.SelectedItem.Value), corporationid); if (dt_corpo.Rows.Count > 0) { //避免目录的重复购买 Response.Write("<script language='javascript'>alert('您已经购买过此目录,不能继续进行购买');</script>"); } else { if (Convert.ToInt32(lbl_allprice.Text) > 0) { string name; int price; if (rbl_menu.SelectedItem != null) { name = rbl_menu.SelectedItem.Text.ToString(); AdminBooktypeTableAdapter ta_book = new AdminBooktypeTableAdapter(); DataTable dt_book = ta_book.GetAdminBooktypeByName(name); price = Convert.ToInt32(dt_book.Rows[0]["price"]); int buycount = Convert.ToInt32(txtBuycount.Value); int allprice = price * buycount; lbl_allprice.Text = allprice.ToString(); int day = buycount; int book_type = Convert.ToInt32(rbl_menu.SelectedItem.Value); //通过insertbill数据来表明账单已经产生 BillTableAdapter ta_bill = new BillTableAdapter(); ta_bill.InsertBill(DateTime.Now.ToString(), day, allprice, 1, corporationid); DataTable dt_bill = ta_bill.GetCurrentBill(); //bill_id是在企业中显示他们买了哪些目录,以便显示出他们拥有的目录 int bill_id = Convert.ToInt32(dt_bill.Rows[0]["id"]); sql = "insert into Billtype (bill_id,abooktype_id) values (" + bill_id + "," + book_type + ")"; connect.ExecuteSql(sql); string book_path = "corporation/upload/" + corporation.name; /*购买了目录,那么目录就会全部移植到cbooktype和cbook,cbt中*/ //开始进行booktype表的转移 a[i] = Convert.ToInt32(rbl_menu.SelectedItem.Value); //递归来进行booktype的转移 MoveMenu(a[i]); //得到a数组中保存的booktype的id,全部insert到子公司目录中 int j = 0; while (j <= i) { sql = "insert into CorpoBooktype (abooktype_id,name,price,parent_id,corporation_id) select id,name,price,parent_id," + corporationid + " as corporation_id from AdminBooktype where id=" + a[j]; connect.ExecuteSql(sql); j++; } //开始进行book表的转移 int k = 0; int n = -1; int q = 0; while (k <= i) { AdminBookTableAdapter ta_admin = new AdminBookTableAdapter(); DataTable dt_admin = ta_admin.GetBookByBooktypeId(a[k]); if (dt_admin.Rows.Count > 0) { for (q = 0; q < dt_admin.Rows.Count; q++) { ++n; book[n] = dt_admin.Rows[q]["url"].ToString(); string[] split = book[n].Split(new[] { "/" }, StringSplitOptions.RemoveEmptyEntries); cbook[n] = book_path + "/" + split[3]; } } ++k; } k = 0; while (k <= n) { sql = "insert into CorpoBook (abook_id,corporation_id,name,url,star,author,keyword,score,filetype) " + "select id," + corporationid + " as corporation_id,name,'" + cbook[k] + "' as book_path,star,author,keyword,score,filetype FROM AdminBook inner join AdminBT on AdminBT.abook_id = AdminBook.id " + " where AdminBook.url='" + book[k] + "'"; connect.ExecuteSql(sql); ++k; } //开始进行bt表的转移 int m = 0; while (m <= i) { sql = "insert into CorpoBT (cbook_id,cbooktype_id,corporation_id) select abook_id,abooktype_id," + corporationid + " as corporation_id from AdminBT where abooktype_id = " + a[m]; connect.ExecuteSql(sql); m++; } Response.Write("<script language='javascript'>alert('购买成功,可进入订单列表查看');</script>"); } else { Response.Write("<script language='javascript'>alert('未选定目录');</script>"); } } } }