Esempio n. 1
0
        public static ResultBOL <object> ExecuteScalar(string query, Hashtable hashTable)
        {
            string tag = _tag + "[ExcuteScalar]";

            try
            {
                SqlConnection conn = new SqlConnection(ConnectionString());
                SqlCommand    cmd  = CreateSqlCommandQuery(conn, query, hashTable);

                conn.Open();

                object result = cmd.ExecuteScalar();

                cmd.Dispose();
                conn.Close();

                return(new ResultBOL <object>()
                {
                    Code = 0,
                    Data = result
                });
            }
            catch (Exception ex)
            {
                LogHelpers.WriteError(tag, ex.ToString());

                return(new ResultBOL <object>()
                {
                    Code = ex.HResult,
                    ErrorMessage = ex.Message,
                    Data = null
                });
            }
        }
Esempio n. 2
0
        public static string GetErrorMessage(string key)
        {
            string tag = "[Utilities][GetErrorMessage]";

            try
            {
                string  path = HttpContext.Current.Server.MapPath("~/XML/ErrorMessage.xml");
                DataSet ds   = new DataSet();
                ds.ReadXml(path);

                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    if (row["Key"].ToString() == key)
                    {
                        return(row["Value"].ToString());
                    }
                }

                return(string.Empty);
            }
            catch (Exception ex)
            {
                LogHelpers.WriteError(tag, ex.ToString());
                return(ex.Message);
            }
        }
Esempio n. 3
0
        public static ResultBOL <DataSet> ExecuteQuery(string query, Hashtable hashTable)
        {
            string tag = _tag + "[ExecuteQuery]";

            try
            {
                SqlConnection conn = new SqlConnection(ConnectionString());
                SqlCommand    cmd  = CreateSqlCommandQuery(conn, query, hashTable);
                conn.Open();

                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataSet        ds = new DataSet();
                da.Fill(ds);

                cmd.Dispose();
                conn.Close();

                return(new ResultBOL <DataSet>()
                {
                    Code = 0,
                    Data = ds
                });
            }
            catch (Exception ex)
            {
                LogHelpers.WriteError(tag, ex.ToString());

                return(new ResultBOL <DataSet>()
                {
                    Code = ex.HResult,
                    ErrorMessage = ex.Message,
                    Data = null
                });
            }
        }
Esempio n. 4
0
        private static string SaveFileToServer(string url, string dir)
        {
            string tag = "[Utilities][SaveFileToServer]";

            try
            {
                string ext      = Path.GetExtension(url);
                string fileName = string.Format("{0}{1}", DateTime.Now.ToString("MMddyyyy-HHmmssfff"), ext);
                //---
                string dirServer = HttpContext.Current.Server.MapPath(dir);
                if (!Directory.Exists(dirServer))
                {
                    Directory.CreateDirectory(dirServer);
                }

                string fullPath = Path.Combine(dirServer, fileName);

                WebClient wc = new WebClient();
                wc.DownloadFile(new Uri(url), fullPath);

                return(Path.Combine(dir, fileName));
            }
            catch (Exception ex)
            {
                LogHelpers.WriteError(tag, ex.ToString());
                return(string.Empty);
            }
        }
Esempio n. 5
0
        public static string GetSortImageUrl(string key)
        {
            string tag = "[Utilities][GetSortImageUrl]";

            try
            {
                string      path   = HttpContext.Current.Server.MapPath("~/XML/GridView.xml");
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(path);

                var node = xmlDoc.SelectSingleNode(string.Format("Resources/{0}", key));
                if (node == null)
                {
                    return(string.Empty);
                }

                return(node.InnerText);
            }
            catch (Exception ex)
            {
                LogHelpers.WriteError(tag, ex.ToString());

                return(string.Empty);
            }
        }
