예제 #1
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);
            }
        }
예제 #2
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"
            });
        }
예제 #3
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);
            }
        }
예제 #4
0
        public static string EncryptPassword(string input)
        {
            if (string.IsNullOrEmpty(input))
            {
                return(string.Empty);
            }

            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);
            }
        }
예제 #5
0
        private void StartBindingCategory()
        {
            string tag = _tag + "[StartBindingCategory]";

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

            try
            {
                var result = MenuDAL.GetAllSubMenuProjects();
                if (result.Code < 0)
                {
                    lbError.InnerText = result.ErrorMessage;
                    lbError.Visible   = true;
                    LogHelpers.WriteError(tag, result.ErrorMessage);

                    return;
                }
            }
            catch (Exception ex)
            {
                LogHelpers.WriteException(tag, ex.ToString());
                //--
                lbError.InnerText = ex.Message;
                lbError.Visible   = true;
            }
            finally
            {
                LogHelpers.WriteStatus(tag, "End.");
            }
        }
예제 #6
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
                });
            }
        }
예제 #7
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
                });
            }
        }
예제 #8
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string tag = _tag + "[btnSubmit_Click]";

            MenuBOL obj = new MenuBOL()
            {
                Name_VN        = tbxNameVN.Text,
                Description_VN = tbxDesVN.Text,
                Name_EN        = tbxNameEN.Text,
                Description_EN = tbxDesEN.Text,
                InsertDate     = DateTime.Now,
                UpdatedDate    = DateTime.Now
            };

            if (_menuId > 0)
            {
                obj.Id = _menuId;
            }
            else if (_parentId > 0)
            {
                obj.ParentId = _parentId;
            }

            var result = MenuDAL.InsertOrUpdate(obj);

            if (result.Code < 0)
            {
                LogHelpers.WriteError(tag, result.ErrorMessage);
            }
            else
            {
                GoBackPage();
            }
        }
예제 #9
0
 public static void SaveLoggedInfo(UserBOL user)
 {
     try
     {
         var session = HttpContext.Current.Session;
         session["LoggedId"]       = user.Id;
         session["LoggedUsername"] = user.Username;
         session["LoggedFullName"] = user.FirstName_VN + " " + user.LastName_VN;
     }
     catch (Exception ex)
     {
         LogHelpers.WriteError("[Utilities][SaveLoggedInfo] Exception: " + ex.ToString());
     }
 }
예제 #10
0
        public static DateTime ToDateTime(string input)
        {
            try
            {
                DateTime result = DateTime.ParseExact(input, "yyyy-MM-dd", null);

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

                return(DateTime.Now);
            }
        }
예제 #11
0
        public static string ReplaceImageUri(string html, string imageDir)
        {
            string tag = "[Utilities][ReplaceImageUri]";

            if (string.IsNullOrEmpty(html))
            {
                return("");
            }

            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("://"))
                    {
                        src = src.Replace(imageDir, "");
                    }
                    else if (!src.Contains(ConfigurationManager.AppSettings["ImagesUrl"]))
                    {
                        src = SaveFileToServer(src, imageDir);
                    }

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


                    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);
            }
        }
예제 #12
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);
            }
        }
예제 #13
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);
            }
        }
예제 #14
0
        public static string UploadFileToServer(string address, string dir)
        {
            string tag = "[Utilities][SaveFileToServer]";

            LogHelpers.WriteStatus(tag, string.Format("Address: {0} - Dir: {1}",
                                                      address,
                                                      dir),
                                   "Start...");

            try
            {
                string ext      = Path.GetExtension(address);
                string folder   = DateTime.Now.ToString("MMddyyyy");
                string fileName = DateTime.Now.ToString("HHmmssfff") + ext;
                string result   = Path.Combine(folder, fileName);
                //---

                string dirServer = HttpContext.Current.Server.MapPath(Path.Combine(dir, folder));
                if (!Directory.Exists(dirServer))
                {
                    Directory.CreateDirectory(dirServer);
                }

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

                WebClient wc = new WebClient();
                wc.DownloadFile(address, fullPath);

                return(result.Replace("\\", "/"));
            }
            catch (Exception ex)
            {
                LogHelpers.WriteError(tag, ex.ToString());
                return(string.Empty);
            }
            finally
            {
                LogHelpers.WriteStatus(tag, string.Format("Address: {0} - Dir: {1}",
                                                          address,
                                                          dir),
                                       "End.");
            }
        }
