private void Checklist_SelectedIndexChanged(object sender, EventArgs e) { lblCauHoi.Text = ""; checkBox1.Text = ""; checkBox1.Checked = false; checkBox2.Text = ""; checkBox2.Checked = false; checkBox3.Text = ""; checkBox3.Checked = false; checkBox4.Text = ""; checkBox4.Checked = false; checkBox5.Text = ""; checkBox5.Checked = false; checkBox6.Text = ""; checkBox6.Checked = false; CheckListBoxItem cl = checklist.SelectedItem as CheckListBoxItem; lblGoiY.Text = cl.GoiY; lblCauHoi.Text = cl.CauHoi; checkBox1.Text = cl.CauTL1; checkBox1.Checked = cl.IsDung1; checkBox2.Text = cl.CauTL2; checkBox2.Checked = cl.IsDung2; checkBox3.Text = cl.CauTL3; checkBox3.Checked = cl.IsDung3; checkBox4.Text = cl.CauTL4; checkBox4.Checked = cl.IsDung4; checkBox5.Text = cl.CauTL5; checkBox5.Checked = cl.IsDung5; checkBox6.Text = cl.CauTL6; checkBox6.Checked = cl.IsDung6; }
private void FillListBox() { var optionSetOptions = AttributeMetadata.OptionSet.Options; if (_initialValues.Any()) { foreach (var item in _initialValues.OrderBy(v => v)) { if (optionSetOptions.Any(o => o.Value == item)) { continue; } var newItem = new CheckListBoxItem() { Content = string.Format("{0} - UnknownValue", item), Value = item, IsChecked = true, }; newItem.PropertyChanged += this.checkListBoxItem_PropertyChanged; lstBValues.Items.Add(newItem); } } foreach (var item in optionSetOptions.OrderBy(o => o.Value)) { StringBuilder name = new StringBuilder(); name.Append(item.Value); var label = CreateFileHandler.GetLocalizedLabel(item.Label); var description = CreateFileHandler.GetLocalizedLabel(item.Description); if (!string.IsNullOrEmpty(label)) { name.AppendFormat(" - {0}", label); } else if (!string.IsNullOrEmpty(description)) { name.AppendFormat(" - {0}", description); } var newItem = new CheckListBoxItem() { Content = name.ToString(), Value = item.Value.Value, IsChecked = _initialValues.Contains(item.Value.Value), }; newItem.PropertyChanged += this.checkListBoxItem_PropertyChanged; lstBValues.Items.Add(newItem); } }
private void CheckBox1_CheckedChanged(object sender, EventArgs e) { CheckListBoxItem cl = checklist.SelectedItem as CheckListBoxItem; CheckBox checkBox = sender as CheckBox; switch (int.Parse(checkBox.Tag.ToString())) { case 1: cl.IsDung1 = checkBox.Checked; break; case 2: cl.IsDung2 = checkBox.Checked; break; case 3: cl.IsDung3 = checkBox.Checked; break; case 4: cl.IsDung4 = checkBox.Checked; break; case 5: cl.IsDung5 = checkBox.Checked; break; case 6: cl.IsDung6 = checkBox.Checked; break; default: break; } List <bool> vs = new List <bool>(); vs.Add(cl.IsDung1); vs.Add(cl.IsDung2); vs.Add(cl.IsDung3); vs.Add(cl.IsDung4); vs.Add(cl.IsDung5); vs.Add(cl.IsDung6); foreach (var item in vs) { if (item == true) { checklist.SetItemChecked(checklist.SelectedIndex, true); return; } } checklist.SetItemChecked(checklist.SelectedIndex, false); }
private void LoadCheckList() { List <DeThi_CauHoi> deThi_CauHois = quanLyThiDataContext.DeThi_CauHois.Where(p => p.MaDT.Equals(deThi.MaDeThi)).ToList(); int i = 1; foreach (var item in deThi_CauHois) { CheckListBoxItem checkListBoxItem = new CheckListBoxItem(); checkListBoxItem.Text = "Câu: " + i.ToString(); CauHoi cauHoi = quanLyThiDataContext.CauHois.Where(p => p.IDCauHoi.Equals(item.IDCauHoi)).Single(); checkListBoxItem.CauHoi = cauHoi.CauHoiDeBai; checkListBoxItem.GoiY = cauHoi.GoiY; List <DapAn> dapAns = quanLyThiDataContext.DapAns.Where(p => p.IDCauHoi.Equals(cauHoi.IDCauHoi)).ToList(); foreach (DapAn da in dapAns) { switch (da.STTDapAn) { case 1: checkListBoxItem.CauTL1 = da.DapAnCauHoi; break; case 2: checkListBoxItem.CauTL2 = da.DapAnCauHoi; break; case 3: checkListBoxItem.CauTL3 = da.DapAnCauHoi; break; case 4: checkListBoxItem.CauTL4 = da.DapAnCauHoi; break; case 5: checkListBoxItem.CauTL5 = da.DapAnCauHoi; break; case 6: checkListBoxItem.CauTL6 = da.DapAnCauHoi; break; default: break; } } checklist.Items.Add(checkListBoxItem, false); i++; } }
//Save New User Implementation private void SaveNewUser() { user newUser = new user(); newUser.salutation = comboBoxSalutaion.Text.Trim(); newUser.firstname = txtFirstName.Text.Trim(); newUser.lastname = txtSurname.Text.Trim(); newUser.other_name = txtOtherName.Text.Trim(); newUser.affix = comboBoxAffix.Text.Trim(); newUser.sex = comboBoxSex.Text.Trim(); newUser.email = txtEmail.Text.Trim(); newUser.doctor = txtDoctor.Text.Trim(); newUser.username = txtUsername.Text.Trim(); newUser.acronym = txtAcronym.Text.Trim(); newUser.password = txtPassword.Text.Trim(); newUser.confirm_password = txtConfirmPassword.Text.Trim(); newUser.image = (userPictureBox.ImageLocation != null) ? ConvertPicture(userPictureBox.ImageLocation) : newUser.image; newUser.isActive = (checkBoxActive.Checked) ? active + 1 : active; foreach (var item in checkedListBox1.CheckedItems) { CheckListBoxItem citem = (CheckListBoxItem)item; user_detail user_Detail = new user_detail(); user_Detail.department_id = citem.Tag; newUser.user_detail.Add(user_Detail); } bool validationResult = ValidateFields(); bool chkPassword = PaswordChecker(newUser.password, newUser.confirm_password); if (!validationResult) { MessageBox.Show("Enter Required Fields!", "Error"); } else if (!chkPassword) { MessageBox.Show("Password is not valid or does not match", "Error"); } else { using (emedEntities db = new emedEntities()) { db.users.Add(newUser); db.SaveChanges(); MessageBox.Show("New User Added Successfully!", "Message"); Close(); } } }
private void btnNop_Click(object sender, EventArgs e) { foreach (var item in checklist.Items) { CheckListBoxItem cl = item as CheckListBoxItem; if (cl.IsDung1) { quanLyThiDataContext.CauTraLois.InsertOnSubmit(new CauTraLoi { NguoiDungID = hocsinh.NguoiDungID, MaDeThi = deThi.MaDeThi, DapAn = 1, MaKyThi = _kythi.MaKT, CauHoiID = quanLyThiDataContext.CauHois.Where(p => p.CauHoiDeBai.Equals(cl.CauHoi)).Single().IDCauHoi }); quanLyThiDataContext.SubmitChanges(); } if (cl.IsDung2) { quanLyThiDataContext.CauTraLois.InsertOnSubmit(new CauTraLoi { NguoiDungID = hocsinh.NguoiDungID, MaDeThi = deThi.MaDeThi, DapAn = 2, MaKyThi = _kythi.MaKT, CauHoiID = quanLyThiDataContext.CauHois.Where(p => p.CauHoiDeBai.Equals(cl.CauHoi)).Single().IDCauHoi }); quanLyThiDataContext.SubmitChanges(); } if (cl.IsDung3) { quanLyThiDataContext.CauTraLois.InsertOnSubmit(new CauTraLoi { NguoiDungID = hocsinh.NguoiDungID, MaDeThi = deThi.MaDeThi, DapAn = 3, MaKyThi = _kythi.MaKT, CauHoiID = quanLyThiDataContext.CauHois.Where(p => p.CauHoiDeBai.Equals(cl.CauHoi)).Single().IDCauHoi }); quanLyThiDataContext.SubmitChanges(); } if (cl.IsDung4) { quanLyThiDataContext.CauTraLois.InsertOnSubmit(new CauTraLoi { NguoiDungID = hocsinh.NguoiDungID, MaDeThi = deThi.MaDeThi, DapAn = 4, MaKyThi = _kythi.MaKT, CauHoiID = quanLyThiDataContext.CauHois.Where(p => p.CauHoiDeBai.Equals(cl.CauHoi)).Single().IDCauHoi }); quanLyThiDataContext.SubmitChanges(); } if (cl.IsDung5) { quanLyThiDataContext.CauTraLois.InsertOnSubmit(new CauTraLoi { NguoiDungID = hocsinh.NguoiDungID, MaDeThi = deThi.MaDeThi, DapAn = 5, MaKyThi = _kythi.MaKT, CauHoiID = quanLyThiDataContext.CauHois.Where(p => p.CauHoiDeBai.Equals(cl.CauHoi)).Single().IDCauHoi }); quanLyThiDataContext.SubmitChanges(); } if (cl.IsDung6) { quanLyThiDataContext.CauTraLois.InsertOnSubmit(new CauTraLoi { NguoiDungID = hocsinh.NguoiDungID, MaDeThi = deThi.MaDeThi, DapAn = 6, MaKyThi = _kythi.MaKT, CauHoiID = quanLyThiDataContext.CauHois.Where(p => p.CauHoiDeBai.Equals(cl.CauHoi)).Single().IDCauHoi }); quanLyThiDataContext.SubmitChanges(); } } int total = quanLyThiDataContext.DeThi_CauHois.Where(p => p.MaDT.Equals(deThi.MaDeThi)).ToList().Count; int socaudung = Socaudung(); float diem = tinhdiem(); quanLyThiDataContext.BaiLamHs.InsertOnSubmit(new BaiLamH { MaNguoiDung = hocsinh.NguoiDungID, MaKT = _kythi.MaKT, MaDT = deThi.MaDeThi, DiemThi = diem.ToString() }); MessageBox.Show($"Số câu đúng : {socaudung}/{total}\n" + $"Số điểm : {diem}"); this.Close(); }