예제 #1
0
        public static RootTransaction Desirialize(string jsonResponse)
        {
            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(RootTransaction));
            MemoryStream    stream = new MemoryStream(Encoding.ASCII.GetBytes(jsonResponse));
            RootTransaction obj    = serializer.ReadObject(stream) as RootTransaction;

            return(obj);
        }
예제 #2
0
            async public Task GetTransactions(DateTime transactionDate, bool updateToday = false)
            {
                int  index = -1;
                bool today = false, newday = false;

                if (Transactions.Count == 0)
                {
                    newday = true;
                }
                else
                {
                    DateTime firstTransactionDate = DateTime.Parse(Transactions[0].date);
                    today = DateTime.Today.ToString("yyyy-MM-dd") == firstTransactionDate.ToString("yyyy-MM-dd") &&
                            DateTime.Today.ToString("yyyy-MM-dd") == transactionDate.ToString("yyyy-MM-dd");
                    newday = transactionDate.Day > firstTransactionDate.Day && transactionDate > firstTransactionDate;
                }

                if (today)
                {
                    if (!updateToday)
                    {
                        return;
                    }
                    if (Transactions.Count != 0)
                    {
                        Transactions.RemoveAt(0);
                    }
                }
                else if (!newday)
                {
                    for (int i = 0; i < Transactions.Count; i++)
                    {
                        DateTime d = DateTime.Parse(Transactions[i].date);
                        if (d.ToString("yyyy-MM-dd") == transactionDate.ToString("yyyy-MM-dd"))
                        {
                            if (d.TimeOfDay.TotalSeconds != 0)
                            {
                                index = i;
                                break;
                            }
                            else
                            {
                                return;
                            }
                        }
                    }
                }

                await Task.Delay(200);

                string post = string.Format("{{\"account\":{0},\"day\":{1},\"month\":{2},\"year\":{3}}}", (UniversalAccount ? "true" : "false"), transactionDate.Day, transactionDate.Month, transactionDate.Year);

                WebClient client = createClient();

                client.Headers.Add("Content-Type", "application/json;charset=UTF-8");
                string result = await client.UploadStringTaskAsync(soldVouchersUrl, post);

                RootTransaction root = RootTransaction.Desirialize(result);

                Transaction transaction = root.data.details.Count == 0 ?
                                          new Transaction()
                {
                    date = transactionDate.ToString("yyyy-MM-dd"), myLogInvoiceResponses = new List <MyLogInvoiceResponse>()
                }
                    : root.data.details[0];

                if (newday || (today && updateToday))
                {
                    transaction.date = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                    Transactions.Insert(0, transaction);
                }
                else if (index != -1)
                {
                    Transactions[index] = transaction;
                }
                else
                {
                    Transactions.Add(transaction);
                }
            }