Exemplo n.º 1
0
        private void buttonOk_Click(object sender, EventArgs e)
        {
            if (validate())
            {
                User user = new User();
                user.id           = userId;
                user.cellPhone    = textBoxCellPhone.Text.Trim();
                user.mail         = textBoxMail.Text.Trim();
                user.name         = textBoxAdminName.Text.Trim();
                user.roleId       = 1;
                user.storeId      = 0;
                user.memo         = textBoxMemo.Text.Trim();
                user.passwordSalt = PasswordEncryption.generateSalt();
                user.password     = PasswordEncryption.generatePassword(textBoxPassword.Text.Trim(), user.passwordSalt);
                user.active       = true;

                Tenant tenant = new Tenant();
                tenant.id             = tenantId;
                tenant.enableWorkFlow = checkBoxEnableWorkFlow.Checked;
                tenant.createdDate    = dateTimePickerCreatedDate.Value;
                tenant.categoryId     = Convert.ToUInt16(comboBoxCategory.SelectedValue);
                tenant.statusId       = Convert.ToUInt16(comboBoxStatus.SelectedValue);
                tenant.shardName      = textBoxShardName.Text.Trim();
                tenant.name           = textBoxName.Text.Trim();

                if (isCreating)
                {
                    if (GlobalDb.createTenant(tenant, user))
                    {
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("新建失败! 请联系管理员!");
                    }
                }
                else
                {
                    //update
                    if (GlobalDb.updateTenant(tenant, user))
                    {
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("更新失败! 请联系管理员!");
                    }
                }
            }
        }
Exemplo n.º 2
0
        private bool validate(string username, string password)
        {
            User user = GlobalDb.getUserByCellPhone(textBoxUserName.Text);

            if (user.cellPhone.Length > 0)
            {
                if (PasswordEncryption.validate(password, user.password, user.passwordSalt))
                {
                    if (user.tenantId == 1)
                    {
                        //administrator of all tenants
                        Sharevariables.IsTenantAdministrator = true;
                        return(true);
                    }
                    Tenant tenant = GlobalDb.getTenantById(user.tenantId);
                    if (tenant.id != 0)
                    {
                        Sharevariables.EnableWorkFlow          = tenant.enableWorkFlow;
                        Sharevariables.ShardDbConnectionString = "server=" + PropertyHandler.HostName + ";uid=" + PropertyHandler.UserName + ";pwd=" + PropertyHandler.Password + ";database=" + tenant.shardName;
                        Sharevariables.UserName    = user.cellPhone.ToString();
                        Sharevariables.UserLevel   = user.roleId;
                        Sharevariables.StoreId     = user.storeId;
                        Sharevariables.UserAddress = user.mail;
                        Sharevariables.TenantId    = user.tenantId;
                        return(true);
                    }
                    else
                    {
                        MessageBox.Show("此用户的数据不存在!");
                        return(false);
                    }
                }
                else
                {
                    MessageBox.Show("用户名或密码错误!");
                    return(false);
                }
            }
            else
            {
                MessageBox.Show("用户名或者密码错误!");
                return(false);
            }
        }
Exemplo n.º 3
0
        private void buttonOk_Click(object sender, EventArgs e)
        {
            if (validate())
            {
                User user = new User();
                user.id           = userId;
                user.cellPhone    = textBoxCellPhone.Text.Trim();
                user.mail         = textBoxMail.Text.Trim();
                user.name         = textBoxName.Text.Trim();
                user.roleId       = Convert.ToInt16(comboBoxRole.SelectedValue);
                user.storeId      = Convert.ToInt16(comboBoxStore.SelectedValue);
                user.tenantId     = Sharevariables.TenantId;
                user.memo         = textBoxMemo.Text.Trim();
                user.passwordSalt = PasswordEncryption.generateSalt();
                user.password     = PasswordEncryption.generatePassword(textBoxPassword.Text.Trim(), user.passwordSalt);
                user.active       = checkBoxActive.Checked;

                if (isCreating)
                {
                    if (GlobalDb.createUser(user))
                    {
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("新建失败! 请联系管理员!");
                    }
                }
                else
                {
                    //update
                    if (GlobalDb.updateUser(user))
                    {
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("更新失败! 请联系管理员!");
                    }
                }
            }
        }