Beispiel #1
0
 public JsonMessage<Cart> Purchase(string cupom)
 {
     JsonMessage<Cart> jsonReturn = new JsonMessage<Cart>();
     Cart cart = CartService.GetCart();
     if (cupom.ToUpper().Equals("SHIPIT"))
     {
         cart.Total = cart.Total - ((cart.Total * 10) / 100);
     }
     jsonReturn.BusinessObject = cart;
     return jsonReturn;
 }
Beispiel #2
0
        public JsonMessage RemoveItem(Developer dev)
        {
            JsonMessage jsonReturn = new JsonMessage();
            try
            {

                CartService.RemoveCartItem(new CartItem() { Developer = dev });
                jsonReturn.Success = "OK";
            }
            catch (Exception e)
            {
                jsonReturn.Err = "Error " + e.Message;
            }
            return jsonReturn;
        }
        public JsonMessage<List<Developer>> GetPage(int page)
        {
            JsonMessage<List<Developer>> jsonReturn = new JsonMessage<List<Developer>>();
            try
            {
                DeveloperService devService = new DeveloperService();
                jsonReturn.BusinessObject = devService.page(page);
                jsonReturn.Success = "OK";
            }
            catch (Exception e)
            {
                jsonReturn.Success = "Error" + e.Message;
            }

            return jsonReturn;
        }
Beispiel #4
0
        public JsonMessage<Cart> GetAll()
        {
            JsonMessage<Cart> jsonReturn = new JsonMessage<Cart>();
            try
            {

                Cart cart = CartService.GetCart();
                jsonReturn.BusinessObject = cart;
                jsonReturn.Success = "OK";
            }
            catch (Exception e)
            {
                jsonReturn.Err = "Error " + e.Message;
            }

            return jsonReturn;
        }
Beispiel #5
0
 protected override void OnDisposed(object sender, ChannelDisposedEventArgs e)
 {
     base.OnDisposed(sender, e);
     Console.WriteLine("{0} disposed", e.Channel.EndPoint);
     JsonMessage msg = new JsonMessage();
     User user = new User();
     user.Name = e.Channel.Name;
     user.ID = e.Channel.ClientID;
     user.IP = e.Channel.EndPoint.ToString();
     msg.type = "unregister";
     msg.data = (User)e.Channel.Tag;
     foreach (IChannel item in this.Server.GetOnlines())
     {
         if (item != e.Channel)
             item.Send(msg);
     }
 }
Beispiel #6
0
        public void Say(string Content)
        {
            IChannel channel = MethodContext.Current.Channel;
            JsonMessage msg = new JsonMessage();
            SayText st = new SayText();
            st.Name = channel.Name;
            st.ID = channel.ClientID;
            st.Date = DateTime.Now;
            st.Content = Content;
            st.IP = channel.EndPoint.ToString();
            msg.type = "say";
            msg.data = st;
            foreach (IChannel item in channel.Server.GetOnlines())
            {
                item.Send(msg);
            }

        }
Beispiel #7
0
	public override BaseMessage DynamicCreate (byte[] data, MessageHead head)
	{
		if(MessageInfo.MessageTypeCheck(MessageDataType.Json))
		{
			JsonMessage message = new JsonMessage();
			message.MessageType = KMessageType.None;
			if (BitConverter.IsLittleEndian)
				Array.Reverse(data);
			
			message.DataBody.m_FirstValue = System.Text.Encoding.UTF8.GetString(data);
			if (head != null)
			{
				message.DataHead = head;
				message.MessageType = (KMessageType)head.CMD;
			}
			
			return message;
		}
		return null;
	}
Beispiel #8
0
 public long Register(string name)
 {
    
     IChannel channel = MethodContext.Current.Channel;
     Console.WriteLine("{0} register name:{1}", channel.EndPoint, name);
     channel.Name = name;
     JsonMessage msg = new JsonMessage();
     User user = new User();
     user.Name = name;
     user.ID = channel.ClientID;
     user.IP = channel.EndPoint.ToString();
     channel.Tag = user;
     msg.type = "register";
     msg.data = user;
     foreach (IChannel item in channel.Server.GetOnlines())
     {
         if (item != channel)
             item.Send(msg);
     }
     return channel.ClientID;
 }
Beispiel #9
0
        public ActionResult Actions()
        {
            var msg      = new JsonMessage();
            var dnUser   = new DNUserAddItem();
            var json     = "";
            var date     = Request["StartDay"];
            var birthDay = Request["BirthDay_"];

            switch (DoAction)
            {
            case ActionType.Add:
                UpdateModel(dnUser);
                if (!string.IsNullOrEmpty(date))
                {
                    dnUser.StartDate = date.StringToDecimal(0);
                }
                if (!string.IsNullOrEmpty(birthDay))
                {
                    dnUser.BirthDay = birthDay.StringToDecimal(0);
                }
                dnUser.UserId = Guid.NewGuid();
                json          = new JavaScriptSerializer().Serialize(dnUser);
                msg           = _dnUserApi.Add(UserItem.AgencyID, json);
                break;

            case ActionType.Edit:
                UpdateModel(dnUser);
                if (!string.IsNullOrEmpty(date))
                {
                    dnUser.StartDate = date.StringToDecimal(0);
                }
                if (!string.IsNullOrEmpty(birthDay))
                {
                    dnUser.BirthDay = birthDay.StringToDecimal(0);
                }
                dnUser.UserId = GuiId.FirstOrDefault();
                json          = new JavaScriptSerializer().Serialize(dnUser);
                msg           = _dnUserApi.Update(UserItem.AgencyID, json);
                break;

            case ActionType.Active:
                var listInt = Request["listInt"];
                var userId  = Request["userId"];
                msg = _dnUserApi.AddModuleUser(listInt, userId, UserItem.AgencyID);
                break;

            case ActionType.Delete:
                msg = _dnUserApi.Delete(json, Request["itemID"]);
                break;

            case ActionType.RoleModule:
                msg = _dnUserApi.UpdateModuleActive(GuiId.FirstOrDefault(), Request["chkActiveRoles"]);
                break;

            case ActionType.Show:
                var c = _dnUserApi.CheckinUser(ArrId.FirstOrDefault(), UserItem.AgencyID);
                if (c == 1)
                {
                    msg.Erros   = false;
                    msg.Message = "Bạn đã chấm công thành công.";
                }
                break;

            case ActionType.Hide:
                msg = _dnUserApi.ShowHide(GuiId.FirstOrDefault(), true);
                break;

            default:
                msg.Erros   = true;
                msg.Message = "Bạn không được phần quyển cho chức năng này.";
                break;
            }
            return(Json(msg, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Actions()
        {
            var msg  = new JsonMessage();
            var city = new System_City();
            List <System_City> ltsCityItems;
            StringBuilder      stbMessage;

            switch (DoAction)
            {
            case ActionType.Add:
                UpdateModel(city);
                _cityDa.Add(city);
                city.LanguageID = Fdisystem.LanguageId;
                _cityDa.Save();
                msg = new JsonMessage
                {
                    Erros   = false,
                    ID      = city.ID.ToString(),
                    Message = string.Format("Đã thêm mới thành phố: <b>{0}</b>", Server.HtmlEncode(city.Name))
                };
                break;

            case ActionType.Edit:
                city = _cityDa.GetById(ArrId.FirstOrDefault());
                UpdateModel(city);
                //city.LanguageID = Fdisystem.LanguageId;
                _cityDa.Save();
                msg = new JsonMessage
                {
                    Erros   = false,
                    ID      = city.ID.ToString(),
                    Message = string.Format("Đã cập nhật thành phố: <b>{0}</b>", Server.HtmlEncode(city.Name))
                };
                break;

            case ActionType.Delete:
                ltsCityItems = _cityDa.GetByListArrId(ArrId.ToString());
                stbMessage   = new StringBuilder();
                foreach (var item in ltsCityItems)
                {
                    if (item.System_District.Any())
                    {
                        stbMessage.AppendFormat("Thành phố <b>{0}</b> đang được sử dụng, không được phép xóa.<br />", Server.HtmlEncode(item.Name));
                    }
                    else
                    {
                        _cityDa.Delete(item);
                        stbMessage.AppendFormat("Đã xóa thành phố <b>{0}</b>.<br />", Server.HtmlEncode(item.Name));
                    }
                }
                msg.ID = string.Join(",", ArrId);
                _cityDa.Save();
                msg.Message = stbMessage.ToString();
                break;

            case ActionType.Show:
                ltsCityItems = _cityDa.GetByListArrId(ArrId.ToString()).Where(o => !o.IsShow).ToList();
                stbMessage   = new StringBuilder();
                foreach (var item in ltsCityItems)
                {
                    item.IsShow = true;
                    stbMessage.AppendFormat("Đã hiển thị thành phố <b>{0}</b>.<br />", Server.HtmlEncode(item.Name));
                }
                _cityDa.Save();
                msg.ID      = string.Join(",", ltsCityItems.Select(o => o.ID));
                msg.Message = stbMessage.ToString();
                break;

            case ActionType.Hide:
                ltsCityItems = _cityDa.GetByListArrId(ArrId.ToString()).Where(o => o.IsShow).ToList();
                stbMessage   = new StringBuilder();
                foreach (var item in ltsCityItems)
                {
                    item.IsShow = false;
                    stbMessage.AppendFormat("Đã ẩn thành phố <b>{0}</b>.<br />", Server.HtmlEncode(item.Name));
                }
                _cityDa.Save();
                msg.ID      = string.Join(",", ltsCityItems.Select(o => o.ID));
                msg.Message = stbMessage.ToString();
                break;
            }
            if (string.IsNullOrEmpty(msg.Message))
            {
                msg.Message = "Không có hành động nào được thực hiện.";
                msg.Erros   = true;
            }
            return(Json(msg, JsonRequestBehavior.AllowGet));
        }
Beispiel #11
0
        public ActionResult Actions()
        {
            var msg   = new JsonMessage();
            var model = new ModulePage();
            List <ModulePage> ltsSysPageItems;
            StringBuilder     stbMessage;
            SysPageItem       parent;

            switch (DoAction)
            {
            case ActionType.Add:
                try
                {
                    UpdateModel(model);
                    model.Type       = 0;
                    model.AgencyID   = Utility.AgencyId;
                    model.CreateDate = DateTime.Now.TotalSeconds();
                    parent           = _da.GetSysPageItem(model.ParentId ?? 0);
                    if (parent != null)
                    {
                        model.Level = parent.Level + 1;
                    }
                    else
                    {
                        model.Level = 1;
                    }
                    _da.Add(model);
                    _da.Save();
                    msg = new JsonMessage
                    {
                        Erros   = false,
                        ID      = model.Id.ToString(),
                        Message = string.Format("Đã thêm mới chuyên mục: <b>{0}</b>", Server.HtmlEncode(model.Name))
                    };
                }
                catch (Exception ex)
                {
                    LogHelper.Instance.LogError(GetType(), ex);
                }
                break;

            case ActionType.Edit:
                try
                {
                    model = _da.Get(ArrId.FirstOrDefault());
                    UpdateModel(model);
                    parent = _da.GetSysPageItem(model.ParentId ?? 0);
                    if (parent != null)
                    {
                        model.Level = parent.Level + 1;
                    }
                    else
                    {
                        model.Level = 1;
                    }
                    model.Type = !string.IsNullOrEmpty(Request["Type"]) ? Convert.ToInt32(Request["Type"]) : 0;
                    _da.Save();
                    msg = new JsonMessage
                    {
                        Erros   = false,
                        ID      = model.Id.ToString(),
                        Message = string.Format("Đã cập nhật chuyên mục: <b>{0}</b>", Server.HtmlEncode(model.Name))
                    };
                }
                catch (Exception ex)
                {
                    LogHelper.Instance.LogError(GetType(), ex);
                }
                break;

            case ActionType.Delete:
                ltsSysPageItems = _da.GetListByArrId(ArrId);
                stbMessage      = new StringBuilder();
                foreach (var item in ltsSysPageItems)
                {
                    try
                    {
                        _da.Delete(item);
                        stbMessage.AppendFormat("Đã xóa chuyên mục <b>{0}</b>.<br />", Server.HtmlEncode(item.Name));
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Instance.LogError(GetType(), ex);
                    }
                }
                msg.ID = string.Join(",", ArrId);
                _da.Save();
                msg.Message = stbMessage.ToString();
                break;

            case ActionType.Show:
                ltsSysPageItems = _da.GetListByArrId(ArrId).ToList();     //Chỉ lấy những đối tượng ko được hiển thị
                stbMessage      = new StringBuilder();
                foreach (var item in ltsSysPageItems)
                {
                    try
                    {
                        stbMessage.AppendFormat("Đã hiển thị chuyên mục <b>{0}</b>.<br />", Server.HtmlEncode(item.Name));
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Instance.LogError(GetType(), ex);
                    }
                }
                _da.Save();
                msg.ID      = string.Join(",", ltsSysPageItems.Select(o => o.Id));
                msg.Message = stbMessage.ToString();
                break;

            case ActionType.Hide:
                ltsSysPageItems = _da.GetListByArrId(ArrId).ToList();     //Chỉ lấy những đối tượng được hiển thị
                stbMessage      = new StringBuilder();
                foreach (var item in ltsSysPageItems)
                {
                    try
                    {
                        stbMessage.AppendFormat("Đã ẩn chuyên mục <b>{0}</b>.<br />", Server.HtmlEncode(item.Name));
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Instance.LogError(GetType(), ex);
                    }
                }
                _da.Save();
                msg.ID      = string.Join(",", ltsSysPageItems.Select(o => o.Id));
                msg.Message = stbMessage.ToString();
                break;

            case ActionType.Order:
                try
                {
                    if (!string.IsNullOrEmpty(Request["OrderValues"]))
                    {
                        var orderValues = Request["OrderValues"];
                        if (orderValues.Contains("|"))
                        {
                            foreach (var keyValue in orderValues.Split('|'))
                            {
                                if (keyValue.Contains("_"))
                                {
                                    var tempCategory = _da.GetById(Convert.ToInt32(keyValue.Split('_')[0]));
                                    tempCategory.Sort = Convert.ToInt32(keyValue.Split('_')[1]);
                                    _da.Save();
                                }
                            }
                        }
                        msg.ID      = string.Join(",", orderValues);
                        msg.Message = "Đã cập nhật lại thứ tự chuyên mục";
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.Instance.LogError(GetType(), ex);
                }
                break;
            }

            if (string.IsNullOrEmpty(msg.Message))
            {
                msg.Message = "Không có hành động nào được thực hiện.";
                msg.Erros   = true;
            }

            return(Json(msg, JsonRequestBehavior.AllowGet));
        }
        public ActionResult AnswerActions()
        {
            var msg    = new JsonMessage();
            var answer = new FAQ_Answer();
            List <FAQ_Answer> ltsAnswerItems;
            StringBuilder     stbMessage;

            switch (DoAction)
            {
            case ActionType.Add:
                UpdateModel(answer);
                answer.TitleAscii  = FDIUtils.Slug(answer.Title);
                answer.DateCreated = DateTime.Now;
                _answerDa.Add(answer);
                _answerDa.Save();
                msg = new JsonMessage
                {
                    Erros   = false,
                    ID      = answer.ID.ToString(),
                    Message = string.Format("Đã thêm mới câu trả lời: <b>{0}</b>", Server.HtmlEncode(answer.Title))
                };
                break;

            case ActionType.Edit:
                answer = _answerDa.GetById(ArrId.FirstOrDefault());
                UpdateModel(answer);
                answer.TitleAscii = FDIUtils.Slug(answer.Title);

                _answerDa.Save();
                msg = new JsonMessage
                {
                    Erros   = false,
                    ID      = answer.ID.ToString(),
                    Message = string.Format("Đã cập nhật câu trả lời: <b>{0}</b>", Server.HtmlEncode(answer.Title))
                };
                break;

            case ActionType.Delete:
                ltsAnswerItems = _answerDa.GetListByArrID(ArrId);
                stbMessage     = new StringBuilder();
                foreach (var item in ltsAnswerItems)
                {
                    _answerDa.Delete(item);
                    stbMessage.AppendFormat("Đã xóa câu trả lời <b>{0}</b>.<br />", Server.HtmlEncode(item.Title));
                }
                msg.ID = string.Join(",", ArrId);
                _answerDa.Save();
                msg.Message = stbMessage.ToString();
                break;

            case ActionType.Show:
                ltsAnswerItems = _answerDa.GetListByArrID(ArrId).Where(o => !o.IsShow).ToList();     //Chỉ lấy những đối tượng ko được hiển thị
                stbMessage     = new StringBuilder();
                foreach (var item in ltsAnswerItems)
                {
                    item.IsShow = true;
                    stbMessage.AppendFormat("Đã hiển thị câu trả lời <b>{0}</b>.<br />", Server.HtmlEncode(item.Title));
                }
                _answerDa.Save();
                msg.ID      = string.Join(",", ltsAnswerItems.Select(o => o.ID));
                msg.Message = stbMessage.ToString();
                break;

            case ActionType.Hide:
                ltsAnswerItems = _answerDa.GetListByArrID(ArrId).Where(o => o.IsShow).ToList();     //Chỉ lấy những đối tượng được hiển thị
                stbMessage     = new StringBuilder();
                foreach (var item in ltsAnswerItems)
                {
                    item.IsShow = false;
                    stbMessage.AppendFormat("Đã ẩn câu trả lời <b>{0}</b>.<br />", Server.HtmlEncode(item.Title));
                }
                _answerDa.Save();
                msg.ID      = string.Join(",", ltsAnswerItems.Select(o => o.ID));
                msg.Message = stbMessage.ToString();
                break;
            }

            if (string.IsNullOrEmpty(msg.Message))
            {
                msg.Message = "Không có hành động nào được thực hiện.";
                msg.Erros   = true;
            }

            return(Json(msg, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Actions()
        {
            var msg     = new JsonMessage();
            var product = new Shop_Product_Detail();
            List <Shop_Product_Detail> lstProduct;
            StringBuilder stbMessage;

            var lsttag    = Request["values-arr-tag"];
            var images    = Request["Value_Images"];
            var lstCate   = Request["Value_CategoryValues"];
            var lstimages = Request["Value_ImagesProducts"];

            switch (DoAction)
            {
            case ActionType.Add:
                try
                {
                    UpdateModel(product);
                    product.DateCreate = DateTime.Now.TotalSeconds();
                    product.IsDelete   = false;
                    //product.AgencyID = Utility.AgencyId;
                    product.IsShow = true;
                    //product.LanguageId = Fdisystem.LanguageId;
                    if (!string.IsNullOrEmpty(images))
                    {
                        product.PictureID = Convert.ToInt32(images);
                    }
                    if (!string.IsNullOrEmpty(lstCate))
                    {
                        product.Categories = _da.GetListCateByArrId(lstCate);
                    }
                    if (!string.IsNullOrEmpty(lstimages))
                    {
                        product.Gallery_Picture2 = _da.GetListPictureByArrId(lstimages);
                    }
                    if (string.IsNullOrEmpty(lsttag))
                    {
                        product.System_Tag = _da.GetListIntTagByArrId(lsttag);
                    }
                    _da.Add(product);
                    _da.Save();
                    msg = new JsonMessage
                    {
                        Erros   = false,
                        ID      = product.ID.ToString(),
                        Message = string.Format("Đã thêm mới sản phẩm: <b>{0}</b>", Server.HtmlEncode(product.Name))
                    };
                }
                catch (Exception)
                {
                }
                break;

            case ActionType.Edit:
                try
                {
                    product = _da.GetById(ArrId.FirstOrDefault());
                    UpdateModel(product);
                    product.Name = Convert.ToString(product.Name);
                    if (!string.IsNullOrEmpty(images))
                    {
                        product.PictureID = Convert.ToInt32(images);
                    }
                    product.Categories.Clear();
                    if (!string.IsNullOrEmpty(lstCate))
                    {
                        product.Categories = _da.GetListCateByArrId(lstCate);
                    }
                    product.Gallery_Picture2.Clear();
                    if (!string.IsNullOrEmpty(lstimages))
                    {
                        product.Gallery_Picture2 = _da.GetListPictureByArrId(lstimages);
                    }
                    product.System_Tag.Clear();
                    if (!string.IsNullOrEmpty(lsttag))
                    {
                        product.System_Tag = _da.GetListIntTagByArrId(lsttag);
                    }
                    _da.Save();
                    msg = new JsonMessage
                    {
                        Erros   = false,
                        ID      = product.ID.ToString(),
                        Message = string.Format("Đã cập nhật sản phẩm: <b>{0}</b>", Server.HtmlEncode(product.Name))
                    };
                }
                catch (Exception)
                {
                }
                break;

            case ActionType.Delete:
                lstProduct = _da.GetListProductDetailByArrId(ArrId);
                stbMessage = new StringBuilder();
                foreach (var item in lstProduct)
                {
                    item.IsDelete = true;
                    stbMessage.AppendFormat("Đã xóa <b>{0}</b>.<br />", Server.HtmlEncode(item.Name));
                }
                msg.ID = string.Join(",", ArrId);
                _da.Save();
                msg.Message = stbMessage.ToString();
                break;

            case ActionType.Show:
                lstProduct = _da.GetListProductDetailByArrId(ArrId);
                stbMessage = new StringBuilder();
                foreach (var item in lstProduct)
                {
                    item.IsShow = true;
                    stbMessage.AppendFormat("Đã hiển thị <b>{0}</b>.<br />", Server.HtmlEncode(item.Name));
                }
                _da.Save();
                msg.ID      = string.Join(",", lstProduct.Select(o => o.ID));
                msg.Message = stbMessage.ToString();
                break;

            case ActionType.Hide:
                lstProduct = _da.GetListProductDetailByArrId(ArrId);
                stbMessage = new StringBuilder();
                foreach (var item in lstProduct)
                {
                    item.IsShow = false;
                    stbMessage.AppendFormat("Đã ẩn <b>{0}</b>.<br />", Server.HtmlEncode(item.Name));
                }
                _da.Save();
                msg.ID      = string.Join(",", lstProduct.Select(o => o.ID));
                msg.Message = stbMessage.ToString();
                break;

            case ActionType.UserModule:
                var model = _da.GetProductById(ArrId.FirstOrDefault());
                product = _da.GetById(ArrId.FirstOrDefault());
                var list = new List <Shop_Product>();
                foreach (var item in model)
                {
                    var name = Request["Size_old" + item.ID];
                    if (string.IsNullOrEmpty(name))
                    {
                        list.Add(item);
                    }
                    else
                    {
                        item.SizeID = int.Parse(name);
                        //item.SizeID = ConvertUtil.ToInt32(Request["Size_old" + item.ID]);
                        //item.PriceNew = ConvertUtil.ToDecimal(Request["PriceNew_old" + item.ID]);
                        //item.PriceOld = ConvertUtil.ToDecimal(Request["PriceOld_old" + item.ID]);
                    }
                }
                foreach (var item in list)
                {
                    _da.DeleteProduct(item);
                }
                var stt = ConvertUtil.ToInt32(Request["do_stt"]);
                for (int i = 1; i <= stt; i++)
                {
                    var name = Request["Size_add_" + i];
                    if (!string.IsNullOrEmpty(name))
                    {
                        var obj = new Shop_Product()
                        {
                            ProductDetailID = product.ID,
                            //PriceNew = ConvertUtil.ToDecimal(Request["PriceNew_add_" + i]),
                            //PriceOld = ConvertUtil.ToDecimal(Request["PriceOld_add_" + i]),
                            SizeID = int.Parse(name),
                            //SizeID = ConvertUtil.ToInt32(Request["Size_add_" + i]),
                            IsShow   = true,
                            IsDelete = false,
                        };
                        _da.AddProduct(obj);
                    }
                }
                _da.Save();
                msg = new JsonMessage
                {
                    Erros   = false,
                    ID      = product.ID.ToString(),
                    Message = string.Format("Đã thêm mới sản phẩm: <b>{0}</b>", Server.HtmlEncode(product.Name))
                };
                break;
            }

            if (string.IsNullOrEmpty(msg.Message))
            {
                msg.Message = "Không có hành động nào được thực hiện.";
                msg.Erros   = true;
            }
            return(Json(msg, JsonRequestBehavior.AllowGet));
        }
Beispiel #14
0
 private static void JsonMessageSerialize(Utf8JsonWriter writer, JsonMessage value) => throw new NotImplementedException();
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            //context.Response.Write("Hello World");
            string action      = context.Request["action"];
            string SourceTable = "";

            if (context.Request["SourceTable"] != null)
            {
                SourceTable = context.Request["SourceTable"];
            }
            Guid ToId = new Guid();

            if (context.Request["ToId"] != null)
            {
                ToId = Guid.Parse(context.Request["ToId"]);
            }
            string ShowName = "";

            if (context.Request["ShowName"] != null)
            {
                ShowName = context.Request["ShowName"];
            }
            string      JsonMsg = "";
            JsonMessage jmsg    = new JsonMessage();

            switch (action)
            {
            case "addImg":    //上传文件
                #region
                string            FileIdSet = "";
                List <File_Image> listFile  = new List <File_Image>();
                bool     IsValid            = true;//检查只能为图片,仅小于100k可以上传
                string   messge             = "";
                string[] Types = { ".jpg", ".jpeg", ".gif", ".bmp", ".png", ".ico" };
                int      lenth = 1024 * 500;//一百k
                if (context.Request.Files.Count > 0)
                {
                    for (int i = 0; i < context.Request.Files.Count; i++)
                    {
                        HttpPostedFile hpFile = context.Request.Files[i];
                        if (!String.IsNullOrEmpty(hpFile.FileName))
                        {
                            string ext = System.IO.Path.GetExtension(hpFile.FileName);
                            if (!Types.Contains(ext.ToLower()))
                            {
                                IsValid = false;
                                messge  = "只能为图片类型";
                                break;
                            }
                            else if (hpFile.ContentLength > lenth)
                            {
                                IsValid = false;
                                messge  = "文件不能大于" + lenth / 1024 + "kB";
                                break;
                            }
                        }
                    }
                }
                if (context.Request.Files.Count > 0 && IsValid)
                {
                    for (int i = 0; i < context.Request.Files.Count; i++)
                    {
                        File_Image file = new File_Image();
                        file.Id = Guid.NewGuid();
                        if (context.Request["ToId"] == null)
                        {
                            file.ToId = file.Id;
                        }
                        else
                        {
                            file.ToId = ToId;
                        }
                        file.AddTime     = DateTime.Now;
                        file.UpdateTime  = DateTime.Now;
                        file.SourceTable = SourceTable;

                        file.ShowName = ShowName;
                        HttpPostedFile hpFile = context.Request.Files[i];
                        if (!String.IsNullOrEmpty(hpFile.FileName))
                        {
                            string ext = System.IO.Path.GetExtension(hpFile.FileName);
                            if (hpFile.ContentType != "image/jpeg" || hpFile.ContentType != "image/pjpeg")
                            {
                                file.FileType = "图片";
                                file.Suffix   = ext;
                                //给文件取随及名
                                Random ran = new Random();
                                file.FileName = hpFile.FileName.Substring(hpFile.FileName.LastIndexOf("\\") + 1);
                                if (String.IsNullOrEmpty(file.ShowName))
                                {
                                    file.ShowName = file.FileName;
                                }
                                int RandKey = ran.Next(100, 999);
                                file.FileName = DateTime.Now.ToString("yyyyMMddhhmmss") + "_" + RandKey + ext;
                                string fileName = file.FileName;
                                //保存文件
                                string path = context.Request.MapPath(fileName);

                                string uriString = System.Web.HttpContext.Current.Server.MapPath("~/Upload/").ToString();
                                file.Route     = "/Upload/";
                                file.FullRoute = "/Upload/" + path.Substring(path.LastIndexOf("\\") + 1);
                                hpFile.SaveAs(uriString + file.FullRoute.Substring(file.FullRoute.LastIndexOf("/") + 1));
                                //提示上传成功
                            }


                            /*添加一条信息;*/
                            object res = OPBiz.Add(file);
                            listFile.Add(file);
                            FileIdSet += file.FullRoute + ",";
                        }
                    }
                }
                if (IsValid)
                {
                    if (!String.IsNullOrEmpty(FileIdSet))
                    {
                        JsonMsg = JsonHelper.ToJson(new JsonMessage
                        {
                            Success = true,
                            Data    = JsonHelper.ToJson(listFile, true),
                            Message = "添加成功"
                        });
                    }
                    else
                    {
                        JsonMsg = JsonHelper.ToJson(new JsonMessage
                        {
                            Success = true,
                            Data    = "[]",
                            Message = "没有数据"
                        });
                    }
                }
                else
                {
                    JsonMsg = JsonHelper.ToJson(new JsonMessage
                    {
                        Success = false,
                        Data    = "[]",
                        Message = messge
                    });
                }

                context.Response.Write(JsonMsg);
                context.Response.End();

                #endregion
                break;

            case "addFile":    //上传文件
                #region
                string            FileIdSet2 = "";
                List <File_Image> listFile2  = new List <File_Image>();
                bool   IsValid2 = true;         //检查只能为图片,仅小于100k可以上传
                string messge2  = "";
                int    lenth2   = 1024 * 20000; //一百k
                if (context.Request.Files.Count > 0)
                {
                    for (int i = 0; i < context.Request.Files.Count; i++)
                    {
                        HttpPostedFile hpFile = context.Request.Files[i];
                        if (!String.IsNullOrEmpty(hpFile.FileName))
                        {
                            string ext = System.IO.Path.GetExtension(hpFile.FileName);

                            if (hpFile.ContentLength > lenth2)
                            {
                                IsValid = false;
                                messge2 = "文件不能大于" + lenth2 / 1024 + "kB";
                                break;
                            }
                        }
                    }
                }
                if (context.Request.Files.Count > 0 && IsValid2)
                {
                    for (int i = 0; i < context.Request.Files.Count; i++)
                    {
                        File_Image file = new File_Image();
                        file.Id = Guid.NewGuid();
                        if (context.Request["ToId"] == null)
                        {
                            file.ToId = file.Id;
                        }
                        else
                        {
                            file.ToId = ToId;
                        }
                        file.AddTime     = DateTime.Now;
                        file.UpdateTime  = DateTime.Now;
                        file.SourceTable = SourceTable;

                        file.ShowName = ShowName;
                        HttpPostedFile hpFile = context.Request.Files[i];
                        if (!String.IsNullOrEmpty(hpFile.FileName))
                        {
                            string ext = System.IO.Path.GetExtension(hpFile.FileName);
                            if (hpFile.ContentType != "image/jpeg" || hpFile.ContentType != "image/pjpeg")
                            {
                                file.FileType = "文件";
                                file.Suffix   = ext;
                                //给文件取随及名
                                Random ran = new Random();
                                file.FileName = hpFile.FileName.Substring(hpFile.FileName.LastIndexOf("\\") + 1);
                                if (String.IsNullOrEmpty(file.ShowName))
                                {
                                    file.ShowName = file.FileName;
                                }
                                int RandKey = ran.Next(100, 999);
                                file.FileName = DateTime.Now.ToString("yyyyMMddhhmmss") + "_" + RandKey + ext;
                                string fileName = file.FileName;
                                //保存文件
                                string path = context.Request.MapPath(fileName);

                                string uriString = System.Web.HttpContext.Current.Server.MapPath("~/Upload/file/").ToString();
                                file.Route     = "/Upload/file/";
                                file.FullRoute = "/Upload/file/" + path.Substring(path.LastIndexOf("\\") + 1);
                                hpFile.SaveAs(uriString + file.FullRoute.Substring(file.FullRoute.LastIndexOf("/") + 1));
                                //提示上传成功
                            }


                            /*添加一条信息;*/
                            object res = OPBiz.Add(file);
                            listFile2.Add(file);
                            FileIdSet2 += file.FullRoute + ",";
                        }
                    }
                }
                if (IsValid2)
                {
                    if (!String.IsNullOrEmpty(FileIdSet2))
                    {
                        JsonMsg = JsonHelper.ToJson(new JsonMessage
                        {
                            Success = true,
                            Data    = JsonHelper.ToJson(listFile2, true),
                            Message = "添加成功"
                        });
                    }
                    else
                    {
                        JsonMsg = JsonHelper.ToJson(new JsonMessage
                        {
                            Success = true,
                            Data    = "[]",
                            Message = "没有数据"
                        });
                    }
                }
                else
                {
                    JsonMsg = JsonHelper.ToJson(new JsonMessage
                    {
                        Success = false,
                        Data    = "[]",
                        Message = messge2
                    });
                }

                context.Response.Write(JsonMsg);
                context.Response.End();

                #endregion
                break;

            case "GetFileList":    //根据id集获取文件列表

                #region
                string id = context.Request["ToId"];
                if (!string.IsNullOrEmpty(id))
                {
                    var mql = File_ImageSet.SelectAll().Where(File_ImageSet.ToId.Equal(id));
                    List <File_Image> list = OPBiz.GetOwnList(mql);
                    context.Response.Write(JsonHelper.ToJson(list, true));
                }
                else
                {
                    context.Response.Write("[]");
                }
                context.Response.End();
                #endregion
                break;

            case "SaveToid":    //保存更改ToID

                #region

                string Tid   = context.Request["ToId"];
                string IdSet = context.Request["IdSet"];
                if (!string.IsNullOrEmpty(context.Request["ToId"]) && !string.IsNullOrEmpty(context.Request["IdSet"]))
                {
                    string sql = " update File_Image set ToId='" + Tid + "'  where Id in (" + IdSet + ")";
                    int    i   = OPBiz.ExecuteSqlWithNonQuery(sql);
                    if (i > 0)
                    {
                        jmsg.Success = true;
                        jmsg.Data    = i.ToString();
                        jmsg.Message = "上传成功";
                    }
                    else
                    {
                        jmsg.Success = false;
                        jmsg.Data    = "0";
                        jmsg.Message = "上传失败";
                    }
                }
                else
                {
                    jmsg.Success = false;
                    jmsg.Data    = "0";
                    jmsg.Message = "数据为空";
                }
                context.Response.Write(JsonHelper.ToJson(jmsg, true));
                context.Response.End();

                #endregion
                break;

            case "Delfile":    //删除文件

                #region


                if (!string.IsNullOrEmpty(context.Request["IdSet"]))
                {
                    string sql = " delete from  File_Image   where Id in (" + context.Request["IdSet"] + ")";
                    int    i   = OPBiz.ExecuteSqlWithNonQuery(sql);
                    if (i > 0)
                    {
                        jmsg.Success = true;
                        jmsg.Data    = i.ToString();
                        jmsg.Message = "删除成功";
                    }
                    else
                    {
                        jmsg.Success = false;
                        jmsg.Data    = "0";
                        jmsg.Message = "删除失败";
                    }
                }
                else
                {
                    jmsg.Success = false;
                    jmsg.Data    = "0";
                    jmsg.Message = "数据为空";
                }
                context.Response.Write(JsonHelper.ToJson(jmsg, true));
                context.Response.End();

                #endregion
                break;

            case "Download":
                #region
                if (!string.IsNullOrEmpty(context.Request["Url"]))
                {
                    // 检查请求下载文件的有效性
                    string filePath = System.Web.HttpContext.Current.Server.MapPath(context.Request["Url"]);
                    if (!System.IO.File.Exists(filePath))
                    {
                        throw new ArgumentException("无效文件,文件不存在!");
                    }

                    //WriteFile实现下载
                    string   fileName = context.Request["fileName"];  //客户端保存的文件名
                    FileInfo fileInfo = new FileInfo(filePath);
                    context.Response.Clear();
                    context.Response.ClearContent();
                    context.Response.ClearHeaders();
                    context.Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
                    context.Response.AddHeader("Content-Length", fileInfo.Length.ToString());
                    context.Response.AddHeader("Content-Transfer-Encoding", "binary");
                    context.Response.ContentType     = "application/octet-stream";
                    context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
                    context.Response.WriteFile(fileInfo.FullName);
                    context.Response.Flush();
                    context.Response.End();
                }
                #endregion

                break;
            }
        }
Beispiel #16
0
 public void SendMessageToServer(JsonMessage msg, TCPMessageHandler.CallbackDelegate cb)
 {
     views._mh.SendMessageToServer(msg, cb);
 }
        public ActionResult Actions()
        {
            var msg     = new JsonMessage();
            var picture = new Gallery_Picture();

            switch (DoAction)
            {
            case ActionType.Add:
                try
                {
                    UpdateModel(picture);
                    picture.LanguageId  = Fdisystem.LanguageId;
                    picture.DateCreated = DateTime.Now.TotalSeconds();
                    picture.CreateBy    = User.Identity.Name;
                    picture.UpdateBy    = User.Identity.Name;
                    picture.IsDeleted   = false;
                    picture.Type        = !string.IsNullOrEmpty(Request["Type"]) ? Convert.ToInt32(Request["Type"]) : 0;
                    picture.CategoryID  = !string.IsNullOrEmpty(Request["CategoryID"]) ? Convert.ToInt32(Request["CategoryID"]) : 0;
                    _pictureDa.Add(picture);
                    _pictureDa.Save();
                    msg = new JsonMessage
                    {
                        Erros   = false,
                        ID      = picture.ID.ToString(),
                        Message = string.Format("Đã thêm mới hình ảnh: <b>{0}</b>", Server.HtmlEncode(picture.Name))
                    };
                }
                catch (Exception ex)
                {
                    LogHelper.Instance.LogError(GetType(), ex);
                }

                break;

            case ActionType.Edit:
                try
                {
                    picture          = _pictureDa.GetById(ArrId.FirstOrDefault());
                    picture.UpdateBy = User.Identity.Name;
                    UpdateModel(picture);
                    picture.Type       = !string.IsNullOrEmpty(Request["Type"]) ? Convert.ToInt32(Request["Type"]) : 0;
                    picture.CategoryID = !string.IsNullOrEmpty(Request["CategoryID"]) ? Convert.ToInt32(Request["CategoryID"]) : 0;
                    _pictureDa.Save();
                    msg = new JsonMessage
                    {
                        Erros   = false,
                        ID      = picture.ID.ToString(),
                        Message = string.Format("Đã cập nhật hình ảnh: <b>{0}</b>", Server.HtmlEncode(picture.Name))
                    };
                }
                catch (Exception ex)
                {
                    LogHelper.Instance.LogError(GetType(), ex);
                }

                break;

            case ActionType.Delete:
                //ltsPictureItems = _pictureDa.GetListByArrId(ArrId);
                //stbMessage = new StringBuilder();
                //foreach (var item in ltsPictureItems)
                //{
                //    try
                //    {
                //        item.IsDeleted = true;
                //        stbMessage.AppendFormat("Đã xóa hình ảnh <b>{0}</b>.<br />", Server.HtmlEncode(item.Name));
                //    }
                //    catch (Exception ex)
                //    {
                //        LogHelper.Instance.LogError(GetType(), ex);
                //    }

                //}
                //msg.ID = string.Join(",", ArrId);
                //_pictureDa.Save();
                //msg.Message = stbMessage.ToString();
                break;

            case ActionType.Show:
                //ltsPictureItems = _pictureDa.GetListByArrId(ArrId).Where(o => o.IsShow == false).ToList();
                //stbMessage = new StringBuilder();
                //foreach (var item in ltsPictureItems)
                //{
                //    try
                //    {
                //        item.IsShow = true;
                //        stbMessage.AppendFormat("Đã hiển thị hình ảnh <b>{0}</b>.<br />", Server.HtmlEncode(item.Name));
                //    }
                //    catch (Exception ex)
                //    {
                //        LogHelper.Instance.LogError(GetType(), ex);
                //    }

                //}
                //_pictureDa.Save();
                //msg.ID = string.Join(",", ltsPictureItems.Select(o => o.ID));
                //msg.Message = stbMessage.ToString();
                break;

            case ActionType.Hide:
                //ltsPictureItems = _pictureDa.GetListByArrId(ArrId).Where(o => o.IsShow == true).ToList();
                //stbMessage = new StringBuilder();
                //foreach (var item in ltsPictureItems)
                //{
                //    try
                //    {
                //        item.IsShow = false;
                //        stbMessage.AppendFormat("Đã ẩn hình ảnh <b>{0}</b>.<br />", Server.HtmlEncode(item.Name));
                //    }
                //    catch (Exception ex)
                //    {
                //        LogHelper.Instance.LogError(GetType(), ex);
                //    }

                //}
                //_pictureDa.Save();
                //msg.ID = string.Join(",", ltsPictureItems.Select(o => o.ID));
                //msg.Message = stbMessage.ToString();
                break;
            }

            if (string.IsNullOrEmpty(msg.Message))
            {
                msg.Message = "Không có hành động nào được thực hiện.";
                msg.Erros   = true;
            }

            return(Json(msg, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Actions()
        {
            var msg = new JsonMessage();
            var systemMessageTemplate = new System_MessageTemplate();
            List <System_MessageTemplate> ltsSystemMessageTemplate;
            StringBuilder stbMessage;

            switch (DoAction)
            {
            case ActionType.Add:
                try
                {
                    UpdateModel(systemMessageTemplate);
                    systemMessageTemplate.IsDeleted = false;
                    _systemMessageTemplateDa.Add(systemMessageTemplate);
                    _systemMessageTemplateDa.Save();
                    msg = new JsonMessage
                    {
                        Erros   = false,
                        ID      = systemMessageTemplate.ID.ToString(),
                        Message = string.Format("Đã thêm mới hành động: <b>{0}</b>", Server.HtmlEncode(systemMessageTemplate.Name))
                    };
                }
                catch (Exception ex)
                {
                    LogHelper.Instance.LogError(GetType(), ex);
                }
                break;

            case ActionType.Edit:
                try
                {
                    systemMessageTemplate = _systemMessageTemplateDa.GetById(ArrId.FirstOrDefault());
                    UpdateModel(systemMessageTemplate);
                    systemMessageTemplate.IsDeleted = false;
                    _systemMessageTemplateDa.Save();

                    msg = new JsonMessage
                    {
                        Erros   = false,
                        ID      = systemMessageTemplate.ID.ToString(),
                        Message = string.Format("Đã cập nhật: <b>{0}</b>", Server.HtmlEncode(systemMessageTemplate.Name))
                    };
                }
                catch (Exception ex)
                {
                    LogHelper.Instance.LogError(GetType(), ex);
                }
                break;

            case ActionType.Delete:
                ltsSystemMessageTemplate = _systemMessageTemplateDa.GetListByArrID(ArrId);
                stbMessage = new StringBuilder();
                foreach (var item in ltsSystemMessageTemplate)
                {
                    _systemMessageTemplateDa.Delete(item);
                    stbMessage.AppendFormat("Đã xóa <b>{0}</b>.<br />", Server.HtmlEncode(item.Name));
                }
                msg.ID = string.Join(",", ArrId);
                _systemMessageTemplateDa.Save();
                msg.Message = stbMessage.ToString();
                break;

            case ActionType.Show:
                ltsSystemMessageTemplate = _systemMessageTemplateDa.GetListByArrID(ArrId).Where(o => o.IsActive != null && o.IsActive == false && o.IsDeleted == false).ToList();     //Chỉ lấy những đối tượng ko được hiển thị
                stbMessage = new StringBuilder();
                foreach (var item in ltsSystemMessageTemplate)
                {
                    item.IsActive = true;
                    stbMessage.AppendFormat("Đã hiển thị <b>{0}</b>.<br />", Server.HtmlEncode(item.Name));
                }
                _systemMessageTemplateDa.Save();
                msg.ID      = string.Join(",", ltsSystemMessageTemplate.Select(o => o.ID));
                msg.Message = stbMessage.ToString();
                break;

            case ActionType.Hide:
                ltsSystemMessageTemplate = _systemMessageTemplateDa.GetListByArrID(ArrId).Where(o => o.IsActive != null && o.IsActive == true && o.IsDeleted == false).ToList();     //Chỉ lấy những đối tượng được hiển thị
                stbMessage = new StringBuilder();
                foreach (var item in ltsSystemMessageTemplate)
                {
                    item.IsActive = false;
                    stbMessage.AppendFormat("Đã ẩn <b>{0}</b>.<br />", Server.HtmlEncode(item.Name));
                }
                _systemMessageTemplateDa.Save();
                msg.ID      = string.Join(",", ltsSystemMessageTemplate.Select(o => o.ID));
                msg.Message = stbMessage.ToString();
                break;
            }

            if (string.IsNullOrEmpty(msg.Message))
            {
                msg.Message = "Không có hành động nào được thực hiện.";
                msg.Erros   = true;
            }
            return(Json(msg, JsonRequestBehavior.AllowGet));
        }
Beispiel #19
0
 public void SendMessageToServer(JsonMessage msg)
 {
     views._mh.SendMessageToServer(msg);
 }
Beispiel #20
0
 // Static
 public new static JsonQuitResponseMessage Parse(string value)
 {
     return(JsonMessage.Parse <JsonQuitResponseMessage>(value));
 }
Beispiel #21
0
        public ActionResult AddStorage(string key, string json, Guid userId)
        {
            var msg = new JsonMessage(false, "Cập nhật dữ liệu thành công.");

            try
            {
                if (key != Keyapi)
                {
                    return(Json(0, JsonRequestBehavior.AllowGet));
                }
                var ncc           = _da.GetbyId(ItemId);
                var totalquantity = 0;
                var stt           = ConvertUtil.ToInt32(Request["do_stt"]);
                for (var i = 1; i <= stt; i++)
                {
                    var name = Request["SalaryType_" + i];
                    if (!string.IsNullOrEmpty(name))
                    {
                        var quantity = ConvertUtil.ToInt32(Request["QuantityActive_add_" + i] ?? "0");
                        var price    = ConvertUtil.ToDecimal(Request["Price_add_" + i] ?? "0");
                        var supId    = ConvertUtil.ToInt32(Request["DNSupplie_" + i] ?? "0");
                        var today    = ConvertUtil.ToDecimal(Request["today"] ?? "0");
                        var hours    = ConvertUtil.ToInt32(Request["hourstoday"] ?? "0");
                        var cateId   = ConvertUtil.ToInt32(Request["CateId"] ?? "0");
                        var hourI    = Request["Hours_add_" + i] ?? "0";
                        var dateI    = ConvertUtil.ToDateTime(Request["Date_add_" + i]).TotalSeconds();
                        totalquantity += quantity;
                        var obj = new StorageProduct
                        {
                            UserID      = userId,
                            AgencyId    = Agencyid(),
                            IsDelete    = false,
                            DateCreated = DateTime.Now.TotalSeconds(),
                            Code        = DateTime.Now.Millisecond.ToString(),
                            Quantity    = quantity,
                            Price       = price,
                            SupID       = supId,
                            Today       = today,
                            Hour        = hours,
                            TotalID     = ncc.ID,
                            CateID      = cateId,
                            DateImport  = dateI,
                            HoursImport = int.Parse(hourI)
                        };
                        _da.AddStora(obj);
                    }
                }
                if (totalquantity > (ncc.Quantity - ncc.QuantityOut))
                {
                    msg = new JsonMessage
                    {
                        Erros   = true,
                        Message = "Bạn đã xuất quá số lượng thực tế.!"
                    };
                    return(Json(msg, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    ncc.QuantityOut += totalquantity;
                    _da.Save();
                }
            }
            catch (Exception ex)
            {
                msg.Erros   = true;
                msg.Message = "Dữ liệu chưa được cập nhật.";
                Log2File.LogExceptionToFile(ex);
            }
            return(Json(msg, JsonRequestBehavior.AllowGet));
        }
Beispiel #22
0
        public ActionResult Actions()
        {
            var msg       = new JsonMessage();
            var googleMap = new GoogleMap();
            List <GoogleMap> lstGoogleMaps;
            StringBuilder    stbMessage;

            switch (DoAction)
            {
            case ActionType.Add:
                try
                {
                    UpdateModel(googleMap);
                    googleMap.LanguageId = Fdisystem.LanguageId;
                    if (!string.IsNullOrEmpty(Request["DistrictID"]))
                    {
                        googleMap.DistrictID = Convert.ToInt32(Request["DistrictID"]);
                    }
                    _googleMapDa.Add(googleMap);
                    _googleMapDa.Save();
                    msg = new JsonMessage
                    {
                        Erros   = false,
                        ID      = googleMap.ID.ToString(),
                        Message = string.Format("Đã thêm mới hành động: <b>{0}</b>", Server.HtmlEncode(googleMap.Name))
                    };
                }
                catch (Exception ex)
                {
                    LogHelper.Instance.LogError(GetType(), ex);
                }
                break;

            case ActionType.Edit:
                try
                {
                    googleMap = _googleMapDa.GetById(ArrId.FirstOrDefault());
                    UpdateModel(googleMap);
                    if (!string.IsNullOrEmpty(Request["DistrictID"]))
                    {
                        googleMap.DistrictID = Convert.ToInt32(Request["DistrictID"]);
                    }
                    _googleMapDa.Save();

                    msg = new JsonMessage
                    {
                        Erros   = false,
                        ID      = googleMap.ID.ToString(),
                        Message = string.Format("Đã cập nhật: <b>{0}</b>", Server.HtmlEncode(googleMap.Name))
                    };
                }
                catch (Exception ex)
                {
                    LogHelper.Instance.LogError(GetType(), ex);
                }
                break;

            case ActionType.Delete:
                lstGoogleMaps = _googleMapDa.GetListByArrId(ArrId);
                stbMessage    = new StringBuilder();
                foreach (var item in lstGoogleMaps)
                {
                    _googleMapDa.Delete(item);
                    stbMessage.AppendFormat("Đã xóa <b>{0}</b>.<br />", Server.HtmlEncode(item.Name));
                }
                msg.ID = string.Join(",", ArrId);
                _googleMapDa.Save();
                msg.Message = stbMessage.ToString();
                break;

            case ActionType.Show:
                lstGoogleMaps = _googleMapDa.GetListByArrId(ArrId).Where(o => o.IsShow != null && !o.IsShow.Value).ToList();
                stbMessage    = new StringBuilder();
                foreach (var item in lstGoogleMaps)
                {
                    item.IsShow = true;
                    stbMessage.AppendFormat("Đã hiển thị <b>{0}</b>.<br />", Server.HtmlEncode(item.Name));
                }
                _googleMapDa.Save();
                msg.ID      = string.Join(",", lstGoogleMaps.Select(o => o.ID));
                msg.Message = stbMessage.ToString();
                break;

            case ActionType.Hide:
                lstGoogleMaps = _googleMapDa.GetListByArrId(ArrId).Where(o => o.IsShow != null && o.IsShow.Value).ToList();
                stbMessage    = new StringBuilder();
                foreach (var item in lstGoogleMaps)
                {
                    item.IsShow = false;
                    stbMessage.AppendFormat("Đã ẩn <b>{0}</b>.<br />", Server.HtmlEncode(item.Name));
                }
                _googleMapDa.Save();
                msg.ID      = string.Join(",", lstGoogleMaps.Select(o => o.ID));
                msg.Message = stbMessage.ToString();
                break;
            }

            if (string.IsNullOrEmpty(msg.Message))
            {
                msg.Message = "Không có hành động nào được thực hiện.";
                msg.Erros   = true;
            }

            return(Json(msg, JsonRequestBehavior.AllowGet));
        }
Beispiel #23
0
        public void WriteJsonMessage(JsonMessage message)
        {
            if (message.Error != null)
            {
                var error = new ErrorRecord(new Exception(message.Error.Message), null, ErrorCategory.OperationStopped, null);
                _cmdlet.WriteError(error);
            }
            else if (message.Progress != null)
            {
                var id = message.ID ?? "";
                int activity;
                if (!_idToActivity.TryGetValue(id, out activity))
                {
                    activity = _nextActivity;
                    _nextActivity++;
                    _idToActivity.Add(id, activity);
                }

                var activityName = new StringBuilder(id);
                if (activityName.Length == 0)
                {
                    activityName.Append("Operation");
                }

                if (message.From != null)
                {
                    activityName.AppendFormat("(from {0})", message.From);
                }

                var record = new ProgressRecord(activity, activityName.ToString(), message.Status ?? "Processing");

                var progress = message.Progress;
                if (progress.Total > 0)
                {
                    record.PercentComplete = (int)(progress.Current * 100 / progress.Total);
                }

                if (progress.Current > 0)
                {
                    record.CurrentOperation = string.Format(" ({0} bytes)", progress.Current);
                }

                _cmdlet.WriteProgress(record);
            }
            else
            {
                var info = new StringBuilder();
                if (message.ID != null)
                {
                    info.Append(message.ID);
                    info.Append(": ");
                }

                if (message.From != null)
                {
                    info.AppendFormat("(from {0})", message.From);
                }

                var infoRecord = new HostInformationMessage();
                if (message.Stream != null)
                {
                    info.Append(message.Stream);
                    infoRecord.NoNewLine = true;
                }
                else
                {
                    info.Append(message.Status);
                }

                infoRecord.Message = info.ToString();
                _cmdlet.WriteInformation(infoRecord, new string[] { "PSHOST" });
            }
        }
        public ActionResult AjaxFormPictureSubmit()
        {
            var date = DateTime.Now;
            var msg  = new JsonMessage {
                Erros = false
            };
            var intTotalFile = Convert.ToInt32(Request["NumberOfImage"]);
            var folder       = date.Year + "\\" + date.Month + "\\" + date.Day + "\\";
            var fileinsert   = date.Year + "/" + date.Month + "/" + date.Day + "/";
            var folderinsert = fileinsert;

            for (var idx = 0; idx < intTotalFile; idx++)
            {
                var fileNameLocal = Request["ImageFile_" + idx + ""];
                var file          = fileNameLocal.Split('.');
                var nameslug      = FomatString.Slug(file[0]);
                var fileName      = nameslug + "-" + date.ToString("HHmmss") + "." + file[1];
                if (!nameslug.Contains(ConfigData.WebTitle))
                {
                    fileName = ConfigData.WebTitle + nameslug + "-" + date.ToString("HHmmss") + "." + file[1];
                }

                var fileTemp    = nameslug + "." + file[1];
                var imageSource = Image.FromFile(ConfigData.TempFolder + fileTemp);
                var checkfolder = false;
                if (Request["ckImage_" + (int)FolderImage.Originals] != null)
                {
                    checkfolder = true;
                    ImageProcess.CreateForder(ConfigData.OriginalFolder); // tạo forder Năm / Tháng / Ngày
                    if (imageSource.Width > ConfigData.ImageFullHdFile.Width)
                    {
                        var image = ImageProcess.ResizeImage(imageSource, ConfigData.ImageFullHdFile);
                        ImageProcess.SaveJpeg(ConfigData.OriginalFolder + folder + fileName, new Bitmap(image), 92L); // Save file Original
                    }
                    else
                    {
                        System.IO.File.Copy(ConfigData.TempFolder + fileTemp, ConfigData.OriginalFolder + folder + fileName);
                    }
                    folderinsert = "Originals/" + fileinsert;
                }

                if (Request["ckImage_" + (int)FolderImage.Images] != null)
                {
                    checkfolder = true;
                    ImageProcess.CreateForder(ConfigData.ImageFolder); // tạo forder Năm / Tháng / Ngày
                    if (imageSource.Width > ConfigData.ImageHdFile.Width)
                    {
                        var image = ImageProcess.ResizeImage(imageSource, ConfigData.ImageHdFile);
                        ImageProcess.SaveJpeg(ConfigData.ImageFolder + folder + fileName, new Bitmap(image), 92L); // Save file Images
                    }
                    else
                    {
                        System.IO.File.Copy(ConfigData.TempFolder + fileTemp, ConfigData.ImageFolder + folder + fileName);
                    }
                    folderinsert = "Images/" + fileinsert;
                }

                //Resize ảnh 640
                if (Request["ckImage_" + (int)FolderImage.Mediums] != null)
                {
                    checkfolder = true;
                    ImageProcess.CreateForder(ConfigData.ImageUploadMediumFolder); // tạo forder Năm / Tháng / Ngày
                    if (imageSource.Width > ConfigData.ImageMediumFile.Width)
                    {
                        var image = ImageProcess.ResizeImage(imageSource, ConfigData.ImageFullHdFile);
                        ImageProcess.SaveJpeg(ConfigData.ImageUploadMediumFolder + folder + fileName, new Bitmap(image), 92L); // Save file Medium
                    }
                    else
                    {
                        System.IO.File.Copy(ConfigData.TempFolder + fileTemp, ConfigData.ImageUploadMediumFolder + folder + fileName);
                    }
                    folderinsert = "Mediums/" + fileinsert;
                }

                if (!checkfolder)
                {
                    folderinsert = "Thumbs/" + fileinsert;
                }

                if (Request["ckImage_" + (int)FolderImage.Thumbs] != null)
                {
                    ImageProcess.CreateForder(ConfigData.ThumbsFolder);
                }

                if (imageSource.Width < ConfigData.ImageThumbsSize.Width)
                {
                    ImageProcess.SaveJpeg(ConfigData.ThumbsFolder + folder + fileName, new Bitmap(imageSource), 92L); // Save file Thumbs
                }
                else
                {
                    imageSource = ImageProcess.ResizeImage(imageSource, ConfigData.ImageThumbsSize);
                    ImageProcess.SaveJpeg(ConfigData.ThumbsFolder + folder + fileName, new Bitmap(imageSource), 92L); // Save file Thumbs
                }
                imageSource.Dispose();
                //Lấy thông tin cần thiết
                var picture = new Gallery_Picture
                {
                    Type = !string.IsNullOrEmpty(Request["type"]) ? Convert.ToInt32(Request["type"]) : 0,
                    //CategoryID =
                    //    !string.IsNullOrEmpty(Request["CategoryID"]) ? Convert.ToInt32(Request["CategoryID"]) : 1,
                    LanguageId  = Fdisystem.LanguageId,
                    DateCreated = date.TotalSeconds(),
                    Folder      = folderinsert,
                    Name        = Request["ImageName_" + idx],
                    IsShow      = true,
                    Url         = fileName,
                    IsDeleted   = false,
                    CreateBy    = User.Identity.Name,
                    UpdateBy    = User.Identity.Name
                };
                _pictureDa.Add(picture);
                msg.Message += string.Format("Đã thêm hình ảnh: <b>{0}</b><br/>", picture.Name);
            }
            _pictureDa.Save();
            return(Json(msg, JsonRequestBehavior.AllowGet));
        }
Beispiel #25
0
        public string Get(Para para)
        {
            //var ipAddress = HttpContext.GetUserIp();
            //var browser = HttpContext.GetUserBrowser();
            JsonMessage msg = new JsonMessage();

            if (!string.IsNullOrEmpty(para.CrsCode))
            {
                if (!string.IsNullOrEmpty(para.CameraOne)) //相机一开||关
                {
                    msg = _ctl.CameraOne(para.CrsCode, para.CameraOne);
                }
                if (!string.IsNullOrEmpty(para.CameraTwo))//相机二开||关
                {
                    msg = _ctl.CameraTwo(para.CrsCode, para.CameraTwo);
                }
                if (!string.IsNullOrEmpty(para.CameraThree))//相机三开||关
                {
                    msg = _ctl.CameraThree(para.CrsCode, para.CameraThree);
                }
                if (!string.IsNullOrEmpty(para.Fot))//光端机重启
                {
                    msg = _ctl.Fot(para.CrsCode, para.Fot);
                }
                if (!string.IsNullOrEmpty(para.Router))//路由器重启
                {
                    msg = _ctl.Router(para.CrsCode, para.Router);
                }
                if (!string.IsNullOrEmpty(para.Fan))//风扇开||关
                {
                    msg = _ctl.Fan(para.CrsCode, para.Fan);
                }
                if (!string.IsNullOrEmpty(para.Acb))//空开开||关
                {
                    msg = _ctl.Acb(para.CrsCode, para.Acb);
                }
                if (!string.IsNullOrEmpty(para.CloseAlarm))//报警信息开||关
                {
                    msg = _ctl.CloseAlarm(para.CrsCode, para.CloseAlarm);
                }
                if (!string.IsNullOrEmpty(para.CoolingTemp))//设置冷却温度
                {
                    msg = _ctl.CoolingTemp(para.CrsCode, para.CoolingTemp);
                }
                if (!string.IsNullOrEmpty(para.AlarmTemp))//设置报警温度
                {
                    msg = _ctl.AlarmTemp(para.CrsCode, para.AlarmTemp);
                }
                if (!string.IsNullOrEmpty(para.SwitchOnSum))//设置空开合闸次数
                {
                    msg = _ctl.SwitchOnSum(para.CrsCode, para.SwitchOnSum);
                }
                if (!string.IsNullOrEmpty(para.SwitchInt))//设置空开合闸间隔
                {
                    msg = _ctl.SwitchInt(para.CrsCode, para.SwitchInt);
                }
                if (!string.IsNullOrEmpty(para.AliveTime))//设置通信链接时间
                {
                    msg = _ctl.AliveTime(para.CrsCode, para.AliveTime);
                }
                if (!string.IsNullOrEmpty(para.ThresholdVoltage))//设置电池合闸门限电压
                {
                    msg = _ctl.ThresholdVoltage(para.CrsCode, para.ThresholdVoltage);
                }
            }
            else
            {
                msg = new JsonMessage()
                {
                    Title = "CrsCode参数不能为空", Message = "请检查参数是否正确", Success = false
                };
            }
            return(msg.ToJson());
        }
        public ActionResult Actions()
        {
            var msg = new JsonMessage {
                Erros = false, Message = "Cập nhật dữ liệu thành công !"
            };
            var url = Request.Form.ToString();

            url = HttpUtility.UrlDecode(url);
            var lstFile     = Request["lstFile"];
            var lstDocument = new List <FilesItem>();

            switch (DoAction)
            {
            case ActionType.Add:
                if (!string.IsNullOrEmpty(lstFile))
                {
                    lstDocument = Utility.UploadDocument(lstFile);
                }
                var jsonAdd = new JavaScriptSerializer().Serialize(lstDocument);
                var json1   = _documentFilesApi.AddList(jsonAdd);
                if (_documentApi.Add(string.Join(",", json1), url) == 0)
                {
                    msg.Erros   = true;
                    msg.Message = "Có lỗi xảy ra!";
                }
                break;

            case ActionType.Edit:
                if (!string.IsNullOrEmpty(lstFile))
                {
                    lstDocument = Utility.UploadDocument(lstFile);
                }
                var jsonUpdate = new JavaScriptSerializer().Serialize(lstDocument);
                var json2      = _documentFilesApi.AddList(jsonUpdate);
                if (_documentApi.Update(string.Join(",", json2), url) == 0)
                {
                    msg.Erros   = true;
                    msg.Message = "Có lỗi xảy ra!";
                }
                break;

            case ActionType.Delete:
                var lst1 = string.Join(",", ArrId);
                _documentApi.Delete(lst1, UserItem.UserName);
                msg.Message = "Cập nhật thành công.";
                break;

            case ActionType.Active:
                var lstArrId = string.Join(",", ArrId);
                if (_documentApi.Active(lstArrId, UserItem.UserId) == 0)
                {
                    msg.Erros   = true;
                    msg.Message = "Có lỗi xảy ra.";
                }
                break;
            }
            if (string.IsNullOrEmpty(msg.Message))
            {
                msg.Message = "Không có hành động nào được thực hiện.";
                msg.Erros   = true;
            }

            return(Json(msg, JsonRequestBehavior.AllowGet));
        }
Beispiel #27
0
        public ActionResult Actions()
        {
            var msg    = new JsonMessage();
            var module = new DN_Module();
            List <DN_Module> ltsModuleItems;
            StringBuilder    stbMessage;
            var list = Request["GroupId"];

            switch (DoAction)
            {
            case ActionType.Add:
                try
                {
                    UpdateModel(module);
                    module.IsDelete = false;
                    _moduleDa.Add(module);
                    module.ST_Group = _moduleDa.ListST_GroupByArrID(FDIUtils.StringToListInt(list));
                    _moduleDa.Save();
                    if (module.IsAll == true)
                    {
                        _moduleDa.AddItemByIAll(module.ID, list);
                    }
                    msg = new JsonMessage
                    {
                        Erros   = false,
                        ID      = module.ID.ToString(),
                        Message = string.Format("Đã thêm mới: <b>{0}</b>", Server.HtmlEncode(module.NameModule))
                    };
                }
                catch (Exception ex)
                {
                    LogHelper.Instance.LogError(GetType(), ex);
                }
                break;

            case ActionType.Edit:
                try
                {
                    module = _moduleDa.GetById(ArrId.FirstOrDefault());
                    UpdateModel(module);
                    module.ST_Group.Clear();
                    module.ST_Group = _moduleDa.ListST_GroupByArrID(FDIUtils.StringToListInt(list));
                    _moduleDa.Save();
                    if (module.IsAll == true)
                    {
                        _moduleDa.AddItemByIAll(module.ID, list);
                    }
                    else
                    {
                        _moduleDa.DeleteItemByIAll(module.ID, list);
                    }
                    msg = new JsonMessage
                    {
                        Erros   = false,
                        ID      = module.ID.ToString(),
                        Message = string.Format("Đã cập nhật : <b>{0}</b>", Server.HtmlEncode(module.NameModule))
                    };
                }
                catch (Exception ex)
                {
                    LogHelper.Instance.LogError(GetType(), ex);
                }
                break;


            case ActionType.Delete:
                ltsModuleItems = _moduleDa.GetListByArrID(ArrId);
                stbMessage     = new StringBuilder();
                foreach (var item in ltsModuleItems)
                {
                    item.IsDelete = true;
                    stbMessage.AppendFormat("Đã xóa  <b>{0}</b>.<br />", Server.HtmlEncode(item.NameModule));
                }
                msg.ID = string.Join(",", ArrId);
                _moduleDa.Save();
                msg.Message = stbMessage.ToString();
                break;

            case ActionType.Show:
                ltsModuleItems = _moduleDa.GetListByArrID(ArrId).Where(o => o.IsShow != true).ToList();     //Chỉ lấy những đối tượng ko được hiển thị
                stbMessage     = new StringBuilder();
                foreach (var item in ltsModuleItems)
                {
                    item.IsShow = true;
                    stbMessage.AppendFormat("Đã hiển thị <b>{0}</b>.<br />", Server.HtmlEncode(item.NameModule));
                }
                _moduleDa.Save();
                msg.ID      = string.Join(",", ltsModuleItems.Select(o => o.ID));
                msg.Message = stbMessage.ToString();
                break;

            case ActionType.Hide:
                ltsModuleItems = _moduleDa.GetListByArrID(ArrId).Where(o => o.IsShow == true).ToList();     //Chỉ lấy những đối tượng được hiển thị
                stbMessage     = new StringBuilder();
                foreach (var item in ltsModuleItems)
                {
                    item.IsShow = false;
                    stbMessage.AppendFormat("Đã ẩn <b>{0}</b>.<br />", Server.HtmlEncode(item.NameModule));
                }
                _moduleDa.Save();
                msg.ID      = string.Join(",", ltsModuleItems.Select(o => o.ID));
                msg.Message = stbMessage.ToString();
                break;

            case ActionType.Order:
                if (!string.IsNullOrEmpty(Request["OrderValues"]))
                {
                    var orderValues = Request["OrderValues"];
                    if (orderValues.Contains("|"))
                    {
                        foreach (var keyValue in orderValues.Split('|'))
                        {
                            if (keyValue.Contains("_"))
                            {
                                var tempCategory = _moduleDa.GetById(Convert.ToInt32(keyValue.Split('_')[0]));
                                tempCategory.Ord = Convert.ToInt32(keyValue.Split('_')[1]);
                                _moduleDa.Save();
                            }
                        }
                    }
                    msg.ID      = string.Join(",", orderValues);
                    msg.Message = "Đã cập nhật lại thứ tự ";
                }
                break;
            }

            if (string.IsNullOrEmpty(msg.Message))
            {
                msg.Message = "Không có hành động nào được thực hiện.";
                msg.Erros   = true;
            }

            return(Json(msg, JsonRequestBehavior.AllowGet));
        }
Beispiel #28
0
        public static JsonType DeserializeMessage(string message, out JsonMessage parse_msg)
        {
            parse_msg = (JsonMessage)JsonUtil.Deserialize<JsonMessage>(message);

            JsonType type = JsonType.None;
            switch (parse_msg.key.ToLower())
            {
                // Fuction
                case "setting":
                    type = JsonType.Setting;
                    break;
                case "title":
                    type = JsonType.Title;
                    break;
                case "login":
                    type = JsonType.Login;
                    break;
                case "logout":
                    type = JsonType.Logout;
                    break;
                case "chat":
                    type = JsonType.Chat;
                    break;
                case "im":
                    type = JsonType.IM;
                    break;
                case "sit":
                    type = JsonType.Sit;
                    break;
                case "standup":
                    type = JsonType.Standup;
                    break;
                case "touch":
                    type = JsonType.Touch;
                    break;
                case "teleportfromlandmark":
                    type = JsonType.TeleportFromLandmark;
                    break;
                case "teleportfromsimname":
                    type = JsonType.TeleportFromSimName;
                    break;
                case "teleportfromsimname2":
                    type = JsonType.TeleportFromSimName2;
                    break;
                case "movement":
                    type = JsonType.Movement;
                    break;
                case "agenthead":
                    type = JsonType.AgentHead;
                    break;
                case "requestimage":
                    type = JsonType.RequestImage;
                    break;
                case "requestobjectinfo":
                    type = JsonType.RequestObjectInfo;
                    break;
                case "requestpathinfo":
                    type = JsonType.RequestPathInfo;
                    break;

                // Event
                case "state":
                    type = JsonType.State;
                    break;
                case "agentinfo":
                    type = JsonType.AgentInfo;
                    break;
                case "agentanimationlist":
                    type = JsonType.AgentAnimationList;
                    break;
                case "chatreceived":
                    type = JsonType.ChatReceived;
                    break;
                case "imreceived":
                    type = JsonType.IMReceived;
                    break;
                case "clicked":
                    type = JsonType.Clicked;
                    break;
                case "objectinfo":
                    type = JsonType.ObjectInfo;
                    break;
                case "pathinfo":
                    type = JsonType.PathInfo;
                    break;

                // Inside
                case "stateinside":
                    type = JsonType.StateInside;
                    break;
                case "objectupdated":
                    type = JsonType.ObjectUpdated;
                    break;
            }

            return type;
        }
        public ActionResult Actions()
        {
            var msg      = new JsonMessage();
            var question = new FAQ_Question();
            List <FAQ_Question> ltsQuestionItems;
            StringBuilder       stbMessage;

            if (Request["do"] != null && Request["do"] == "reply")
            {
                try
                {
                    question = _questionDa.GetById(ArrId.FirstOrDefault());
                    var content = question.Content;
                    UpdateModel(question);
                    if (question.FAQ_Answer != null && question.FAQ_Answer.FirstOrDefault() != null)
                    {
                        var answer = question.FAQ_Answer.FirstOrDefault();
                        if (answer != null)
                        {
                            answer.Content     = question.Content;
                            question.Content   = content;
                            answer.DateCreated = DateTime.Now;
                            answer.IsShow      = true;
                        }
                    }
                    else
                    {
                        var faqAnswer = new FAQ_Answer {
                            Content = question.Content
                        };
                        question.Content      = content;
                        faqAnswer.DateCreated = DateTime.Now;
                        faqAnswer.IsShow      = true;

                        if (question.FAQ_Answer != null)
                        {
                            question.FAQ_Answer.Add(faqAnswer);
                        }
                    }

                    _questionDa.Save();
                    msg = new JsonMessage
                    {
                        Erros   = false,
                        Message = "Đã trả lời câu hỏi"
                    };
                }
                catch (Exception)
                {
                }
                return(Json(msg, JsonRequestBehavior.AllowGet));
            }
            switch (DoAction)
            {
            case ActionType.Add:
                UpdateModel(question);
                question.TitleAscii  = FDIUtils.Slug(question.Title);
                question.DateCreated = DateTime.Now;
                question.LanguageId  = Fdisystem.LanguageId;
                _questionDa.Add(question);
                _questionDa.Save();
                msg = new JsonMessage
                {
                    Erros   = false,
                    ID      = question.ID.ToString(),
                    Message = string.Format("Đã thêm mới câu hỏi: <b>{0}</b>", Server.HtmlEncode(question.Title))
                };
                break;

            case ActionType.Edit:
                question = _questionDa.GetById(ArrId.FirstOrDefault());
                UpdateModel(question);
                _questionDa.Save();
                msg = new JsonMessage
                {
                    Erros   = false,
                    ID      = question.ID.ToString(),
                    Message = string.Format("Đã cập nhật câu hỏi: <b>{0}</b>", Server.HtmlEncode(question.Title))
                };
                break;

            case ActionType.Delete:
                ltsQuestionItems = _questionDa.GetListByArrId(ArrId);
                stbMessage       = new StringBuilder();
                foreach (var item in ltsQuestionItems)
                {
                    _questionDa.Delete(item);
                    stbMessage.AppendFormat("Đã xóa câu hỏi <b>{0}</b>.<br />", Server.HtmlEncode(item.Title));
                }
                msg.ID = string.Join(",", ArrId);
                _questionDa.Save();
                msg.Message = stbMessage.ToString();
                break;

            case ActionType.Show:
                ltsQuestionItems = _questionDa.GetListByArrId(ArrId).Where(o => o.IsShow == false).ToList();
                stbMessage       = new StringBuilder();
                foreach (var item in ltsQuestionItems)
                {
                    item.IsShow = true;
                    stbMessage.AppendFormat("Đã hiển thị câu hỏi <b>{0}</b>.<br />", Server.HtmlEncode(item.Title));
                }
                _questionDa.Save();
                msg.ID      = string.Join(",", ltsQuestionItems.Select(o => o.ID));
                msg.Message = stbMessage.ToString();
                break;

            case ActionType.Hide:
                ltsQuestionItems = _questionDa.GetListByArrId(ArrId).Where(o => o.IsShow == true).ToList();
                stbMessage       = new StringBuilder();
                foreach (var item in ltsQuestionItems)
                {
                    item.IsShow = false;
                    stbMessage.AppendFormat("Đã ẩn câu hỏi <b>{0}</b>.<br />", Server.HtmlEncode(item.Title));
                }
                _questionDa.Save();
                msg.ID      = string.Join(",", ltsQuestionItems.Select(o => o.ID));
                msg.Message = stbMessage.ToString();
                break;
            }
            if (string.IsNullOrEmpty(msg.Message))
            {
                msg.Message = "Không có hành động nào được thực hiện.";
                msg.Erros   = true;
            }
            return(Json(msg, JsonRequestBehavior.AllowGet));
        }
Beispiel #30
0
        /// <summary>
        /// Parse first message from the data buffer and remove it from the buffer value.  The remaining buffer value is returned to the caller.
        /// </summary>
        /// <param name="buffer">Data buffer value.</param>
        /// <returns>JsonMessage or null if no message is available in the buffer.</returns>
        internal static JsonMessage GetNextJsonMessage(StringBuilder buffer)
        {
            if (buffer == null)
            {
                return(null);
            }

            // find the header
            int messageIndex = buffer.IndexOf(PyonHeader, false);

            if (messageIndex < 0)
            {
                return(null);
            }
            // set starting message index
            messageIndex += PyonHeader.Length;

            // find the first CrLf or Lf character after the header
            int startIndex = FindStartIndex(buffer, messageIndex);

            if (startIndex < 0)
            {
                return(null);
            }

            // find the footer
            int endIndex = FindEndIndex(buffer, startIndex);

            if (endIndex < 0)
            {
                return(null);
            }

            // create the message and set received time stamp
            var message = new JsonMessage {
                Received = DateTime.UtcNow
            };

            // get the message name
            message.Key = buffer.Substring(messageIndex, startIndex - messageIndex);

            // get the PyON message
            buffer.SubstringBuilder(startIndex, message.Value, endIndex - startIndex);
            // replace PyON values with JSON values
            message.Value.Replace(": None", ": null");
            message.Value.Replace(": True", ": true");
            message.Value.Replace(": False", ": false");

            // set the index so we know where to trim the string (end plus footer length)
            int nextStartIndex = endIndex + PyonFooter.Length;

            // if more buffer is available set it and return, otherwise set the buffer empty
            if (nextStartIndex < buffer.Length)
            {
                buffer.Remove(0, nextStartIndex);
            }
            else
            {
                buffer.Clear();
            }

            return(message);
        }
Beispiel #31
0
        public ActionResult Actions()
        {
            var msg     = new JsonMessage();
            var product = new Shop_Product();
            List <Shop_Product> lstProduct;
            StringBuilder       stbMessage;
            var lsttag    = Request["values-arr-tag"];
            var lstCate   = Request["Value_CategoryValues"];
            var images    = Request["Value_Images"];
            var lstimages = Request["Value_ImagesProducts"];

            switch (DoAction)
            {
            case ActionType.Add:
                try
                {
                    UpdateModel(product);
                    product.CreateDate = DateTime.Now.TotalSeconds();
                    product.IsDelete   = false;
                    product.CreateBy   = User.Identity.Name;
                    product.LanguageId = Fdisystem.LanguageId;

                    _productDa.Add(product);
                    _productDa.Save();

                    msg = new JsonMessage
                    {
                        Erros   = false,
                        ID      = product.ID.ToString(),
                        Message = string.Format("Đã thêm mới sản phẩm: <b>{0}</b>", Server.HtmlEncode(product.Shop_Product_Detail.Name))
                    };
                }
                catch (Exception)
                {
                }
                break;

            case ActionType.Edit:
                try
                {
                    product = _productDa.GetById(ArrId.FirstOrDefault());
                    UpdateModel(product);
                    product.IsDelete = false;
                    _productDa.Save();
                    msg = new JsonMessage
                    {
                        Erros   = false,
                        ID      = product.ID.ToString(),
                        Message = string.Format("Đã cập nhật sản phẩm: <b>{0}</b>", Server.HtmlEncode(product.Shop_Product_Detail.Name))
                    };
                }
                catch (Exception)
                {
                    //Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                }
                break;

            case ActionType.Delete:
                lstProduct = _productDa.GetListArrId(ArrId);
                stbMessage = new StringBuilder();
                foreach (var item in lstProduct)
                {
                    item.IsDelete = true;
                    stbMessage.AppendFormat("Đã xóa <b>{0}</b>.<br />", Server.HtmlEncode(item.Shop_Product_Detail.Name));
                }
                msg.ID = string.Join(",", ArrId);
                _productDa.Save();
                msg.Message = stbMessage.ToString();
                break;

            case ActionType.Show:
                lstProduct = _productDa.GetListArrId(ArrId);
                stbMessage = new StringBuilder();
                foreach (var item in lstProduct)
                {
                    item.IsShow = true;
                    stbMessage.AppendFormat("Đã hiển thị <b>{0}</b>.<br />", Server.HtmlEncode(item.Shop_Product_Detail.Name));
                }
                _productDa.Save();
                msg.ID      = string.Join(",", lstProduct.Select(o => o.ID));
                msg.Message = stbMessage.ToString();
                break;

            case ActionType.Hide:
                lstProduct = _productDa.GetListArrId(ArrId);
                stbMessage = new StringBuilder();
                foreach (var item in lstProduct)
                {
                    item.IsShow = false;
                    stbMessage.AppendFormat("Đã ẩn <b>{0}</b>.<br />", Server.HtmlEncode(item.Shop_Product_Detail.Name));
                }
                _productDa.Save();
                msg.ID      = string.Join(",", lstProduct.Select(o => o.ID));
                msg.Message = stbMessage.ToString();
                break;
            }

            if (string.IsNullOrEmpty(msg.Message))
            {
                msg.Message = "Không có hành động nào được thực hiện.";
                msg.Erros   = true;
            }

            return(Json(msg, JsonRequestBehavior.AllowGet));
        }
Beispiel #32
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="model">返回用户信息</param>
        /// <param name="user_id">登录名</param>
        /// <param name="pwd">密码</param>
        /// <returns></returns>
        public JsonMessage Login(ref AccountModel model, string user_id, string pwd)
        {
            JsonMessage jsonMsg = new JsonMessage(); //返回Json
            int         result  = -1;                //类型(成功 、失败)

            try
            {
                if (ValidateHelper.IsNullOrEmpty(StringHelper.Trim(user_id)))
                {
                    throw new CustomException(0, "用户名不能为空");
                }
                if (ValidateHelper.IsNullOrEmpty(pwd))
                {
                    throw new CustomException(0, "密码不能为空");
                }

                //UserID = userId;
                DataTable            dt   = _userRep.Login(user_id, MD5Cryption.MD5(pwd));
                IList <SysUserModel> list = ConverHelper.ToList <SysUserModel>(dt);
                if (list.Count < 1)
                {
                    throw new CustomException(2, "用户名或密码错误");//用户名或密码错误
                }
                if (!ConverHelper.ToBool(list[0].IS_ABLED))
                {
                    throw new CustomException(3, "账号已被禁用,请联系系统管理员");//账号是否被禁用
                }
                model.UserCode = list[0].USER_CODE;
                model.UserName = list[0].USER_NAME;
                model.LoginNo  = list[0].USER_CODE;
                model.QRCode   = list[0].QR_CODE;
                model.DeptCode = list[0].DEPT_CODE;

                jsonMsg = ServiceResult.Message(1, "登录成功");

                SessionHelper.SetSession("Account", model);

                CookieHelper.SetCookie("Account", DESCryption.Encrypt(ConverHelper.ToJson(model)));
            }
            catch (CustomException ex)
            {
                jsonMsg = ServiceResult.Message(ex.ResultFlag, ex.Message);
            }
            catch (Exception ex)
            {
                jsonMsg = ServiceResult.Message(-1, ex.Message);
            }
            //写入log
            SysLogLoginModel log = new SysLogLoginModel();

            log.LOGIN_ID      = GuidHelper.GenerateComb().ToString();
            log.USER_CODE     = user_id;
            log.USER_PWD      = MD5Cryption.MD5(pwd);
            log.USER_PWD_LAWS = pwd;
            log.LOGIN_IP      = NetHelper.GetUserIp;
            log.LOGIN_RESULT  = jsonMsg.type == 1 ? "SUCCESS" : "FAIL";
            log.LOGIN_MSG     = jsonMsg.message;
            _loglRep.Insert(log);

            return(jsonMsg);
        }
 // Static
 public new static JsonTunnelRequestMessage Parse(string value)
 {
     return(JsonMessage.Parse <JsonTunnelRequestMessage>(value));
 }
Beispiel #34
0
 private void OnMessageUpdated(JsonMessage arg)
 => MessageUpdated?.Invoke(this, new Message(arg, this));
Beispiel #35
0
        public ActionResult Actions()
        {
            var msg      = new JsonMessage();
            var district = new System_District();
            List <System_District> ltsDistrictItems;
            StringBuilder          stbMessage;

            switch (DoAction)
            {
            case ActionType.Add:
                UpdateModel(district);
                _districtDa.Add(district);
                _districtDa.Save();
                msg = new JsonMessage
                {
                    Erros   = false,
                    ID      = district.ID.ToString(),
                    Message = string.Format("Đã thêm mới quận huyện: <b>{0}</b>", Server.HtmlEncode(district.Name))
                };
                break;

            case ActionType.Edit:
                district = _districtDa.GetById(ArrId.FirstOrDefault());
                UpdateModel(district);
                _districtDa.Save();
                msg = new JsonMessage
                {
                    Erros   = false,
                    ID      = district.ID.ToString(),
                    Message = string.Format("Đã cập nhật quận huyện: <b>{0}</b>", Server.HtmlEncode(district.Name))
                };
                break;

            case ActionType.Delete:
                ltsDistrictItems = _districtDa.GetByListArrId(ArrId);
                stbMessage       = new StringBuilder();
                foreach (var item in ltsDistrictItems)
                {
                    _districtDa.Delete(item);
                    stbMessage.AppendFormat("Đã xóa quận huyện <b>{0}</b>.<br />", Server.HtmlEncode(item.Name));
                }
                msg.ID = string.Join(",", ArrId);
                _districtDa.Save();
                msg.Message = stbMessage.ToString();
                break;

            case ActionType.Show:
                ltsDistrictItems = _districtDa.GetByListArrId(ArrId).Where(o => !o.IsShow).ToList();
                stbMessage       = new StringBuilder();
                foreach (var item in ltsDistrictItems)
                {
                    item.IsShow = true;
                    stbMessage.AppendFormat("Đã hiển thị quận huyện <b>{0}</b>.<br />", Server.HtmlEncode(item.Name));
                }
                _districtDa.Save();
                msg.ID      = string.Join(",", ltsDistrictItems.Select(o => o.ID));
                msg.Message = stbMessage.ToString();
                break;

            case ActionType.Hide:
                ltsDistrictItems = _districtDa.GetByListArrId(ArrId).Where(o => o.IsShow).ToList();
                stbMessage       = new StringBuilder();
                foreach (var item in ltsDistrictItems)
                {
                    item.IsShow = false;
                    stbMessage.AppendFormat("Đã ẩn quận huyện <b>{0}</b>.<br />", Server.HtmlEncode(item.Name));
                }
                _districtDa.Save();
                msg.ID      = string.Join(",", ltsDistrictItems.Select(o => o.ID));
                msg.Message = stbMessage.ToString();
                break;
            }

            if (string.IsNullOrEmpty(msg.Message))
            {
                msg.Message = "Không có hành động nào được thực hiện.";
                msg.Erros   = true;
            }

            return(Json(msg, JsonRequestBehavior.AllowGet));
        }
Beispiel #36
0
 /// <summary>
 /// Initializes a new instance of the MessageUpdatedEventArgs class.
 /// </summary>
 /// <param name="jsonMessage">The JSON message.</param>
 public MessageReceivedEventArgs(JsonMessage jsonMessage)
 {
     JsonMessage = jsonMessage;
 }
Beispiel #37
0
        public ActionResult Actions()
        {
            var model = new Customer();
            var msg   = new JsonMessage(false, "Thêm mới dữ liệu thành công.");

            //List<Customer> ltsCustomerItems;
            //StringBuilder stbMessage;
            switch (DoAction)
            {
            case ActionType.Add:
                try
                {
                    UpdateModel(model);
                    var birth    = Request["Birthday_"];
                    var parent   = Request["Parent"];
                    var serial   = Request["CardSerial"];
                    var pin      = Request["PinCard"];
                    var NoteCate = Request["NoteCate"];

                    if (!string.IsNullOrEmpty(serial))
                    {
                        var carditem = _da.GetCardItem(serial, pin);
                        model.CardID = carditem.ID;
                    }
                    model.Birthday     = ConvertDate.TotalSeconds(ConvertUtil.ToDateTime(birth));
                    model.DateCreated  = ConvertDate.TotalSeconds(DateTime.Now);
                    model.IsDelete     = false;
                    model.IsActive     = true;
                    model.PasswordSalt = FDIUtils.CreateSaltKey(5);
                    model.PassWord     = FDIUtils.CreatePasswordHash(model.PassWord ?? "ssc123456", model.PasswordSalt);
                    if (!string.IsNullOrEmpty(NoteCate))
                    {
                        var customerCare = new Customer_Care
                        {
                            Note     = NoteCate,
                            AgencyId = AgencyId
                        };
                        model.Customer_Care.Add(customerCare);
                    }
                    _da.Add(model);
                    _da.Save();
                }
                catch (Exception ex)
                {
                    msg.Erros   = true;
                    msg.Message = "Thêm mới thất bại.";
                }
                break;

            case ActionType.Edit:
                try
                {
                    model = _da.GetById(ArrId.FirstOrDefault());
                    var birth  = Request["Birthday_"];
                    var serial = Request["CardSerial"];
                    var pin    = Request["PinCard"];
                    model.Birthday = ConvertDate.TotalSeconds(ConvertUtil.ToDateTime(birth));
                    var phone = model.Phone;
                    UpdateModel(model);
                    if (!model.CardID.HasValue && !string.IsNullOrEmpty(serial))
                    {
                        var carditem = _da.GetCardItem(serial, pin);
                        if (carditem != null)
                        {
                            model.CardID = carditem.ID;
                        }
                    }
                    if (!string.IsNullOrEmpty(model.PassWord))
                    {
                        model.PassWord = FDIUtils.CreatePasswordHash(model.PassWord, model.PasswordSalt);
                    }
                    model.Phone = phone;
                    _da.Save();
                    msg.Message = "Cập nhật dữ liệu thành công";
                }
                catch (Exception ex)
                {
                    msg.Erros   = true;
                    msg.Message = "Dữ liệu chưa được cập nhật";
                    Log2File.LogExceptionToFile(ex);
                }
                break;

            case ActionType.Delete:
                try
                {
                    var lst = _da.GetListByArrId(ArrId);
                    foreach (var item in lst)
                    {
                        item.IsDelete = true;
                    }
                    _da.Save();
                    msg.Message = "Xóa dữ liệu thành công";
                }
                catch (Exception ex)
                {
                    msg.Erros   = true;
                    msg.Message = "Dữ liệu chưa được xóa";
                    Log2File.LogExceptionToFile(ex);
                }
                break;

            default:
                msg.Message = "Không có hành động nào được thực hiện.";
                msg.Erros   = true;
                break;
            }
            return(Json(msg, JsonRequestBehavior.AllowGet));
        }
Beispiel #38
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="model">返回用户信息</param>
        /// <param name="user_id">登录名</param>
        /// <param name="pwd">密码</param>
        /// <returns></returns>
        public JsonMessage Login(string user_id, string pwd, string qr_code)
        {
            JsonMessage jsonMsg = new JsonMessage(); //返回Json
            int         result  = -1;                //类型(成功 、失败)

            try
            {
                if (ValidateHelper.IsNullOrEmpty(user_id) && ValidateHelper.IsNullOrEmpty(qr_code))
                {
                    throw new CustomException(0, "用户名和二维码不能同时为空");
                }
                if (ValidateHelper.IsNullOrEmpty(pwd) && ValidateHelper.IsNullOrEmpty(qr_code))
                {
                    throw new CustomException(0, "密码和二维码不能同时为空");
                }
                DataTable dt;
                if (ValidateHelper.IsNullOrEmpty(qr_code))
                {
                    dt = _userRep.Login(user_id, pwd);
                }
                else
                {
                    dt = _userRep.Login(qr_code);
                }
                IList <SysUserModel> list = ConverHelper.ToList <SysUserModel>(dt);
                if (list.Count < 1)
                {
                    if (ValidateHelper.IsNullOrEmpty(qr_code))
                    {
                        throw new CustomException(2, "用户名或密码错误");//用户名或密码错误
                    }
                    else
                    {
                        throw new CustomException(2, "二维码不正确");//二维码不正确
                    }
                }
                if (!ConverHelper.ToBool(list[0].IS_ABLED))
                {
                    throw new CustomException(3, "账号已被禁用,请联系系统管理员");//账号是否被禁用
                }

                jsonMsg = ServiceResult.Message(1, "登录成功", list[0]);
            }
            catch (CustomException ex)
            {
                jsonMsg = ServiceResult.Message(ex.ResultFlag, ex.Message);
            }
            catch (Exception ex)
            {
                jsonMsg = ServiceResult.Message(-1, ex.Message);
            }

            //写入log
            SysLogLoginModel log = new SysLogLoginModel();

            log.LOGIN_ID      = GuidHelper.GenerateComb().ToString();
            log.USER_CODE     = user_id;
            log.USER_PWD      = MD5Cryption.MD5(pwd);
            log.USER_PWD_LAWS = ValidateHelper.IsNullOrEmpty(user_id) ? qr_code : pwd;
            log.LOGIN_IP      = NetHelper.GetUserIp;
            log.LOGIN_RESULT  = jsonMsg.type == 1 ? "SUCCESS" : "FAIL";
            log.LOGIN_MSG     = jsonMsg.message;
            _loglRep.Insert(log);

            return(jsonMsg);
        }
Beispiel #39
0
        /// <summary>
        /// 频繁提交过滤,页面上需要加隐藏域
        /// </summary>
        /// <param name="filterContext"></param>
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            string httpMethod = filterContext.RequestContext.HttpContext.Server.HtmlEncode(filterContext.RequestContext.HttpContext.Request.HttpMethod);

            if (httpMethod == "POST" && filterContext.RequestContext.HttpContext.Request.IsAjaxRequest())
            {
                string cacheToken = filterContext.HttpContext.Request[hiddenToken];
                if (cacheToken != null)
                {
                    if (System.Web.HttpContext.Current.Cache[cacheToken] == null)
                    {
                        System.Web.HttpContext.Current.Cache.Insert(cacheToken, cacheToken, null, DateTime.MaxValue, TimeSpan.FromSeconds(1));
                    }
                    else
                    {
                        var         context     = filterContext.HttpContext;
                        string      callback    = context.Request["callback"];
                        string      content     = string.Empty;
                        JsonMessage jsonMessage = new JsonMessage();
                        jsonMessage.Flag    = false;
                        jsonMessage.Message = "请不要频繁提交,太快了,臣妾受不了";
                        if (!string.IsNullOrEmpty(callback))
                        {
                            string jsoncallback = context.Request["callback"];
                            content = jsoncallback + "(" + JsonConvert.SerializeObject(jsonMessage) + ")";
                        }
                        else
                        {
                            content = JsonConvert.SerializeObject(jsonMessage);
                        }
                        context.Response.Clear();
                        context.Response.ContentEncoding = Encoding.UTF8;
                        context.Response.ContentType     = "application/json";
                        context.Response.Expires         = 0;
                        context.Response.Cache.SetNoStore();
                        context.Response.Write(content);
                        context.Response.End();
                        filterContext.Result = new ContentResult();
                    }
                }
                else
                {
                    // 如果post请求中没有带token,则识为非法请求
                    var         context     = filterContext.HttpContext;
                    string      callback    = context.Request["callback"];
                    string      content     = string.Empty;
                    JsonMessage jsonMessage = new JsonMessage();
                    jsonMessage.Flag    = false;
                    jsonMessage.Message = "非法请求";
                    if (!string.IsNullOrEmpty(callback))
                    {
                        string jsoncallback = context.Request["callback"];
                        content = jsoncallback + "(" + JsonConvert.SerializeObject(jsonMessage) + ")";
                    }
                    else
                    {
                        content = JsonConvert.SerializeObject(jsonMessage);
                    }
                    context.Response.Clear();
                    context.Response.ContentEncoding = Encoding.UTF8;
                    context.Response.ContentType     = "application/json";
                    context.Response.Expires         = 0;
                    context.Response.Cache.SetNoStore();
                    context.Response.Write(content);
                    context.Response.End();
                    filterContext.Result = new ContentResult();
                }
            }
        }
Beispiel #40
0
        private static void SerializeResponseMessage(IServerResponseChannelSinkStack sinkStack
            , IMessage responseMsg
            , ref ITransportHeaders responseHeaders
            , ref Stream responseStream)
        {
            if (sinkStack == null)
                throw new ArgumentNullException("sinkStack");
            if (responseMsg == null)
                throw new ArgumentNullException("responseMsg");

            var methodReturnMessage = responseMsg as IMethodReturnMessage;
            if (methodReturnMessage == null)
                throw new ArgumentException(string.Format(
                    "Invalid response message type: '{0}'.", responseMsg.GetType()), "responseMsg");

            if (responseHeaders == null)
                responseHeaders = new TransportHeaders();

            bool shouldRewindStream = false;

            if (responseStream == null)
            {
                responseStream = sinkStack.GetResponseStream(responseMsg, responseHeaders);

                if (responseStream == null)
                {
                    responseStream = new MemoryStream();
                    shouldRewindStream = true;
                }
            }

            var m = new JsonMessage();
            m.Return = methodReturnMessage.ReturnValue;
            m.Exception = methodReturnMessage.Exception;
            JSONSerializer.Serialize(responseStream, m, typeof(JsonMessage));

            if (shouldRewindStream)
            {
                responseStream.Position = 0;
            }
        }