protected RemoteControllerBase()
 {
     try
     {
         if (App.Configs.ServiceUri == null)
         {
             if (App.Configs.ServiceUri.StartsWith("net.tcp"))
             {
                 m_Binding = CommonUtils.CreateTcpBinding();
             }
             if (App.Configs.ServiceUri.StartsWith("http"))
             {
                 m_Binding = CommonUtils.CreateHttpBinding();
             }
             m_EndpointAddress = new EndpointAddress(App.Configs.ServiceUri + "/" + GetType().Name);
         }
         else
         {
             if (App.Configs.ServiceUri.StartsWith("net.tcp"))
             {
                 m_Binding = CommonUtils.CreateTcpBinding();
             }
             if (App.Configs.ServiceUri.StartsWith("http"))
             {
                 m_Binding = CommonUtils.CreateHttpBinding();
             }
             m_EndpointAddress = new EndpointAddress(App.Configs.ServiceUri + "/" + GetType().Name);
         }
     }
     catch (Exception ex)
     {
         throw ErrorUtils.CreateErrorWithSubMessage(ERR_SYSTEM.ERR_SYSTEM_CONNECT_TO_SERVER_FAIL, ex.Message);
     }
 }
Beispiel #2
0
 public static void DiscoveryParameters(NpgsqlCommand comm)
 {
     try
     {
         var cachedKey = comm.CommandText;
         if (m_CachedNpgParameters.ContainsKey(cachedKey))
         {
             var source = m_CachedNpgParameters[cachedKey];
             foreach (var param in source)
             {
                 comm.Parameters.Add((NpgsqlParameter)((ICloneable)param).Clone());
             }
         }
         else
         {
             NpgsqlCommandBuilder.DeriveParameters(comm);
             comm.CommandText = cachedKey;
             var source = new NpgsqlParameter[comm.Parameters.Count];
             for (var i = 0; i < comm.Parameters.Count; i++)
             {
                 source[i] = (NpgsqlParameter)((ICloneable)comm.Parameters[i]).Clone();
             }
             m_CachedNpgParameters.Add(cachedKey, source);
         }
     }
     catch (Exception ex)
     {
         throw ErrorUtils.CreateErrorWithSubMessage(ERR_SQL.ERR_SQL_DISCOVERY_PARAMS_FAIL, ex.Message, comm.CommandText);
     }
 }
 private void Process()
 {
     foreach (var batch in m_Batchs)
     {
         try
         {
             if (ProcessComplete != null)
             {
                 ProcessComplete(batch, true, null);
             }
         }
         catch (FaultException ex)
         {
             ProcessComplete(batch, false, ex);
             return;
         }
         catch (Exception ex)
         {
             ProcessComplete(batch, false, ErrorUtils.CreateErrorWithSubMessage(ERR_SYSTEM.ERR_SYSTEM_UNKNOWN, ex.Message));
             return;
         }
     }
     if (EndBatch != null)
     {
         EndBatch(this, new EventArgs());
     }
 }
