/// <summary>
        /// This method is used to Import Port Storage Location
        /// </summary>
        /// <param name="BatchId"></param>
        /// <param name="User"></param>
        /// <returns></returns>
        public PortStorageVehicleImportProp ImportPortStorageLocation(int BatchId, string User)
        {
            PortStorageVehicleImportProp result = new PortStorageVehicleImportProp();

            try
            {
                CommonSettings.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, Resources.loggerMsgStart, DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name));
                result = _serviceInstance.ImportPortStorageLocation(BatchId, User);
            }
            catch (Exception ex)
            {
                LogHelper.LogErrorToDb(ex);
                bool displayErrorOnUI = false;
                CommonSettings.logger.LogError(this.GetType(), ex);
                if (displayErrorOnUI)
                {
                    throw;
                }
            }
            finally
            {
                CommonSettings.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, Resources.loggerMsgEnd, DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name));
            }

            return(result);
        }
Пример #2
0
        /// <summary>
        /// This method is used to get message from storeprocedure.
        /// </summary>
        /// <param name="BatchId"></param>
        /// <param name="User"></param>
        /// <returns></returns>
        public PortStorageVehicleImportProp ImportPortStorageLocation(int BatchId, string User)
        {
            PortStorageVehicleImportProp portStorageVehicleImportProp = new PortStorageVehicleImportProp();

            // creating the object of PortStorageEntities Database
            using (PortStorageEntities objAppWorksEntities = new PortStorageEntities())
            {
                //int result = 0;
                CommonDAL.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, "Called {2} function ::{0} {1}.", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name));
                try
                {
                    ((IObjectContextAdapter)objAppWorksEntities).ObjectContext.CommandTimeout = 1800;
                    /// Calling The Stored Procedure
                    var result = objAppWorksEntities.spImportPortStorageLocations(BatchId, User).FirstOrDefault();
                    if (result != null)
                    {
                        portStorageVehicleImportProp.ReturnCode    = result.ReturnCode;
                        portStorageVehicleImportProp.ReturnMessage = result.ReturnMessage;
                    }
                    return(portStorageVehicleImportProp);
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    CommonDAL.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, "End {2} function ::{0} {1}.", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name));
                }
            }
        }
        /// <summary>
        /// This function is used to Process File in database
        /// </summary>
        /// <param name="obj"></param>
        public void ProcessFile(object obj)
        {
            try
            {
                PortStorageVehicleImportProp portStorageVehicleImportProp = new PortStorageVehicleImportProp();

                CommonSettings.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, Resources.loggerMsgStart, DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name));
                if (BatchId > 0)
                {
                    portStorageVehicleImportProp = ImportPortStorageVehicles(BatchId, _User);

                    if (portStorageVehicleImportProp != null)
                    {
                        if (portStorageVehicleImportProp.ReturnCode == 0)
                        {
                            //MessageBox.Show(Message);
                            MessageBox.Show("" + portStorageVehicleImportProp.ReturnMessage + "", " Import Complete.");
                            GetPortStorageVehicleImportList(BatchId);
                        }
                        else
                        {
                            MessageBox.Show("The following error was encountered while processing the batch, Error Code: " + portStorageVehicleImportProp.ReturnCode + " Error Message: " + portStorageVehicleImportProp.ReturnMessage + "", "Data Import Error");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Please Load Batch for Process File");
                }
            }
            catch (Exception ex)
            {
                LogHelper.LogErrorToDb(ex);
                bool displayErrorOnUI = false;
                CommonSettings.logger.LogError(this.GetType(), ex);
                if (displayErrorOnUI)
                {
                    throw;
                }
            }

            finally
            {
                CommonSettings.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, Resources.loggerMsgEnd, DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name));
            }
        }
        /// <summary>
        /// This function is used to Import And Process File in database
        /// </summary>
        /// <param name="obj"></param>
        public void ImportAndProcessFile(object obj)
        {
            // creating the object of service property

            try
            {
                PortStorageVehicleImportProp portStorageVehicleImportProp = new PortStorageVehicleImportProp();
                CommonSettings.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, Resources.loggerMsgStart, DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name));
                BatchId = GetPortStorageLocationBatchId();
                if (BatchId > 0)
                {
                    bool Result = SetPortStorageLocationNextBatchId(BatchId);
                    if (Result)
                    {
                        bool Data = LocationImportTransactionProcess(BatchId, _User);
                        if (Data)
                        {
                            portStorageVehicleImportProp = ImportPortStorageLocation(BatchId, _User);
                            if (portStorageVehicleImportProp != null)
                            {
                                if (portStorageVehicleImportProp.ReturnCode == 0)
                                {
                                    //MessageBox.Show(Message);
                                    MessageBox.Show("The Port Storage location update import completed successfully!", " Import Complete.");
                                    GetPortStorageLocationImportList(BatchId);
                                }
                                else
                                {
                                    MessageBox.Show("The following error was encountered while processing the batch, Error Code: " + portStorageVehicleImportProp.ReturnCode + " Error Message: " + portStorageVehicleImportProp.ReturnMessage + "", "Data Import Error");
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("There was an error inserting one of the location records, the import has been aborted!", "Error Inserting Record");
                        }
                    }

                    else
                    {
                        MessageBox.Show("There was an error setting the next batchid. Import has been aborted!", "Error Setting Next Batch ID");
                    }
                }
                else
                {
                    MessageBox.Show("There was an error getting the next batchid. Import has been aborted!", "Error Getting Batch ID");
                }
            }
            catch (Exception ex)
            {
                LogHelper.LogErrorToDb(ex);
                bool displayErrorOnUI = false;
                CommonSettings.logger.LogError(this.GetType(), ex);
                if (displayErrorOnUI)
                {
                    throw;
                }
            }

            finally
            {
                CommonSettings.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, Resources.loggerMsgEnd, DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name));
            }
        }
