Example #1
0
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            Func <Transaction, bool> whereQuery = (Func <Transaction, bool>)e.Argument;

            worker.ReportProgress(1);
            BillingDataDataContext db = new BillingDataDataContext();

            List <Transaction> transactions = db.Transactions.Where(whereQuery).ToList();
            double             transCount   = transactions.Count;

            double i = 0;

            foreach (Transaction trans in transactions)
            {
                if (trans.ConnsignmentNo == "X10477603")
                {
                    Debug.WriteLine("ABC");
                }
                trans.AmountCharged = (decimal)UtilityClass.getCost(trans.CustCode, trans.BilledWeight ?? 0, trans.Destination, trans.Type.Trim(), trans.DOX);
                if (trans.Insurance != null)
                {
                    trans.AmountCharged = trans.AmountCharged + (decimal)trans.Insurance;
                }

                worker.ReportProgress((int)((i / transCount) * 94 + 1));
                i++;
            }
            ChangeSet changeSet = db.GetChangeSet();

            db.SubmitChanges();
            worker.ReportProgress(100);
            e.Result = "Completed for " + ((int)transCount).ToString() + " transactions";
        }
Example #2
0
 private void dataGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
 {
     if (e.EditAction == DataGridEditAction.Commit)
     {
         RuntimeData rData = ((RuntimeData)e.Row.Item);
         double      weight;
         if (double.TryParse((e.EditingElement as TextBox).Text, out weight))
         {
             if (e.Column.Header.ToString() == "Billed Weight")
             {
                 rData.BilledWeight = weight;
             }
             else if (e.Column.Header.ToString() == "Billed Amount")
             {
                 rData.FrAmount = (decimal)weight;
             }
         }
         else
         {
             MessageBox.Show("Unable to edit record!! Please check if input does not contain any invalid characters.", "Error");
             return;
         }
         if (rData == null)
         {
             MessageBox.Show("Unable to edit record....");
             return;
         }
         RuntimeData sData = dataGridHelper.getCurrentDataStack.SingleOrDefault(x => x.ConsignmentNo == rData.ConsignmentNo);
         if (sData == null)
         {
             MessageBox.Show("Unable to edit transaction. Please reload the data and try again..", "Error");
             return;
         }
         BillingDataDataContext db    = new BillingDataDataContext();
         RuntimeData            dData = db.RuntimeDatas.SingleOrDefault(x => x.ConsignmentNo == rData.ConsignmentNo && x.UserId == SecurityModule.currentUserName && dataGridHelper.currentSheetNumber == x.SheetNo);
         if (dData == null)
         {
             MessageBox.Show("Unable to edit transaction. Please check if data exists and try again..", "Error");
             return;
         }
         if (e.Column.Header.ToString() == "Billed Weight")
         {
             dData.BilledWeight = rData.BilledWeight;
             dData.FrAmount     = (decimal)UtilityClass.getCost(rData.CustCode, weight, rData.Destination, rData.Type.Trim(), rData.DOX ?? 'N');
             db.SubmitChanges();
             rData.FrAmount     = dData.FrAmount;
             sData.BilledWeight = dData.BilledWeight;
             sData.FrAmount     = dData.FrAmount;
         }
         if (e.Column.Header.ToString() == "Billed Amount")
         {
             dData.FrAmount = rData.FrAmount;
             db.SubmitChanges();
             sData.FrAmount = rData.FrAmount;
         }
     }
 }
        private void GetRateButton_Click(object sender, RoutedEventArgs e)
        {
            Client  client  = (Client)Client_Combo.SelectedItem;
            Service service = (Service)Service_Combo.SelectedItem;
            char    dox     = Dox_Combo.Text == "Non-Dox" ? 'N' : 'D';
            City    city    = (City)City_Combo.SelectedItem;
            double  weight;

            if (!double.TryParse(WeightRuleTextBox.Text, out weight))
            {
                return;
            }
            if (client == null || service == null || city == null)
            {
                return;
            }
            RateRuleTextBox.Text = UtilityClass.getCost(client.CLCODE, weight, city.CITY_CODE, service.SER_CODE, dox).ToString();
        }
