/// <summary>
 /// 新增或修改渠道
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!Page.IsPostBack)
     {
         //获取渠道类型列表数据
         ViewState["ChannelTypeList"] = new ChannelTypeBll().GetEntities();
         //修改渠道,首先获取渠道数据
         int id;
         if (int.TryParse(Request.QueryString["id"], out id))
         {
             ViewState["Channel"] = new ChannelBll().GetEntityById(id);
         }
     }
     else
     {
         //将渠道新增或修改的数据保存到数据库
         var entity = new ChannelEntity()
         {
             ID = Request.Form["ID"] == null ? 0 : int.Parse(Request.Form["ID"]),
             Name = Request.Form["Name"],
             ChannelTypeId = int.Parse(Request.Form["ChannelTypeId"])
         };
         new ChannelBll().UpdateOrInsertEntity(entity);
         //回到渠道列表页面
         Response.Redirect("ChannelList.aspx");
         Response.End();
     }
 }
Example #2
0
 /// <summary>
 /// 添加或修改渠道
 /// </summary>
 /// <param name="viewEntity">渠道实体</param>
 /// <returns></returns>
 public bool UpdateOrInsertEntity(ChannelEntity viewEntity)
 {
     if (viewEntity.ID > 0)
     {
         var entity = viewEntity.GetDataEntity(viewEntity);
         var dbEntity = new ChannelDll().LoadEntity(p => p.ID == entity.ID);
         entity.SceneId = dbEntity.SceneId;
         entity.Qrcode = dbEntity.Qrcode;
         return new ChannelDll().UpdateEntity(entity);
     }
     else
     {
         //新增渠道时,需要获取渠道的二维码
         GetQrcode(viewEntity);
         var entity = viewEntity.GetDataEntity(viewEntity);
         return new ChannelDll().AddEntity(entity).ID > 0;
     }
 }
Example #3
0
 /// <summary>
 /// 更新渠道信息
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 public bool Update(ChannelEntity entity)
 {
     return(new ChannelDAL().Update(entity));
 }
Example #4
0
 /// <summary>
 /// 新增渠道信息
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 public int Insert(ChannelEntity entity)
 {
     return(new ChannelDAL().Insert(entity));
 }
 public Response <int> Update(ChannelEntity input)
 {
     _commandChannelRepo.Update(input);
     return(Response <int> .Create(input.Id, ResponseType.Success));
 }
