Exemplo n.º 1
0
        public static async Task <string> HttpGet(string url)
        {
            var result = "";

            try
            {
                using (HttpClient client = new HttpClient())
                {
                    client.DefaultRequestHeaders.Clear();
                    client.DefaultRequestHeaders.Add("Authorization", "Basic aGVsbGRlbW9uczpfUEBzc3cwcmRz");
                    using (HttpResponseMessage response = await client.GetAsync(url))
                        using (HttpContent content = response.Content)
                        {
                            result = MessageEngine.GetHTTPStatusCodes(response.StatusCode.ToString(), ConfigEngine.Language);
                            if (string.IsNullOrEmpty(result))
                            {
                                result = await content.ReadAsStringAsync();
                            }
                        }
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException.Message.ToLower().Contains("unable to connect to the remote server"))
                {
                    logger.Error(ex);
                }
                logger.Error(ex);
                result = MessageEngine.GetHTTPStatusCodes("InternalServerError", ConfigEngine.Language);
            }

            return(result);
        }
Exemplo n.º 2
0
        public static void ShowMessage(string message, MessageType type, bool is_code = false)
        {
            string         title = "";
            MessageBoxIcon icon  = MessageBoxIcon.Error;

            if (is_code)
            {
                message = LanguageEngine.GetMessageCaption(message, ConfigEngine.Language);
            }
            switch (type)
            {
            case MessageType.Error:
                title = "ERROR_TITLE_CAPTION";
                icon  = MessageBoxIcon.Error;
                break;

            case MessageType.Success:
                title = "MESSAGE_TITLE_CAPTION";
                icon  = MessageBoxIcon.Information;
                break;

            case MessageType.Warning:
                title = "ERROR_SYSTEM_TITLE_CAPTION";
                icon  = MessageBoxIcon.Warning;
                break;
            }
            title = LanguageEngine.GetMessageCaption(title, ConfigEngine.Language);
            if (type == 0)
            {
                logger.Error(message);
            }
            XtraMessageBox.Show(message, title, MessageBoxButtons.OK, icon);
        }
Exemplo n.º 3
0
        public static string GetBaseUrl(bool is_service = true)
        {
            string result = "";

            try
            {
                if (!string.IsNullOrEmpty(ConfigEngine.PortNumber))
                {
                    result = ConfigEngine.Domain + ":" + ConfigEngine.PortNumber;
                }
                else
                {
                    result = ConfigEngine.Domain;
                }

                result += "/";
                if (is_service)
                {
                    result += ConfigEngine.ServiceName;
                }

                return(result);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }

            return("");
        }
Exemplo n.º 4
0
        public static DataTable ConvertObjectListToDataTable <T>(IEnumerable <T> list)
        {
            try
            {
                DataTable      dtResult = new DataTable();
                PropertyInfo[] oProps   = null;

                if (list == null)
                {
                    return(null);
                }

                foreach (T item in list)
                {
                    if (oProps == null)
                    {
                        oProps = ((Type)item.GetType()).GetProperties();
                        foreach (PropertyInfo oProp in oProps)
                        {
                            Type colType = oProp.PropertyType;
                            if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition() == typeof(Nullable <>)))
                            {
                                colType = colType.GetGenericArguments()[0];
                            }

                            dtResult.Columns.Add(new DataColumn(oProp.Name, colType));
                        }
                    }

                    DataRow dr = dtResult.NewRow();
                    foreach (PropertyInfo oProp in oProps)
                    {
                        var value = oProp.GetValue(item, null);
                        dr[oProp.Name] = value == null ? DBNull.Value : value;
                    }
                    dtResult.Rows.Add(dr);
                }

                return(dtResult);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                return(null);
            }
        }
Exemplo n.º 5
0
 public void OpenConnection()
 {
     try
     {
         if (mConn != null)
         {
             if (mConn.State != ConnectionState.Open)
             {
                 mConn.Open();
             }
         }
     }
     catch (Exception ex)
     {
         logger.Error(ex);
         return;
     }
 }
Exemplo n.º 6
0
        //protected Helper.Configuration mConfig;
        #endregion

        public SQLDatabase()
        {
            logger            = new LogEngine();
            mConnectionString = GetConnectionString();
            try
            {
                mConn = new SqlConnection(mConnectionString);
            }
            catch (Exception ex)
            {
                logger.Error(@"Can't create new sql database engine because " + ex.Message);
            }
        }
