Ejemplo n.º 1
0
        private void btnCreateBackUp_Click(object sender, EventArgs e)
        {
            int backupID = 0;

            if (ValidateBackUpName())
            {
                BackupHistoryModel backupData = new BackupHistoryModel();
                backupData = GetInsertBackupHistory();
                backupID   = backuprestoreData.AddBackupHistory(backupData);
                if (backupID > 0)
                {
                    string folderPath = "";
                    folderPath = this.GetBackupFolderPath(backupID.ToString());
                    //
                    if (folderPath == "")
                    {
                        MessageBox.Show(MessageConstants.Cannotcreatebackupfilepathisinvalid, MessageConstants.TitleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        //Dele
                    }
                    else
                    {
                        if (Directory.Exists(folderPath))
                        {
                            FilesUtilBll.DeleteDirectory(folderPath);
                        }

                        if (!ExportTableToTextFile(folderPath, backupID))
                        {
                            FilesUtilBll.DeleteDirectory(folderPath);
                            backuprestoreData.UpdateDeletedFlagBackupHistory(backupID, UserName);
                            MessageBox.Show(MessageConstants.Cannotcreatebackupfileerrorexportcsvfile, MessageConstants.TitleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        else
                        {
                            MessageBox.Show(MessageConstants.Createbackupfilesuccessfull, MessageConstants.TitleInfomation, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
                txtBackupName.Text = "";
                RefreshData();
                FocusOnLastRow();
            }
            else
            {
                MessageBox.Show(MessageConstants.BackupNamemustnotbeNullorBlank, MessageConstants.TitleWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Ejemplo n.º 2
0
        private bool RestoreDataByTableName(int backupID, string folderPath)
        {
            List <ConfigBackupTable>   bckTable  = lstBackupTable.OrderBy(o => o.TableSeq).ToList <ConfigBackupTable>();
            List <BackupHistoryDetail> bckDetail = backuprestoreData.LoadBackupHistoryDetailByBackupID(backupID);

            try
            {
                foreach (ConfigBackupTable bck in bckTable)
                {
                    int seqTable = bck.TableSeq;
                    List <BackupHistoryDetail> bDetail = (from b in bckDetail
                                                          where b.BackupSeq == bck.TableSeq
                                                          select b).ToList <BackupHistoryDetail>();
                    string    fullPath = folderPath + @bDetail[0].FileName;
                    DataTable dtFormat = new DataTable();
                    DataTable dtImport = new DataTable();
                    dtFormat = backuprestoreData.GetSchemaTableByTableName(bDetail[0].BackupTable);
                    if (dtFormat != null)
                    {
                        dtImport = FilesUtilBll.GetDataTableFromTextFile(dtFormat, fullPath, ",", true, true);
                    }
                    else
                    {
                        dtImport = FilesUtilBll.GetDataTableFromTextFile(fullPath, ",", true, true);
                    }
                    if (dtImport != null)
                    {
                        if (!backuprestoreData.RestoreDataByTableName(bDetail[0].BackupTable, dtImport))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                log.Error(String.Format("Exception : {0}", ex.StackTrace));
                return(false);
            }
        }
Ejemplo n.º 3
0
 private bool ExportTableToTextFile(string folderPath, int backupID)
 {
     try
     {
         foreach (ConfigBackupTable bck in lstBackupTable.OrderBy(o => o.TableSeq).ToList <ConfigBackupTable>())
         {
             int       tableSeq     = bck.TableSeq;
             string    tableName    = bck.TableName;
             string    fileName     = bck.TableName + @".csv";
             string    fullPath     = folderPath + @"\" + fileName;
             DataTable dtExportFile = backuprestoreData.GetSchemaTableByTableName(tableName);
             if (FilesUtilBll.ExportTextFileFromDataTable(fullPath, dtExportFile, ",", true, true))
             {
                 BackupHistoryDetail backupDetail = new BackupHistoryDetail();
                 backupDetail.BackupID    = backupID;
                 backupDetail.BackupSeq   = tableSeq;
                 backupDetail.BackupTable = tableName;
                 backupDetail.FileName    = fileName;
                 backupDetail.CreateDate  = DateTime.Now;
                 backupDetail.CreateBy    = UserName;
                 //Insert History Detail
                 if (!backuprestoreData.AddBackupHistoryDetail(backupDetail))
                 {
                     return(false);
                 }
             }
             else
             {
                 return(false);
             }
         }
         return(true);
     }
     catch (Exception ex)
     {
         log.Error(String.Format("Exception : {0}", ex.StackTrace));
         return(false);
     }
 }
Ejemplo n.º 4
0
        private void btnDeleteBackUp_Click(object sender, EventArgs e)
        {
            List <int>    selectedRow = GetListSelected();
            List <string> error       = new List <string>();
            string        errorMsg    = "";
            int           selected    = selectedRow.Count;

            if (selected > 0)
            {
                try
                {
                    DialogResult dialogresult = MessageBox.Show(MessageConstants.Doyouwanttodeletebackupdata, MessageConstants.TitleClearDataConfirmation, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (dialogresult == DialogResult.Yes)
                    {
                        //delete backup
                        foreach (int idx in selectedRow)
                        {
                            int backupID = 0;
                            backupID = int.Parse(dgvBackUpHistory.Rows[idx].Cells[1].Value.ToString());
                            if (backupID > 0)
                            {
                                //delete Directory
                                string folderPath = "";
                                folderPath = this.GetBackupFolderPath(backupID.ToString());
                                if (folderPath == "")
                                {
                                    errorMsg += MessageConstants.CannotdeletebackupfilewithbackupID + backupID + "." + Environment.NewLine;
                                }
                                else
                                {
                                    if (FilesUtilBll.DeleteDirectory(folderPath))
                                    {
                                        //update flag
                                        backuprestoreData.UpdateDeletedFlagBackupHistory(backupID, UserName);
                                    }
                                    else
                                    {
                                        errorMsg += MessageConstants.CannotdeletebackupfilewithbackupID + backupID + "." + Environment.NewLine;
                                    }
                                }
                            }
                        }
                        if (errorMsg != "")
                        {
                            MessageBox.Show(errorMsg, MessageConstants.TitleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        else
                        {
                            MessageBox.Show(MessageConstants.Deletebackupdatasuccessfull, MessageConstants.TitleInfomation, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        RefreshData();
                    }
                }
                catch (Exception ex)
                {
                    log.Error(String.Format("Exception : {0}", ex.StackTrace));
                    MessageBox.Show(MessageConstants.Cannotdeletebackupdata, MessageConstants.TitleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show(MessageConstants.CannotdeletebackupdataPleaseselectrecordfordelete, MessageConstants.TitleWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }