Esempio n. 1
0
        /// <summary>
        /// 把经过base64编码的字符串保存为文件
        /// </summary>
        /// <param name="base64String">经base64加码后的字符串 </param>
        /// <param name="fileName">保存文件的路径和文件名 </param>
        /// <returns>保存文件是否成功 </returns>
        public static bool StringToFile(string base64String, string fileName)
        {
            bool bl = false;

            System.IO.FileStream   fs = new System.IO.FileStream(fileName, System.IO.FileMode.Create);
            System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fs);
            try
            {
                if (!string.IsNullOrEmpty(base64String) && System.IO.File.Exists(fileName))
                {
                    //base64String = base64String.Replace("data:image/png;base64,", "");
                    base64String = base64String.Split(',')[1];
                    bw.Write(Convert.FromBase64String(base64String));
                    bw.Dispose();
                    fs.Dispose();
                    bw.Close();
                    fs.Close();
                }
                bl = true;
            }
            catch (Exception ex)
            {
                PublicClass.AddLog("Save the picture", "StringToFile", fileName + "---" + ex.ToString());
            }
            finally
            {
                bw.Dispose();
                fs.Dispose();
                bw.Close();
                fs.Close();
                GC.Collect();
            }
            return(bl);
        }
Esempio n. 2
0
        /// <summary>
        /// 删除角色信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public string DelFunction(string id)
        {
            ResultInfo result = new ResultInfo();
            DataTable  dt     = new BLL.sys_rolemenu().GetList("menucode = '" + id + "'");

            if (dt != null && dt.Rows.Count > 0)
            {
                result.IsSucceed = false;
                result.Message   = "The menu is already in use and can not be deleted!";
            }
            else
            {
                if (new BLL.sys_rolemenu().Delete(id))
                {
                    result.IsSucceed = true;
                    result.Message   = "Delete Successful!";
                    PublicClass.AddLog("Operating", "Delete Function!");
                }
                else
                {
                    result.IsSucceed = false;
                    result.Message   = "Delete Failed!";
                }
            }
            return(JsonConvert.SerializeObject(result));
        }
Esempio n. 3
0
        public string SaveCustomer(string json)
        {
            ResultInfo result   = new ResultInfo(false);
            JObject    jo       = JObject.Parse(json);
            LoginInfo  userInfo = SessionHelper.ReadSession <LoginInfo>(SessionKeys.LoginInfoKey);
            var        bll      = new MultiColorPen.BLL.customer();

            //新增
            if (jo["id"].ToString() == "-1")
            {
                var model = new MultiColorPen.Model.customer
                {
                    name    = jo["name"].ToString(),
                    address = jo["address"].ToString(),
                    tel     = jo["tel"].ToString(),
                    person  = jo["person"].ToString(),
                    is_del  = "0",
                    mark    = jo["mark"].ToString()
                };
                if (bll.Add(model))
                {
                    result.IsSucceed = true;
                    result.Message   = "操作成功!";
                    PublicClass.AddLog("Operating", "新增商家" + model.name + "!");
                }
                else
                {
                    result.IsSucceed = false;
                    result.Message   = "新增失败!";
                }
            }
            //修改
            else
            {
                int id     = int.Parse(jo["id"].ToString());
                var umodel = bll.GetModel(id);
                umodel.name    = jo["name"].ToString();
                umodel.address = jo["address"].ToString();
                umodel.tel     = jo["tel"].ToString();
                umodel.person  = jo["person"].ToString();
                umodel.mark    = jo["mark"].ToString();
                List <string> btncode = new List <string>();
                if (bll.Update(umodel))
                {
                    result.IsSucceed = true;
                    result.Message   = "操作成功!";
                    PublicClass.AddLog("Operating", "编辑商家信息" + umodel.name + "!");
                }
                else
                {
                    result.IsSucceed = false;
                    result.Message   = "修改失败!";
                }
            }
            return(JsonConvert.SerializeObject(result));
        }