Esempio n. 6
0
        public static RedirectUrlBOL GetRedirectUrlObject(string name)
        {
            string tag = "[Utilities][GetRedirectUrlObject]";

            try
            {
                string  path = HttpContext.Current.Server.MapPath("~/XML/MenuRedirectUrl.xml");
                DataSet ds   = new DataSet();
                ds.ReadXml(path);

                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    if (row["Name"].ToString() == name)
                    {
                        return(new RedirectUrlBOL(row));
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelpers.WriteError(tag, ex.ToString());
            }

            return(new RedirectUrlBOL()
            {
                Id = 0,
                Value = "~/Default.aspx"
            });
        }
Esempio n. 7
0
 public static void SaveLoggedInfo(UserBOL user)
 {
     try
     {
         var session = HttpContext.Current.Session;
         session["LoggedId"]       = user.Id;
         session["LoggedUsername"] = user.Username;
     }
     catch (Exception ex)
     {
         LogHelpers.WriteError("[Utilities][SaveLoggedInfo] Exception: " + ex.ToString());
     }
 }
Esempio n. 8
0
        private static string ConnectionString()
        {
            string tag = _tag + "[ConnectionString]";

            try
            {
                string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

                return(connectionString);
            }
            catch (Exception ex)
            {
                LogHelpers.WriteError(tag, ex.ToString());
                return(string.Empty);
            }
        }
Esempio n. 9
0
        public static string CreateMapPath(string dir, string file)
        {
            string tag = "[Utilities][CreateMapPath]";

            try
            {
                string result = HttpContext.Current.Server.MapPath(Path.Combine(dir, file));

                return(result);
            }
            catch (Exception ex)
            {
                LogHelpers.WriteError(string.Format("{0}  -  Directory: {1} - File: {2}", tag, dir, file), ex.ToString());

                return(string.Empty);
            }
        }
Esempio n. 10
0
        public static ResultBOL <DataSet> ExecuteStoredReturnDataSet(string stored, Object obj)
        {
            string tag = _tag + "[ExecuteStoredReturnDataSet]";

            try
            {
                SqlConnection conn = new SqlConnection(ConnectionString());
                SqlCommand    cmd  = CreateSqlCommandStored(conn, stored, Utilities.GetParameters(obj));

                SqlParameter dbReturn = cmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int);
                dbReturn.Direction = ParameterDirection.ReturnValue;

                conn.Open();

                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataSet        ds = new DataSet();
                da.Fill(ds);

                cmd.Dispose();
                conn.Close();

                return(new ResultBOL <DataSet>()
                {
                    Code = 0,
                    DbReturnValue = (int)dbReturn.Value,
                    Data = ds
                });
            }
            catch (Exception ex)
            {
                LogHelpers.WriteError(tag, ex.ToString());

                return(new ResultBOL <DataSet>()
                {
                    Code = ex.HResult,
                    ErrorMessage = ex.Message,
                    Data = null
                });
            }
        }
Esempio n. 11
0
        public static string ReplaceImageUri(string html, string imageDir)
        {
            string tag = "[Utilities][ReplaceImageUri]";

            try
            {
                HtmlDocument htmlDoc = new HtmlDocument();
                htmlDoc.OptionAutoCloseOnEnd = true;
                htmlDoc.LoadHtml(html);

                foreach (HtmlNode node in htmlDoc.DocumentNode.SelectNodes("//img[@src]"))
                {
                    var src = node.Attributes["src"].Value.Split('?')[0];
                    if (!src.Contains("://"))
                    {
                        continue;
                    }

                    //var width = node.Attributes["width"].Value.Replace("px", "");
                    //var height = node.Attributes["height"].Value.Replace("px", "");

                    src = SaveFileToServer(src, imageDir);
                    node.SetAttributeValue("src", src);

                    //node.SetAttributeValue("src", string.Format(
                    //    "{0}?width={1}&height={2}",
                    //    src,
                    //    width == null ? "auto" : width,
                    //    height == null ? "auto" : height));
                }

                return(htmlDoc.DocumentNode.OuterHtml);
            }
            catch (Exception ex)
            {
                LogHelpers.WriteError(tag, ex.ToString());
                return(html);
            }
        }
Esempio n. 12
0
        private static SqlCommand CreateSqlCommandStored(SqlConnection conn, string stored, Hashtable hashTable)
        {
            string tag = _tag + "[CreateSqlCommandStored]";

            try
            {
                SqlCommand cmd = new SqlCommand(stored, conn);
                cmd.CommandType    = CommandType.StoredProcedure;
                cmd.CommandTimeout = _commandTimeout;

                if (hashTable == null || hashTable.Count == 0)
                {
                    return(cmd);
                }

                foreach (DictionaryEntry entry in hashTable)
                {
                    if (entry.Key == null || string.IsNullOrEmpty(entry.Key.ToString()))
                    {
                        continue;
                    }

                    string key   = "@" + entry.Key.ToString();
                    object value = entry.Value == null ? DBNull.Value : entry.Value;

                    SqlParameter para = new SqlParameter(key, value);
                    cmd.Parameters.Add(para);
                }

                return(cmd);
            }
            catch (Exception ex)
            {
                LogHelpers.WriteError(tag, ex.ToString());

                return(null);
            }
        }