Example #4
0
        private void getrate()
        {
            try
            {
                if (Destination.Text == "" || Destination.Text == null)
                {
                    throw new Exception("Enter destination properly..");
                }
                if (CustomerSelected.Text == "" || CustomerSelected.Text == null)
                {
                    throw new Exception("Select client properly...");
                }
                if (TypeComboBox.Text == "" || TypeComboBox.Text == null)
                {
                    throw new Exception("Select Service type properly...");
                }
                if (DoxCombobox.Text == "" || DoxCombobox.Text == null)
                {
                    throw new Exception("Select DOX/NDOX properly...");
                }
                double weight;
                if (!double.TryParse(BilledWeightTextBox.Text, out weight))
                {
                    throw new Exception("Enter billed weight properly...");
                }

                string custCode    = ((Client)CustomerSelected.SelectedItem).CLCODE.Trim();
                string destination = ((City)Destination.SelectedItem).CITY_CODE.Trim();
                string type        = ((Service)TypeComboBox.SelectedItem).SER_CODE.Trim();
                char   dox         = DoxCombobox.Text.ElementAt(0);
                double cost        = UtilityClass.getCost(custCode, weight, destination, type, dox);
                this.BilledAmount.Text = string.Format("{0:0.00}", cost);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }
Example #5
0
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            Client client = DataSources.ClientCopy.FirstOrDefault(x => x.CLCODE == clientCodeSelectedValue);

            errorNos = "";
            if (startCOnnNoIndex <= endConnNoIndex && startCOnnNoIndex != -1 && endConnNoIndex != -1)
            {
                int total = endConnNoIndex - startCOnnNoIndex;
                var cs    = (from m in db.Cities select m).ToList();
                for (int i = startCOnnNoIndex; i <= endConnNoIndex; i++)
                {
                    RuntimeData data = DataStack.ElementAt(i);

                    data = db.RuntimeDatas.Single(x => x.Id == data.Id);
                    var c = cs.Where(x => x.CITY_CODE == data.Destination).FirstOrDefault();
                    if (c == null)
                    {
                        c = db.Cities.SingleOrDefault(x => x.CITY_CODE == "DEL");
                    }
                    data.CustCode = clientCodeSelectedValue;
                    if (client != null)
                    {
                        data.Client_Desc = client.CLNAME;
                    }
                    if (data.FrWeight == null)
                    {
                        data.FrWeight = data.Weight;
                    }
                    if (data.BilledWeight == null)
                    {
                        data.BilledWeight = data.Weight;
                    }
                    if (setWeightCheck == true)
                    {
                        data.BilledWeight = weight;
                    }
                    if (subClientCheck == true)
                    {
                        data.SubClient = subClient;
                    }
                    if (consignerCheck == true)
                    {
                        data.ConsignerName = consigner;
                    }
                    if (consigneeCheck == true)
                    {
                        data.ConsigneeName = consignee;
                    }
                    if (calcRateCheck == true)
                    {
                        try
                        {
                            decimal costObt = (decimal)UtilityClass.getCost(data.CustCode.Trim(), (double)data.BilledWeight, data.Destination.Trim(), data.Type.Trim(), (char)data.DOX);
                            if (data.Insurance != null)
                            {
                                costObt = costObt + (decimal)data.Insurance;
                            }
                            data.FrAmount = costObt;
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex.Message + ": Occured in " + data.ConsignmentNo);
                            data.FrAmount = -1;
                        }
                    }
                    try
                    {
                        RuntimeData ndata = DataStack.ElementAt(i);
                        dupliData(data, ndata);
                        db.SubmitChanges();
                    }
                    catch (Exception)
                    {
                        errorNos = errorNos + "\n " + data.ConsignmentNo;
                    }
                    worker.ReportProgress((((i - startCOnnNoIndex + 1) * 100) / total));
                }
            }
        }
        void bgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            unreadableData = new List <string>();
            Guid Id = Guid.NewGuid();
            BillingDataDataContext db = new BillingDataDataContext();
            MatchCollection        matches;
            double progress = 0;

            try
            {
                PdfReader     reader = new PdfReader((string)e.Argument);
                StringBuilder text   = new StringBuilder();
                for (int i = 1; i <= reader.NumberOfPages; i++)
                {
                    text.Append(PdfTextExtractor.GetTextFromPage(reader, i));
                }
                Regex reg = new Regex(@"(\d+)\s+([A-Za-z]\d+)\s+\d+\s+(\d{1,2}/){2}\d{2}\s+([^\d]*)(\d+\.\d*)\s+(\w{3})\s+([^\d]*\d+\.\d*)");
                matches  = reg.Matches(text.ToString());
                progress = 5;
                bgWorker.ReportProgress((int)progress);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                throw new Exception("Unable to parse invoice");
            }
            double count = matches.Count, ctr = 0;

            foreach (Match match in matches)
            {
                InvoiceAnalyzeResult data = new InvoiceAnalyzeResult();
                double temp;
                bool   isValid = true;
                data.AnalyzeId   = Id;
                data.Id          = Guid.NewGuid();
                data.SrlNo       = match.Groups[1].Value;
                data.ConnNo      = match.Groups[2].Value;
                data.Destination = match.Groups[4].Value;
                if (double.TryParse(match.Groups[5].Value, out temp) == true)
                {
                    data.Weight = temp;
                }
                else
                {
                    isValid = false;
                }
                data.serviceCode = match.Groups[6].Value;
                if (double.TryParse(match.Groups[7].Value, out temp) == true)
                {
                    data.Amount = temp;
                }
                else
                {
                    isValid = false;
                }
                if (isValid)
                {
                    db.InvoiceAnalyzeResults.InsertOnSubmit(data);
                    db.SubmitChanges();
                }
                else
                {
                    unreadableData.Add(match.Groups[1].Value);
                }
                ctr++;
                bgWorker.ReportProgress((int)(((ctr / count) * 50) + progress));
            }
            Results = db.InvoiceAnalyzeResults.Where(x => x.AnalyzeId == Id);
            List <TransactionCityView> Transactions = (from transaction in db.TransactionCityViews
                                                       join result in Results
                                                       on transaction.ConnsignmentNo equals result.ConnNo
                                                       select transaction).ToList();

            progress = 60;
            bgWorker.ReportProgress((int)progress);
            count = Results.Count();
            ctr   = 0;
            db.UpdateBillingAmount();
            foreach (InvoiceAnalyzeResult result in Results)
            {
                TransactionCityView trans = Transactions.SingleOrDefault(x => x.ConnsignmentNo == result.ConnNo);
                result.MisMatchDesc = "";
                try
                {
                    if (trans == null)
                    {
                        result.hasError     = true;
                        result.MisMatchDesc = "Transaction not found";
                        continue;
                    }

                    if (trans.WeightByFranchize != result.Weight)
                    {
                        result.MisMatchDesc = "Weight should be " + trans.WeightByFranchize;
                        result.WeightDif    = (decimal)((result.Weight ?? 0) - (trans.WeightByFranchize ?? 0));
                    }
                    if (trans.CITY_DESC.Trim() != result.Destination.Trim())
                    {
                        result.MisMatchDesc = result.MisMatchDesc + " Destination should be " + trans.CITY_DESC;
                    }
                    if (trans.Type.Trim() != result.serviceCode.Trim())
                    {
                        result.MisMatchDesc = result.MisMatchDesc + " Service should be " + trans.Type.Trim();
                    }
                    trans.AmountCharged = (decimal)UtilityClass.getCost("<DTDC>", (double)trans.WeightByFranchize, trans.Destination.Trim(), trans.Type.Trim(), trans.DOX);
                    if (Math.Abs((trans.AmountCharged - (decimal)result.Amount) ?? 0) > 2)
                    {
                        result.hasError     = true;
                        result.MisMatchDesc = result.MisMatchDesc + " Amount should be " + Math.Round((trans.AmountCharged ?? 0), 2);
                        result.AmountDiff   = (decimal)(result.Amount ?? 0) - (decimal)(trans.AmountCharged ?? 0);
                    }
                }
                catch (Exception ex)
                {
                    result.hasError     = true;
                    result.MisMatchDesc = result.MisMatchDesc + " Unable to process record:  " + ex.Message;
                }
                ctr++;
                bgWorker.ReportProgress((int)(((ctr / count) * 30) + progress));
            }
            bgWorker.ReportProgress(100);
        }