Пример #5
0
        public void BillingExport(object obj)
        {
            try
            {
                PortStorageVehicleImportProp portStorageVehicleImportProp = new PortStorageVehicleImportProp();
                CommonSettings.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, Resources.loggerMsgStart, DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name));
                MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Export Billing Records?", "Are you sure you wish to export the Billing Records?", System.Windows.MessageBoxButton.YesNo);
                if (messageBoxResult == MessageBoxResult.Yes)
                {
                    if (EXportTypeZero == true)
                    {
                        ExportType = 0;
                    }
                    else if (EXportTypeOne == true)
                    {
                        ExportType = 1;
                    }

                    if (ExportType == 1)
                    {
                        if (ExportDate == null)
                        {
                            MessageBox.Show("You must select the date that the billing records were previously exported.", "Enter Export Date");
                            return;
                        }
                    }

                    ListBillingRecordExport = _serviceInstance.GetBillingRecordExport(ExportType, ExportDate).ToList();


                    if (ListBillingRecordExport.Count < 1)
                    {
                        MessageBox.Show("There are no billing records to export using the current export type.", "No Billing Records To Export");
                        return;
                    }
                    if (ExportType == 0)
                    {
                        BatchId = _serviceInstance.GetBillingExportBatchId();
                        if (BatchId > 0)
                        {
                            bool value = _serviceInstance.SetBillingExportNextBatchId(BatchId);
                            if (!value)
                            {
                                MessageBox.Show("The system was unable to set the next billing export batch id!");
                                return;
                            }
                        }
                        else
                        {
                            MessageBox.Show("The system was unable to get the next billing export batch id!", "Unable To Get Batch ID");
                            return;
                        }
                    }

                    FilePath = _serviceInstance.GetBillingExportFilePath();
                    if (FilePath != null)
                    {
                        if (Directory.Exists(FilePath))
                        {
                            string        fileName     = string.Empty;
                            StringBuilder dataWriter   = new StringBuilder();
                            string        prevYear     = string.Empty;
                            string        prevMonth    = string.Empty;
                            string        prevCustOf   = string.Empty;
                            int           fileExported = 0;

                            foreach (var item in ListBillingRecordExport)
                            {
                                fileName = "I" + item.CustomerOf + Convert.ToDateTime(item.InvoiceDate).ToString("MMM") + item.TheYear.ToString();

                                string invoiceDate              = Convert.ToDateTime(item.InvoiceDate).ToString("MMddyyyy");
                                string customerNumber           = item.CustomerNumber;
                                string invoiceNumber            = item.InvoiceNumber;
                                string debitAccountNumber       = item.DebitAccountNumber;
                                string debitProfitCenterNumber  = item.DebitProfitCenterNumber;
                                string debitCostCenterNumber    = item.DebitCostCenterNumber;
                                string creditAccountNumber      = item.CreditAccountNumber;
                                string creditProfitCenterNumber = item.CreditProfitCenterNumber;
                                string creditCostCenterNumber   = item.CreditCostCenterNumber;
                                string aRTransactionAmount      = item.ARTransactionAmount == null ? string.Empty : item.ARTransactionAmount.ToString();
                                string creditMemoInd            = item.CreditMemoInd == null ? string.Empty : item.CreditMemoInd.ToString();
                                string description              = item.Description;

                                var row = string.Format("{0,-6}{1,-10}{2}{3,-5}{4,-2}{5,-3}{6,-5}{7,-2}{8,-3}{9,-8}{10,-1}{11,-30}{12,-1}", customerNumber, invoiceNumber, invoiceDate, debitAccountNumber, debitProfitCenterNumber, debitCostCenterNumber, creditAccountNumber, creditProfitCenterNumber, creditCostCenterNumber, aRTransactionAmount, creditMemoInd, description, "Z");

                                dataWriter = dataWriter.Append(row);
                                dataWriter = dataWriter.Append(Environment.NewLine);
                                if (!File.Exists(FilePath + "\\" + fileName + ".txt"))
                                {
                                    File.Create(FilePath + "\\" + fileName + ".txt").Close();
                                    dataWriter = new StringBuilder();
                                    string rowUpdated = string.Format("{0,-6}{1,-10}{2}{3,-5}{4,-2}{5,-3}{6,-5}{7,-2}{8,-3}{9,-8}{10,-1}{11,-30}{12,-1}", customerNumber, invoiceNumber, invoiceDate, debitAccountNumber, debitProfitCenterNumber, debitCostCenterNumber, creditAccountNumber, creditProfitCenterNumber, creditCostCenterNumber, aRTransactionAmount, creditMemoInd, description, "Z");
                                    dataWriter = dataWriter.Append(rowUpdated);
                                    dataWriter = dataWriter.Append(Environment.NewLine);
                                }
                                using (StreamWriter writer = new StreamWriter(FilePath + "\\" + fileName + ".txt", false))
                                {
                                    writer.WriteLine(dataWriter);
                                    fileExported++;
                                }

                                prevMonth = Convert.ToString(item.TheMonth);
                                prevYear  = Convert.ToString(item.TheYear);
                                UserCode  = Application.Current.Properties["LoggedInUserName"].ToString();
                                _serviceInstance.UpdateBillingLineItem(BatchId, item.BillingLineItemsID, UserCode);
                            }
                            if (ListBillingRecordExport.Count > 0)
                            {
                                var objReportData = ListBillingRecordExport.Select(d => new Appworks.Reports.BillingExportProp
                                {
                                    BatchID      = BatchId,
                                    CompanyName  = CompanyName,
                                    CreditAcc    = d.CreditAccountNumber,
                                    CreditCost   = d.CreditCostCenterNumber,
                                    CreditProfit = d.CreditProfitCenterNumber,
                                    CustomerID   = Convert.ToInt32(d.CustomerNumber),
                                    DebitAcc     = d.DebitAccountNumber,
                                    DebitCost    = d.DebitCostCenterNumber,
                                    DebitProfit  = d.DebitProfitCenterNumber,
                                    TransAmount  = d.ARTransactionAmount,
                                    Description  = d.Description,
                                    ExportDate   = d.ExportedDate == null ? DateTime.Now : d.ExportedDate,
                                    Invoice      = d.InvoiceNumber,
                                    InvoiceDate  = d.InvoiceDate
                                }).ToList();

                                ///billing Invoice report that displays batchid
                                var report = new BillingInvoiceRPT();
                                report.DataSource = objReportData.ToList();
                                MyReportSource    = report;

                                BillingInvoiceReportWindow objPrintWindow = new BillingInvoiceReportWindow(MyReportSource);
                                objPrintWindow.ShowDialog();
                            }
                            int countWindow = 0;
                            if (fileExported > 0)
                            {
                                MessageBox.Show("Data exported succesfully.");
                                foreach (System.Windows.Window window in System.Windows.Application.Current.Windows)
                                {
                                    if (countWindow == 1)
                                    {
                                        window.Close();
                                    }
                                    countWindow++;
                                }
                            }
                            else
                            {
                                MessageBox.Show("Unable to export data.");
                                foreach (System.Windows.Window window in System.Windows.Application.Current.Windows)
                                {
                                    if (countWindow == 1)
                                    {
                                        window.Close();
                                    }
                                    countWindow++;
                                }
                            }
                        }
                        else
                        {
                            //if it doesn't, create it
                            // Directory.CreateDirectory(directoryPath);
                            MessageBox.Show("The Billing Line Items Export file export path does not exist!", "Export Path Does Not Exist");
                        }
                    }
                    else
                    {
                        MessageBox.Show("There was an error loading the data.", "Error Loading Data");
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.LogErrorToDb(ex);
                bool displayErrorOnUI = false;
                CommonSettings.logger.LogError(this.GetType(), ex);
                if (displayErrorOnUI)
                {
                    throw;
                }
            }

            finally
            {
                CommonSettings.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, Resources.loggerMsgEnd, DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name));
            }
        }