Esempio n. 13
0
        private void StartUpdateSiteVisitors()
        {
            string tag = __tag + "[StartUpdateSiteVisitors]";

            LogHelpers.WriteStatus(tag, "Start...");

            try
            {
                var result = SiteVisitorsDAL.UpdateSiteVisitors();
                if (result.Code < 0)
                {
                    LogHelpers.WriteError(tag, result.ErrorMessage);
                }
            }
            catch (Exception ex)
            {
                LogHelpers.WriteException(tag, ex.ToString());
            }
            finally
            {
                LogHelpers.WriteStatus(tag, "End.");
            }
        }
Esempio n. 14
0
        private void StartGetMenuName(int _menuId)
        {
            string tag = __tag + "[StartGetMenuName]";

            LogHelpers.WriteStatus(tag, "menuId: " + _menuId.ToString(), "Start...");

            try
            {
                var result = MenuDAL.GetMenuName(_menuId);
                if (result.Code < 0)
                {
                    LogHelpers.WriteError(tag, result.ErrorMessage);

                    return;
                }

                lbContentHeader.InnerText = result.Data.ToString();
            }
            catch (Exception ex)
            {
                LogHelpers.WriteException(tag, ex.Message);
            }
        }
Esempio n. 15
0
        public static string EncryptPassword(string input)
        {
            try
            {
                MD5 md5 = MD5.Create();

                byte[] hashData = md5.ComputeHash(Encoding.Default.GetBytes(input));

                StringBuilder result = new StringBuilder();

                for (int i = 0; i < hashData.Length; i++)
                {
                    result.Append(hashData[i].ToString("X2"));
                }

                return(result.ToString());
            }
            catch (Exception ex)
            {
                LogHelpers.WriteError("[Utilities][EncryptPassword] Exception: " + ex.ToString());

                return(string.Empty);
            }
        }
Esempio n. 16
0
        public static string SetFullLinkImage(string html, string rootImageDir)
        {
            string tag = "[Utilities][SetFullLinkImage]";

            try
            {
                HtmlDocument htmlDoc = new HtmlDocument();
                htmlDoc.OptionAutoCloseOnEnd = true;
                htmlDoc.LoadHtml(html);

                foreach (HtmlNode node in htmlDoc.DocumentNode.SelectNodes("//img[@src]"))
                {
                    var src = node.Attributes["src"].Value.Split('?')[0];
                    if (src.Contains("://"))
                    {
                        continue;
                    }

                    string fullPath = Path.Combine(rootImageDir, src);
                    node.SetAttributeValue("src", fullPath.Replace("\\", "/"));

                    //node.SetAttributeValue("src", string.Format(
                    //    "{0}?width={1}&height={2}",
                    //    src,
                    //    width == null ? "auto" : width,
                    //    height == null ? "auto" : height));
                }

                return(htmlDoc.DocumentNode.OuterHtml);
            }
            catch (Exception ex)
            {
                LogHelpers.WriteError(tag, ex.ToString());
                return(html);
            }
        }
Esempio n. 17
0
        public static ResultBOL <int> ExecuteStored(string stored, Hashtable hashTable)
        {
            string tag = _tag + "[ExecuteStored]";

            try
            {
                SqlConnection conn = new SqlConnection(ConnectionString());
                SqlCommand    cmd  = CreateSqlCommandStored(conn, stored, hashTable);

                SqlParameter dbReturn = cmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int);
                dbReturn.Direction = ParameterDirection.ReturnValue;

                conn.Open();

                cmd.ExecuteNonQuery();

                cmd.Dispose();
                conn.Close();

                return(new ResultBOL <int>()
                {
                    Code = (int)dbReturn.Value,
                    DbReturnValue = (int)dbReturn.Value
                });
            }
            catch (Exception ex)
            {
                LogHelpers.WriteError(tag, ex.ToString());

                return(new ResultBOL <int>()
                {
                    Code = ex.HResult,
                    ErrorMessage = ex.Message
                });
            }
        }