Пример #1
0
        public static string GetDataUpdatedDate(DataRow row)
        {
            string tag = "[Utilities][GetDataUpdatedDate]";

            if (row == null)
            {
                return("-2");
            }

            try
            {
                DateTime lastItem = row.Field <DateTime>("UpdatedDate");

                return(lastItem.ToString("MMddyyyy HH:mm:ss.fff"));
            }
            catch (Exception ex)
            {
                LogHelpers.WriteException(tag, ex.ToString());
                return("-3");
            }
        }
Пример #2
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
                });
            }
        }
Пример #3
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);
            }
        }
Пример #4
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);
            }
        }
Пример #5
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.");
            }
        }
Пример #6
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);
            }
        }
Пример #7
0
        public static ResultBOL <DataSet> ExecuteQuery(string query)
        {
            string tag = _tag + "[ExecuteQuery]";

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

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

                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
                });
            }
        }
Пример #8
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);
            }
        }
Пример #9
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);
            }
        }
Пример #10
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
                });
            }
        }