Skip to content

Instantly share code, notes, and snippets.

@isdaviddong
Created February 9, 2019 13:17
Show Gist options
  • Select an option

  • Save isdaviddong/34a6b63ca029c2c2b467752b5bcb7a1d to your computer and use it in GitHub Desktop.

Select an option

Save isdaviddong/34a6b63ca029c2c2b467752b5bcb7a1d to your computer and use it in GitHub Desktop.
ProcessCommand(...)方法中新增的部分
//如果是 '/add'開頭
if (msg.ToLower().StartsWith("/add")) //表單新增
{
//以 '/' 分割收到的字串
var words = msg.Split('/');
try
{
//嘗試抓取每一個欄位
float num = float.Parse(words[2]);
string datetime = words[5];
string memo = words[4];
string AccountType = words[3];
string rep = "";
//清空狀態,準備新增
Utility.SetState(e.source.userId, "");
//紀錄
if (Utility.SaveToDB(e.source.userId, num, AccountType, memo))
rep = $"${num} 已記錄為 {AccountType}";
else
rep = "記錄失敗";
//顯示訊息
isRock.LineBot.Bot b = new isRock.LineBot.Bot();
isRock.LineBot.TextMessage TextMessage = new isRock.LineBot.TextMessage(rep);
b.ReplyMessage(e.replyToken, TextMessage);
return true;
}
catch (Exception ex)
{
//回覆QuickReply
isRock.LineBot.Bot b = new isRock.LineBot.Bot();
isRock.LineBot.TextMessage TextMessage = new isRock.LineBot.TextMessage("新增失敗...");
b.ReplyMessage(e.replyToken, TextMessage);
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment