Esempio n. 1
0
        public List <ReceiptDatumWithUid> Get()
        {
            string sql = $"SELECT * FROM {TABLE}; SELECT * FROM {ITEMS_TABLE};";

            Dictionary <int, ReceiptDatumWithUid> tmpDict = new Dictionary <int, ReceiptDatumWithUid>();

            DoCommand(sql, (SqlCommand cmd) =>
            {
                using var reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    ReceiptDatumWithUid receipt = ConvertTo(reader);

                    tmpDict.Add(receipt.Uid, receipt);
                }

                reader.NextResult();

                while (reader.Read())
                {
                    ReceiptItemDatumWithRUid item = ConvertToItem(reader);

                    tmpDict[item.ReceiptUid].AddItem(item);
                }
            });

            return(tmpDict.Values.ToList());
        }
        public void Patch([FromBody] string value)
        {
            ReceiptDatumWithUid datum = Newtonsoft.Json.JsonConvert.DeserializeObject <ReceiptDatumWithUid>(value);

            GlobalInstance.DB.RecordTable.Insert("Receipt Update", datum);
            GlobalInstance.DB.ReceiptTable.Update(datum);
        }
Esempio n. 3
0
        public void Update(ReceiptDatumWithUid datum)
        {
            string sql =
                $"UPDATE {TABLE} SET {FIELD_ID}=?,{FIELD_PAYEE}=?,{FIELD_DATE}=? WHERE {FIELD_UID}=?; "
                + $"DELETE FROM {ITEMS_TABLE} WHERE {ITEMS_FIELD_RECEIPT_UID}=?; ";
            List <object> parameter = new List <object>()
            {
                datum.Id, datum.Payee, datum.Date, datum.Uid, datum.Uid
            };

            foreach (var item in datum.Items)
            {
                sql += $" INSERT INTO {ITEMS_TABLE} ({ITEMS_FIELD_RECEIPT_UID}, {ITEMS_FIELD_PRODUCT_NAME}, {ITEMS_FIELD_PRICE}, {ITEMS_FIELD_NUMBER}) "
                       + $" VALUES (?, ?, ?, ?); ";
                parameter.Add(datum.Uid);
                parameter.Add(item.ProductName);
                parameter.Add(item.Price);
                parameter.Add(item.ProductNumber);
            }

            DoExecuteNonQuery(sql, parameter.ToArray());
        }