コード例 #1
0
ファイル: SheetWrapper.cs プロジェクト: kekoses/GoogleWrapper
 public void GetSheet(string sheetNameId)
 {
     if (_sheetService == null)
     {
         return;
     }
     Sheet = _sheetService.GetSheet(sheetNameId);
     if (Sheet != null)
     {
         SpreadSheetId = sheetNameId;
     }
     else
     {
         SpreadSheetId = null;
     }
 }
コード例 #2
0
        public async Task GetSheet([Remainder] string Name = null)
        {
            if (Name.NullorEmpty())
            {
                var c = GetCharacter();

                if (c == null)
                {
                    await ReplyAsync("You have no active character.");

                    return;
                }

                var msg = await ReplyAsync("Loading sheet...");

                var embed = await SheetService.GetSheet(c);

                await msg.ModifyAsync(x => x.Embed = embed);

                await msg.ModifyAsync(x => x.Content = " ");
            }
            else
            {
                var all = GetAllSheets();
                if (all.Count() == 0)
                {
                    await ReplyAsync("You have no characters! Import one by using the `!import` command.");

                    return;
                }

                var chars = all.Where(x => x.Type == SheetType.Character && x.Name.ToLower().StartsWith(Name.ToLower()));

                if (chars.Count() == 0)
                {
                    await ReplyAsync("You have no character whose name starts with that.");

                    return;
                }

                else if (chars.Count() == 1)
                {
                    var u = GetUser();
                    var c = chars.FirstOrDefault();
                    u.Character = c;
                    UpdateUser(u);

                    await ReplyAsync("Changed your active character to " + c.Name + ".");

                    return;
                }
                else
                {
                    var sb = new StringBuilder();
                    for (int i = 0; i < chars.Count(); i++)
                    {
                        sb.AppendLine("`[" + i + "`] " + Icons.SheetType[chars.ElementAt(i).Type] + " " + chars.ElementAt(i).Name);
                    }
                    var msg = await ReplyAsync("Multiple characters were found, please specify which one you wish to assign as your active character:\n" + sb.ToString());

                    var reply = await NextMessageAsync(timeout : TimeSpan.FromSeconds(10));

                    if (reply == null)
                    {
                        await msg.ModifyAsync(x => x.Content = "Timed out on selection.");

                        return;
                    }
                    if (int.TryParse(reply.Content, out int index))
                    {
                        if (index >= chars.Count())
                        {
                            await msg.ModifyAsync(x => x.Content = "Invalid choice, operation cancelled.");

                            return;
                        }
                        else
                        {
                            var c = chars.ElementAt(index);
                            var u = GetUser();
                            u.Character = c;
                            UpdateUser(u);
                            await ReplyAsync("Changed your active character to " + c.Name + ".");

                            return;
                        }
                    }
                    else
                    {
                        await msg.ModifyAsync(x => x.Content = "Invalid choice, operation cancelled.");

                        return;
                    }
                }
            }
        }
コード例 #3
0
ファイル: ProcessTest.cs プロジェクト: 929496959/ExeclWeb
        /// <summary>
        /// 单个单元格刷新
        /// </summary>
        /// <param name="requestMsg">请求信息</param>
        /// <param name="gridKey">execl文档key</param>
        /// <returns></returns>
        private static async Task Operation_V(JObject requestMsg, string gridKey)
        {
            // 请求信息
            var jObject = requestMsg.Value <JObject>();
            var i       = jObject.Value <string>("i");
            var v       = jObject.Value <JObject>("v");
            var r       = jObject.Value <int>("r");
            var c       = jObject.Value <int>("c");

            // sheet页
            var sheetModel = await SheetService.GetSheet(gridKey, i);

            var sheet    = (JObject)sheetModel.json_data;
            var cellData = sheet.Value <JArray>("celldata");

            if (cellData.Count > 0)
            {
                // 有单元格处理
                var item = (JObject)cellData.FirstOrDefault(p => p.Value <int>("r") == r && p.Value <int>("c") == c);
                if (item != null)
                {
                    var index = cellData.IndexOf(item);
                    var cell  = new JObject()
                    {
                        { "r", r },
                        { "v", v },
                        { "v", v }
                    };
                    cellData[index] = cell;
                    // 如果该单元格的 v 是null,删除该单元格
                    if (item.Value <JObject>("v") == null)
                    {
                        cellData.Remove(index);
                    }
                }
            }
            else
            {
                // 如果celldata 是空,则添加
                var cell = new JObject()
                {
                    { "r", r },
                    { "v", v },
                    { "v", v }
                };
                cellData.Add(cell);
            }

            // 提交修改
            await SheetService.UpdateSheet(sheetModel.id, gridKey, sheetModel.index, sheet.ToJson(), sheetModel.status, sheetModel.order, sheetModel.is_delete);
        }