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(); }
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 EditRole_Load(object sender, EventArgs e) { using (session_1_dbDataContext db = new session_1_dbDataContext()) { var query = (from u in db.Users where (u.ID == LoginMain.seletedIndex) select u).First(); txtEmail.Text = query.Email.ToString(); txtFirstName.Text = query.FirstName.ToString(); txtLastName.Text = query.LastName.ToString(); if (query.RoleID == 1) { rdAdmin.Checked = true; } else { rdUser.Checked = true; } var officeSource = from u in db.Offices select new { id = u.ID, title = u.Title }; cbOffice.DataSource = officeSource.ToList(); cbOffice.ValueMember = "id"; cbOffice.DisplayMember = "title"; int oID = (int)query.OfficeID; // 1 3 4 5 6 if (oID == 1) { oID = 0; } else if (oID >= 3) { oID -= 2; } cbOffice.SelectedIndex = oID; } }
private void Logout_Load(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(); lblNotify.Text = "No logout detected for your last login on " + query.Date.ToShortDateString() + " at " + query.Login.ToString(); } rbSystem.Checked = true; }
private void MainLoginUser_Load(object sender, EventArgs e) { lblHello.Text = "Hi " + Constain.userName + ", Welcome to AMONIC Airlines."; timerSpent.Start(); int temp = 0; using (session_1_dbDataContext db = new session_1_dbDataContext()) { var queru = from u in db.TimeOnSystems from v in db.Users where (u.UserID == v.ID && v.Email == Constain.userName) select new { id = u.ID, date = u.Date, login = u.Login, logout = u.Logout, spentTime = u.SumTime, reason = u.Reason }; dtgvTime.DataSource = queru.ToList(); foreach (var item in queru) { if (item.logout == null) { temp++; dtgvTime["Logout", item.id - 1].Value = "**"; dtgvTime.Rows[item.id - 1].DefaultCellStyle.BackColor = Color.Red; } if (item.spentTime == null) { dtgvTime["SumTime", item.id - 1].Value = "**"; } else { dtgvTime["SumTime", item.id - 1].Value = item.spentTime.ToString(); } } } lblCrash.Text = "Number of crashes: " + temp; SetDataOnDFirst(); }
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 { } } }
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 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; } }
private void DatabaseSetup() { db = new session_1_dbDataContext(); }