Esempio n. 1
0
        private void SyncSqlServer2SSCE(object sender, RoutedEventArgs e)
        {
            string server   = sqlServerLoginControl1.X_Result.Server;
            string database = sqlServerLoginControl1.X_Result.DbName;
            string username = sqlServerLoginControl1.X_Result.UID;
            string pwd      = sqlServerLoginControl1.X_Result.PWD;

            if (core == null)
            {
                "ImportNeedSelectTables".GetFromResourece().Notify();
                return;
            }

            if (string.IsNullOrEmpty(server) || string.IsNullOrEmpty(database) ||
                string.IsNullOrEmpty(username))
            {
                "ImportEachElement".GetFromResourece().Notify();
                return;
            }
            string sdfFile = txtTargetFile.Text;

            PageSwitchProgressBar dp     = PageSwitchProgressBar.X_BeginLoadingDialog();
            List <SyncResultArgs> result = null;

            try
            {
                List <string> proecssTableList = new List <string>();

                foreach (string item in tableList.SelectedItems)
                {
                    proecssTableList.Add(item);
                }

                result = CommonUtil.SyncDataFromSqlServerToSSCE(core, sdfFile, proecssTableList, (bool)chkIsNeedCopyData.IsChecked);
            }
            catch (Exception ee)
            {
                ee.HandleMyException();
            }
            finally
            {
                if (!dp.IsDisposed)
                {
                    dp.X_EndLoadingDialog();
                }
            }

            if (result != null)
            {
                ShowSyncResult rShow = new ShowSyncResult(result);
#if DEBUG
#else
                rShow.Owner = this;
#endif

                rShow.ShowDialog();
            }
        }
        /// <summary>
        /// Finish Step
        /// Notice : Each table schema from Core can't be changed .
        /// We will filter the table schema for each target handler in this method.
        /// </summary>
        /// <param name="srcHandler"></param>
        /// <param name="targetHandler"></param>
        /// <param name="tableList"></param>
        /// <param name="isShowUI">This value will be false when UT</param>
        private bool DoExchangeData(CoreEA.ICoreEAHander srcHandler, CoreEA.ICoreEAHander targetHandler, List <string> tableList
                                    , bool isShowUI = true)
        {
            bool ret = false;
            //Due to the old code use .ForEach way, it is hard to detect the error position and status
            //So use this boolean object to indicate whether there has error in the for each cycle .
            //Is true,didn't show the UI error messgae when UI , just set this value to true .
            bool isHasError = false;

            if (tableList.Count < 1)
            {
                "DataTransferNoTableMsg".GetFromResourece().Show();
                return(false);
            }

            List <SyncResultArgs> result            = new List <SyncResultArgs>();
            List <string>         targetDbTableList = targetHandler.GetTableListInDatabase();
            PageSwitchProgressBar dp = null;

            if (isShowUI)
            {
                dp = PageSwitchProgressBar.X_BeginLoadingDialog();
            }
            try
            {
                foreach (string tableName in tableList)
                {
                    SyncResultArgs curStatus = new SyncResultArgs();

                    //Get target table schema info
                    BaseTableSchema tableSchmea = srcHandler.GetTableSchemaInfoObject(tableName);

                    try
                    {
                        //If table not existed ,then create it.
                        if (!targetDbTableList.Contains(tableName))
                        {
                            if (true)
                            {
                                switch (targetHandler.HostedType)
                                {
                                case CoreE.UsedDatabaseType.OleDb:
                                    throw new NotImplementedException();
                                    break;

                                case CoreE.UsedDatabaseType.SqlServer:
                                    targetHandler.CreateTable(tableSchmea);
                                    try
                                    {
                                        CommonUtil.ExchangeDataBetweenAnyDbs(srcHandler, targetHandler, tableName);
                                    }
                                    catch (Exception exee)
                                    {
                                        Debug.WriteLine(exee.Message);
                                        targetHandler.DeleteTable(tableSchmea.TableName);
                                    }
                                    break;

                                case CoreE.UsedDatabaseType.MySql:
                                    targetHandler.CreateTable(tableSchmea);
                                    try
                                    {
                                        CommonUtil.ExchangeDataBetweenAnyDbs(srcHandler, targetHandler, tableName);
                                    }
                                    catch (Exception exee)
                                    {
                                        Debug.WriteLine(exee.Message);
                                        targetHandler.DeleteTable(tableSchmea.TableName);
                                    }
                                    finally
                                    {
                                    }
                                    break;

                                case CoreE.UsedDatabaseType.SqlCE35:
                                    FilterTableSchemInfoWithSSCE(tableSchmea);
                                    targetHandler.CreateTable(tableSchmea);
                                    CommonUtil.CopyTable(srcHandler.GetConnection(), (SqlCeConnection)targetHandler.GetConnection(),
                                                         string.Format("Select * from {0}", srcHandler.GetMaskedTableName(tableName)), tableName);
                                    break;

                                case CoreE.UsedDatabaseType.Sqlite:
                                    targetHandler.CreateTable(tableSchmea);
                                    CommonUtil.ExchangeDataBetweenAnyDbs(srcHandler, targetHandler, tableName);
                                    break;

                                case CoreE.UsedDatabaseType.Firebird:
                                    throw new NotImplementedException();
                                    break;

                                case CoreE.UsedDatabaseType.CSV:
                                    targetHandler.CreateTable(tableSchmea);
                                    try
                                    {
                                        PreProcessCSV(srcHandler, targetHandler, tableName);
                                    }
                                    catch (Exception exee)
                                    {
                                        Debug.WriteLine(exee.Message);
                                        targetHandler.DeleteTable(tableSchmea.TableName);
                                    }
                                    break;

                                case CoreE.UsedDatabaseType.Excel:
                                    throw new NotImplementedException();

                                case CoreE.UsedDatabaseType.Oracle:
                                    throw new NotImplementedException();

                                default:
                                    break;
                                }
                            }

                            curStatus.ProcessStatus = true;
                            curStatus.TableName     = tableName;
                        }
                    }
                    catch (Exception sss)
                    {
                        curStatus.LastErrorMsg  = sss.Message;
                        curStatus.ProcessStatus = false;
                        curStatus.TableName     = tableName;
                        if (isShowUI)
                        {
                            sss.HandleMyException();
                        }
                        else
                        {
                            isHasError = true;
                        }
                        return(false);
                    }
                    finally
                    {
                        result.Add(curStatus);
                        butNext.Content   = "End";
                        butNext.IsEnabled = false;
                    }
                }
                ;
                if (isHasError)
                {
                    ret = false;
                }
                else
                {
                    ret = true;
                }
            }
            finally
            {
                if (isShowUI)
                {
                    if (!dp.IsDisposed)
                    {
                        dp.X_EndLoadingDialog();
                    }
                }
            }
            if (isShowUI)
            {
                if ("DataTransfer_ConfirmViewReport".GetFromResourece().Confirm())
                {
                    ShowSyncResult rShow = new ShowSyncResult(result);
                    rShow.ShowDialog();
                }

                Close();
            }

            return(ret);
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void butBackupDb_Click(object sender, RoutedEventArgs e)
        {
            WPFCommonControl.SqlServerLoginControl.X_CollectionData controlResult =
                this.sqlServerLoginControl1.X_Result;

            if (string.IsNullOrEmpty(controlResult.Server) || string.IsNullOrEmpty(controlResult.DbName) ||
                string.IsNullOrEmpty(controlResult.UID))
            {
                "ImportEachElement".GetFromResourece().Notify();
                return;
            }

            App.MainEngineer = new CoreEA.CoreE(CoreEA.CoreE.UsedDatabaseType.SqlServer).X_Handler;

            LoginInfo_SqlServer info = new LoginInfo_SqlServer()
            {
                X_Server              = controlResult.Server,
                X_Database            = controlResult.DbName,
                X_Pwd                 = controlResult.PWD,
                X_UserName            = controlResult.UID,
                X_Port                = controlResult.Port.ToString(),
                X_CurDbConnectionMode = controlResult.CurType.CurConnMode,
                IsTrustedConn         = controlResult.IsTrust,
            };
            PageSwitchProgressBar dp = null;

            try
            {
                App.MainEngineer.Open(info);
                if (App.MainEngineer.IsOpened)
                {
                    if (!"InfoBackupDb".GetFromResourece().Confirm())
                    {
                        return;
                    }

                    SaveFileDialog sf = new SaveFileDialog();
                    sf.Filter = MyGlobal.BackupDatabase_FILE_FILTER;


                    if ((bool)sf.ShowDialog())
                    {
                        string cmdStr = string.Format("BACKUP DATABASE {0} TO  DISK = N'{1}' WITH NOFORMAT, NOINIT,NAME = N'{2}', SKIP, NOREWIND, NOUNLOAD,  STATS = 10",
                                                      App.MainEngineer.CurDatabase, sf.FileName, "BackupDataFile");

                        IDbCommand cmd = App.MainEngineer.GetNewStringCommand(cmdStr);
                        cmd.CommandTimeout = int.MaxValue / 2;
                        dp = PageSwitchProgressBar.X_BeginLoadingDialog();

                        cmd.ExecuteNonQuery();
                        dp.X_EndLoadingDialog();
                        dp = null;
                        "InfoBackupSuccesful".GetFromResourece().Show();
                    }
                }
            }
            catch (Exception ee)
            {
                ee.HandleMyException();
            }
            finally
            {
                if (null != dp)
                {
                    dp.X_EndLoadingDialog();
                }
                App.ResetMainEngineer();
            }
        }