Esempio n. 4
0
 public override void OnException(ExceptionContext filterContext)
 {
     if (IsCheck)
     {
         string r_str = string.Empty;
         if (filterContext.HttpContext.Session[SessionKeys.LoginInfoKey] == null)
         {
             if (filterContext.HttpContext.Request.IsAjaxRequest())
             {
                 ResultInfo <string> result = new ResultInfo <string>();
                 result.IsSucceed = false;
                 result.Message   = "The certificate has expired. Please login again!";
                 result.Entity    = "../../Home/Login";
                 r_str            = JsonConvert.SerializeObject(result);
             }
             else
             {
                 //跳转到登陆页
                 r_str = "<script>alert('The certificate has expired. Please login again!');window.parent.location.href='/Home/Login';</script>";
             }
         }
         else
         {
             base.OnException(filterContext);
             string mess = "Error message:" + filterContext.Exception.Message + ",Error controller:" + filterContext.Controller.ToString()
                           + ",Error method:" + filterContext.Exception.TargetSite.ToString()
                           + ",Error object:" + filterContext.Exception.Source + ",Error location:" + filterContext.Exception.StackTrace;
             PublicClass.AddLog("error", mess);     //写入报错日志
             filterContext.ExceptionHandled = true; //设置异常已处理
             if (filterContext.HttpContext.Request.IsAjaxRequest())
             {
                 ResultInfo <string> result = new ResultInfo <string>();
                 result.IsSucceed = false;
                 result.Message   = "The system has an exception!";
                 result.Entity    = "../../Content/html/Error.html";
                 r_str            = JsonConvert.SerializeObject(result);
             }
             else
             {
                 //跳转到登陆页
                 r_str = "<script>alert('系统出现异常!');window.parent.location.href='../../Content/html/Error.html';</script>";
             }
         }
         filterContext.RequestContext.HttpContext.Response.Write(r_str);
         filterContext.RequestContext.HttpContext.Response.End();
     }
 }
Esempio n. 5
0
        /// <summary>
        /// 日志删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public string LogManageDelete(int id)
        {
            ResultInfo <string> result = new ResultInfo <string>();

            if (new MultiColorPen.BLL.sys_loginfo().Delete(id))
            {
                result.IsSucceed = true;
                result.Message   = "Save Successful!";
                PublicClass.AddLog("Operating", "Delete Log!");
            }
            else
            {
                result.IsSucceed = false;
                result.Message   = "operation failed!";
            }
            return(JsonConvert.SerializeObject(result));
        }
Esempio n. 6
0
        public string LogOn(string username, string pwd, string vcode)
        {
            string s_vcode = SessionHelper.ReadSession <string>(SessionKeys.CheckCodeKey);

            if (string.IsNullOrEmpty(s_vcode) || (!s_vcode.ToLower().Equals(vcode.ToLower())))
            {
                return("vcode");
            }
            DataTable u_dt = new BLL.base_userinfo().GetList("username='******'");

            if (u_dt != null && u_dt.Rows.Count > 0)
            {
                pwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "MD5");
                if (u_dt.Rows[0]["password"].ToString() == pwd)
                {
                    if (u_dt.Rows[0]["isenable"].ToString() == "0")
                    {
                        return("enable");
                    }
                    else
                    {
                        LoginInfo model = new LoginInfo
                        {
                            UserName = username,
                            PName    = u_dt.Rows[0]["pname"].ToString(),
                            RoleCode = u_dt.Rows[0]["rolecode"].ToString(),
                            Phone    = u_dt.Rows[0]["phone"].ToString(),
                        };
                        string token = Guid.NewGuid().ToString();
                        new BLL.base_userinfo().UpdateToken(username, token);
                        SessionHelper.WriteSession(SessionKeys.LoginStateCode, token);
                        SessionHelper.WriteSession(SessionKeys.LoginInfoKey, model);
                        PublicClass.AddLog("Login", "User " + model.PName + " Loin in System!");
                        return("success");
                    }
                }
                else
                {
                    return("pwd");
                }
            }
            else
            {
                return("acc");
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Admin启用或禁用
        /// </summary>
        /// <param name="id"></param>
        /// <param name="ised"></param>
        /// <returns></returns>
        public string AdminEnableOrDisabled(int id, string ised)
        {
            ResultInfo <string> result = new ResultInfo <string>();
            var bll   = new MultiColorPen.BLL.base_userinfo();
            var model = bll.GetModel(id);

            model.isenable = int.Parse(ised);
            if (bll.Update(model) > 0)
            {
                result.IsSucceed = true;
                result.Message   = "operation Successful!";
                PublicClass.AddLog("Operating", (model.isenable == 1 ? "Enable insiders:" : "Disable insider:") + model.username + "," + model.pname + "!");
            }
            else
            {
                result.IsSucceed = false;
                result.Message   = "operation Failed!";
            }
            return(JsonConvert.SerializeObject(result));
        }
Esempio n. 8
0
        public string DeleteCommodity(int id)
        {
            ResultInfo result = new ResultInfo(false);
            var        bll    = new MultiColorPen.BLL.commodity();
            var        umodel = bll.GetModel(id);

            umodel.is_del = "1";
            if (bll.Update(umodel))
            {
                result.IsSucceed = true;
                result.Message   = "操作成功!";
                PublicClass.AddLog("Operating", "删除商品信息" + umodel.name + "!");
            }
            else
            {
                result.IsSucceed = false;
                result.Message   = "删除失败!";
            }
            return(JsonConvert.SerializeObject(result));
        }
Esempio n. 9
0
        /// <summary>
        /// 按钮启用或禁用
        /// </summary>
        /// <param name="id"></param>
        /// <param name="ised"></param>
        /// <returns></returns>
        public string BtnEnableOrDisabled(int id, string ised)
        {
            ResultInfo <string> result = new ResultInfo <string>();
            var bll   = new MultiColorPen.BLL.sys_buttoninfo();
            var model = bll.GetModel(id);

            model.isenable = int.Parse(ised);
            if (bll.Update(model))
            {
                result.IsSucceed = true;

                result.Message = "Operation Successful!";
                PublicClass.AddLog("Operating", model.isenable == 1 ? "Enable button:" + model.btnname + " " : "Disable button:" + model.btnname + " ");
            }
            else
            {
                result.IsSucceed = false;
                result.Message   = "Operation Failed!";
            }
            return(JsonConvert.SerializeObject(result));
        }
Esempio n. 10
0
        /// <summary>
        /// 保存Admin
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public string AdminManageSave(string json)
        {
            ResultInfo result   = new ResultInfo(false);
            JObject    jo       = JObject.Parse(json);
            LoginInfo  userInfo = SessionHelper.ReadSession <LoginInfo>(SessionKeys.LoginInfoKey);
            var        bll      = new MultiColorPen.BLL.base_userinfo();

            bool   avatar     = false;
            string folderName = Server.MapPath("~/Upload/Avatar");

            if (Directory.Exists(folderName) == false)
            {
                Directory.CreateDirectory(folderName);
            }
            string fileName = Guid.NewGuid().ToString("N");
            string filePath = folderName + "/" + fileName + ".jpg";

            if (jo["avatar"].ToString() == "-1" && jo["base64"].ToString() != "-1" && StringToFile(jo["base64"].ToString(), filePath))
            {
                avatar = true;
            }
            try
            {
                //新增
                if (jo["id"].ToString() == "-1")
                {
                    var list = bll.GetModelList("username='******' and A.isenable=1");
                    if (list.Count > 0)
                    {
                        result.IsSucceed = false;
                        result.Message   = "Duplicate login name!";
                    }
                    else
                    {
                        var model = new MultiColorPen.Model.base_userinfo
                        {
                            usercode   = bll.GetMaxNo(),
                            username   = jo["username"].ToString(),
                            phone      = jo["phone"].ToString(),
                            pname      = jo["pname"].ToString(),
                            rolecode   = jo["rolecode"].ToString(),
                            wechat     = jo["wechat"].ToString(),
                            password   = "******",
                            avatar     = avatar ? fileName : jo["avatar"].ToString() == "-1" ? "" : jo["avatar"].ToString(),
                            isenable   = 1,
                            createtime = DateTime.Now,
                            createman  = userInfo.UserName
                        };
                        if (bll.Add(model) > 0)
                        {
                            result.IsSucceed = true;
                            result.Message   = "Save success, the initial password is 888888!";
                            PublicClass.AddLog("Operating", "Add insiders " + model.username + "," + model.pname + "!");
                        }
                        else
                        {
                            result.IsSucceed = false;
                            result.Message   = "Save failed!";
                        }
                    }
                }
                //修改
                else
                {
                    int id   = int.Parse(jo["id"].ToString());
                    var list = bll.GetModelList("username='******' and A.id!=" + id + " and A.isenable=1");
                    if (list.Count > 0)
                    {
                        result.IsSucceed = false;
                        result.Message   = "Duplicate login name!";
                    }
                    else
                    {
                        var    umodel = bll.GetModel(id);
                        string oldstr = JsonHelper.GetObjectToJSON(umodel);
                        umodel.phone      = jo["phone"].ToString();
                        umodel.pname      = jo["pname"].ToString();
                        umodel.wechat     = jo["wechat"].ToString();
                        umodel.rolecode   = jo["rolecode"].ToString();
                        umodel.avatar     = avatar ? fileName : jo["avatar"].ToString() == "-1" ? "" : jo["avatar"].ToString();
                        umodel.updateman  = userInfo.UserName;
                        umodel.updatetime = DateTime.Now;
                        string newstr = JsonHelper.GetObjectToJSON(umodel);

                        if (bll.Update(umodel) > 0)
                        {
                            result.IsSucceed = true;
                            result.Message   = "Saved successfully!";
                            PublicClass.AddLog("Operating", "Modify internal staff " + umodel.username + "!", "", "", "base_userinfo", umodel.id.ToString(), oldstr, newstr);
                        }
                        else
                        {
                            result.IsSucceed = false;
                            result.Message   = "Save failed!";
                        }
                    }
                }
                return(JsonConvert.SerializeObject(result));
            }
            catch (Exception ex)
            {
                result.IsSucceed = false;
                result.Message   = ex.Message;
                return(JsonConvert.SerializeObject(result));
            }
        }
Esempio n. 11
0
        public string SaveCommodity(string json)
        {
            ResultInfo result   = new ResultInfo(false);
            JObject    jo       = JObject.Parse(json);
            LoginInfo  userInfo = SessionHelper.ReadSession <LoginInfo>(SessionKeys.LoginInfoKey);
            var        bll      = new MultiColorPen.BLL.commodity();

            //新增
            if (jo["id"].ToString() == "-1")
            {
                var model = new MultiColorPen.Model.commodity
                {
                    name           = jo["name"].ToString(),
                    number         = "NUM" + DateTime.Now.ToString().Replace("/", "").Replace(" ", "").Replace(":", ""),
                    count          = (int)jo["count"],
                    price          = (decimal)jo["price"],
                    type           = jo["type"].ToString(),
                    unit           = jo["unit"].ToString(),
                    is_del         = "0",
                    special_supply = jo["special_supply"].ToString(),
                    mark           = jo["mark"].ToString()
                };
                if (bll.Add(model))
                {
                    result.IsSucceed = true;
                    result.Message   = "操作成功!";
                    PublicClass.AddLog("Operating", "新增商品" + model.name + "!");
                }
                else
                {
                    result.IsSucceed = false;
                    result.Message   = "新增失败!";
                }
            }
            //修改
            else
            {
                int id     = int.Parse(jo["id"].ToString());
                var umodel = bll.GetModel(id);
                umodel.name           = jo["name"].ToString();
                umodel.count          = (int)jo["count"];
                umodel.price          = (decimal)jo["price"];
                umodel.type           = jo["type"].ToString();
                umodel.unit           = jo["unit"].ToString();
                umodel.special_supply = jo["special_supply"].ToString();
                umodel.mark           = jo["mark"].ToString();
                List <string> btncode = new List <string>();
                if (bll.Update(umodel))
                {
                    result.IsSucceed = true;
                    result.Message   = "操作成功!";
                    PublicClass.AddLog("Operating", "编辑商品信息" + umodel.name + "!");
                }
                else
                {
                    result.IsSucceed = false;
                    result.Message   = "修改失败!";
                }
            }
            return(JsonConvert.SerializeObject(result));
        }
Esempio n. 12
0
        /// <summary>
        /// 新增、修改角色保存
        /// </summary>
        /// <returns></returns>
        public string RoleSave(string json)
        {
            ResultInfo result   = new ResultInfo(false);
            JObject    jo       = JObject.Parse(json);
            LoginInfo  userInfo = SessionHelper.ReadSession <LoginInfo>(SessionKeys.LoginInfoKey);

            BLL.sys_roleinfo bll = new BLL.sys_roleinfo();
            //新增
            if (jo["id"].ToString() == "-1")
            {
                MultiColorPen.Model.sys_roleinfo model = new MultiColorPen.Model.sys_roleinfo
                {
                    rolecode   = bll.GetMaxNo(),
                    rolename   = jo["rolename"].ToString(),
                    isenable   = 1,
                    remark     = jo["remark"].ToString(),
                    createtime = DateTime.Now,
                    createman  = userInfo.UserName
                };
                if (!string.IsNullOrEmpty(jo["rolesort"].ToString()))
                {
                    model.rolesort = int.Parse(jo["rolesort"].ToString());
                }
                else
                {
                    model.rolesort = 99;
                }
                if (bll.Add(model) > 0)
                {
                    result.IsSucceed = true;
                    result.Message   = "Save Successful!";
                    PublicClass.AddLog("Operating", "Add Role" + model.rolename + "!");
                }
                else
                {
                    result.IsSucceed = false;
                    result.Message   = "Save Failed!";
                }
            }
            else//修改
            {
                string id     = jo["id"].ToString();
                var    umodel = bll.GetModel(id);
                umodel.rolename = jo["rolename"].ToString();
                if (!string.IsNullOrEmpty(jo["rolesort"].ToString()))
                {
                    umodel.rolesort = int.Parse(jo["rolesort"].ToString());
                }
                else
                {
                    umodel.rolesort = 99;
                }
                umodel.remark     = jo["remark"].ToString();
                umodel.updateman  = userInfo.UserName;
                umodel.updatetime = DateTime.Now;
                if (bll.Update(umodel))
                {
                    result.IsSucceed = true;
                    result.Message   = "Save Successful!";
                    PublicClass.AddLog("Operating", "Edit Role" + umodel.rolename + "!");
                }
                else
                {
                    result.IsSucceed = false;
                    result.Message   = "Save Failed!";
                }
            }
            return(JsonConvert.SerializeObject(result));
        }
Esempio n. 13
0
        /// <summary>
        /// 菜单添加/修改保存
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public string FunctionSave(string json)
        {
            ResultInfo result   = new ResultInfo(false);
            JObject    jo       = JObject.Parse(json);
            LoginInfo  userInfo = SessionHelper.ReadSession <LoginInfo>(SessionKeys.LoginInfoKey);
            var        bll      = new MultiColorPen.BLL.sys_menuinfo();

            //新增
            if (jo["did"].ToString() == "-1")
            {
                string code  = bll.GetMaxNo();
                var    model = new MultiColorPen.Model.sys_menuinfo
                {
                    pmenucode   = jo["pmenucode"].ToString(),
                    menucode    = code,
                    menuname    = jo["menuname"].ToString(),
                    menuicon    = jo["menuicon"].ToString(),
                    linkaddress = jo["linkaddress"].ToString(),
                    isenable    = 1,
                    createtime  = DateTime.Now,
                    createman   = userInfo.UserName
                };
                if (!string.IsNullOrEmpty(jo["menusort"].ToString()))
                {
                    model.menusort = int.Parse(jo["menusort"].ToString());
                }
                else
                {
                    model.menusort = 99;
                }
                var           list    = jo["btncode"];
                List <string> btncode = new List <string>();
                if (list != null && list.Count() > 0)
                {
                    for (int i = 0; i < list.Count(); i++)
                    {
                        btncode.Add(list[i].ToString());
                    }
                }
                if (bll.Add(model, btncode) > 0)
                {
                    result.IsSucceed = true;
                    result.Message   = "Operation Successful!";
                    PublicClass.AddLog("Operating", "Add System Function" + model.menuname + "!");
                }
                else
                {
                    result.IsSucceed = false;
                    result.Message   = "Save Failed!";
                }
            }
            //修改
            else
            {
                int id     = int.Parse(jo["did"].ToString());
                var umodel = bll.GetModel(id);
                umodel.pmenucode = jo["pmenucode"].ToString();
                umodel.menuname  = jo["menuname"].ToString();
                umodel.menuicon  = jo["menuicon"].ToString();
                if (!string.IsNullOrEmpty(jo["menusort"].ToString()))
                {
                    umodel.menusort = int.Parse(jo["menusort"].ToString());
                }
                else
                {
                    umodel.menusort = 99;
                }
                umodel.linkaddress = jo["linkaddress"].ToString();
                umodel.updateman   = userInfo.UserName;
                umodel.updatetime  = DateTime.Now;
                var           list    = jo["btncode"];
                List <string> btncode = new List <string>();
                if (list != null && list.Count() > 0)
                {
                    for (int i = 0; i < list.Count(); i++)
                    {
                        btncode.Add(list[i].ToString());
                    }
                }
                if (bll.Update(umodel, btncode))
                {
                    result.IsSucceed = true;
                    result.Message   = "Operating Successful!";
                    PublicClass.AddLog("Operating", "Edit System Function" + umodel.menuname + "!");
                }
                else
                {
                    result.IsSucceed = false;
                    result.Message   = "Save Failed!";
                }
            }
            return(JsonConvert.SerializeObject(result));
        }
Esempio n. 14
0
        /// <summary>
        /// 按钮添加/修改保存
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public string BtnManageSave(string json)
        {
            ResultInfo result   = new ResultInfo(false);
            JObject    jo       = JObject.Parse(json);
            LoginInfo  userInfo = SessionHelper.ReadSession <LoginInfo>(SessionKeys.LoginInfoKey);
            var        bll      = new MultiColorPen.BLL.sys_buttoninfo();

            //新增
            if (jo["id"].ToString() == "-1")
            {
                var model = new MultiColorPen.Model.sys_buttoninfo
                {
                    btncode    = bll.GetMaxNo(),
                    btnname    = jo["btnname"].ToString(),
                    btnclass   = jo["btnclass"].ToString(),
                    btnicon    = jo["btnicon"].ToString(),
                    btnmethod  = jo["btnmethod"].ToString(),
                    isenable   = 1,
                    createtime = DateTime.Now,
                    createman  = userInfo.UserName
                };
                if (!string.IsNullOrEmpty(jo["btnsort"].ToString()))
                {
                    model.btnsort = int.Parse(jo["btnsort"].ToString());
                }
                else
                {
                    model.btnsort = 99;
                }
                if (bll.Add(model) > 0)
                {
                    result.IsSucceed = true;
                    result.Message   = "Save Successful!";
                    PublicClass.AddLog("Operating", "Add Button!" + model.btnname + "!");
                }
                else
                {
                    result.IsSucceed = false;
                    result.Message   = "Save Failed!";
                }
            }
            //修改
            else
            {
                int id     = int.Parse(jo["id"].ToString());
                var umodel = bll.GetModel(id);
                umodel.btnname   = jo["btnname"].ToString();
                umodel.btnclass  = jo["btnclass"].ToString();
                umodel.btnicon   = jo["btnicon"].ToString();
                umodel.btnmethod = jo["btnmethod"].ToString();
                if (!string.IsNullOrEmpty(jo["btnsort"].ToString()))
                {
                    umodel.btnsort = int.Parse(jo["btnsort"].ToString());
                }
                else
                {
                    umodel.btnsort = 99;
                }
                umodel.updateman  = userInfo.UserName;
                umodel.updatetime = DateTime.Now;
                if (bll.Update(umodel))
                {
                    result.IsSucceed = true;
                    result.Message   = "Save Successful!";
                    PublicClass.AddLog("Operating", "Edit Button!" + umodel.btnname + "!");
                }
                else
                {
                    result.IsSucceed = false;
                    result.Message   = "Save Failed!";
                }
            }
            return(JsonConvert.SerializeObject(result));
        }