/*
        private void bindTreeView()
        {
            trDepartment.Nodes.Clear();
            // ---- BIND DU LIEU VAO LISTVIEW --
            cls_DepartmentInformation dInfor = new cls_DepartmentInformation();
            dInfor.CompanyId = Convert.ToInt16(ddlCompany.SelectedValue);
            DataTable dtDepart = dInfor.SelectByComId();
            ViewState["countDepartment"] = dtDepart.Rows.Count.ToString();

            DataRow[] _Row = dtDepart.Select("DepartParentId=0");
            if (_Row.Count() > 0)
            {
                for (int i = 0; i < _Row.Count(); i++)
                {
                    TreeNode node = new TreeNode();
                    node.Text = _Row[i]["DepartName"].ToString();
                    node.Value = _Row[i]["Id"].ToString();

                    trDepartment.Nodes.Add(node);
                    addNode(_Row[i]["Id"].ToString(), node, dtDepart);
                }
            }
        }

        private void addNode(string parentId, TreeNode parentNode, DataTable dtDepart)
        {
            try
            {
                DataRow[] _Row = dtDepart.Select("DepartParentId=" + parentId);
                if (_Row.Count() > 0)
                {
                    for (int i = 0; i < _Row.Count(); i++)
                    {
                        TreeNode childNode = new TreeNode();
                        childNode.Text = _Row[i]["DepartName"].ToString();
                        childNode.Value = _Row[i]["Id"].ToString();

                        parentNode.ChildNodes.Add(childNode);
                        addNode(_Row[i]["Id"].ToString(), childNode, dtDepart);
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
         * */
        private void bindData()
        {
            ckbActive.Checked = true;

            if (dAction != 2)
            {
                try
                {
                    //LAY THONG TIN PHONG BAN
                    cls_DepartmentInformation cDepart = new cls_DepartmentInformation();
                    cDepart.Id = Convert.ToInt32(Request["D_Id"]);
                    cDepart = cDepart.Select();

                    if (cDepart != null)
                    {
                        txtDepartName.Text = cDepart.Name;
                        rtxtOrder.Text = cDepart.Order.ToString();
                        ddlBelongCompany.SelectedValue = cDepart.CompanyId.ToString();
                        if(cDepart.Established_Date.CompareTo(new DateTime(1900, 1, 1)) > 0)
                            dateEstablish.SelectedDate = cDepart.Established_Date;

                        txtEstaNumber.Text = cDepart.Established_Number;
                        txtSigner.Text = cDepart.Established_Signer;
                        txtSeatPosition.Text = cDepart.SeatPosition;
                        ckbActive.Checked = (cDepart.IsActive == 1) ? true : false;
                        ckbCalSalary.Checked = (cDepart.CalculateSalary == 1) ? true : false;

                        if (cDepart.CompanyId > 0)
                        {
                            rcbDepartment_Bind();
                            bindRadCombo();
                        }

                        RadTreeView rTree = (RadTreeView)rcbDepartment.Items[0].FindControl("rtrDepartment");
                        RadTreeNode node = rTree.FindNodeByValue(cDepart.Belong_DepartmentId.ToString());
                        node.Selected = true;
                        rcbDepartment.Items[0].Text = node.Text;

                        cboLeader.SelectedValue = cDepart.LeaderId.ToString();
                        cboAdministrator.SelectedValue = cDepart.AdministratorId.ToString();
                    }
                    bind_M_Grid_Data(-1);
                    bind_Ls_HonourName(-1);
                }
                catch (Exception ex)
                {
                }
            }
            else                                    //insert them department moi
            {
                bind_M_Grid_Data(-1);
                bind_Ls_HonourName(-1);

                if (ViewState["countHName"].ToString() == "0")
                    lvHonourName.Items[0].Visible = false;
                if (ViewState["countDRoles"].ToString() == "0")
                    m_grid.Rows[0].Visible = false;

                if ((ViewState["countDRoles"].ToString() == "0") && (ViewState["countHName"].ToString() == "0"))
                {
                    //VIEW DU LIEU LEN
                    txtDepartName.Text = "";
                    rtxtOrder.Text = "";
                    txtEstaNumber.Text = "";
                    txtSigner.Text = "";
                }
                rcbDepartment_Bind();
                bindRadCombo();

                RadTreeView rTree = (RadTreeView)rcbDepartment.Items[0].FindControl("rtrDepartment");
                rTree.Nodes[0].Selected = true;
                rcbDepartment.Items[0].Text = rTree.Nodes[0].Text;
                cboAdministrator.SelectedValue = cboLeader.SelectedValue = "0";
            }
        }