示例#1
0
        void DeleteUser()
        {
            if (MessageBox.Show("Czy na pewno chcesz usunąć wskazane pozycje?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
            {
                try
                {
                    var sqlString         = UserSQL.DeleteUser();
                    var RecordCount       = 0;
                    var sqlParamWithValue = new HashSet <Tuple <string, object> >();

                    foreach (User U in olvUser.CheckedObjects)
                    {
                        sqlParamWithValue.Add(new Tuple <string, object>("@Login", U.Login));
                    }
                    using (var scope = AppSession.TypeContainer.BeginLifetimeScope())
                    {
                        var dbs = scope.Resolve <IDataBaseService>();
                        RecordCount = dbs.RemoveManyRecordsAsync(sqlString, sqlParamWithValue).Result;
                    }
                    RefreshData();
                    MessageBox.Show($"{RecordCount} rekordów zostało usuniętych.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
示例#2
0
        private void cmdAddNew_Click(object sender, EventArgs e)
        {
            using (var dlg = new frmUser(UserSQL.SelectSomeUsers(UserSession.User.Settings.SchoolID.ToString())))
            {
                dlg.cmdClose.Text   = "Anuluj";
                dlg.cmdSave.Enabled = false;
                dlg.cmdSave.Visible = true;

                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    var TeacherList = new List <Teacher>();
                    foreach (User U in dlg.olvUser.CheckedObjects)
                    {
                        TeacherList.Add(new Teacher {
                            Login = U.Login, Role = U.Role, Status = U.Status, FirstName = U.FirstName, LastName = U.LastName
                        });
                    }
                    if (TeacherList.Count == 0)
                    {
                        return;
                    }
                    var Rec = AddSchoolTeacher(TeacherList);
                    if (Rec > 0)
                    {
                        GetData(olvSubject);
                        MessageBox.Show("Dodano rekordów: " + Rec.ToString(), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Ups! Coś poszło nie tak.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
        }
示例#3
0
 public int UpdatePassword()
 {
     using (var scope = AppSession.TypeContainer.BeginLifetimeScope())
     {
         var dbs = scope.Resolve <IDataBaseService>();
         return(dbs.UpdateRecordAsync(UserSQL.ChangePassword(), CreateUpdateParams()).Result);
     }
 }
示例#4
0
        private void ZarzadzanieUzytkownikamitoolStripMenuItem_Click(object sender, EventArgs e)
        {
            var frm = new frmUser(UserSQL.SelectAllUsers());

            SetFormProperties(frm);

            ZarzadzanieUzytkownikamitoolStripMenuItem.Enabled = false;
            frm.TheEnd += (s, ex) => ZarzadzanieUzytkownikamitoolStripMenuItem.Enabled = true;
            frm.Show();
        }
示例#5
0
 async Task <long> AddUser()
 {
     try
     {
         using (var scope = AppSession.TypeContainer.BeginLifetimeScope())
         {
             var dbs = scope.Resolve <IDataBaseService>();
             return(await dbs.AddRecordAsync(UserSQL.InsertUser(), CreateInsertParams()));
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
示例#6
0
 private static async Task <long> LogUserEnterAttempt(string userName, byte status)
 {
     try
     {
         using (var scope = AppSession.TypeContainer.BeginLifetimeScope())
         {
             var dbs = scope.Resolve <IDataBaseService>();
             return(await dbs.AddRecordAsync(UserSQL.LogIn(), CreateInsertParams(userName, status)));
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
示例#7
0
 public static async Task <IEnumerable <AppUser> > GetUsers()
 {
     try
     {
         using (var scope = AppSession.TypeContainer.BeginLifetimeScope())
         {
             var dbs = scope.Resolve <IDataBaseService>();
             return(await dbs.FetchRecordSetAsync(UserSQL.SelectUsers(), UserModel));
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
示例#8
0
 private static async Task LogUserExit(long IdEvent)
 {
     try
     {
         using (var scope = AppSession.TypeContainer.BeginLifetimeScope())
         {
             var dbs = scope.Resolve <IDataBaseService>();
             await dbs.UpdateRecordAsync(UserSQL.LogOut(), new Tuple <string, object>("@IdRecord", IdEvent));
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
示例#9
0
        int AddUser(List <User> usr)
        {
            try
            {
                var count             = 0;
                var sqlString         = UserSQL.InsertUser();
                var sqlParamWithValue = new HashSet <IDictionary <string, object> >();
                foreach (var U in usr)
                {
                    var plainPwd           = StringHelper.RandomizePassword();
                    var SaltedPasswordHash = Enigma.HashHelper.CreatePassword(plainPwd);
                    U.Password = Convert.ToBase64String(SaltedPasswordHash);

                    sqlParamWithValue.Add(new Dictionary <string, object>
                    {
                        { "@Login", U.Login },
                        { "@LastName", U.LastName },
                        { "@FirstName", U.FirstName },
                        { "@Password", U.Password },
                        { "@Role", U.Role },
                        { "@Status", U.Status },
                        { "@Sex", U.Sex },
                        { "@Email", U.Email },
                        { "@Owner", UserSession.User.Login },
                        { "@User", UserSession.User.Login },
                        { "@IP", AppSession.HostIP },
                    });
                    U.Password = plainPwd;
                    UsersToPrint.Add(U);
                }
                using (var scope = AppSession.TypeContainer.BeginLifetimeScope())
                {
                    var dbs = scope.Resolve <IDataBaseService>();
                    count = dbs.AddManyRecordsAsync(sqlString, sqlParamWithValue).Result.RecordCount;
                }
                if (count > 0)
                {
                    PrintAccountInfo();
                }
                return(count);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(-1);
            }
        }
示例#10
0
        private void Form1_Load(object sender, EventArgs e)
        {
            DataTable dt = UserSQL.getAllUser();

            if (dt != null)
            {
                this.dataGridView1.Rows.Clear();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    this.dataGridView1.Rows.Add(i + 1,
                                                dt.Rows[i]["UserName"],
                                                dt.Rows[i]["UserRole"],
                                                "删除");
                    this.dataGridView1.Rows[i].Tag = dt.Rows[i];
                }
            }
            this.dataGridView1.ClearSelection();
        }
示例#11
0
        private void ReFresh()
        {
            this.dataGridView1.Rows.Clear();
            DataTable dt = UserSQL.getAllUser();

            if (dt != null)
            {
                this.dataGridView1.Rows.Clear();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    this.dataGridView1.Rows.Add(i + 1,
                                                dt.Rows[i]["UserName"],
                                                dt.Rows[i]["UserRole"],
                                                "删除");
                    this.dataGridView1.Rows[i].Tag = dt.Rows[i];
                }
            }
            this.dataGridView1.ClearSelection();
        }
示例#12
0
        internal static bool CheckLoginExist(string Login)
        {
            //int UserCount = 0;
            try
            {
                using (var scope = AppSession.TypeContainer.BeginLifetimeScope())
                {
                    var dbs = scope.Resolve <IDataBaseService>();
                    int.TryParse(dbs.FetchSingleValueAsync(UserSQL.CountUser(Login)).Result, out int userCount);
                    return(userCount == 0);
                }
            }
            catch (Exception)
            {
                throw;
            }

            //using (var cmd = new MySql.Data.MySqlClient.MySqlCommand() { CommandText = UserSQL.CountUser(Login), Connection = AppSession.Conn })
            //{
            //    int.TryParse(cmd.ExecuteScalar().ToString(), out UserCount);
            //    return UserCount == 0;
            //}
        }
示例#13
0
        private async Task <int> UpdateUserAsync(dlgUser dlg, string login)
        {
            User.UserRole R = User.UserRole.Rodzic; // = (User.UserRole)Enum.Parse(typeof(User.UserRole), dlg.cbRola.SelectedValue.ToString());
            Enum.TryParse(dlg.cbRola.SelectedValue.ToString(), out R);
            var sqlParamWithValue = new Dictionary <string, object>()
            {
                { "@Login", login },
                { "@Nazwisko", dlg.txtNazwisko.Text.Trim() },
                { "@Imie", dlg.txtImie.Text.Trim() },
                { "@Rola", R },
                { "@Email", dlg.txtEmail.Text.Trim() },
                { "@Status", dlg.chkStatus.Checked },
                { "@Sex", dlg.chkSex.Checked },
                { "@User", UserSession.User.Login },
                { "@IP", AppSession.HostIP }
            };

            using (var scope = AppSession.TypeContainer.BeginLifetimeScope())
            {
                var dbs = scope.Resolve <IDataBaseService>();
                return(await dbs.UpdateRecordAsync(UserSQL.UpdateUser(), sqlParamWithValue));
            }
        }