/// <summary> /// 获取当前用户能够操作的公司ID,以“,”分割 /// </summary> /// <returns></returns> public static string GetOwnerCompanyId() { string allOwnerCompanyId = ""; bool bol = true; #region 加载所有公司 try { string path = "silverlightcache\\" + Utility.CurrentUser.EMPLOYEEID + "ID.txt"; var company = SLCache.GetCache <string>(path, 5); if (company != null) { allOwnerCompanyId = company; return(company); } else { SMT.Saas.Tools.OrganizationWS.OrganizationServiceClient osc = new Saas.Tools.OrganizationWS.OrganizationServiceClient(); osc.GetCompanyViewAsync(Utility.CurrentUser.EMPLOYEEID, "3", ""); osc.GetCompanyViewCompleted += (obj, args) => { if (args.Result != null) { string companylist = ""; foreach (var ent in args.Result) { companylist += "'" + ent.COMPANYID + "',"; } allOwnerCompanyId = companylist.TrimEnd(','); SLCache.SaveData <string>(companylist.TrimEnd(','), path); } bol = false; }; //等异步完成 while (bol) { //等异步完成 } ; return(allOwnerCompanyId); } } catch (Exception ee) { SMT.SaaS.FrameworkUI.ChildWidow.ComfirmWindow.ConfirmationBox("错误信息", ee.Message, "确定"); return(null); } #endregion }
/// <summary> /// ComboBox 绑定所有公司T_HR_COMPANY,显示CNAME /// </summary> /// <param name="cboCompany">ComboBox</param> /// <param name="companyidSelect">被选中的公司ID,如果是空,则默认为登录人员所属公司ID</param> public static void ComboBoxBindAllCompany(ComboBox cboCompany, string companyidSelect) { #region 加载所有公司 try { //string path = "silverlightcache\\t_hr_company.txt"; //实际位置:C:\Users\longkc\AppData\LocalLow\Microsoft\Silverlight\is\5qkvd2vt.kdf\ngv1qcai.xbm\1\s\4nhtt330ofuzh0pwkcqvwnecnu2bejhgref3w4wo5cz02n5f0haaaaga\f\silverlightcache\t_hr_company.txt // var company = SLCache.GetCache<ObservableCollection<SMT.Saas.Tools.OrganizationWS.T_HR_COMPANY>>(path); string path = "silverlightcache\\" + Utility.CurrentUser.EMPLOYEEID + ".txt"; var company = SLCache.GetCache <ObservableCollection <SMT.Saas.Tools.OrganizationWS.V_COMPANY> >(path, 2); if (company == null) { osc.GetCompanyViewAsync(Utility.CurrentUser.EMPLOYEEID, "3", ""); osc.GetCompanyViewCompleted += (obj, args) => { if (args.Result != null) { if (company != null) { company.Clear(); } var result = args.Result; company = result; var selobj = company.Where(c => c.CNAME == "=请选择=").FirstOrDefault(); if (selobj == null) { company.Insert(0, new Saas.Tools.OrganizationWS.V_COMPANY { COMPANYID = "", CNAME = "=请选择=" }); //if (selobj.CNAME.IndexOf("=请选择=") < 0) //{ // company.Insert(0, new Saas.Tools.OrganizationWS.V_COMPANY { COMPANYID = "", CNAME = "=请选择=" }); //} } // company.Insert(0, new Saas.Tools.OrganizationWS.V_COMPANY { COMPANYID = "", CNAME = "=请选择=" }); cboCompany.ItemsSource = result.OrderBy(c => c.CNAME); cboCompany.DisplayMemberPath = "CNAME"; if (string.IsNullOrEmpty(companyidSelect)) { string companyid = SMT.SAAS.Main.CurrentContext.Common.CurrentLoginUserInfo.UserPosts[0].CompanyID; cboCompany.SelectedByObject <SMT.Saas.Tools.OrganizationWS.V_COMPANY>("COMPANYID", companyid); } else { cboCompany.SelectedByObject <SMT.Saas.Tools.OrganizationWS.V_COMPANY>("COMPANYID", companyidSelect); } SLCache.SaveData <ObservableCollection <SMT.Saas.Tools.OrganizationWS.V_COMPANY> >(result, path); } }; #region 没有权限 //osc.GetCompanyAllAsync(""); //osc.GetCompanyAllCompleted += (obj, args) => //{ // if (args.Result != null) // { // var result = args.Result; // company = result; // company.Insert(0, new Saas.Tools.OrganizationWS.T_HR_COMPANY { COMPANYID = "", CNAME = "=请选择=" }); // cboCompany.ItemsSource = result.OrderBy(c => c.CNAME); // cboCompany.DisplayMemberPath = "CNAME"; // if (string.IsNullOrEmpty(companyidSelect)) // { // string companyid = SMT.SAAS.Main.CurrentContext.Common.CurrentLoginUserInfo.UserPosts[0].CompanyID; // cboCompany.SelectedByObject<SMT.Saas.Tools.OrganizationWS.T_HR_COMPANY>("COMPANYID", companyid); // } // else // { // cboCompany.SelectedByObject<SMT.Saas.Tools.OrganizationWS.T_HR_COMPANY>("COMPANYID", companyidSelect); // } // SLCache.SaveData<ObservableCollection<SMT.Saas.Tools.OrganizationWS.T_HR_COMPANY>>(result, path); // } //}; #endregion } else { //var selobj = company.Where(c => c.CNAME == "=请选择=").FirstOrDefault(); //if (selobj != null) //{ // company.Remove(selobj); //} //if (selobj.CNAME.IndexOf("=请选择=") < 0) //{ // company.Insert(0, new Saas.Tools.OrganizationWS.V_COMPANY { COMPANYID = "", CNAME = "=请选择=" }); //} cboCompany.ItemsSource = company.OrderBy(c => c.CNAME); cboCompany.DisplayMemberPath = "CNAME"; if (string.IsNullOrEmpty(companyidSelect)) { string companyid = SMT.SAAS.Main.CurrentContext.Common.CurrentLoginUserInfo.UserPosts[0].CompanyID; cboCompany.SelectedByObject <SMT.Saas.Tools.OrganizationWS.V_COMPANY>("COMPANYID", companyid); } else { cboCompany.SelectedByObject <SMT.Saas.Tools.OrganizationWS.V_COMPANY>("COMPANYID", companyidSelect); } } } catch { if (cboCompany.Items.Count < 2)//小于1是因为=请选择= 有一个 { osc.GetCompanyViewAsync(Utility.CurrentUser.EMPLOYEEID, "3", ""); osc.GetCompanyViewCompleted += (obj, args) => { if (args.Result != null) { cboCompany.ItemsSource = null; var result = args.Result; //var sel = new Saas.Tools.OrganizationWS.T_HR_COMPANY { COMPANYID = "", CNAME = "=请选择=" }; var s = from c in result where c.COMPANYID == "" select c; if (s.FirstOrDefault() == null) { result.Insert(0, new Saas.Tools.OrganizationWS.V_COMPANY { COMPANYID = "", CNAME = "=请选择=" }); } //var company = result; //company.Insert(0, new Saas.Tools.OrganizationWS.T_HR_COMPANY { COMPANYID = "", CNAME = "=请选择=" }); cboCompany.ItemsSource = result.OrderBy(c => c.CNAME); cboCompany.DisplayMemberPath = "CNAME"; if (string.IsNullOrEmpty(companyidSelect)) { string companyid = SMT.SAAS.Main.CurrentContext.Common.CurrentLoginUserInfo.UserPosts[0].CompanyID; cboCompany.SelectedByObject <SMT.Saas.Tools.OrganizationWS.V_COMPANY>("COMPANYID", companyid); } else { cboCompany.SelectedByObject <SMT.Saas.Tools.OrganizationWS.V_COMPANY>("COMPANYID", companyidSelect); } } }; #region 重新绑定 //osc.GetCompanyAllAsync(""); //osc.GetCompanyAllCompleted += (obj, args) => //{ // if (args.Result != null) // { // cboCompany.ItemsSource = null; // var result = args.Result; // //var sel = new Saas.Tools.OrganizationWS.T_HR_COMPANY { COMPANYID = "", CNAME = "=请选择=" }; // var s = from c in result where c.COMPANYID == "" select c; // if (s.FirstOrDefault() == null) // { // result.Insert(0, new Saas.Tools.OrganizationWS.T_HR_COMPANY { COMPANYID = "", CNAME = "=请选择=" }); // } // //var company = result; // //company.Insert(0, new Saas.Tools.OrganizationWS.T_HR_COMPANY { COMPANYID = "", CNAME = "=请选择=" }); // cboCompany.ItemsSource = result.OrderBy(c => c.CNAME); // cboCompany.DisplayMemberPath = "CNAME"; // if (string.IsNullOrEmpty(companyidSelect)) // { // string companyid = SMT.SAAS.Main.CurrentContext.Common.CurrentLoginUserInfo.UserPosts[0].CompanyID; // cboCompany.SelectedByObject<SMT.Saas.Tools.OrganizationWS.T_HR_COMPANY>("COMPANYID", companyid); // } // else // { // cboCompany.SelectedByObject<SMT.Saas.Tools.OrganizationWS.T_HR_COMPANY>("COMPANYID", companyidSelect); // } // } //}; #endregion } else { if (string.IsNullOrEmpty(companyidSelect)) { string companyid = SMT.SAAS.Main.CurrentContext.Common.CurrentLoginUserInfo.UserPosts[0].CompanyID; cboCompany.SelectedByObject <SMT.Saas.Tools.OrganizationWS.V_COMPANY>("COMPANYID", companyid); } else { cboCompany.SelectedByObject <SMT.Saas.Tools.OrganizationWS.V_COMPANY>("COMPANYID", companyidSelect); } } } #endregion }