Example #6
0
        public static List <ChannelEntity> CreateListOfChannelEntities <T>(bool channelGroup, bool channel,
                                                                           bool presence, bool awaitingConnectCallback,
                                                                           Action <T> userCallback, Action <T> connectCallback,
                                                                           Action <T> wildcardPresenceCallback, Action <T> disconnectCallback
                                                                           )
        {
            var dictSM = new Dictionary <string, object>();

            dictSM.Add("k", "v");
            dictSM.Add("k2", "v2");


            ChannelEntity ce1 = Helpers.CreateChannelEntity <T>("ch1", false, false, dictSM,
                                                                userCallback, connectCallback,
                                                                Common.ErrorCallback, disconnectCallback,
                                                                wildcardPresenceCallback);

            var dictSM2 = new Dictionary <string, object>();

            dictSM2.Add("k3", "v3");
            dictSM2.Add("k4", "v4");

            ChannelEntity ce2 = Helpers.CreateChannelEntity <T>("ch2", false, false, dictSM2,
                                                                userCallback, connectCallback,
                                                                Common.ErrorCallback, disconnectCallback,
                                                                wildcardPresenceCallback);

            var dictSM3 = new Dictionary <string, object>();

            dictSM3.Add("k5", "v5");
            dictSM3.Add("k6", "v6");

            ChannelEntity ce3 = Helpers.CreateChannelEntity <T>("cg1", false, true, dictSM3,
                                                                userCallback, connectCallback,
                                                                Common.ErrorCallback, disconnectCallback,
                                                                wildcardPresenceCallback);

            var dictSM4 = new Dictionary <string, object>();

            dictSM4.Add("k7", "v7");
            dictSM4.Add("k8", "v8");

            ChannelEntity ce4 = Helpers.CreateChannelEntity <T>("cg2", false, true, dictSM4,
                                                                userCallback, connectCallback,
                                                                Common.ErrorCallback, disconnectCallback,
                                                                wildcardPresenceCallback);

            var dictSM5 = new Dictionary <string, object>();

            dictSM5.Add("k7", "v7");
            dictSM5.Add("k8", "v8");

            ChannelEntity ce5 = Helpers.CreateChannelEntity <T>("cg2-pnpres", false, true, dictSM5,
                                                                userCallback, connectCallback,
                                                                Common.ErrorCallback, disconnectCallback,
                                                                wildcardPresenceCallback);


            var dictSM6 = new Dictionary <string, object>();

            dictSM6.Add("k7", "v7");
            dictSM6.Add("k8", "v8");

            ChannelEntity ce6 = Helpers.CreateChannelEntity <T>("ch2-pnpres", false, false, dictSM6,
                                                                userCallback, connectCallback,
                                                                Common.ErrorCallback, disconnectCallback,
                                                                wildcardPresenceCallback);


            var dictSM7 = new Dictionary <string, object>();

            dictSM7.Add("k7", "v7");
            dictSM7.Add("k8", "v8");

            ChannelEntity ce7 = Helpers.CreateChannelEntity <T>("ch7", true, false, dictSM7,
                                                                userCallback, connectCallback,
                                                                Common.ErrorCallback, disconnectCallback,
                                                                wildcardPresenceCallback);

            var dictSM8 = new Dictionary <string, object>();

            dictSM8.Add("k7", "v7");
            dictSM8.Add("k8", "v8");

            ChannelEntity ce8 = Helpers.CreateChannelEntity <T>("cg8", true, true, dictSM8,
                                                                userCallback, connectCallback,
                                                                Common.ErrorCallback, disconnectCallback,
                                                                wildcardPresenceCallback);

            List <ChannelEntity> lstCE = new List <ChannelEntity>();

            if (channel)
            {
                lstCE.Add(ce1);
                lstCE.Add(ce2);
                if (presence)
                {
                    lstCE.Add(ce6);
                }

                if (awaitingConnectCallback)
                {
                    lstCE.Add(ce7);
                }
            }
            if (channelGroup)
            {
                lstCE.Add(ce3);
                lstCE.Add(ce4);
                if (presence)
                {
                    lstCE.Add(ce5);
                }

                if (awaitingConnectCallback)
                {
                    lstCE.Add(ce8);
                }
            }
            return(lstCE);
        }
