private void btnGetSchool_Click(object sender, EventArgs e) { GiaoDucClient client = new GiaoDucClient(); client.ClientCredentials.UserName.UserName = this.username; client.ClientCredentials.UserName.Password = this.password; client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None; BindingList <SchoolProfile> sPList = new BindingList <SchoolProfile>(); try { arrSchool = client.GetSchoolProfile(); client.Close(); for (int i = 0; i < arrSchool.Length; i++) { sPList.Add(arrSchool[i]); } labelNumberSchool.Text = "Tổng số trường: " + arrSchool.Length; schoolProfileBindingSource.DataSource = sPList; } catch (Exception es) { MessageBox.Show(es.ToString(), "Lỗi kết nối đến máy chủ", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnGetDataStudent_Click(object sender, EventArgs e) { //listStudent.Clear(); //dataGridViewStudent.Rows.Clear(); //dataGridViewStudent.Refresh(); GiaoDucClient client = new GiaoDucClient(); client.ClientCredentials.UserName.UserName = this.username; client.ClientCredentials.UserName.Password = this.password; client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None; BindingList <PupilProfile> listStudentBiding = new BindingList <PupilProfile>(); try { Item itemSelect = comboBoxSchoolStudent.SelectedItem as Item; PupilProfile[] arrStudent = client.GetPupilProfile(itemSelect.value, 2017, 2000, 1); client.Close(); labelSumStudent.Text = "Tổng số học sinh: " + arrStudent.Length; for (int i = 0; i < arrStudent.Length; i++) { Console.WriteLine("\n" + arrStudent[i].PupilCode); listStudent.Add(arrStudent[i]); } listStudent.Sort(new NameComparer()); //listStudentBiding = listStudent; //labelNumberSchool.Text = "Tổng số trường: " + arrSchool.Length; pupilProfileBindingSource.DataSource = listStudent; MessageBox.Show("Dkm thành công !!!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (NullReferenceException) { MessageBox.Show("Chọn trường trong danh sách ", "Lỗi con mẹ nó rồi", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception es) { MessageBox.Show(es.ToString(), "Lỗi kết nối đến máy chủ", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnGetDataEmployee_Click(object sender, EventArgs e) { GiaoDucClient client = new GiaoDucClient(); client.ClientCredentials.UserName.UserName = this.username; client.ClientCredentials.UserName.Password = this.password; client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None; BindingList <Employee> eList = new BindingList <Employee>(); try { //lấy truongID từ combobox Item item = (Item)comboBoxSchoolEmployee.SelectedItem; //Debug.Print(item.value.ToString()); arrEmployee = client.GetEmployee(item.value); client.Close(); for (int i = 0; i < arrEmployee.Length; i++) { eList.Add(arrEmployee[i]); } //eList.ToList<Employee>().Sort(new Nam); labelNumberSchool.Text = "Tổng số trường: " + arrSchool.Length; employeeBindingSource.DataSource = eList; } catch (NullReferenceException) { MessageBox.Show("Chọn trường trong danh sách ", "Lỗi con mẹ nó rồi", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception es) { MessageBox.Show(es.ToString(), "Lỗi kết nối đến máy chủ", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnExportStudent_Click(object sender, EventArgs e) { GiaoDucClient client = new GiaoDucClient(); client.ClientCredentials.UserName.UserName = this.username; client.ClientCredentials.UserName.Password = this.password; client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None; ClassProfile[] cProfile; try { Item i = comboBoxSchoolStudent.SelectedItem as Item; cProfile = client.GetClassProfile(i.value, 2017); //for(int j=0; j<cProfile.Length; j++) //Debug.Print(cProfile[j].ClassProfileId+"-------------"+cProfile[j].ClassName); //if (!listStudent.Any()) // { using (SaveFileDialog sfd = new SaveFileDialog() { Filter = "Excel workbook|*.xls" }) { sfd.FileName = comboBoxSchoolStudent.Text; if (sfd.ShowDialog() == DialogResult.OK) { String fileName = sfd.FileName; Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application(); Workbook wb = excel.Workbooks.Add(XlSheetType.xlWorksheet); Worksheet ws = excel.ActiveSheet; //ws.EnableSelection = Microsoft.Office.Interop.Excel.XlEnableSelection.xlNoSelection; ws.UsedRange.NumberFormat = "@"; excel.Visible = false; //Đặt tên cột trong file Excel ws.Cells[1, 1] = "Số thứ tự"; ws.Cells[1, 2] = "Mã học sinh"; ws.Cells[1, 3] = "Họ và tên"; ws.Cells[1, 4] = "Giới tính"; ws.Cells[1, 5] = "Lớp"; ws.Cells[1, 6] = "Ngày sinh"; ws.Cells[1, 7] = "Nơi sinh"; ws.Cells[1, 8] = "Tỉnh thành"; ws.Cells[1, 9] = "Địa chỉ"; ws.Cells[1, 10] = "Dân tộc"; int index = 1; foreach (PupilProfile pf in listStudent) { index++; ws.Cells[index, 1] = index - 1; ws.Cells[index, 2] = pf.PupilCode; ws.Cells[index, 3] = pf.FullName; ws.Cells[index, 4] = pf.Genre; String classname = ""; for (int k = 0; k < cProfile.Length; k++) { if (pf.ClassID == cProfile[k].ClassProfileId) { classname = cProfile[k].ClassName; //Debug.Print("Tìm được tên lớp: " + classname); break; //else ws.Cells[index, 7] = "Looix"; } } ws.Cells[index, 5].value = "'" + classname; ws.Cells[index, 6] = pf.BirthPlace; ws.Cells[index, 7] = pf.BirthDate; ws.Cells[index, 8] = pf.Province; ws.Cells[index, 9] = pf.Area; ws.Cells[index, 10] = pf.Ethnic; } //Lưu file // Thread th = new Thread( ()=>{ ws.SaveAs(fileName, XlFileFormat.xlWorkbookDefault, Type.Missing, Type.Missing, true, false, XlSaveAsAccessMode.xlNoChange, XlSaveConflictResolution.xlLocalSessionChanges, Type.Missing); excel.Quit(); // }); // th.Start(); // if(th.IsAlive == false) { MessageBox.Show("Xuất danh sách học sinh thành công", "Thành công", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } // } // else MessageBox.Show("Danh sách trường hiện tại đang trống, vui lòng lấy danh sách từ cổng thông tin", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception es) { MessageBox.Show("Không lấy được danh sách lớp, vui lòng kiểm tra lại\n" + es.ToString(), "Lỗi CMNR!!!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }