Esempio n. 1
0
        void SetDataOnDFirst()
        {
            using (session_1_dbDataContext db = new session_1_dbDataContext())
            {
                TimeOnSystem timeOnSystem = new TimeOnSystem();
                timeOnSystem.Date    = Constain.dateTimeLogin;
                Constain.ID          = (from u in db.TimeOnSystems select u).Count() + 1;
                timeOnSystem.ID      = Constain.ID;
                timeOnSystem.Login   = Constain.loginTime.ToShortTimeString();
                timeOnSystem.Logout  = null;
                timeOnSystem.SumTime = null;
                timeOnSystem.UserID  = (from v in db.Users
                                        where (v.Email == Constain.userName)
                                        select v.ID).First();

                db.TimeOnSystems.InsertOnSubmit(timeOnSystem);

                try
                {
                    db.SubmitChanges();
                }
                catch
                {
                }
            }
        }
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            using (session_1_dbDataContext db = new session_1_dbDataContext())
            {
                var query = (from u in db.TimeOnSystems where (u.ID == Login.index) select u).First();
                if (rbSystem.Checked == true)
                {
                    query.Reason = "Power outage";
                }
                else
                {
                    query.Reason = "Hanging program";
                }

                try
                {
                    db.SubmitChanges();
                    MessageBox.Show("Thanks for your respond!", "", MessageBoxButtons.OK, MessageBoxIcon.None);
                }
                catch
                {
                    MessageBox.Show("Please try again later!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            this.Close();
        }
Esempio n. 3
0
        void SetDataToDB()
        {
            using (session_1_dbDataContext db = new session_1_dbDataContext())
            {
                var query = (from u in db.TimeOnSystems
                             from v in db.Users
                             where (v.Email == Constain.userName && v.ID == u.UserID && u.ID == Constain.ID)
                             select u).First();

                query.Logout  = Constain.logoutTime.ToShortTimeString();
                query.SumTime = SpentTime();

                try
                {
                    db.SubmitChanges();
                }
                catch
                {
                }
            }
        }
Esempio n. 4
0
        private void btnApply_Click(object sender, EventArgs e)
        {
            if (txtEmail.Text.ToString() == "" || txtFirstName.Text.ToString() == "" || txtLastName.Text.ToString() == "")
            {
                MessageBox.Show("You must input all information!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
            else
            {
                using (session_1_dbDataContext db = new session_1_dbDataContext())
                {
                    var query = (from u in db.Users where (u.ID == LoginMain.seletedIndex) select u).First();
                    query.Email     = txtEmail.Text;
                    query.LastName  = txtLastName.Text;
                    query.FirstName = txtFirstName.Text;

                    if (rdAdmin.Checked == true)
                    {
                        query.RoleID = 1;
                    }
                    else
                    {
                        query.RoleID = 2;
                    }

                    try
                    {
                        db.SubmitChanges();
                        MessageBox.Show("Changed successful!", "Notify", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch
                    {
                        MessageBox.Show("Changed unsuccessful! Try again later.", "Notify", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
        }
        private void btnEDLogin_Click(object sender, EventArgs e)
        {
            if (rowIndex != -1)
            {
                var getUN = (from ord in db.Users
                             where ord.Email == dtgvUser["EmailAddress", rowIndex].Value.ToString()
                             select ord).First();
                if (getUN.Email != Constain.userName)
                {
                    var val = dtgvUser["active", rowIndex].Value;
                    if (val.ToString() == "True")
                    {
                        dtgvUser["active", rowIndex].Value = false;
                        var query =
                            from ord in db.Users
                            where ord.Email == dtgvUser["EmailAddress", rowIndex].Value.ToString()
                            select ord;

                        // Execute the query, and change the column values
                        // you want to change.
                        //if (query.First().Email == Constain.userName)
                        foreach (var ord in query)
                        {
                            ord.Active = false;
                            // Insert any additional changes to column values.
                        }



                        // Submit the changes to the database.
                        try
                        {
                            db.SubmitChanges();
                            cbAllOffices_SelectedIndexChanged(sender, e);
                            dtgvUser.Rows[rowIndex].DefaultCellStyle.BackColor = Color.Red;
                            dtgvUser["active", rowIndex].Value = "False";
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Can't disable this account!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            // Provide for exceptions.
                        }
                    }
                    else
                    {
                        var query =
                            from ord in db.Users
                            where ord.Email == dtgvUser["EmailAddress", rowIndex].Value.ToString()
                            select ord;

                        // Execute the query, and change the column values
                        // you want to change.
                        foreach (var ord in query)
                        {
                            ord.Active = true;
                            // Insert any additional changes to column values.
                        }



                        // Submit the changes to the database.
                        try
                        {
                            db.SubmitChanges();
                            cbAllOffices_SelectedIndexChanged(sender, e);

                            if (dtgvUser["UserRole", rowIndex].Value.ToString() == "office user")
                            {
                                dtgvUser.Rows[rowIndex].DefaultCellStyle.BackColor = Color.White;
                            }
                            else
                            {
                                dtgvUser.Rows[rowIndex].DefaultCellStyle.BackColor = Color.GreenYellow;
                            }

                            dtgvUser["active", rowIndex].Value = "True";
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Can't enable this account!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            // Provide for exceptions.
                        }
                    }
                }
                else
                {
                    MessageBox.Show("You can't change role yourself!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            int    a = 0, b = 0, c = 0, d = 0, e1 = 0, f = 0, g = 0, h = 0;
            string email     = txtEmail.Text;
            string firstName = txtFirstName.Text;
            string lastName  = txtLastName.Text;
            string office    = cbOffice.SelectedText;

            //string date = txtDate.Text;
            DateTime date;

            DateTime.TryParseExact(txtDate.Text, "dd/MM/yy", null,
                                   System.Globalization.DateTimeStyles.None, out date);
            string pass = txtPassword.Text;

            int temp = (from u in db.Users where (u.Email == email) select u).Count();


            if (email == "")
            {
                txtEmail.Text      = "* What's your email adress?";
                txtEmail.ForeColor = Color.Red;
                a = 1;
            }

            if (temp == 1)
            {
                txtEmail.Text      = "* This email have been used!";
                txtEmail.ForeColor = Color.Red;
                b = 1;
            }


            if (firstName == "")
            {
                txtFirstName.Text      = "* What's your first name?";
                txtFirstName.ForeColor = Color.Red;
                c = 1;
            }

            if (lastName == "")
            {
                txtLastName.Text      = "* What's your last name?";
                txtLastName.ForeColor = Color.Red;
                d = 1;
            }

            if (pass == "")
            {
                txtPassword.UseSystemPasswordChar = false;
                txtPassword.Text      = "* Input your password!?";
                txtPassword.ForeColor = Color.Red;
                e1 = 1;
            }

            if (date == null)
            {
                txtPassword.Text      = "* Input your password!?";
                txtPassword.ForeColor = Color.Red;
                f = 1;
            }

            if (cbOffice.Text == "Office name" || cbOffice.Text == "")
            {
                cbOffice.ForeColor = Color.Red;
                cbOffice.Text      = "* Choose your office name correctly!";
                g = 1;
            }

            if (txtDate.Text == "[ dd/MM/yy ]" || txtDate.Text == "")
            {
                txtDate.Text      = "* Input your birthday!";
                txtDate.ForeColor = Color.Red;
                h = 1;
            }

            if (txtEmail.Text == "* What's your email adress?" ||
                txtEmail.Text == "* This email have been used!" ||
                txtFirstName.Text == "* What's your first name?" ||
                txtLastName.Text == "* What's your last name?" ||
                txtPassword.Text == "* Input your password!?" ||
                cbOffice.Text == "* Choose your office name correctly!" ||
                txtDate.Text == "* Input your birthday!")
            {
                MessageBox.Show("You must input all information!", "Notify", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            if (a == 0 && b == 0 && c == 0 && d == 0 && e1 == 0 && f == 0 && g == 0 && h == 0)
            {
                using (session_1_dbDataContext db = new session_1_dbDataContext())
                {
                    User user = new User();
                    user.Email     = email;
                    user.Birthdate = date;
                    user.Active    = true;
                    user.FirstName = firstName;
                    user.LastName  = lastName;
                    int idx = cbOffice.SelectedIndex;
                    if (idx < 1)
                    {
                        idx += 1;
                    }
                    else
                    {
                        idx += 2;
                    }
                    user.OfficeID = idx;
                    user.Password = GenerateMD5(pass);
                    user.RoleID   = 2;
                    user.ID       = (from u in db.Users select(u)).Count() + 1;

                    db.Users.InsertOnSubmit(user);

                    try
                    {
                        db.SubmitChanges();
                        MessageBox.Show("Added successfuly!", "Notify", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        LoadData();
                        LoginMain loginMain = new LoginMain();
                        loginMain.LoadData();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Can't add this account!\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            else
            {
                return;
            }
        }