Beispiel #1
0
        private bool updateUser(string associateId, string firstname, string lastname, string fullname, string username, string email, string role, string group, string license, DataGridViewRow item)
        {
            bool result = false;

            try
            {
                SoUser user = SoUser.ManageUser(Convert.ToInt32(associateId));
                SuperOffice.CRM.Entities.Person p = user.Person;
                p.Firstname = firstname;
                p.Lastname  = lastname;
                //p.PersonNumber = username;
                String   pwd = username;
                EmailRow em  = null;
                if (p.Emails.Count == 0)
                {
                    em = p.Emails.AddNew();
                    em.SetDefaults();
                }
                else
                {
                    em = p.Emails[0];
                }

                // always set correct email; we have just the one address
                em.EmailAddress = email;
                em.Protocol     = "SMTP";

                // save complete person entity
                p.Save();
                //Console.WriteLine("\tPerson/email done");

                // set our various properties
                user.SetPassword(pwd);
                user.GroupIdx      = _groups[group];
                user.OtherGroupIds = new int[0];

                user.RoleIdx   = _roles[role];
                user.LogonName = username;
                user.Tooltip   = fullname + " (" + SoSystemInfo.GetCurrent().CompanyName + ")";

                // add licenses
                if (user.GetModuleLicense("SuperOffice", DefaultLicense).CanAssign)
                {
                    user.GetModuleLicense("SuperOffice", DefaultLicense).Assigned = true;
                    item.Cells["AssignedLicenses"].Value = "Assigned Default";
                }
                else
                {
                    item.Cells["AssignedLicenses"].Value = "Cannot Assign";
                }
                //user.GetModuleLicense(SoLicenseNames.SuperLicenseServicePro).Assigned = true;

                /*user.GetModuleLicense(SoLicenseNames.User).Assigned = true;
                 * user.GetModuleLicense(SoLicenseNames.Web).Assigned = true;*/
                user.GetModuleLicense(SoLicenseNames.VisibleFor).Assigned = true;

                // save the user
                user.Save();
                //Console.WriteLine("\tUser saved\n");
                result = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            return(result);
        }
Beispiel #2
0
        private void btnLoadFile_Click(object sender, EventArgs e)
        {
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                using (var _session = SoSession.Authenticate(Username, Password))
                {
                    DataGridViewComboBoxColumn rolesColumn = (DataGridViewComboBoxColumn)dtUsersList.Columns["Role"];
                    rolesColumn.DataSource    = roles.ToList();
                    rolesColumn.DisplayMember = "Name";

                    DataGridViewComboBoxColumn groupsColumn = (DataGridViewComboBoxColumn)dtUsersList.Columns["UserGroup"];
                    groupsColumn.DataSource    = groups.ToList();
                    groupsColumn.DisplayMember = "Value";
                    p = new FileParser(openFileDialog.FileName);

                    MessageBox.Show("File parsed, " + p.UserInfos.Count.ToString() + " users read\n");

                    foreach (ImportUserInfo ui in p.UserInfos)
                    {
                        ContactTableInfo          cti  = TablesInfo.GetContactTableInfo();
                        OwnerContactLinkTableInfo octi = TablesInfo.GetOwnerContactLinkTableInfo();
                        Select findOc = S.NewSelect("Find OC");

                        findOc.JoinRestriction.InnerJoin(cti.ContactId.Equal(octi.ContactId));

                        // if contact name contains a comma, assume that pre-comma is name and post-comma is department (db & file are set up that way)
                        if (ui.Company.Contains(","))
                        {
                            findOc.Restriction = cti.Name.Equal(S.Parameter(ui.Company.Split(',')[0].Trim())).
                                                 And(cti.Department.Equal(S.Parameter(ui.Company.Split(',')[1].Trim())));
                        }
                        else
                        {
                            findOc.Restriction = cti.Name.Equal(S.Parameter(ui.Company));
                        }

                        findOc.ReturnFields.Add(cti.ContactId);

                        int ocId = QueryExecutionHelper.ExecuteTypedScalar <int>(findOc);

                        if (ocId == 0)
                        {
                            //MessageBox.Show("Owner company " + ui.Company + "(referenced by " + ui.UID + ")  does not exist OR is not an Owner Company - setting to License Owner " + SoSystemInfo.GetCurrent().CompanyName);
                            ui.Company = SoSystemInfo.GetCurrent().CompanyName;
                            if (!_contacts.ContainsKey(SoSystemInfo.GetCurrent().CompanyName))
                            {
                                _contacts.Add(ui.Company, SoSystemInfo.GetCurrent().CompanyId);
                            }
                        }
                        else if (!_contacts.ContainsKey(ui.Company))
                        {
                            _contacts.Add(ui.Company, ocId);
                        }

                        if (!_roles.ContainsKey(ui.Role))
                        {
                            ui.Role = DefaultRole;
                        }
                        if (!_groups.ContainsKey(ui.Group))
                        {
                            ui.Group = DefaultGroup;
                        }
                    }
                    Dictionary <string, int> users = Importer.FindUsers();

                    dtUsersList.AutoGenerateColumns = false;
                    dtUsersList.Columns["FirstName"].DataPropertyName   = "FirstName";
                    dtUsersList.Columns["LastName"].DataPropertyName    = "LastName";
                    dtUsersList.Columns["FullName"].DataPropertyName    = "FullName";
                    dtUsersList.Columns["UserName"].DataPropertyName    = "UID";
                    dtUsersList.Columns["Email"].DataPropertyName       = "Email";
                    dtUsersList.Columns["Role"].DataPropertyName        = "Role";
                    dtUsersList.Columns["UserGroup"].DataPropertyName   = "Group";
                    dtUsersList.Columns["Company"].DataPropertyName     = "Company";
                    dtUsersList.Columns["AssociateId"].DataPropertyName = "AssociateId";
                    dtUsers = Importer.ConvertToDataTable <ImportUserInfo>(p.UserInfos);
                    dtUsersList.DataSource = dtUsers;
                    //dtUsersList.DataSource = p.UserInfos;
                    progressBar.Value = 0;
                    foreach (DataGridViewRow item in dtUsersList.Rows)
                    {
                        string username = item.Cells["UserName"].Value.ToString();
                        if (users.ContainsKey(username))
                        {
                            item.Cells["Status"].Value      = "Exists";
                            item.Cells["AssociateId"].Value = users[username];
                            string license = Importer.GetLicense(users[username], LookupList);
                            item.Cells["AssignedLicenses"].Value = license;
                        }
                        else
                        {
                            item.Cells["AssociateId"].Value      = DBNull.Value;
                            item.Cells["Status"].Value           = "New";
                            item.Cells["AssignedLicenses"].Value = "";
                        }
                    }
                }
                btnProcess.Enabled = true;
                progressBar.Value  = 0;
                txtSearch.Text     = "";
                lblSearch.Visible  = true;
                txtSearch.Visible  = true;
            }
        }