Exemplo n.º 7
0
        //protected Helper.Configuration mConfig;
        #endregion

        public SQLDatabase()
        {
            logger = new LogEngine();
            mConnectionString = GetConnectionString();
            try
            {
                mConn = new SqlConnection(mConnectionString);
            }
            catch (Exception ex)
            {
                logger.Error(@"Can't create new sql database engine because " + ex.Message);
            }
        }
Exemplo n.º 8
0
        public string InsertActionLog(SYS_tblActionLogDTO log)
        {
            string result = "";

            try
            {
                result = db.sExecuteSQL("SYS_spfrmActionLog", new string[] { "Activity", "Username", "LanguageID", "FullName", "ComputerName", "AccountWindows", "ActionVN", "ActionEN", "ActionTime", "FunctionID", "FunctionNameVN", "FunctionNameEN", "IPLAN", "IPWAN", "MacAddress", "DescriptionVN", "DescriptionEN" }, new object[] { log.Activity, log.UserID, log.LanguageID, log.FullName, log.ComputerName, log.AccountWindows, log.ActionVN, log.ActionEN, DateTime.Now, log.FunctionID, log.FunctionNameVN, log.FunctionNameEN, log.IPLAN, log.IPWAN, log.MacAddress, log.DescriptionVN, log.DescriptionEN });

                if (!string.IsNullOrEmpty(result))
                {
                    logger.Error(result);
                }

                return(result);
            }
            catch (Exception ex)
            {
                result = ex.Message;
                logger.Error(ex);
            }

            return(result);
        }
Exemplo n.º 9
0
        public async static Task <bool> CheckValidImportTemplate(string username, string language_id, string store_procedure, string file_name, string module_id, string function_id, string file_path)
        {
            bool result = false;

            Excel.Application App   = null;
            Excel.Workbook    Book  = null;
            Excel.Worksheet   Sheet = null;
            Excel.Range       Range = null;

            object Missing = System.Reflection.Missing.Value;

            try
            {
                SYS_tblImportFileConfigDRO tmpItem = await iPOS.BUS.Systems.SYS_tblImportFileConfigBUS.CheckValidImportTemplate(username, language_id, store_procedure, file_name, module_id, function_id);

                if (tmpItem != null && (tmpItem.ImportFileConfigItem != null && tmpItem.ImportFileConfigItem.ImportFileConfigID.ToString() != "0"))
                {
                    result = true;
                }
                else
                {
                    App   = new Excel.Application();
                    Book  = App.Workbooks.Open(file_path);
                    Sheet = (Excel.Worksheet)Book.Worksheets[1];
                    Range = Sheet.UsedRange;
                    int colCount = Range.Columns.Count;
                    int rowCount = Range.Rows.Count;

                    List <iPOS.DTO.Tools.OBJ_TableColumnDTO> objList = await iPOS.BUS.Tools.OBJ_TableColumnBUS.GetTableColumnList(username, store_procedure);

                    if (objList != null && objList.Count > 0)
                    {
                        int count = 0;
                        for (int i = 1; i <= colCount; i++)
                        {
                            if (string.IsNullOrEmpty(Sheet.Cells[2, i].Value + ""))
                            {
                                break;
                            }
                            string tmp = Sheet.Cells[2, i].Value.ToString().ToLower().Trim();
                            if (string.IsNullOrEmpty(tmp))
                            {
                                break;
                            }
                            if (tmp != "stt" && tmp != "seq" && tmp != "$hidecolumn$" && tmp != "$deletecolumn$")
                            {
                                tmp = "@" + tmp;
                                var objs = (from obj in objList
                                            where obj.ColumnName.ToLower().Equals(tmp.ToLower())
                                            select obj).ToList();
                                if (objs.Count == 0)
                                {
                                    count++;
                                }
                            }
                        }
                        //result = count < 3;
                        result = count == 0;    //!= 0 is different all
                    }
                    else
                    {
                        result = false;
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                return(false);
            }
            finally
            {
                if (App != null)
                {
                    App.Quit();
                }
                GC.Collect();
                if (Range != null)
                {
                    Marshal.FinalReleaseComObject(Range);
                }
                if (Sheet != null)
                {
                    Marshal.FinalReleaseComObject(Sheet);
                }
                if (Book != null)
                {
                    //Book.Close(true, Missing, Missing);
                    Marshal.FinalReleaseComObject(Book);
                }
                if (App != null)
                {
                    Marshal.FinalReleaseComObject(App);
                }
            }

            return(result);
        }