Example #1
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);
                }
            }
        }