Example #7
0
 /// <summary> Removes the sync logic for member _channel</summary>
 /// <param name="signalRelatedEntity">If set to true, it will call the related entity's UnsetRelatedEntity method</param>
 /// <param name="resetFKFields">if set to true it will also reset the FK fields pointing to the related entity</param>
 private void DesetupSyncChannel(bool signalRelatedEntity, bool resetFKFields)
 {
     this.PerformDesetupSyncRelatedEntity(_channel, new PropertyChangedEventHandler(OnChannelPropertyChanged), "Channel", Mecca.CMT.DAL.RelationClasses.StaticChannelOwnerRelations.ChannelEntityUsingChannelIdStatic, true, signalRelatedEntity, "ChannelOwners", resetFKFields, new int[] { (int)ChannelOwnerFieldIndex.ChannelId });
     _channel = null;
 }
        // POST: api/GameServer
        public object Post([FromBody] string jsonData)
        {
            RetValue ret     = new RetValue();
            JsonData jsonStr = JsonMapper.ToObject(jsonData);
            //时间戳
            long t = Convert.ToInt64(jsonStr["t"].ToString());
            //设备标识符
            string deviceIdentifier = jsonStr["deviceIdentifier"].ToString();
            string deviceModel      = jsonStr["deviceModel"].ToString();
            //签名
            string sign = jsonStr["sign"].ToString();

            //1、判断时间戳 允许时间差3秒
            if (MFDSAUtil.GetTimestamp() - t > 3)
            {
                ret.HasError = true;
                ret.ErrorMsg = "请求无效";
                return(ret);
            }

            //2、验证签名
            string signServer = MFEncryptUtil.Md5(string.Format("{0}:{1}", t, deviceIdentifier));

            if (!signServer.Equals(sign, StringComparison.CurrentCultureIgnoreCase))
            {
                ret.HasError = true;
                ret.ErrorMsg = "请求无效";
                return(ret);
            }

            int type = Convert.ToInt32(jsonStr["Type"].ToString());

            if (type == 0)
            {
                string channelId    = jsonStr["ChannelId"].ToString();
                string innerVersion = jsonStr["InnerVersion"].ToString();

                //先获取渠道状态 根据渠道状态 来加载不同的区服
                ChannelEntity entity = ChannelCacheModel.Instance.GetEntity(string.Format("[ChannelId]={0} and [InnerVersion]={1}", channelId, innerVersion));
                if (entity == null)
                {
                    ret.HasError = true;
                    ret.ErrorMsg = "渠道号不存在";
                }

                //获取页签
                return(GameServerCacheModel.Instance.GetGameServerPageList(string.Format("[ChannelStatus]={0}", entity.ChannelStatus)));
            }
            else if (type == 1)
            {
                string channelId    = jsonStr["ChannelId"].ToString();
                string innerVersion = jsonStr["InnerVersion"].ToString();

                //先获取渠道状态 根据渠道状态 来加载不同的区服
                ChannelEntity entity = ChannelCacheModel.Instance.GetEntity(string.Format("[ChannelId]={0} and [InnerVersion]={1}", channelId, innerVersion));
                if (entity == null)
                {
                    ret.HasError = true;
                    ret.ErrorMsg = "渠道号不存在";
                }

                int pageIndex = int.Parse(jsonStr["pageIndex"].ToString());
                //获取区服列表
                return(GameServerCacheModel.Instance.GetGameServerList(pageIndex, string.Format("[ChannelStatus]={0}", entity.ChannelStatus)));
            }
            else if (type == 2)
            {
                //更新最后登陆信息
                int    userId         = int.Parse(jsonStr["userId"].ToString());
                int    lastServerId   = int.Parse(jsonStr["lastServerId"].ToString());
                string lastServerName = jsonStr["lastServerName"].ToString();

                Dictionary <string, object> dic = new Dictionary <string, object>();
                dic["Id"] = userId;
                dic["LastLogOnServerId"]   = lastServerId;
                dic["LastLogOnServerName"] = lastServerName;
                dic["LastLogOnServerTime"] = DateTime.Now;

                AccountCacheModel
                .Instance
                .Update("LastLogOnServerId=@LastLogOnServerId,LastLogOnServerName=@LastLogOnServerName,LastLogOnServerTime=@LastLogOnServerTime", "Id=@Id", dic);
            }

            return(ret);
        }
        public void TestSubscription()
        {
            PNConfiguration pnConfiguration = new PNConfiguration();

            pnConfiguration.Origin           = EditorCommon.Origin;
            pnConfiguration.SubscribeKey     = EditorCommon.SubscribeKey;
            pnConfiguration.PublishKey       = EditorCommon.PublishKey;
            pnConfiguration.CipherKey        = "enigma";
            pnConfiguration.LogVerbosity     = PNLogVerbosity.BODY;
            pnConfiguration.PresenceTimeout  = 60;
            pnConfiguration.PresenceInterval = 30;
            PubNubUnity pnUnity = new PubNubUnity(pnConfiguration, null, null);

            pnUnity.SubscriptionInstance.CleanUp();
            PNLoggingMethod pnLog = new PNLoggingMethod(pnConfiguration.LogVerbosity);
            //Add CE with ch cg, ch-pres, cgpres, 2 awaiting connect callback with userstate
            List <ChannelEntity> channelEntities = EditorCommon.CreateListOfChannelEntities(true, true, true, true, pnLog);

            pnUnity.SubscriptionInstance.Add(channelEntities);

            // Test All
            RunAssertions(pnUnity, "{\"ch1\":{\"k\":\"v\",\"k2\":\"v2\"},\"ch2\":{\"k3\":\"v3\",\"k4\":\"v4\"},\"ch2-pnpres\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"ch7\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"cg1\":{\"k5\":\"v5\",\"k6\":\"v6\"},\"cg2\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"cg2-pnpres\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"cg8\":{\"k7\":\"v7\",\"k8\":\"v8\"}}",
                          false, true, true, true, true, 4, 4,
                          new string[] { "cg1", "cg2", "cg2-pnpres", "cg8" },
                          new string[] { "ch1", "ch2", "ch2-pnpres", "ch7" },
                          new string[] { "ch1", "ch2", "ch7", "cg1", "cg2", "cg8" },
                          new string[] { "cg2-pnpres", "ch2-pnpres" },
                          new string[] { "ch7", "cg8" },
                          new string[] { "ch1", "ch2", "ch2-pnpres", "ch7", "cg1", "cg2", "cg2-pnpres", "cg8" });


            // Delete 2
            ChannelEntity ce = Helpers.CreateChannelEntity("ch2", false, false, null, pnLog);

            pnUnity.SubscriptionInstance.Delete(ce);
            ChannelEntity ce2 = Helpers.CreateChannelEntity("cg2", false, true, null, pnLog);

            pnUnity.SubscriptionInstance.Delete(ce2);

            // Test All
            RunAssertions(pnUnity, "{\"ch1\":{\"k\":\"v\",\"k2\":\"v2\"},\"ch2-pnpres\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"ch7\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"cg1\":{\"k5\":\"v5\",\"k6\":\"v6\"},\"cg2-pnpres\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"cg8\":{\"k7\":\"v7\",\"k8\":\"v8\"}}",
                          false, true, true, true, true, 3, 3,
                          new string[] { "cg1", "cg2-pnpres", "cg8" },
                          new string[] { "ch1", "ch2-pnpres", "ch7" },
                          new string[] { "ch1", "ch7", "cg1", "cg8" },
                          new string[] { "cg2-pnpres", "ch2-pnpres" },
                          new string[] { "ch7", "cg8" },
                          new string[] { "ch1", "ch2-pnpres", "ch7", "cg1", "cg2-pnpres", "cg8" });


            // UpdateOrAddUserStateOfEntity
            ChannelEntity ce3     = Helpers.CreateChannelEntity("ch1", false, false, null, pnLog);
            var           dictSMN = new Dictionary <string, object>();

            dictSMN.Add("k", "v9");

            pnUnity.SubscriptionInstance.TryUpdateOrAddUserStateOfEntity(ref ce3, dictSMN, true);

            // Test All
            RunAssertions(pnUnity, "{\"ch1\":{\"k\":\"v9\",\"k2\":\"v2\"},\"ch2-pnpres\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"ch7\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"cg1\":{\"k5\":\"v5\",\"k6\":\"v6\"},\"cg2-pnpres\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"cg8\":{\"k7\":\"v7\",\"k8\":\"v8\"}}",
                          false, true, true, true, true, 3, 3,
                          new string[] { "cg1", "cg2-pnpres", "cg8" },
                          new string[] { "ch1", "ch2-pnpres", "ch7" },
                          new string[] { "ch1", "ch7", "cg1", "cg8" },
                          new string[] { "cg2-pnpres", "ch2-pnpres" },
                          new string[] { "ch7", "cg8" },
                          new string[] { "ch1", "ch2-pnpres", "ch7", "cg1", "cg2-pnpres", "cg8" });

            // UpdateIsAwaitingConnectCallbacksOfEntity
            ChannelEntity ce4 = Helpers.CreateChannelEntity("ch7", false, false, null, pnLog);
            ChannelEntity ce5 = Helpers.CreateChannelEntity("cg8", false, true, null, pnLog);

            List <ChannelEntity> lstCE = new List <ChannelEntity>();

            lstCE.Add(ce4);
            lstCE.Add(ce5);

            pnUnity.SubscriptionInstance.UpdateIsAwaitingConnectCallbacksOfEntity(lstCE, false);

            // Test All
            RunAssertions(pnUnity, "{\"ch1\":{\"k\":\"v9\",\"k2\":\"v2\"},\"ch2-pnpres\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"ch7\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"cg1\":{\"k5\":\"v5\",\"k6\":\"v6\"},\"cg2-pnpres\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"cg8\":{\"k7\":\"v7\",\"k8\":\"v8\"}}",
                          true, true, true, true, true, 3, 3,
                          new string[] { "cg1", "cg2-pnpres", "cg8" },
                          new string[] { "ch1", "ch2-pnpres", "ch7" },
                          new string[] { "ch1", "ch7", "cg1", "cg8" },
                          new string[] { "cg2-pnpres", "ch2-pnpres" },
                          new string[] { "ch7", "cg8" },
                          new string[] { "ch1", "ch2-pnpres", "ch7", "cg1", "cg2-pnpres", "cg8" });

            // CleanUp
            pnUnity.SubscriptionInstance.CleanUp();

            // Test All

            RunAssertions(pnUnity, String.Empty,
                          false, false, false, false, false, 0, 0,
                          new string[] {},
                          new string[] {},
                          new string[] {},
                          new string[] {},
                          new string[] {},
                          new string[] {});
        }
Example #10
0
        public static List <ChannelEntity> CreateListOfChannelEntities(bool channelGroup, bool channel, bool presence, bool awaitingConnectCallback, PNLoggingMethod pnLog)
        {
            var dictSM = new Dictionary <string, object>();

            dictSM.Add("k", "v");
            dictSM.Add("k2", "v2");


            ChannelEntity ce1 = Helpers.CreateChannelEntity("ch1", false, false, dictSM, pnLog);

            var dictSM2 = new Dictionary <string, object>();

            dictSM2.Add("k3", "v3");
            dictSM2.Add("k4", "v4");

            ChannelEntity ce2 = Helpers.CreateChannelEntity("ch2", false, false, dictSM2, pnLog);

            var dictSM3 = new Dictionary <string, object>();

            dictSM3.Add("k5", "v5");
            dictSM3.Add("k6", "v6");

            ChannelEntity ce3 = Helpers.CreateChannelEntity("cg1", false, true, dictSM3, pnLog);

            var dictSM4 = new Dictionary <string, object>();

            dictSM4.Add("k7", "v7");
            dictSM4.Add("k8", "v8");

            ChannelEntity ce4 = Helpers.CreateChannelEntity("cg2", false, true, dictSM4, pnLog);

            var dictSM5 = new Dictionary <string, object>();

            dictSM5.Add("k7", "v7");
            dictSM5.Add("k8", "v8");

            ChannelEntity ce5 = Helpers.CreateChannelEntity("cg2-pnpres", false, true, dictSM5, pnLog);

            var dictSM6 = new Dictionary <string, object>();

            dictSM6.Add("k7", "v7");
            dictSM6.Add("k8", "v8");

            ChannelEntity ce6 = Helpers.CreateChannelEntity("ch2-pnpres", false, false, dictSM6, pnLog);

            var dictSM7 = new Dictionary <string, object>();

            dictSM7.Add("k7", "v7");
            dictSM7.Add("k8", "v8");

            ChannelEntity ce7 = Helpers.CreateChannelEntity("ch7", true, false, dictSM7, pnLog);

            var dictSM8 = new Dictionary <string, object>();

            dictSM8.Add("k7", "v7");
            dictSM8.Add("k8", "v8");

            ChannelEntity ce8 = Helpers.CreateChannelEntity("cg8", true, true, dictSM8, pnLog);

            List <ChannelEntity> lstCE = new List <ChannelEntity>();

            if (channel)
            {
                lstCE.Add(ce1);
                lstCE.Add(ce2);
                if (presence)
                {
                    lstCE.Add(ce6);
                }

                if (awaitingConnectCallback)
                {
                    lstCE.Add(ce7);
                }
            }
            if (channelGroup)
            {
                lstCE.Add(ce3);
                lstCE.Add(ce4);
                if (presence)
                {
                    lstCE.Add(ce5);
                }

                if (awaitingConnectCallback)
                {
                    lstCE.Add(ce8);
                }
            }
            return(lstCE);
        }
        public async Task <bool> Boost(
            ChannelEntity channel,
            Youtube.Domain.Entities.ChannelEntity youtubeChannel,
            Video video)
        {
            var query = this.names.GetRandomName();

            var usersCount = 10;
            var users      = new List <InstaUser>();

            while (usersCount <= 100)
            {
                var result = await this.instagramProvider.SearchPeopleAsync(query, usersCount);

                if (!result.Succeeded)
                {
                    this.logger.LogError($"{result.Info?.Message}");
                    return(false);
                }

                users = result.Value.Users
                        .Where(u =>
                               !u.IsPrivate &&
                               u.FollowersCount < 1000)
                        .ToList();

                if (users.Any())
                {
                    break;
                }

                usersCount += 10;
            }

            if (!users.Any())
            {
                return(false);
            }

            foreach (var user in users.Shuffle())
            {
                if (user.UserName == channel.OriginalChannelId ||
                    user.UserName == channel.ChannelId ||
                    user.UserName == youtubeChannel.Name)
                {
                    continue;
                }

                var mediaList = await this.instagramProvider.GetLastMedia(user.UserName);

                if (mediaList == null || !mediaList.Any())
                {
                    continue;
                }

                foreach (var media in mediaList)
                {
                    if (media?.Caption == null ||
                        string.IsNullOrEmpty(media.Caption.MediaId) ||
                        media.IsCommentsDisabled)
                    {
                        continue;
                    }

                    if (!int.TryParse(media.CommentsCount, out var commentsCount))
                    {
                        continue;
                    }

                    if (commentsCount > 3)
                    {
                        continue;
                    }

                    var res = await this.instagramProvider.CommentMediaAsync(
                        media.Caption.MediaId,
                        video.GetInstagramBoostText());

                    if (!res.Succeeded)
                    {
                        this.logger.LogError($"{res.Info?.Message}");
                        continue;
                    }

                    this.logger.LogTrace($"[{media.GetInstagramUrl()}] [{user.UserName}] [{user.FullName}]");
                    return(true);
                }
            }

            return(false);
        }
Example #12
0
 /// <summary>
 /// 根据ID获取渠道
 /// </summary>
 /// <param name="id">渠道ID</param>
 /// <returns></returns>
 public ChannelEntity GetEntityById(int id)
 {
     var entity = new ChannelDll().LoadEntity(p => p.ID == id);
     var viewEntity = new ChannelEntity();
     return viewEntity.GetViewModel(entity);
 }
Example #13
0
 /// <summary>
 /// 获取渠道列表
 /// </summary>
 /// <returns></returns>
 public List<ChannelEntity> GetEntities()
 {
     var entities = new ChannelDll().LoadEntities(p => p.ID > 0).ToList();
     var viewEntity = new ChannelEntity();
     return entities.Select(p => viewEntity.GetViewModel(p)).ToList();
 }
Example #14
0
 /// <summary>
 /// 获取渠道的二维码
 /// </summary>
 /// <param name="channelName">渠道实体</param>
 /// <returns></returns>
 private void GetQrcode(ChannelEntity entity)
 {
     //获取微信公众平台接口访问凭据
     string accessToken = AccessTokenContainer.TryGetToken(ConfigurationManager.AppSettings["appID"], ConfigurationManager.AppSettings["appsecret"]);
     //找出一个未被使用的场景值ID,确保不同渠道使用不同的场景值ID
     int scenid = GetNotUsedSmallSceneId();
     if (scenid <= 0 || scenid > 100000)
     {
         throw new Exception("抱歉,您的二维码已经用完,请删除部分后重新添加");
     }
     CreateQrCodeResult createQrCodeResult = QrCode.Create(accessToken, 0, scenid);
     if (!string.IsNullOrEmpty(createQrCodeResult.ticket))
     {
         using (MemoryStream stream = new MemoryStream())
         {
             //根据ticket获取二维码
             QrCode.ShowQrCode(createQrCodeResult.ticket, stream);
             //将获取到的二维码图片转换为Base64String格式
             byte[] imageBytes = stream.ToArray();
             string base64Image = System.Convert.ToBase64String(imageBytes);
             //由于SqlServerCompact数据库限制最长字符4000,本测试项目将二维码保存到磁盘,正式项目中可直接保存到数据库
             string imageFile = "QrcodeImage" + scenid.ToString() + ".img";
             File.WriteAllText(System.Web.HttpContext.Current.Server.MapPath("~/App_Data/") + imageFile, base64Image);
             entity.Qrcode = imageFile;
             entity.SceneId = scenid;
         }
     }
     else
     {
         throw new Exception("抱歉!获取二维码失败");
     }
 }
