Beispiel #1
0
        public void finish()
        {
            bool flagSave = false;

            // Kiểm tra dữ liệu vào hợp lệ
            if (CheckDataInput())
            {
                if (person == null)
                {
                    flagSave = PatientModelManage.Instance.CreatePerson(GetData());
                }
                else
                {
                    flagSave = PatientModelManage.Instance.UpdatePerson(GetData());
                }
                if (flagSave)
                {
                    PanelListPatient.RefeshDataTable(null);
                    ResetGui();
                    SetEnableComponents(true);
                }
            }

            if (!flagSave)
            {
                MessageBoxEX.DialogMessageBox("Thông báo", "Lưu không thành công", "Chưa thực hiện được thao tác này. \n Vui lòng kiểm tra lại dữ liệu hoặc thao tác của bạn!");
            }
        }
Beispiel #2
0
        private bool CheckDataInput()
        {
            // Thêm mới thông tin
            if (person == null)
            {
                // Kiểm tra có trùng mã ID
                tb_person _patient = PatientModelManage.Instance.FindPatientByCode(txtMaSo.Text);
                if (_patient != null)
                {
                    MessageBoxEX.DialogMessageBox("Thông báo", "Mã bệnh nhân đã tồn tại", "Vui lòng kiểm tra mã bệnh nhân. Mã này đã tồn tại trong hệ thống");
                    return(false);
                }
            }
            // Sửa lại thông tin
            else
            {
                return(true);
            }

            // Kiểm tra nhập tên khác rỗng
            if (txtHoTen.Text.Equals(""))
            {
                MessageBoxEX.DialogMessageBox("Thông báo", "Tên bệnh nhân không được để trống", "Trường tên không được để trống. Yêu cầu phải nhập tên bệnh nhân");
                return(false);
            }

            return(true);
        }
Beispiel #3
0
        public void finish()
        {
            if (rbRetoreAll.Checked)
            {
                if (!System.IO.Path.GetExtension(txtPathFile.Text).Equals(".bak"))
                {
                    MessageBox.Show("Vui lòng kiểm tra lại đường dẫn lưu file sao lưu !");
                    txtPathFile.Text = folderBrowserDialog.SelectedPath + "//backup_" + DateTime.Now.ToFileTime().ToString() + extendFile;
                    return;
                }

                ManagerPartient.CustomControl.FormLoad f = new ManagerPartient.CustomControl.FormLoad();
                f.TopMost     = true;
                f.TopLevel    = true;
                f.Size        = new System.Drawing.Size(SystemInformation.VirtualScreen.Width, SystemInformation.VirtualScreen.Height);
                f.WindowState = FormWindowState.Maximized;
                f.Show();

                con = new SqlConnection("Data Source=.\\SQLEXPRESS;Database=Master;data source=.; uid=sa; pwd=123456;");
                con.Open();
                cmd = new SqlCommand("Backup database nks_db to disk='" + txtPathFile.Text + "'", con);
                cmd.ExecuteNonQuery();
                con.Close();

                f.Close();
                DialogResult dialogResult = MessageBoxEX.DialogMessageBox("Thông báo", "Sao lưu dữ liệu thành công", "File sao lưu được lưu ở " + txtPathFile.Text);
                if (dialogResult.Equals(DialogResult.OK))
                {
                    this.ParentForm.Close();
                }
            }
            else
            {
                if (rbInsertData.Checked)
                {
                    if (!System.IO.Path.GetExtension(txtPathFile.Text).Equals(".xls"))
                    {
                        MessageBox.Show("Vui lòng kiểm tra lại đường dẫn lưu file sao lưu !");
                        txtPathFile.Text = folderBrowserDialog.SelectedPath + "//backup_" + DateTime.Now.ToFileTime().ToString() + extendFile;
                        return;
                    }
                    ExcelWriter.WriteExcelFile <tb_patient>(txtPathFile.Text, PatientModelManage.Instance.FindAllPatients(), false);
                    this.ParentForm.Close();
                }
            }
        }
Beispiel #4
0
        public void finish()
        {
            string filePath = txtPathFile.Text;

            if (filePath != null && !filePath.Equals(""))
            {
                string extension = System.IO.Path.GetExtension(filePath);
                string header = "YES";
                string conStr, sheetName;

                conStr = string.Empty;
                switch (extension)
                {
                case ".xls":     //Excel 97-03
                    conStr = string.Format(Excel03ConString, filePath, header);
                    break;

                case ".xlsx":     //Excel 07
                    conStr = string.Format(Excel07ConString, filePath, header);
                    break;

                default:
                {
                    MessageBoxEX.DialogMessageBox("Thông báo", "File chọn không tồn tại hoặc hợp lệ", "Bạn hãy kiểm tra lại file chọn cho phù hợp");
                    return;
                }
                }

                //Get the name of the First Sheet.
                using (OleDbConnection con = new OleDbConnection(conStr))
                {
                    using (OleDbCommand cmd = new OleDbCommand())
                    {
                        cmd.Connection = con;
                        con.Open();
                        DataTable dtExcelSchema = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                        sheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString();
                        con.Close();
                    }
                }

                List <tb_person> patients;

                //Read Data from the First Sheet.
                using (OleDbConnection con = new OleDbConnection(conStr))
                {
                    using (OleDbCommand cmd = new OleDbCommand())
                    {
                        using (OleDbDataAdapter oda = new OleDbDataAdapter())
                        {
                            bool flagIdIsNull = false;
                            patients = new List <tb_person>();

                            DataTable dt = new DataTable();
                            cmd.CommandText = "SELECT * From [" + sheetName + "]";
                            cmd.Connection  = con;
                            con.Open();
                            oda.SelectCommand = cmd;
                            oda.Fill(dt);
                            con.Close();

                            foreach (DataRow row in dt.Rows)
                            {
                                Console.WriteLine("------ROW NEXT-----");

                                tb_person patient = new tb_person();

                                foreach (DataColumn column in dt.Columns)
                                {
                                    Console.Write("Item: ");
                                    Console.Write(column.ColumnName);
                                    Console.Write(" ");
                                    Console.WriteLine(row[column]);

                                    switch (column.ColumnName)
                                    {
                                    case "ID": patient.PersonID = row[column].ToString();
                                        break;

                                    case "FullName": patient.FullName = row[column].ToString();
                                        break;

                                    case "Birthday":
                                    {
                                        if (row[column] != null && !row[column].ToString().Equals(""))
                                        {
                                            patient.Birthday = DateTime.Parse(row[column].ToString(), new CultureInfo("en-CA"));
                                        }
                                    }
                                    break;

                                    case "Gender": patient.Gender = (row[column].ToString().Equals("Nam")?"Male":(row[column].ToString().Equals("Nữ")?"Female":"Khác"));
                                        break;

                                    case "Mobile": patient.MobilePhone = row[column].ToString();
                                        break;

                                    case "Phone": patient.Tel = row[column].ToString();
                                        break;

                                    case "Email": patient.Email = row[column].ToString();
                                        break;

                                    case "Address": patient.Address = row[column].ToString();
                                        break;

                                    case "Note": patient.Note = row[column].ToString();
                                        break;

                                    default: break;
                                    }
                                }

                                if (patient.PersonID != null && !patient.PersonID.Equals(""))
                                {
                                    patients.Add(patient);
                                    flagIdIsNull = false;
                                }
                                else
                                {
                                    if (flagIdIsNull)
                                    {
                                        break;
                                    }
                                    flagIdIsNull = true;
                                }
                            }
                        }
                    }
                }

                if (patients != null && patients.Count != 0)
                {
                    ManageSoftware.CustomControl.FormLoad f = new ManageSoftware.CustomControl.FormLoad();
                    f.Visible = true;
                    int num = 0;
                    foreach (tb_person p in patients)
                    {
                        bool flagSave = PatientModelManage.Instance.CreatePerson(p);
                        if (flagSave)
                        {
                            num += 1;
                        }
                    }
                    f.Close();
                    DialogResult dialogResult = MessageBoxEX.DialogMessageBox("Thông báo", "Đã hoàn thành thêm " + num + " bản ghi vào hệ thống", "");
                    if (dialogResult.Equals(DialogResult.OK))
                    {
                        this.ParentForm.Close();
                    }
                    return;
                }
                else
                {
                    MessageBoxEX.DialogMessageBox("Thông báo", "Dữ liệu trong file excel trống.", "Bạn hãy kiểm tra lại");
                    return;
                }
            }
            else
            {
                MessageBoxEX.DialogMessageBox("Thông báo", "Vui lòng chọn file phục hồi phù hợp", "Bạn hãy kiểm tra lại file chọn cho phù hợp");
                return;
            }
        }
        public static DataTable ImportExcel(String filePath)
        {
            string Excel03ConString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='Excel 8.0;HDR={1}'";
            string Excel07ConString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 8.0;HDR={1}'";

            if (filePath != null && !filePath.Equals(""))
            {
                string extension = System.IO.Path.GetExtension(filePath);
                string header = "YES";
                string connectionString, sheetName;

                connectionString = string.Empty;
                switch (extension)
                {
                case ".xls":     //Excel 97-03
                    connectionString = string.Format(Excel03ConString, filePath, header);
                    break;

                case ".xlsx":     //Excel 07
                    connectionString = string.Format(Excel07ConString, filePath, header);
                    break;

                default:
                {
                    MessageBoxEX.DialogMessageBox("Thông báo", "File chọn không hợp lệ. Vui lòng chọn file Excel", "Bạn hãy kiểm tra lại file chọn cho phù hợp");
                    return(null);
                }
                }

                //Get the name of the First Sheet.
                using (OleDbConnection con = new OleDbConnection(connectionString))
                {
                    using (OleDbCommand cmd = new OleDbCommand())
                    {
                        cmd.Connection = con;
                        con.Open();
                        DataTable dtExcelSchema = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                        sheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString();
                        con.Close();
                    }
                }

                using (OleDbConnection con = new OleDbConnection(connectionString))
                {
                    using (OleDbCommand cmd = new OleDbCommand())
                    {
                        using (OleDbDataAdapter oda = new OleDbDataAdapter())
                        {
                            DataTable dt = new DataTable();
                            cmd.CommandText = "SELECT * From [" + sheetName + "]";
                            cmd.Connection  = con;
                            con.Open();
                            oda.SelectCommand = cmd;
                            oda.Fill(dt);
                            con.Close();

                            return(dt);
                        }
                    }
                }
            }
            else
            {
                MessageBoxEX.DialogMessageBox("Thông báo", " Vui lòng chọn file Excel", "Bạn hãy kiểm tra lại file chọn cho phù hợp");
                return(null);
            }
        }
        public void finish()
        {
            if (rbRetoreAll.Checked)
            {
                if (!txtPathFile.Text.Contains(".bak"))
                {
                    MessageBox.Show("File không hợp lệ !");
                    return;
                }

                ManagerPartient.CustomControl.FormLoad f = new ManagerPartient.CustomControl.FormLoad();
                f.TopMost     = true;
                f.TopLevel    = true;
                f.Size        = new System.Drawing.Size(SystemInformation.VirtualScreen.Width, SystemInformation.VirtualScreen.Height);
                f.WindowState = FormWindowState.Maximized;
                f.Show();

                try
                {
                    con = new SqlConnection("Data Source=.\\SQLEXPRESS;Database=Master;data source=.; uid=sa; pwd=123456;");
                    con.Open();
                    cmd = new SqlCommand("ALTER DATABASE nks_db SET SINGLE_USER WITH ROLLBACK IMMEDIATE", con);
                    cmd.ExecuteNonQuery();
                    cmd = new SqlCommand("Restore database nks_db from disk='" + txtPathFile.Text + "' with replace", con);
                    cmd.ExecuteNonQuery();
                    cmd = new SqlCommand("alter database nks_db set multi_user", con);
                    cmd.ExecuteNonQuery();
                    con.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    f.Close();
                }


                DialogResult dialogResult = MessageBoxEX.DialogMessageBox("Thông báo", "Khôi phục dữ liệu thành công", "");
                if (dialogResult.Equals(DialogResult.OK))
                {
                    this.ParentForm.Close();
                    System.Diagnostics.Process.Start(Application.ExecutablePath);
                    //Application.Exit();
                    System.Diagnostics.Process.GetCurrentProcess().Kill();
                }
            }
            else
            {
                if (rbInsertData.Checked)
                {
                    List <tb_patient> patients         = new List <tb_patient>();
                    List <tb_patient> patientsNotVaild = new List <tb_patient>();
                    bool      flagRowEmpty             = false;
                    DataTable tableSheet = ExcelWriter.ImportExcel(txtPathFile.Text);

                    for (int i = 0; i < tableSheet.Rows.Count; i++)
                    {
                        // Duyệt từng dòng lấy dữ liệu
                        tb_patient patient = new tb_patient();
                        patient.PatientID = tableSheet.Rows[i]["PatientID"].ToString();
                        patient.FullName  = tableSheet.Rows[i]["FullName"].ToString();
                        Object birthday = tableSheet.Rows[i]["Birthday"];
                        if (birthday != null && !birthday.ToString().Equals(""))
                        {
                            patient.Birthday = DateTime.Parse(birthday.ToString(), new System.Globalization.CultureInfo("en-CA"));
                        }
                        patient.Gender      = (tableSheet.Rows[i]["Gender"].ToString().Equals("Nam") ? "Male" : (tableSheet.Rows[i]["Gender"].ToString().Equals("Nữ") ? "Female" : "Other"));
                        patient.MobilePhone = tableSheet.Rows[i]["MobilePhone"].ToString();
                        patient.Tel         = tableSheet.Rows[i]["Tel"].ToString();
                        patient.Email       = tableSheet.Rows[i]["Email"].ToString();
                        patient.Address     = tableSheet.Rows[i]["Address"].ToString();
                        patient.Note        = tableSheet.Rows[i]["_Note"].ToString();

                        // Kiểm tra dòng này đã là dòng trống chưa?
                        if (patient.PatientID.Equals("") && patient.FullName.Equals("") && patient.Address.Equals(""))
                        {
                            if (flagRowEmpty)
                            {
                                break;
                            }
                            flagRowEmpty = true;
                        }
                        else
                        {
                            flagRowEmpty = false;
                        }

                        // Không phải dòng trống thì add list
                        if (!flagRowEmpty)
                        {
                            // Kiểm tra cell mã không được bỏ trống
                            if (!patient.PatientID.Equals(""))
                            {
                                // Kiểm tra có trùng mã không?
                                tb_patient patientChk = PatientModelManage.Instance.FindPatientByCode(patient.PatientID);
                                if (patientChk != null)
                                {
                                    patient.Gender = patient.Gender.Equals("Male") ? "Nam" : (patient.Gender.Equals("Female") ? "Nữ" : "Khác");
                                    patientsNotVaild.Add(patient);
                                }
                                else
                                {
                                    patients.Add(patient);
                                }
                            }
                            else
                            {
                                patient.Gender = patient.Gender.Equals("Male") ? "Nam" : (patient.Gender.Equals("Female") ? "Nữ" : "Khác");
                                // Nếu bất kì lỗi gì thì add vào list ko hợp lệ
                                patientsNotVaild.Add(patient);
                            }
                        }
                    }

                    if (patientsNotVaild.Count > 0)
                    {
                        DialogResult result = MessageBoxEX.DialogMessageBox("Thông báo", "Dữ liệu trong file excel có lỗi. Bạn muốn tiếp tục không ghi dữ liệu vào hệ thống?", "Nếu tiếp tục bạn chương trình sẽ xuất ra file Excel các bản ghi lỗi. Còn các bản ghi hợp lệ sẽ được lưu vào trong hệ thống");

                        // Ghi dữ liệu lỗi ra file Excel và hiển thị nó lên
                        string directoryPath = System.IO.Path.GetDirectoryName(txtPathFile.Text);
                        ExcelWriter.WriteExcelFile <tb_patient>(directoryPath + "\\dataError.xls", patientsNotVaild, true);
                        if (result.Equals(DialogResult.Cancel))
                        {
                            return;
                        }
                    }

                    if (patients.Count > 0)
                    {
                        ManagerPartient.CustomControl.FormLoad f = new ManagerPartient.CustomControl.FormLoad();
                        f.TopMost     = true;
                        f.TopLevel    = true;
                        f.Size        = new System.Drawing.Size(SystemInformation.VirtualScreen.Width, SystemInformation.VirtualScreen.Height);
                        f.WindowState = FormWindowState.Maximized;
                        f.Show();
                        int num = 0;
                        foreach (tb_patient p in patients)
                        {
                            bool flagSave = PatientModelManage.Instance.CreatePatient(p);
                            if (flagSave)
                            {
                                num += 1;
                            }
                        }
                        f.Close();
                        DialogResult dialogResult = MessageBoxEX.DialogMessageBox("Thông báo", "Đã hoàn thành thêm " + num + " bản ghi vào hệ thống", "");
                        if (dialogResult.Equals(DialogResult.OK))
                        {
                            this.ParentForm.Close();
                        }
                        return;
                    }
                    else
                    {
                        MessageBoxEX.DialogMessageBox("Thông báo", "Dữ liệu trong file excel trống.", "Bạn hãy kiểm tra lại");
                        return;
                    }
                }
            }
        }