protected void cbpTextPartyEdit_Callback(object source, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e) { IList <DevExpress.Web.ASPxTreeList.TreeListNode> selectedNodes = treeList.GetSelectedNodes(); VOOrgTree node = null; foreach (DevExpress.Web.ASPxTreeList.TreeListNode n in selectedNodes) { node = (VOOrgTree)n.DataItem; break; } textPartyEdit.Text = node.FullName; textPartyEdit.Value = node.ID; }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsCallback) { if (IsRequiredField) { textPartyEdit.SetValidation(ValidationGroup, true); } /*init script*/ treeList.ClientInstanceName = this.ClientID + treeList.ClientID; textPartyEdit.ClientInstanceName = this.ClientID + textPartyEdit.ClientID; popupParty.ClientInstanceName = this.ClientID + popupParty.ClientID; //btnSelect.ClientInstanceName = this.ClientID + btnSelect.ClientID; cbpTextPartyEdit.ClientInstanceName = this.ClientID + cbpTextPartyEdit.ClientID; labelParty.ClientInstanceName = this.ClientID + labelParty.ClientID; hddOrganization.ClientInstanceName = this.ClientID + hddOrganization.ClientID; string jsScriptTxtPartyEdit = @"var tree = " + treeList.ClientInstanceName + @"; var labelFullName = " + labelParty.ClientInstanceName + @"; var textInput = " + textPartyEdit.ClientInstanceName + @"; if(s.GetText()!= '') { var fullname = ''; var isParent = false; for(var i=0; i < tree.cpKeys.length; i++ ) { var id = tree.cpKeys[i]; var parentCode = tree.cpParentCodes[i]; var code = tree.cpCodes[i]; " + (CanSelectUnitOnly ? @"if(parentCode != '' && (s.GetText() == (parentCode+'-'+code))) { tree.SelectNode(id.toString(), true); fullname = tree.cpFullNames[i]; break; } else { tree.SelectNode(id.toString(), false); if(parentCode == '' && (s.GetText() == code)) isParent = true; } " : @"if((s.GetText() == code) || ((parentCode != null)&&(s.GetText() == (parentCode+'-'+code))) ) { tree.SelectNode(id.toString(), true); fullname = tree.cpFullNames[i]; break; } else tree.SelectNode(id.toString(), false);" ) + @" } labelFullName.SetText(fullname); if(fullname == '') { if(isParent) alert('กรุณาเลือกเฉพาะสาขา'); else alert('รหัส '+ s.GetText() +' ไม่มีในระบบ'); //textInput.Focus(); textInput.SelectAll(); } }"; textPartyEdit.ClientSideEvents.ButtonClick = @"function(s, e) { var win = " + popupParty.ClientInstanceName + @".GetWindow(0); " + popupParty.ClientInstanceName + @".ShowWindow(win);" //+ jsScriptTxtPartyEdit + "}"; textPartyEdit.ClientSideEvents.ValueChanged = @"function(s, e) {" + jsScriptTxtPartyEdit + @" }"; String CanSelectUnitOnlyScript = @"function(s, e) { " + popupParty.ClientInstanceName + @".Hide(); var list = new Array(); list[0] = 'ID'; list[1] = 'FullName'; list[2] = 'TypeInString'; list[3] = 'Code'; list[4] = 'ParentCode'; var code; s.GetNodeValues(e.nodeKey, list, function(values) { if(values.length > 0) {" + labelParty.ClientInstanceName + @".SetText(values[1]); if(values[4] != '' && values[4] != 'null') code = values[4] + '-' + values[3]; else code = values[3];" + textPartyEdit.ClientInstanceName + @".SetText(code); if(typeof(oncompleteLoadOrganization) != 'undefined') { oncompleteLoadOrganization(); } } }); }"; String OtherScript = @"function(s, e) { " + popupParty.ClientInstanceName + @".Hide(); var list = new Array(); list[0] = 'ID'; list[1] = 'FullName'; list[2] = 'TypeInString'; list[3] = 'Code'; list[4] = 'ParentCode'; s.GetNodeValues(e.nodeKey, list, function OnGridSelectionComplete(values) { if(values.length > 0) { if(values[2]=='iSabaya.OrgUnit') {" + labelParty.ClientInstanceName + @".SetText(values[1]);" + textPartyEdit.ClientInstanceName + @".SetText(values[4] + '-' + values[3]) ; if(typeof(oncompleteLoadOrganization) != 'undefined') { oncompleteLoadOrganization(); } } else { alert('กรุณาเลือกเฉพาะสาขา'); } } }); }"; if (CanSelectUnitOnly == false) { treeList.ClientSideEvents.NodeDblClick = CanSelectUnitOnlyScript; } else { treeList.ClientSideEvents.NodeDblClick = OtherScript; } /*init script*/ if (IsBank == false) { IList <VOOrgTree> list = new List <VOOrgTree>(); IList <Organization> organizations = iSabaya.Organization.List(iSabayaContext); List <int> ids = new List <int>(); foreach (Organization org in organizations) { list.Add(new VOOrgTree(org)); } if (OrganizationOnly == false) { #region new codes //add org units to the list foreach (Organization org in organizations) { foreach (OrgUnit orgUnit in org.OrgUnits) { list.Add(new VOOrgTree(orgUnit)); } } #endregion new codes #region original codes //ArrayList orgList = ArrayList.Adapter(organizations); //orgList.Sort(new Organization()); //IList<OrgUnit> orgUnits = OrgUnit.List(iSabayaContext); //VOOrgTree vo; //if (IsSellingAgent == false) //{ // foreach (OrgUnit org in orgUnits) // { // vo = new VOOrgTree(org); // list.Add(vo); // } //} //else //{ // foreach (OrgUnit org in orgUnits) // { // bool hit = ArrayList.Adapter((IList)organizations).BinarySearch(org.OrganizationParent, new Organization()) > -1; // if (hit) // { // vo = new VOOrgTree(org); // list.Add(vo); // } // } //} #endregion original codes } treeList.DataSource = list; treeList.DataBind(); treeList.ExpandAll(); Session[this.ID.ToString() + "ctrls_OrganizationOrgUnitControl_VOOrgTree"] = list; } else { //bank IList <VOOrgTree> list = new List <VOOrgTree>(); IList <Organization> banks = Organization.Find(iSabayaContext, TreeListNode.FindRootByCode(iSabayaContext, "Bank")); foreach (Organization org in banks) { VOOrgTree vo = new VOOrgTree(org); list.Add(vo); } if (OrganizationOnly == false) { #region new codes //add org units to the list foreach (Organization org in banks) { foreach (OrgUnit orgUnit in org.OrgUnits) { VOOrgTree vo = new VOOrgTree(orgUnit); list.Add(vo); } } #endregion new codes #region original codes //IList<OrgUnit> orgUnits = OrgUnit.List(iSabayaContext); //foreach (OrgUnit org in orgUnits) //{ // VOOrgTree vo = new VOOrgTree(org); // int parentId = org.OrganizationParent.ID; // bool hit = false; // for (int i = 0; i < list.Count; i++) // { // if (parentId == list[i].ID) // { // hit = true; // break; // } // } // if (hit) // { // list.Add(vo); // } //} #endregion original codes } treeList.DataSource = list; treeList.DataBind(); treeList.ExpandAll(); Session[this.ID.ToString() + "ctrls_OrganizationOrgUnitControl_VOOrgTree"] = list; } } else { if (Session[this.ID.ToString() + "ctrls_OrganizationOrgUnitControl_VOOrgTree"] != null) { treeList.DataSource = (IList <VOOrgTree>)Session[this.ID.ToString() + "ctrls_OrganizationOrgUnitControl_VOOrgTree"]; treeList.DataBind(); } } }