Beispiel #4
0
        public static List <T> ExecuteStoreProcedure <T>(string connectionString, string commandText, params object[] values)
            where T : class, new()
        {
            using (var conn = new SqlConnection(connectionString))
            {
                try
                {
                    conn.Open();
                }
                catch (Exception ex)
                {
                    throw ErrorUtils.CreateErrorWithSubMessage(
                              ERR_SQL.ERR_SQL_OPEN_CONNECTION_FAIL, ex.Message, commandText);
                }
                using (var comm = new SqlCommand(commandText, conn))
                {
                    try
                    {
                        comm.CommandType = CommandType.StoredProcedure;
                        AssignParameters(comm, values);

                        using (var dr = comm.ExecuteReader())
                        {
                            if (
                                comm.Parameters.Contains(CONSTANTS.ORACLE_EXCEPTION_PARAMETER_NAME) &&
                                comm.Parameters[CONSTANTS.ORACLE_EXCEPTION_PARAMETER_NAME].Value != DBNull.Value
                                )
                            {
                                var errCode = int.Parse(comm.Parameters[CONSTANTS.ORACLE_EXCEPTION_PARAMETER_NAME].Value.ToString());
                                if (errCode != 0)
                                {
                                    throw ErrorUtils.CreateError(errCode, commandText, values);
                                }
                            }

                            return(dr.ToList <T>());
                        }
                    }
                    catch (SqlException ex)
                    {
                        throw ThrowSqlUserException(ex, commandText);
                    }
                    catch (FaultException)
                    {
                        throw;
                    }
                    catch (Exception ex)
                    {
                        throw ErrorUtils.CreateErrorWithSubMessage(
                                  ERR_SQL.ERR_SQL_EXECUTE_COMMAND_FAIL, ex.Message, commandText);
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
            }
        }
Beispiel #5
0
        public static OracleDataReader[] ExecuteReader(string connectionString, Session session, string commandText, params object[] values)
        {
            var conn = new OracleConnection(connectionString);

            try
            {
                conn.Open();
            }
            catch (Exception ex)
            {
                throw ErrorUtils.CreateErrorWithSubMessage(
                          ERR_SQL.ERR_SQL_OPEN_CONNECTION_FAIL, ex.Message, commandText);
            }

            try
            {
                var comm = new OracleCommand(commandText, conn)
                {
                    CommandType = CommandType.StoredProcedure
                };
                AssignParameters(comm, session, values);

                comm.ExecuteNonQuery();

                if (
                    comm.Parameters.Contains(CONSTANTS.ORACLE_EXCEPTION_PARAMETER_NAME) &&
                    comm.Parameters[CONSTANTS.ORACLE_EXCEPTION_PARAMETER_NAME].Value != DBNull.Value &&
                    comm.Parameters[CONSTANTS.ORACLE_EXCEPTION_PARAMETER_NAME].Value != null
                    )
                {
                    var errCode = int.Parse(comm.Parameters[CONSTANTS.ORACLE_EXCEPTION_PARAMETER_NAME].Value.ToString());
                    if (errCode != 0)
                    {
                        throw ErrorUtils.CreateError(errCode, commandText, values);
                    }
                }

                var readers = (from OracleParameter param in comm.Parameters
                               where param.OracleDbType == OracleDbType.RefCursor
                               select
                                   (param.Value as OracleDataReader) ?? ((OracleRefCursor)param.Value).GetDataReader()).ToArray();

                return(readers);
            }
            catch (OracleException ex)
            {
                throw ThrowOracleUserException(ex, commandText);
            }
            catch (FaultException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw ErrorUtils.CreateErrorWithSubMessage(
                          ERR_SQL.ERR_SQL_EXECUTE_COMMAND_FAIL, ex.Message, commandText);
            }
        }
Beispiel #6
0
        private static void AssignParameters(SqlCommand comm, Session session, params object[] values)
        {
            try
            {
                comm.Parameters.Clear();
                DiscoveryParameters(comm);
                // assign value
                var index = 0;
                foreach (SqlParameter param in comm.Parameters)
                {
                    if (param.ParameterName == "@" + CONSTANTS.ORACLE_SESSION_USER)
                    {
                        param.Value = session.Username;
                    }
                    else if (param.ParameterName == "@" + CONSTANTS.ORACLE_SESSIONKEY)
                    {
                        param.Value = session.SessionKey;
                    }

                    else if (param.Direction == ParameterDirection.Input || param.Direction == ParameterDirection.InputOutput)
                    {
                        if (values[index] == null || (values[index] is string && (string)values[index] == string.Empty))
                        {
                            param.Value = DBNull.Value;
                        }
                        else
                        {
                            switch (param.SqlDbType)
                            {
                            case SqlDbType.Date:
                                param.Value = Convert.ToDateTime(values[index]);
                                break;

                            case SqlDbType.Decimal:
                                param.Value = Convert.ToDecimal(values[index]);
                                break;

                            default:
                                param.Value = values[index];
                                break;
                            }
                        }
                        index++;
                    }
                }
            }
            catch (FaultException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw ErrorUtils.CreateErrorWithSubMessage(
                          ERR_SQL.ERR_SQL_ASSIGN_PARAMS_FAIL, ex.Message,
                          comm.CommandText, values);
            }
        }
Beispiel #7
0
        public static void FillDataSet(string connectionString, Session session, string moduleID, string commandText, out DataSet ds, params object[] values)
        {
            using (var conn = new SqlConnection(connectionString))
            {
                try
                {
                    conn.Open();
                }
                catch (Exception ex)
                {
                    throw ErrorUtils.CreateErrorWithSubMessage(
                              ERR_SQL.ERR_SQL_OPEN_CONNECTION_FAIL, ex.Message,
                              commandText, values);
                }

                try
                {
                    using (var comm = new SqlCommand(commandText, conn))
                    {
                        comm.CommandType = CommandType.StoredProcedure;
                        AssignParameters(comm, session, moduleID, values);
                        ds = new DataSet();
                        var adap = new SqlDataAdapter(comm);
                        adap.Fill(ds);
                        if (
                            comm.Parameters.Contains(CONSTANTS.ORACLE_EXCEPTION_PARAMETER_NAME) &&
                            comm.Parameters[CONSTANTS.ORACLE_EXCEPTION_PARAMETER_NAME].Value != DBNull.Value
                            )
                        {
                            var errCode = int.Parse(comm.Parameters[CONSTANTS.ORACLE_EXCEPTION_PARAMETER_NAME].Value.ToString());
                            if (errCode != 0)
                            {
                                throw ErrorUtils.CreateError(errCode, commandText, values);
                            }
                        }
                    }
                }
                catch (SqlException ex)
                {
                    throw ThrowSqlUserException(ex, commandText);
                }
                catch (FaultException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    throw ErrorUtils.CreateErrorWithSubMessage(
                              ERR_SQL.ERR_SQL_EXECUTE_COMMAND_FAIL, ex.Message,
                              commandText, values);
                }
                finally
                {
                    conn.Close();
                }
            }
        }
Beispiel #8
0
        public static void ExecuteStoreProcedure(string connectionString, Session session, string commandText, params object[] values)
        {
            using (var conn = new OracleConnection(connectionString))
            {
                try
                {
                    conn.Open();
                }
                catch (Exception ex)
                {
                    throw ErrorUtils.CreateErrorWithSubMessage(
                              ERR_SQL.ERR_SQL_OPEN_CONNECTION_FAIL, ex.Message,
                              commandText, values);
                }

                try
                {
                    var comm = new OracleCommand(commandText, conn)
                    {
                        CommandType = CommandType.StoredProcedure
                    };

                    AssignParameters(comm, session, values);

                    comm.ExecuteNonQuery();
                    if (
                        comm.Parameters.Contains(CONSTANTS.ORACLE_EXCEPTION_PARAMETER_NAME) &&
                        comm.Parameters[CONSTANTS.ORACLE_EXCEPTION_PARAMETER_NAME].Value != DBNull.Value
                        )
                    {
                        var errCode = int.Parse(comm.Parameters[CONSTANTS.ORACLE_EXCEPTION_PARAMETER_NAME].Value.ToString());
                        if (errCode != 0)
                        {
                            throw ErrorUtils.CreateError(errCode, commandText, values);
                        }
                    }
                }
                catch (OracleException ex)
                {
                    throw ThrowOracleUserException(ex, commandText);
                }
                catch (FaultException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    throw ErrorUtils.CreateErrorWithSubMessage(
                              ERR_SQL.ERR_SQL_EXECUTE_COMMAND_FAIL, ex.Message,
                              commandText, values);
                }
                finally
                {
                    conn.Close();
                }
            }
        }
Beispiel #9
0
        //public static SqlDataAdapter[] ExecuteReader(string connectionString, Session session, string commandText, params object[] values)
        //{
        //    var conn = new SqlConnection(connectionString);
        //    try
        //    {
        //        conn.Open();
        //    }
        //    catch (Exception ex)
        //    {
        //        throw ErrorUtils.CreateErrorWithSubMessage(
        //            ERR_SQL.ERR_SQL_OPEN_CONNECTION_FAIL, ex.Message, commandText);
        //    }

        //    try
        //    {
        //        var comm = new SqlCommand(commandText, conn) { CommandType = CommandType.StoredProcedure };
        //        AssignParameters(comm, session, values);

        //        comm.ExecuteNonQuery();

        //        if (
        //            comm.Parameters.Contains(CONSTANTS.ORACLE_EXCEPTION_PARAMETER_NAME) &&
        //            comm.Parameters[CONSTANTS.ORACLE_EXCEPTION_PARAMETER_NAME].Value != DBNull.Value &&
        //            comm.Parameters[CONSTANTS.ORACLE_EXCEPTION_PARAMETER_NAME].Value != null
        //            )
        //        {
        //            var errCode = int.Parse(comm.Parameters[CONSTANTS.ORACLE_EXCEPTION_PARAMETER_NAME].Value.ToString());
        //            if (errCode != 0) throw ErrorUtils.CreateError(errCode, commandText, values);
        //        }

        //        var readers = (from SqlParameter param in comm.Parameters
        //                       where param.SqlDbType == SqlDbType.RefCursor
        //                       select
        //                           (param.Value as OracleDataReader) ?? ((OracleRefCursor)param.Value).GetDataReader()).ToArray();

        //        return readers;
        //    }
        //    catch (SqlException ex)
        //    {
        //        throw ThrowSqlUserException(ex, commandText);
        //    }
        //    catch (FaultException)
        //    {
        //        throw;
        //    }
        //    catch (Exception ex)
        //    {
        //        throw ErrorUtils.CreateErrorWithSubMessage(
        //            ERR_SQL.ERR_SQL_EXECUTE_COMMAND_FAIL, ex.Message, commandText);
        //    }
        //}

        public static void DiscoveryParameters(string connectionString, string commandText, List <OracleParam> @params)
        {
            using (var conn = new SqlConnection(connectionString))
            {
                try
                {
                    conn.Open();
                }
                catch (Exception ex)
                {
                    throw ErrorUtils.CreateErrorWithSubMessage(
                              ERR_SQL.ERR_SQL_OPEN_CONNECTION_FAIL, ex.Message,
                              commandText);
                }

                try
                {
                    var comm = new SqlCommand(commandText, conn)
                    {
                        CommandType = CommandType.StoredProcedure
                    };
                    DiscoveryParameters(comm);

                    //foreach(SqlParameter p in comm.Parameters) {
                    //    var objparam = new OracleParam();
                    //    objparam.StoreName = commandText;
                    //    objparam.Value = p.ParameterName;
                    //    @params.Add(objparam);
                    //}

                    @params.AddRange(from SqlParameter param in comm.Parameters
                                     where param.Direction == ParameterDirection.Input
                                     select new OracleParam
                    {
                        StoreName = commandText,
                        Name      = param.ParameterName
                    });
                }
                catch (FaultException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    throw ErrorUtils.CreateErrorWithSubMessage(
                              ERR_SQL.ERR_SQL_EXECUTE_COMMAND_FAIL, ex.Message,
                              commandText);
                }
                finally
                {
                    conn.Close();
                }
            }
        }
Beispiel #10
0
        private static void AssignParameters(SqlCommand comm, params object[] values)
        {
            try
            {
                DiscoveryParameters(comm);
                // assign value
                var index = 0;
                foreach (SqlParameter param in comm.Parameters)
                {
                    if (param.Direction == ParameterDirection.Input || param.Direction == ParameterDirection.InputOutput)
                    {
                        if (values[index] == null || (values[index] is string && (string)values[index] == string.Empty))
                        {
                            param.Value = DBNull.Value;
                        }
                        else
                        {
                            switch (param.DbType)
                            {
                            case DbType.Date:
                                param.Value = Convert.ToDateTime(values[index]);
                                break;

                            case DbType.Byte:
                            case DbType.Int16:
                            case DbType.Int32:
                            case DbType.Int64:
                            case DbType.Single:
                            case DbType.Double:
                            case DbType.Decimal:
                                param.Value = Convert.ToDecimal(values[index]);
                                break;

                            default:
                                param.Value = values[index];
                                break;
                            }
                        }
                        index++;
                    }
                }
            }

            catch (Exception ex)
            {
                throw ErrorUtils.CreateErrorWithSubMessage(
                          ERR_SQL.ERR_SQL_ASSIGN_PARAMS_FAIL, ex.Message,
                          comm.CommandText, values);
            }
        }
Beispiel #11
0
        public void InstallModule(string fileName)
        {
            try
            {
                var module = CreateModuleInstance(STATICMODULE.INSTALL_MODULE_PACKAGE, CODES.DEFMOD.SUBMOD.MODULE_MAIN);
                module["P01"] = fileName;

                module.ShowDialogModule(m_mainForm);
            }
            catch (FaultException ex)
            {
                frmInfo.ShowError(((IMain)m_mainForm).Language.ApplicationTitle, ex, m_mainForm);
            }
            catch (Exception ex)
            {
                frmInfo.ShowError(((IMain)m_mainForm).Language.ApplicationTitle, ErrorUtils.CreateErrorWithSubMessage(ERR_SYSTEM.ERR_SYSTEM_UNKNOWN, ex.Message), m_mainForm);
            }
        }
Beispiel #12
0
        public static void DiscoveryParameters(string connectionString, string commandText, List <SqlParameter> parrs)
        {
            using (var conn = new SqlConnection(connectionString))
            {
                try
                {
                    conn.Open();
                }
                catch (Exception ex)
                {
                    throw ErrorUtils.CreateErrorWithSubMessage(
                              ERR_SQL.ERR_SQL_OPEN_CONNECTION_FAIL, ex.Message,
                              commandText);
                }

                try
                {
                    var comm = new SqlCommand(commandText, conn)
                    {
                        CommandType = CommandType.StoredProcedure
                    };
                    DiscoveryParameters(comm);
                    parrs.AddRange(from SqlParameter param in comm.Parameters
                                   where param.Direction == ParameterDirection.Input
                                   select new SqlParameter
                    {
                        //StoreName = commandText,
                        DbType        = param.DbType,
                        SqlDbType     = param.SqlDbType,
                        ParameterName = param.ParameterName
                    });
                }
                catch (Exception ex)
                {
                    throw ErrorUtils.CreateErrorWithSubMessage(ERR_SQL.ERR_SQL_EXECUTE_COMMAND_FAIL, ex.Message,
                                                               commandText);
                }
                finally
                {
                    conn.Close();
                }
            }
        }
Beispiel #13
0
 private void _ExecuteModule(string moduleID, string subModule, bool execute)
 {
     try
     {
         var module = CreateModuleInstance(moduleID, subModule);
         module.ShowModule(m_mainForm);
         if (execute)
         {
             module.Execute();
         }
     }
     catch (FaultException ex)
     {
         frmInfo.ShowError(((IMain)m_mainForm).Language.ApplicationTitle, ex, m_mainForm);
     }
     catch (Exception ex)
     {
         frmInfo.ShowError(((IMain)m_mainForm).Language.ApplicationTitle, ErrorUtils.CreateErrorWithSubMessage(ERR_SYSTEM.ERR_SYSTEM_UNKNOWN, ex.Message), m_mainForm);
     }
 }
Beispiel #14
0
        public static Exception ThrowSqlUserException(NpgsqlException ex, string commandText)
        {
            if (ex.ErrorCode == CONSTANTS.SQL_USER_HANDLED_EXCEPTION_CODE)
            {
                var match = Regex.Match(ex.Message, "<ERROR ID=([0-9]+)>([^<]*)</ERROR>");
                if (match.Success)
                {
                    var errCode    = int.Parse(match.Groups[1].Value);
                    var errMessage = match.Groups[2].Value;

                    if (!string.IsNullOrEmpty(errMessage))
                    {
                        return(ErrorUtils.CreateErrorWithSubMessage(errCode, errMessage));
                    }
                    return(ErrorUtils.CreateError(errCode));
                }
            }
            return(ErrorUtils.CreateErrorWithSubMessage(
                       ERR_SQL.ERR_SQL_EXECUTE_COMMAND_FAIL, ex.Message, commandText));
        }
Beispiel #15
0
        public SAController(Session MainSession)
        {
            try
            {
                m_Client = new SAControllerClient(m_Binding, m_EndpointAddress);
                m_Client.Open();

                if (MainSession != null)
                {
                    m_Client.InitializeSessionID(MainSession.SessionKey);
                }
            }
            catch (FaultException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw ErrorUtils.CreateErrorWithSubMessage(ERR_SYSTEM.ERR_SYSTEM_CONNECT_TO_SERVER_FAIL, ex.Message);
            }
        }
Beispiel #16
0
        protected override void InitializeModuleData()
        {
            base.InitializeModuleData();
            CurrentThread = new WorkerThread(delegate
            {
                while (!CurrentThread.AbortRequest)
                {
                    try
                    {
                        using (var ctrlSA = new SAController())
                        {
                            DataContainer alertContainer;
                            ctrlSA.ExecuteAlert(out alertContainer, ModuleInfo.ModuleID, ModuleInfo.SubModule);

                            var rows = alertContainer.DataTable.Rows;

                            if (rows.Count > 0)
                            {
                                m_LastResultRow = alertContainer.DataTable.Rows[0];
                            }
                        }
                    }
                    catch (FaultException ex)
                    {
                        m_LastException = ex;
                    }
                    catch (Exception ex)
                    {
                        m_LastException = ErrorUtils.CreateErrorWithSubMessage(ERR_SYSTEM.ERR_SYSTEM_UNKNOWN, ex.Message);
                    }

                    CurrentThread.ExecuteUpdateGUI();
                    Thread.Sleep(AlertInfo.SleepTime);
                }
            }, MainProcess.GetMainForm());
            CurrentThread.DoUpdateGUI += CurrentThread_DoUpdateGUI;
            CurrentThread.Start();
        }
Beispiel #17
0
        public static void DiscoveryParameters(SqlCommand comm)
        {
            try
            {
                //discovery parameter
                var cachedKey = comm.CommandText;
                if (m_CachedParameters.ContainsKey(cachedKey))
                {
                    var source = m_CachedParameters[cachedKey];
                    foreach (var param in source)
                    {
                        comm.Parameters.Add((SqlParameter)((ICloneable)param).Clone());
                    }
                }
                else
                {
#if DEBUG
                    //comm.CommandText += "--" + (new Random().Next());
#endif
                    SqlCommandBuilder.DeriveParameters(comm);
                    comm.CommandText = cachedKey;
                    var source = new SqlParameter[comm.Parameters.Count];
                    for (var i = 0; i < comm.Parameters.Count; i++)
                    {
                        //source[i] = (SqlParameter)comm.Parameters[i];
                        source[i] = (SqlParameter)((ICloneable)comm.Parameters[i]).Clone();
                    }
                    m_CachedParameters.Add(cachedKey, source);
                }
            }
            catch (Exception ex)
            {
                throw ErrorUtils.CreateErrorWithSubMessage(
                          ERR_SQL.ERR_SQL_DISCOVERY_PARAMS_FAIL, ex.Message,
                          comm.CommandText);
            }
        }
Beispiel #18
0
        static void Main(string[] args)
        {
            // TuanLM tam bo AutoUpdate
            //string strExeFile = "COMS.EXE";

            //string autoUpdateUri = ConfigurationSettings.AppSettings["AutoUpdateUri"];
            //string autoUpdateConfig = ConfigurationSettings.AppSettings["AutoUpdateConfig"];
            //string curentVersionApp = null;
            //string ManifestFile = "AutoUpdate.xml";
            //string strName = null;
            //string strVersion = null;
            //string strDate = null;
            //if (autoUpdateConfig == CONSTANTS.AutoConfigYes)
            //{
            //    try
            //    {
            //        XmlDocument xmld = new XmlDocument();
            //        var webClient = new WebClient();

            //        if (webClient.Proxy != null)
            //        {
            //            MemoryStream ms = new MemoryStream(webClient.DownloadData(autoUpdateUri + ManifestFile));
            //            XmlTextReader rdr = new XmlTextReader(autoUpdateUri + ManifestFile);
            //            xmld.Load(rdr);
            //        }
            //        else
            //        {
            //            xmld.Load(autoUpdateUri + ManifestFile);
            //        }
            //        //TRUNGTT_20140804_End
            //        XmlNodeList xmlNodeList = xmld.SelectNodes("/update/Entry");
            //        foreach (XmlNode xmlNode in xmlNodeList)
            //        {
            //            strName = xmlNode.Attributes.GetNamedItem("filename").Value;
            //            strVersion = xmlNode.Attributes.GetNamedItem("version").Value;
            //            strDate = xmlNode.Attributes.GetNamedItem("date").Value;
            //            if (strName.ToUpper() == strExeFile.ToUpper())
            //                break;
            //        }

            //        if (File.Exists(Application.StartupPath + @"\" + strExeFile))
            //        {
            //            FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(strExeFile);
            //            curentVersionApp = fileVersionInfo.FileMajorPart.ToString() + "." + fileVersionInfo.FileMinorPart.ToString() + "." + fileVersionInfo.FileBuildPart.ToString();
            //            //Application.ProductVersion
            //            //Version curVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;

            //           // if (curentVersionApp != strVersion)
            //            if (curentVersionApp.CompareTo(strVersion) < 0)
            //            {
            //                if (File.Exists(Application.StartupPath + @"\" + "FIS.AutoUpdate.exe"))
            //                {
            //                    Process p = new Process();
            //                    p.StartInfo.FileName = "FIS.AutoUpdate.exe";
            //                    p.Start();
            //                    return;
            //                }
            //                else
            //                {
            //                    throw new FileNotFoundException("Không tìm thấy file FIS.AutoUpdate.exe trong thư mục cài đặt");
            //                }
            //            }
            //        }
            //    }
            //    catch (Exception ex)
            //    {
            //        File.AppendAllText("LastErrors.log", string.Format("Check Auto Update Hệ Thống : {0} : {1} \r\n-------------\r\n", System.DateTime.Now.ToLongTimeString(), ex.ToString()));
            //        MessageBox.Show("Có lỗi trong quá trình Auto Update hệ thống", "Auto Update hệ thống", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //        return;
            //    }

            //}

            //if (args.Length == 2)
            //{
            //    switch (args[0].ToUpper())
            //    {
            //        case "/I":
            //            foreach (var process in Process.GetProcesses())
            //            {
            //                Win32.COPYDATASTRUCT fileInfo;
            //                var bytes = Encoding.UTF8.GetBytes(args[1]);
            //                fileInfo.m_DwData = (IntPtr)0;
            //                fileInfo.m_LpData = args[1];
            //                fileInfo.m_CbData = bytes.Length + 1;

            //                Win32.SendMessage(process.MainWindowHandle, Win32.WM_COPYDATA, process.MainWindowHandle, ref fileInfo);
            //            }
            //            return;
            //    }
            //}

            if (args.Length == 0)
            {
                //MessageBox.Show("TrungTT");
            }
            else
            {
                StrUserName = args[0];
                StrPassWord = args[1];
            }

            var isInited = false;

            try
            {
                DevExpress.UserSkins.BonusSkins.Register();
                DevExpress.UserSkins.OfficeSkins.Register();
                strAppStartUpPath = Application.StartupPath;

                SkinManager.EnableFormSkins();
                frmSplash.ShowSplashScreen();

                for (var count = 1; count <= 3; count++)
                {
                    try
                    {
                        App.Environment = new ClientEnvironment
                        {
                            ClientInfo =
                            {
                                Culture                  = new CultureInfo("en-US")
                                {
                                    DateTimeFormat       =
                                    {
                                        ShortDatePattern = "d/M/yyyy",
                                        LongDatePattern  = "dd MMMM yyyy"
                                    }
                                }
                            }
                        };

                        ThreadUtils.SetClientCultureInfo();

                        isInited = true;
                        break;
                    }

                    catch (Exception e)
                    {
                        var ex = ErrorUtils.CreateErrorWithSubMessage(ERR_SYSTEM.ERR_SYSTEM_UNKNOWN, e.Message);

                        for (var i = 5; i > 0; i--)
                        {
                            frmSplash.ChangeSplashStatus("Connect again after next " + i + "/" + count + " second(s)...");
                            Thread.Sleep(1000);
                        }
                    }
                }

                if (isInited)
                {
                    frmSplash.ChangeSplashStatus("Initializing application...");
                    frmSplash.CloseForm();


                    var frmMain = new frmMainRibbon();
                    Application.Run(frmMain);
                }
            }
            catch (FaultException ex)
            {
                frmInfo.ShowError("Main", ex);
                Environment.Exit(1);
            }
            catch (Exception ex)
            {
                frmInfo.ShowError("Main", ErrorUtils.CreateErrorWithSubMessage(ERR_SYSTEM.ERR_SYSTEM_UNKNOWN, ex.Message));
                Environment.Exit(1);
            }
            finally
            {
                frmSplash.CloseForm();
                Environment.Exit(0);
            }
        }
Beispiel #19
0
        void IMain.ApplyMenu()
        {
            mainMenu.ItemLinks.Clear();

            foreach (BarItem item in mainBar.Items)
            {
                var menuItemInfo = item.Tag as MenuItemInfo;
                if (menuItemInfo != null && !string.IsNullOrEmpty(menuItemInfo.ModuleID))
                {
                    var module = ModuleUtils.GetModuleInfo(menuItemInfo.ModuleID, menuItemInfo.SubModule);

                    if (!string.IsNullOrEmpty(module.RoleID))
                    {
                        var role = (from Role r in MainProcess.Roles
                                    where r.RoleID == module.RoleID
                                    select r).FirstOrDefault();
                        if (role != null && role.RoleValue != "Y")
                        {
                            item.Visibility = BarItemVisibility.Never;
                        }
                        else
                        {
                            item.Visibility = BarItemVisibility.Always;
                        }
                    }
                }
            }

            var count = m_RootCategory.GetItemCount();

            for (int i = 0; i < count; i++)
            {
                mainMenu.ItemLinks.Add(m_RootCategory.GetItem(i));
            }

            var isStop = false;

            foreach (var barItem in mainBar.Items)
            {
                if (barItem is BarSubItem)
                {
                    (barItem as BarSubItem).Visibility = BarItemVisibility.Always;
                }
            }

            while (!isStop)
            {
                isStop = true;
                foreach (BarItem barItem in mainBar.Items)
                {
                    if (barItem is BarSubItem && (barItem as BarSubItem).Visibility == BarItemVisibility.Always)
                    {
                        var isVisible = false;
                        foreach (LinkPersistInfo link in (barItem as BarSubItem).LinksPersistInfo)
                        {
                            if (link.Item.Visibility == BarItemVisibility.Always)
                            {
                                isVisible = true;
                            }
                        }

                        if (!isVisible)
                        {
                            (barItem as BarSubItem).Visibility = BarItemVisibility.Never;
                            isStop = false;
                        }
                    }
                }
            }
#if DEBUG
            mainMenu.ItemLinks.Add(txtModuleID);
#endif
            try
            {
                using (var ctrlSA = new SAController())
                {
                    User userInfo;
                    ctrlSA.GetSessionUserInfo(out userInfo);
                }
            }
            catch (FaultException ex)
            {
                frmInfo.ShowError(Language.ApplicationTitle, ex, this);
            }
            catch (Exception ex)
            {
                frmInfo.ShowError(Language.ApplicationTitle, ErrorUtils.CreateErrorWithSubMessage(ERR_SYSTEM.ERR_SYSTEM_UNKNOWN, ex.Message), this);
            }
        }
Beispiel #20
0
        public static void FillDataTable(string connectionString, Session session, string commandText, out DataTable resultTable, out string SecID, params object[] values)
        {
            using (var conn = new OracleConnection(connectionString))
            {
                try
                {
                    conn.Open();
                }
                catch (Exception ex)
                {
                    throw ErrorUtils.CreateErrorWithSubMessage(
                              ERR_SQL.ERR_SQL_OPEN_CONNECTION_FAIL, ex.Message, commandText);
                }

                try
                {
                    using (var comm = new OracleCommand(commandText, conn))
                    {
                        var adap = new OracleDataAdapter(comm);
                        var ds   = new DataSet();
                        comm.CommandType = CommandType.StoredProcedure;
                        AssignParameters(comm, session, values);

                        adap.Fill(ds);
                        if (
                            comm.Parameters.Contains(CONSTANTS.ORACLE_EXCEPTION_PARAMETER_NAME) &&
                            comm.Parameters[CONSTANTS.ORACLE_EXCEPTION_PARAMETER_NAME].Value != DBNull.Value
                            )
                        {
                            var errCode = int.Parse(comm.Parameters[CONSTANTS.ORACLE_EXCEPTION_PARAMETER_NAME].Value.ToString());
                            if (errCode != 0)
                            {
                                throw ErrorUtils.CreateError(errCode, commandText, values);
                            }
                        }
                        resultTable = ds.Tables[0];
                        var _secid = comm.Parameters[CONSTANTS.ORACLE_OUT_PARAMETER_SECID].Value.ToString();
                        SecID = null;
                        if (!string.IsNullOrEmpty(_secid))
                        {
                            SecID = _secid;
                        }
                    }
                }
                catch (OracleException ex)
                {
                    throw ThrowOracleUserException(ex, commandText);
                }
                catch (FaultException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    throw ErrorUtils.CreateErrorWithSubMessage(
                              ERR_SQL.ERR_SQL_EXECUTE_COMMAND_FAIL, ex.Message, commandText);
                }
                finally
                {
                    conn.Close();
                }
            }
        }
Beispiel #21
0
        public static DataTable ExecuteStoreProcedurePostgreSQLToDataTable(string connectionString, string commandText, params object[] values)
        {
            commandText = SchemaStatic + "." + commandText;
            using (var conn = new NpgsqlConnection(connectionString))
            {
                try
                {
                    conn.Open();
                }
                catch (Exception ex)
                {
                    throw ErrorUtils.CreateErrorWithSubMessage(
                              ERR_SQL.ERR_SQL_OPEN_CONNECTION_FAIL, ex.Message, commandText);
                }
                var comm = new NpgsqlCommand(commandText, conn);
                NpgsqlTransaction tran = conn.BeginTransaction();
                try
                {
                    comm.CommandType = CommandType.StoredProcedure;
                    AssignParameters(comm, values);
                    if (comm.Parameters.Count() > 0)
                    {
                        var checkRefcursor = comm.Parameters.Where(x => x.NpgsqlDbType == NpgsqlTypes.NpgsqlDbType.Refcursor);
                        if (checkRefcursor != null)
                        {
                            if (checkRefcursor.Count() > 0)
                            {
                                var execute = comm.ExecuteNonQuery();
                                comm.CommandText = String.Format("fetch all in \"{0}\"", checkRefcursor.First().ParameterName);
                                comm.CommandType = CommandType.Text;
                            }
                        }
                    }

                    using (var dr = comm.ExecuteReader())
                    {
                        if (comm.Parameters.Contains(CONSTANTS.ORACLE_EXCEPTION_PARAMETER_NAME) && comm.Parameters[CONSTANTS.ORACLE_EXCEPTION_PARAMETER_NAME].Value != DBNull.Value)
                        {
                            var errCode = int.Parse(comm.Parameters[CONSTANTS.ORACLE_EXCEPTION_PARAMETER_NAME].Value.ToString());
                            if (errCode != 0)
                            {
                                throw ErrorUtils.CreateError(errCode, commandText, values);
                            }
                        }
                        return(dr.ToDataTable());
                    }
                }
                catch (NpgsqlException ex)
                {
                    tran.Rollback();
                    throw ThrowSqlUserException(ex, commandText);
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    throw ErrorUtils.CreateErrorWithSubMessage(ERR_SQL.ERR_SQL_EXECUTE_COMMAND_FAIL, ex.Message, commandText);
                }
                finally
                {
                    tran.Commit();
                    conn.Close();
                }
            }
        }
Beispiel #22
0
        private static void AssignParameters(NpgsqlCommand comm, params object[] values)
        {
            try
            {
                DiscoveryParameters(comm);
                // assign value
                var index = 0;
                for (int i = 0; i < comm.Parameters.Count(); i++)// NpgsqlParameter param in comm.Parameters)
                {
                    var param = comm.Parameters[i];
                    if (param.Direction == ParameterDirection.Input && param.NpgsqlDbType != NpgsqlTypes.NpgsqlDbType.Refcursor /* || param.Direction == ParameterDirection.InputOutput*/)
                    {
                        if (values.Length == 0)
                        {
                            continue;
                        }
                        if (values[index] == null || (values[index] is string && (string)values[index] == string.Empty))
                        {
                            param.Value = DBNull.Value;
                        }
                        else
                        {
                            switch (param.DbType)
                            {
                            case DbType.Date:
                                param.Value = Convert.ToDateTime(values[index]);
                                break;

                            case DbType.Boolean:
                                if (values[index].ToString() == "1" || values[index].ToString() == "0")
                                {
                                    param.Value = values[index].ToString() == "1" ? true : false;
                                }
                                else
                                {
                                    param.Value = Convert.ToBoolean(values[index]);
                                }

                                break;

                            case DbType.Byte:
                                param.Value = Convert.ToByte(values[index]);
                                break;

                            case DbType.Int16:
                            case DbType.Int32:
                            case DbType.Int64:
                            case DbType.Single:
                            case DbType.Double:
                            case DbType.Decimal:
                                param.Value = Convert.ToDecimal(values[index]);
                                break;

                            default:
                                var parameter1 = comm.CreateParameter();
                                parameter1.ParameterName = param.ParameterName;
                                parameter1.NpgsqlDbType  = NpgsqlDbType.Text;
                                parameter1.Value         = values[index];
                                param = parameter1;
                                comm.Parameters[i] = parameter1;
                                break;
                            }
                        }
                        index++;
                    }
                    else if (param.NpgsqlDbType == NpgsqlTypes.NpgsqlDbType.Refcursor)
                    {
                        NpgsqlParameter rf = new NpgsqlParameter(param.ParameterName, NpgsqlTypes.NpgsqlDbType.Refcursor);
                        param              = rf;
                        param.Value        = param.ParameterName;//"ref1";
                        comm.Parameters[i] = param;
                        //index++;
                    }
                }
            }

            catch (Exception ex)
            {
                throw ErrorUtils.CreateErrorWithSubMessage(
                          ERR_SQL.ERR_SQL_ASSIGN_PARAMS_FAIL, ex.Message,
                          comm.CommandText, values);
            }
        }
Beispiel #23
0
        private static void AssignParameters(OracleCommand comm, Session session, params object[] values)
        {
            try
            {
                DiscoveryParameters(comm);
                // assign value
                var index = 0;
                foreach (OracleParameter param in comm.Parameters)
                {
                    if (param.ParameterName == CONSTANTS.ORACLE_SESSION_USER)
                    {
                        param.Value = session.Username;
                    }
                    else if (param.ParameterName == CONSTANTS.ORACLE_SESSIONKEY)
                    {
                        param.Value = session.SessionKey;
                    }
                    else if (param.OracleDbType == OracleDbType.RefCursor)
                    {
                        param.Direction = ParameterDirection.Output;
                    }
                    else if (param.Direction == ParameterDirection.Input || param.Direction == ParameterDirection.InputOutput)
                    {
                        if (values[index] == null || (values[index] is string && (string)values[index] == string.Empty))
                        {
                            param.Value = DBNull.Value;
                        }
                        else if (param.OracleDbType == OracleDbType.NClob)
                        {
                            var lob    = new OracleClob(comm.Connection);
                            var buffer = Encoding.Unicode.GetBytes(values[index].ToString());
                            lob.Write(buffer, 0, buffer.Length);

                            param.Value = lob;
                        }
                        else
                        {
                            switch (param.OracleDbType)
                            {
                            case OracleDbType.Date:
                                param.Value = Convert.ToDateTime(values[index], App.Environment.ServerInfo.Culture);
                                break;

                            case OracleDbType.Byte:
                            case OracleDbType.Int16:
                            case OracleDbType.Int32:
                            case OracleDbType.Int64:
                            case OracleDbType.Single:
                            case OracleDbType.Double:
                            case OracleDbType.Decimal:
                                param.Value = Convert.ToDecimal(values[index], App.Environment.ServerInfo.Culture);
                                break;

                            default:
                                param.Value = values[index];
                                break;
                            }
                        }
                        index++;
                    }
                }
            }
            catch (FaultException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw ErrorUtils.CreateErrorWithSubMessage(
                          ERR_SQL.ERR_SQL_ASSIGN_PARAMS_FAIL, ex.Message,
                          comm.CommandText, values);
            }
        }
Beispiel #24
0
        public DataTable LoadDataTable(string connectionString, string commandText, List <NpgsqlParameter> parameters)
        {
            if (commandText.IndexOf("{0}") > 0)
            {
                commandText = string.Format(commandText, Schema);
            }
            using (var conn = new NpgsqlConnection(connectionString))
            {
                try
                {
                    conn.Open();
                }
                catch (Exception ex)
                {
                    throw ErrorUtils.CreateErrorWithSubMessage(
                              ERR_SQL.ERR_SQL_OPEN_CONNECTION_FAIL, ex.Message, commandText);
                }
                var comm = new NpgsqlCommand(commandText, conn);
                NpgsqlTransaction tran = conn.BeginTransaction();
                try
                {
                    comm.CommandType = CommandType.StoredProcedure;
                    if (parameters != null)
                    {
                        foreach (var item in parameters)
                        {
                            comm.Parameters.Add((NpgsqlParameter)((ICloneable)item).Clone());
                        }
                    }

                    if (comm.Parameters.Count() > 0)
                    {
                        var checkRefcursor = comm.Parameters.Where(x => x.NpgsqlDbType == NpgsqlTypes.NpgsqlDbType.Refcursor);
                        if (checkRefcursor != null)
                        {
                            if (checkRefcursor.Count() > 0)
                            {
                                if (checkRefcursor.First().Value == null)
                                {
                                    checkRefcursor.First().Value = checkRefcursor.First().ParameterName;
                                }
                                var execute = comm.ExecuteNonQuery();
                                comm.CommandText = String.Format("fetch all in \"{0}\"", checkRefcursor.First().ParameterName);
                                comm.CommandType = CommandType.Text;
                            }
                        }
                    }

                    using (var dr = comm.ExecuteReader())
                    {
                        var dataTable = new DataTable();
                        dataTable.Load(dr);
                        return(dataTable);
                    }
                }
                catch (NpgsqlException ex)
                {
                    tran.Rollback();
                    throw ThrowSqlUserException(ex, commandText);
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    throw ErrorUtils.CreateErrorWithSubMessage(ERR_SQL.ERR_SQL_EXECUTE_COMMAND_FAIL, ex.Message, commandText);
                }
                finally
                {
                    tran.Commit();
                    conn.Close();
                }
            }
        }
Beispiel #25
0
        //#endif
        private void _ExecuteModule(string moduleID)
        {
            try
            {
                //#if DEBUG
                if (moduleID == "ADVANCE=ON")
                {
                    IsAdvanceDeveloperMode = true;
                    return;
                }
                if (moduleID == "ADVANCE=OFF")
                {
                    IsAdvanceDeveloperMode = false;
                    return;
                }
                if (moduleID.StartsWith("!"))
                {
                    moduleID = moduleID.Substring(1);
                    ForceLoad(moduleID);
                }

                if (moduleID.StartsWith("M?"))
                {
                    var module = CreateModuleInstance(STATICMODULE.MODULE_CONFIG, "MMN");
                    module.SetFieldValue("MODID", moduleID.Substring(2));
                    module.ShowModule(m_mainForm);
                    module.Execute();
                }
                else if (moduleID.StartsWith("CD?"))
                {
                    var module = CreateModuleInstance("03902", "MMN");
                    module.SetFieldValue("MODID", moduleID.Substring(3));
                    module.ShowModule(m_mainForm);
                    module.Execute();
                }
                else if (moduleID.StartsWith("SG?"))
                {
                    var module = CreateModuleInstance("03903", "MMN");
                    module.SetFieldValue("MODID", moduleID.Substring(3));
                    module.ShowModule(m_mainForm);
                    module.Execute();
                }
                else if (moduleID.StartsWith("CL?"))
                {
                    var module = CreateModuleInstance("03904", "MMN");
                    module.SetFieldValue("MODID", moduleID.Substring(3));
                    module.ShowModule(m_mainForm);
                    module.Execute();
                }
                else if (moduleID.StartsWith("CM?"))
                {
                    var module = CreateModuleInstance("03905", "MMN");
                    module.SetFieldValue("MODID", moduleID.Substring(3));
                    module.ShowModule(m_mainForm);
                    module.Execute();
                }
                else if (moduleID.StartsWith("PR?"))
                {
                    var module = CreateModuleInstance("03906", "MMN");
                    module.SetFieldValue("MODID", moduleID.Substring(3));
                    module.ShowModule(m_mainForm);
                    module.Execute();
                }
                else
                {
                    var module = CreateModuleInstance(moduleID);
                    module.ShowModule(m_mainForm);
                }
                //#else
                //                var module = CreateModuleInstance(moduleID);
                //                module.ShowModule(m_mainForm);
                //#endif
            }
            catch (FaultException ex)
            {
                frmInfo.ShowError(((IMain)m_mainForm).Language.ApplicationTitle, ex, m_mainForm);
            }
            catch (Exception ex)
            {
                frmInfo.ShowError(((IMain)m_mainForm).Language.ApplicationTitle, ErrorUtils.CreateErrorWithSubMessage(ERR_SYSTEM.ERR_SYSTEM_UNKNOWN, ex.Message), m_mainForm);
            }
        }
Beispiel #26
0
        public static List <T> ExecuteStoreProcedureGeneric <T>(string connectionString, Session session, string commandText, params object[] values)
        {
            using (var conn = new SqlConnection(connectionString))
            {
                try
                {
                    conn.Open();
                }
                catch (Exception ex)
                {
                    throw ErrorUtils.CreateErrorWithSubMessage(
                              ERR_SQL.ERR_SQL_OPEN_CONNECTION_FAIL, ex.Message,
                              commandText, values);
                }

                try
                {
                    var comm = new SqlCommand(commandText, conn)
                    {
                        CommandType = CommandType.StoredProcedure
                    };
                    AssignParameters(comm, session, values);

                    using (var dr = comm.ExecuteReader())
                    {
                        if (
                            comm.Parameters.Contains(CONSTANTS.ORACLE_EXCEPTION_PARAMETER_NAME) &&
                            comm.Parameters[CONSTANTS.ORACLE_EXCEPTION_PARAMETER_NAME].Value != DBNull.Value
                            )
                        {
                            var errCode = int.Parse(comm.Parameters[CONSTANTS.ORACLE_EXCEPTION_PARAMETER_NAME].Value.ToString());
                            if (errCode != 0)
                            {
                                throw ErrorUtils.CreateError(errCode, commandText, values);
                            }
                        }
                        var list = new List <T>();
                        while (dr.Read())
                        {
                            list.Add((T)Convert.ChangeType(dr.GetValue(0), typeof(T)));
                        }
                        return(list);
                    }
                }
                catch (SqlException ex)
                {
                    throw ThrowSqlUserException(ex, commandText);
                }
                catch (FaultException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    throw ErrorUtils.CreateErrorWithSubMessage(
                              ERR_SQL.ERR_SQL_EXECUTE_COMMAND_FAIL, ex.Message,
                              commandText, values);
                }
                finally
                {
                    conn.Close();
                }
            }
        }
Beispiel #27
0
        public void StartupModules()
        {
            if (App.Environment.ClientInfo.SessionKey != null)
            {
                ThemeUtils.ChangeSkin(App.Environment.ClientInfo.UserProfile.ApplicationSkinName);

                foreach (var module in AllCaches.ModulesInfo)
                {
                    if (module.StartMode == CODES.DEFMOD.STARTMODE.AUTOMATIC)
                    {
                        try
                        {
                            using (var ctrlSA = new SAController())
                            {
                                ctrlSA.CheckRole(module);
                                var startupModule = CreateModuleInstance(module.ModuleID, module.SubModule);
                                startupModule.ShowModule(m_mainForm);
                            }
                        }
                        catch (FaultException ex)
                        {
                            if (ex.Code.Name != ERR_SYSTEM.ERR_SYSTEM_MODULE_NOT_ALLOW_ACCESS.ToString())
                            {
                                frmInfo.ShowError(((IMain)m_mainForm).Language.ApplicationTitle, ex, m_mainForm);
                            }
                        }
                        catch (Exception ex)
                        {
                            frmInfo.ShowError(((IMain)m_mainForm).Language.ApplicationTitle, ErrorUtils.CreateErrorWithSubMessage(ERR_SYSTEM.ERR_SYSTEM_UNKNOWN, ex.Message), m_mainForm);
                        }
                    }
                }
            }
        }
Beispiel #28
0
        public void ExecuteReadFile(WorkerThread worker)
        {
            try
            {
                Parent.LockUserAction();
                try
                {
                    ExcelBufferTable = new DataTable();

                    var workbook = new Workbook();
                    workbook.Open(FileName);
                    var worksheet = workbook.Worksheets[0];

                    var rowLength = worksheet.Cells.MaxRow + 1;
                    var colLength = worksheet.Cells.MaxColumn + 1;

                    var befcol = 'A' - 1;
                    var col    = 'A';
                    for (var i = 0; i < colLength; i++)
                    {
                        if (col > 'Z')
                        {
                            col = 'A';
                            befcol++;
                        }

                        if (befcol == 'A' - 1)
                        {
                            ExcelBufferTable.Columns.Add(new DataColumn(string.Format("{0}", char.ConvertFromUtf32(col)), typeof(object)));
                        }
                        else
                        {
                            ExcelBufferTable.Columns.Add(new DataColumn(string.Format("{0}{1}", char.ConvertFromUtf32(befcol), char.ConvertFromUtf32(col)), typeof(object)));
                        }

                        col++;
                    }

                    ImportComboBoxItems =
                        (from DataColumn column in ExcelBufferTable.Columns
                         select new ImageComboBoxItem
                    {
                        ImageIndex = ThemeUtils.GetImage16x16Index("COLUMN"),
                        Value = column.ColumnName,
                        Description = column.ColumnName
                    }).ToArray();

                    for (var i = 0; i < rowLength; i++)
                    {
                        var row = ExcelBufferTable.NewRow();
                        ExcelBufferTable.Rows.Add(row);

                        for (var j = 0; j < colLength; j++)
                        {
                            row[j] = worksheet.Cells[i, j].Value;
                        }


                        PercentComplete = i * 100.0f / rowLength;
                        if (worksheet.Cells[i, 1].Value != null)
                        {
                            StatusText = worksheet.Cells[i, 1].Value.ToString();
                        }
                        ExecuteUpdateGUI();
                    }

                    ExcelBufferTable.Columns.Add(new DataColumn("COLUMN_ERROR", typeof(string))
                    {
                        Caption = Parent.Language.GetLabelText("COLUMN_ERROR")
                    });

                    PercentComplete = 100;
                    ExecuteUpdateGUI(true);
                }
                catch (IOException ex)
                {
                    ExcelBufferTable = null;
                    throw ErrorUtils.CreateErrorWithSubMessage(ERR_IMPORT.ERR_FILE_OPEN_ERROR, ex.Message);
                }
                catch (Exception ex)
                {
                    ExcelBufferTable = null;
                    throw ErrorUtils.CreateErrorWithSubMessage(ERR_SYSTEM.ERR_SYSTEM_UNKNOWN, ex.Message);
                }
            }
            catch (Exception ex)
            {
                Parent.ShowError(ex);
            }
            finally
            {
                Parent.UnLockUserAction();
            }
        }
        public void ExecuteImport(WorkerThread worker)
        {
            try
            {
                Parent.LockUserAction();

                ErrorInfos = new Dictionary <DataRow, string>();
                int count = 0, total = ImportRows.Count;

                try
                {
                    if (total != 0)
                    {
                        foreach (var importRow in ImportRows)
                        {
                            try
                            {
                                using (var ctrlSA = new SAController())
                                {
                                    List <string> values;
                                    Parent.GetOracleParameterValues(out values, ImportInfo.ImportStore, importRow);
                                    ctrlSA.ExecuteImport(ImportInfo.ModuleID, ImportInfo.SubModule, values);

                                    //add by trungtt - 20130508 - verify data before import
                                    //List<string> valuesVerify;
                                    //if(Program.blVerifyImport == true)
                                    //{
                                    //    Parent.GetOracleParameterValues(out valuesVerify,ImportInfo.VerifyStore);
                                    //    ctrlSA.ExecuteStoreProcedure(ImportInfo.VerifyStore, valuesVerify);
                                    //}
                                    //end trungtt

                                    StatusText = values[1].ToString();
                                    ExecuteUpdateGUI();
                                }
                            }
                            catch (FaultException ex)
                            {
                                ErrorInfos[importRow]  = string.Format("{0}\r\n{1}", ex.ToMessage(), ex.Reason);
                                Program.blEnableImport = false;
                            }
                            catch (Exception cex)
                            {
                                var ex = ErrorUtils.CreateErrorWithSubMessage(ERR_SYSTEM.ERR_SYSTEM_UNKNOWN, cex.Message);
                                ErrorInfos[importRow]  = string.Format("{0}\r\n{1}", ex.ToMessage(), ex.Reason);
                                Program.blEnableImport = false;
                            }
                            finally
                            {
                                PercentComplete = count++ *100.0f / total;
                                ExecuteUpdateGUI();
                            }
                        }
                    }
                }
                catch (FaultException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    throw ErrorUtils.CreateErrorWithSubMessage(ERR_SYSTEM.ERR_SYSTEM_UNKNOWN, ex.Message);
                }
            }
            catch (Exception ex)
            {
                Parent.ShowError(ex);
            }
            finally
            {
                Parent.UnLockUserAction();
                PercentComplete = 100.0f;
                ExecuteUpdateGUI(true);
            }
        }