예제 #15
0
        public static string SetFullLinkImage(string html, string rootImageDir)
        {
            string tag = "[Utilities][SetFullLinkImage]";

            if (string.IsNullOrEmpty(html))
            {
                return("");
            }

            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);

                    //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);
            }
        }
예제 #16
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
                });
            }
        }
예제 #17
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);
            }
        }
예제 #18
0
        public static ResultBOL <int> ExecuteStored(string stored, object obj)
        {
            string tag = _tag + "[ExecuteStored]";

            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();

                int exec = cmd.ExecuteNonQuery();

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

                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
                });
            }
        }
예제 #19
0
        private void StartCheckLogin()
        {
            try
            {
                lbError.InnerText = "";
                lbError.Visible   = false;
                string username = tbxUsername.Text;
                string password = tbxPassword.Text;

                var result = UsersDAL.Login(username, password);
                if (result.Code < 0 || result.DbReturnValue < 0)
                {
                    lbError.InnerText = result.ErrorMessage;
                    lbError.Visible   = true;
                    return;
                }

                if (result.Data.Tables.Count == 0 ||
                    result.Data.Tables[0].Rows.Count == 0)
                {
                    lbError.InnerText = "Sai tên đăng nhập hoặc mật khẩu không đúng.";
                    lbError.Visible   = true;
                    return;
                }

                UserBOL BOL = new UserBOL(result.Data.Tables[0].Rows[0]);
                Utilities.SaveLoggedInfo(BOL);
                //---
                GoToHome();
            }
            catch (Exception ex)
            {
                LogHelpers.WriteError("[Default][btnLogin_Click] Exception: {0}", ex.ToString());
                lbError.InnerText = ex.Message;
                lbError.Visible   = true;
            }
        }
예제 #20
0
        private ProjectBOL CreateNewProject()
        {
            string tag = _tag + "[CreateNewProject]";

            try
            {
                DateTime startDate = DateTime.MinValue;
                if (!string.IsNullOrEmpty(tbxStartDate.Text) &&
                    !DateTime.TryParseExact(tbxStartDate.Text, "MM/dd/yyyy", CultureInfo.CurrentCulture, DateTimeStyles.None, out startDate))
                {
                    startDate = DateTime.MinValue;
                }

                DateTime endDate = DateTime.MinValue;
                if (!string.IsNullOrEmpty(tbxEndDate.Text) &&
                    !DateTime.TryParseExact(tbxEndDate.Text, "MM/dd/yyyy", CultureInfo.CurrentCulture, DateTimeStyles.None, out endDate))
                {
                    endDate = DateTime.MinValue;
                }

                ProjectBOL BOL = new ProjectBOL()
                {
                    Name_VN        = tbxNameVN.Text,
                    Description_VN = tbxDesVN.Text,
                    Content_VN     = txaContentVN.Text,
                    Address_VN     = tbxAddress_VN.Text,
                    //---
                    Name_EN        = tbxNameEN.Text,
                    Description_EN = tbxDesEN.Text,
                    Address_EN     = tbxAddress_EN.Text,
                    Content_EN     = txaContentEN.Text,
                    StartDate      = startDate,
                    EndDate        = endDate,
                    //IsRedirectUrl = chkChooseCategory.Checked ? "Yes" : "No",
                    //RedirectUrl = tbxRedirectLink.Text.Trim(),
                    //--
                    ImageLink = hfListImage.Value,
                    //---
                    InsertDate  = DateTime.Now,
                    UpdatedDate = DateTime.Now
                };
                //---
                int menuId = Utilities.GetRequestParameter("MenuId");
                if (menuId > 0)
                {
                    BOL.MenuId = menuId;
                }

                int id = Utilities.GetRequestParameter("Id");
                if (id > 0)
                {
                    BOL.Id = id;
                }

                return(BOL);
            }
            catch (Exception ex)
            {
                LogHelpers.WriteError(string.Format("{0} Exception: {1}", tag, ex.ToString()));
                return(null);
            }
        }