Example #15
0
 public FrmChannelEdit(ChannelEntity channelEntity) : this()
 {
     this.channelEntity = channelEntity;
 }
Example #16
0
        private bool Save()
        {
            if (!IsFieldValueValid())
            {
                return(false);
            }
            bool success = false;

            if (ConvertUtil.ToInt(txtCode.Text) <= 0)
            {
                MsgBox.Warn("通道编码应为大于0的整数。");
            }
            try
            {
                //是否要修改货位标记
                int isEdit   = 0;
                int bak_Code = 0;
                if (isNew == false)
                {
                    //更改过启用状态
                    if (channelEntity.Is_Active != comboIsActive.Text)
                    {
                        isEdit = 1;
                    }
                    else if (comboIsActive.Text == "N")
                    {
                        isEdit   = 2;
                        bak_Code = channelEntity.Bak_Ch_Code;
                    }
                }
                ChannelEntity editEntity = PrepareSave();
                bool          ret;
                if (isNew)
                {
                    ret = SaveAddChannel(editEntity, isNew, isEdit, bak_Code);
                }
                else
                {
                    ret = SaveUpdateChannelInfo(editEntity, isNew, isEdit, bak_Code);
                }
                //string ret = channelDal.Save(editEntity, isNew, isEdit,bak_Code);
                //if (ret == "-1")
                //    MsgBox.Warn("通道编号或名称已存在,请改为其他的通道编号或名称。");
                //else if (ret == "-2")
                //    MsgBox.Warn("更新失败,该行已经被其他人删除。");
                //else if(ret=="-3")
                //    MsgBox.Warn("更新失败,通道名称已存在,请改为其他通道名称。");
                //else if (ret.Length > 5)
                //{
                //    MsgBox.Warn(ret);
                //}
                //else
                if (ret)
                {
                    success = true;
                    if (DataSourceChanged != null)
                    {
                        DataSourceChanged(editEntity, null);
                    }
                }
            }
            catch (Exception ex)
            {
                MsgBox.Warn(ex.Message);
            }
            return(success);
        }