Exemplo n.º 1
0
        private void ProcessInvoiceXML(string invoiceXMLFile)
        {
            /// Read Invoice.XML and store in object of VoygerBill
            using (VoygerXMLReader xmlReader = new VoygerXMLReader())
            {
                VoygerBill voygerBill = xmlReader.ReadInvoiceXML(invoiceXMLFile);

                if (voygerBill != null)
                {
                    InsertBillData(voygerBill);
                    //TODO:Call WebAPI and Store on RemoteDB
                    //await new WebAPI().Upload(voygerBill);
                }
                else
                {
                    LogEvent.Warning("voygerBill Readed, and it is empty");
                }
                LogEvent.WriteEvent("ProcessInvoiceXml is ended.#" + Watcher.NoOfEvent);
                Watcher.NoOfEvent = 0;
                if (voygerBill != null)
                {
                    voygerBill.Dispose();
                }

                Dispose();
                xmlReader.Dispose();
            }
        }
Exemplo n.º 2
0
        public async Task Upload(VoygerBill vBill)
        {
            //TODO: Here implement or add function to convert payment mode to PayModes unit. so less amount of data will be uploaded
            VoyagerBillInfo bill = new VoyagerBillInfo()
            {
                Amount     = (decimal)vBill.bill.BillAmount,
                BillDate   = vBill.bill.BillTime ?? DateTime.Now,
                ImportDate = DateTime.Now,
                InvoiceNo  = vBill.bill.BillNumber,
                IsUsed     = false,
                PayModes   = 0
            };

            LogEvent.WriteEvent($"UploadFunctionStated with: {bill.VoyagerBillId}");

            await UploadBill(bill);
        }
        private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    // TODO: dispose managed state (managed objects).
                    vBill = null;
                }


                // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
                // TODO: set large fields to null.

                disposedValue = true;
            }
        }
Exemplo n.º 4
0
        public void InsertBillData(VoygerBill voygerBill)
        {
            if (voygerBill != null)
            {
                if (voygerBill.bill.BillType != null)
                {
                    LogEvent.WriteEvent("bill tye: " + voygerBill.bill.BillType);
                }
            }
            VoyBill bill = voygerBill.bill;

            List <LineItem>     lineItemList = voygerBill.lineItems;
            List <VPaymentMode> paymentList  = voygerBill.payModes;

            VoyagerContext voyDatabase;

            using (voyDatabase = new VoyagerContext())
            {
                // TODO:Need to Check line below here
                var v = from vyb in voyDatabase.VoyBills
                        where vyb.BillNumber == bill.BillNumber && vyb.BillTime == bill.BillTime
                        select new { vyb.VoyBillId };

                if (v.Count() > 0)
                {
                    LogEvent.WriteEvent($"Invoice all ready Present in file {v.FirstOrDefault().VoyBillId},{bill.BillNumber}");
                    return;
                }
                else
                {
                    LogEvent.WriteEvent($"Invoice is new with bill no {bill.BillNumber}");
                }

                voyDatabase.VoyBills.Add(bill);
                if (voyDatabase.SaveChanges() > 0)
                {
                    LogEvent.WriteEvent($"Bill with ID: {bill.VoyBillId} is saved!!! ");
                }
                else
                {
                    LogEvent.WriteEvent("bill is not Saved");
                }
                foreach (LineItem item in lineItemList)
                {
                    item.VoyBillId = bill.VoyBillId;
                    voyDatabase.LineItems.Add(item);
                }
                //   LogEvent.WriteEvent("Inserted LinesItem");
                foreach (VPaymentMode item in paymentList)
                {
                    item.VoyBillId = bill.VoyBillId;
                    voyDatabase.VPaymentModes.Add(item);
                }
                //  LogEvent.WriteEvent("Inserted payments");
                InsertDataLog dataLog = new InsertDataLog()
                {
                    BillNumber = bill.BillNumber,
                    Remark     = "First Step",
                    VoyBillId  = bill.VoyBillId,
                };
                LogEvent.WriteEvent("Inserted Datalog,payments,LinesItem,payments");
                voyDatabase.InsertDataLogs.Add(dataLog);

                voyDatabase.SaveChanges();
                LogEvent.WriteEvent("VoyBill is added with BillId: [" + bill.VoyBillId + "]and BillNo: [" + bill.BillNumber + "]");
            }
        }
        /// <summary>
        /// read invoicexml with linq
        /// </summary>
        /// <param name="filename">XML File Invoice.xml </param>
        /// <returns></returns>
        public VoygerBill ReadInvoiceXML(string filename)
        {
            try
            {
                LogEvent.WriteEvent("ReadInvoiceXML: Started and File is : " + filename);

                if (IsFileExist(filename))
                {
                    using (TextReader tr = new StreamReader(filename))
                    {
                        DataSet dataSet = new DataSet();

                        dataSet.ReadXml(tr, XmlReadMode.InferSchema);

                        if (dataSet.Tables.Count > 0)
                        {
                            vBill = new VoygerBill();
                            foreach (DataTable table in dataSet.Tables)
                            {
                                switch (table.TableName)
                                {
                                case VoyTable.T_Bill: ReadBill(table); break;

                                case VoyTable.T_Customer: ReadCustomer(table); break;

                                case VoyTable.T_LineItem: ReadLineItems(table); break;

                                case VoyTable.T_Payments: ReadPaymentDetails(table); break;

                                default:
                                    break;
                                }
                            }
                            LogEvent.WriteEvent("returing vbill with No: " + vBill.bill.BillNumber);

                            dataSet.Clear();
                            dataSet.Dispose();
                            tr.Close();
                            tr.Dispose();
                            return(vBill);
                        }
                        else
                        {
                            LogEvent.Warning("It doesnt have any VoyBill");

                            dataSet.Clear();
                            dataSet.Dispose();
                            tr.Close();
                            tr.Dispose();

                            return(null); // Error: Incase failed to read or no data present
                        }
                    }
                }
                else
                {
                    LogEvent.Warning("It doesnt have any VoyBill and path doesnt exist");
                    return(null); // Error: Incase failed to read or no data present
                }
            }
            catch (Exception e)
            {
                LogEvent.Error("Error/Exception: " + e.Message);
                Watcher.NoOfEvent--;
                return(vBill);
            }
            finally
            {
                Watcher.NoOfEvent--;
            }
        }