private void btnPrint_Click(object sender, EventArgs e)
        {
            ClsSQLDatabaseToDoc    SQLdbtoword    = new ClsSQLDatabaseToDoc();
            ClsOracleDatabaseToDoc ORACLEdbtoword = new ClsOracleDatabaseToDoc();
            ClsFileFunction        ffunc          = new ClsFileFunction();
            String strOption = GetOptionString();

            if (strOption.Contains("0"))
            {
                if (ffunc.CopyFile(clsGlobalVariable.STRServerMapPath + "\\temp.doc", filepath))
                {
                    if (MessageBox.Show("In File Thành Công!\nBạn có muốn mở File để xem? ", "Kết quả",
                                        MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        System.Diagnostics.Process proc = new System.Diagnostics.Process();
                        proc.EnableRaisingEvents = false;
                        proc.StartInfo.FileName  = filepath;
                        proc.Start();
                        //proc.WaitForExit();
                    }
                }
                else
                {
                    MessageBox.Show("In File Thất Bại!", "Kết quả", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                if (sqlConn != null)
                {
                    if (SQLdbtoword.WriteDatabaseStructureToWordFile(sqlConn, filepath, strOption))
                    {
                        if (MessageBox.Show("In File Thành Công!\nBạn có muốn mở File để xem? ", "Kết quả",
                                            MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                        {
                            System.Diagnostics.Process proc = new System.Diagnostics.Process();
                            try
                            {
                                proc.EnableRaisingEvents = false;

                                proc.StartInfo.FileName = filepath;

                                proc.Start();
                            }
                            catch (Exception ex)
                            {
                            }
                            finally { proc.Dispose(); }
                        }
                    }
                    else
                    {
                        MessageBox.Show("In File Thất Bại!", "Kết quả", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else if (oracleConn != null)
                {
                    if (ORACLEdbtoword.WriteDatabaseStructureToWordFile(oracleConn, filepath, strOption))
                    {
                        if (MessageBox.Show("In File Thành Công!\nBạn có muốn mở File để xem? ", "Kết quả",
                                            MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                        {
                            System.Diagnostics.Process proc = new System.Diagnostics.Process();
                            try
                            {
                                proc.EnableRaisingEvents = false;

                                proc.StartInfo.FileName = filepath;

                                proc.Start();
                            }
                            catch (Exception ex)
                            {
                            }
                            finally { proc.Dispose(); }
                        }
                    }
                    else
                    {
                        MessageBox.Show("In File Thất Bại!", "Kết quả", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            this.Dispose();
        }
Example #2
0
        private void bgdWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            clsGlobalVariable.STRServerMapPath = strServerMapPath;
            clsGlobalVariable.STRUserName      = StrUserName;


            if (strdatabasetype == "SQL SERVER")
            {
                if (SQLdbfunc.KetNoiCSDL(StrServer, StrDataBasename, StrUserName, StrPassWord, ref sqlcon))
                {
                    tStrlblstatus.Text = "Đang đọc CSDL...";
                    MessageBox.Show("Kết nối thành công tới CSDL\nBắt đầu tiến hành đọc cấu trúc của CSDL", "Kết nối", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    ClsSQLDatabaseToDoc SQLdbtoword = new ClsSQLDatabaseToDoc();
                    SQLdbtoword.ReadAllDataBaseObjectNumber(sqlcon);
                    ListObject frmoblist = new ListObject();
                    frmoblist.ShowDialog();
                    if (frmoblist.DialogResult == DialogResult.Cancel)
                    {
                        return;
                    }
                    else
                    {
                        if (clsGlobalVariable.STRObjectRead.Contains("Tables"))
                        {
                            if (MessageBox.Show("Bạn có muốn đọc cấu trúc của từng bảng không?", "Cấu trúc bảng", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                            {
                                clsGlobalVariable.STRObjectRead += "Tables Detail";
                            }
                        }
                        SQLdbtoword.ReadAllObjectStructure(sqlcon, clsGlobalVariable.STRObjectRead);
                        if (File.Exists(strServerMapPath + "\\temp.doc"))
                        {
                            File.Delete(strServerMapPath + "\\temp.doc");
                        }
                        SQLdbtoword.WriteDatabaseStructureToWordFile(sqlcon, strServerMapPath + "\\temp.doc", "0");
                        MessageBox.Show("Đọc cấu trúc CSDL thành công", "Đã đọc", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }

                    sqlcon.Close();

                    blerror = false;
                }
                else
                {
                    MessageBox.Show("Không kết nối được tới CSDL đã chọn", "Lỗi Kết nối", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else if (strdatabasetype == "ORACLE")
            {
                if (ORACLEdbfunc.KetNoiCSDL(StrServer, StrDataBasename, StrUserName, StrPassWord, ref orclcon))
                {
                    tStrlblstatus.Text = "Đang đọc CSDL...";

                    MessageBox.Show("Kết nối thành công tới CSDL\nBắt đầu tiến hành đọc cấu trúc của CSDL", "Kết nối", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //ptboxprocess.Visible = true;
                    ClsOracleDatabaseToDoc ORACLEdbtoword = new ClsOracleDatabaseToDoc();
                    ORACLEdbtoword.ReadAllDataBaseObjectNumber(orclcon);
                    ListObject frmoblist = new ListObject();
                    frmoblist.ShowDialog();
                    if (frmoblist.DialogResult == DialogResult.Cancel)
                    {
                        return;
                    }
                    else
                    {
                        if (clsGlobalVariable.STRObjectRead.Contains("Tables"))
                        {
                            if (MessageBox.Show("Bạn có muốn đọc cấu trúc của từng bảng không?", "Cấu trúc bảng", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                            {
                                clsGlobalVariable.STRObjectRead += "Tables Detail";
                            }
                        }
                        ORACLEdbtoword.ReadAllObjectStructure(orclcon, clsGlobalVariable.STRObjectRead);
                        if (File.Exists(strServerMapPath + "\\temp.doc"))
                        {
                            File.Delete(strServerMapPath + "\\temp.doc");
                        }
                        ORACLEdbtoword.WriteDatabaseStructureToWordFile(orclcon, strServerMapPath + "\\temp.doc", "0");
                        MessageBox.Show("Đọc cấu trúc CSDL thành công", "Đã đọc", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }

                    orclcon.Close();

                    blerror = false;
                }
                else
                {
                    MessageBox.Show("Không kết nối được tới CSDL đã chọn", "Lỗi Kết nối", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }