Example #1
0
        private static DeleteFormCellDependency DeleteFormCellDependency(long FormCellDependencyId, string Url, string Username, string Drowssap)
        {
            DeleteFormCellDependency result = null;

            try
            {
                string query = string.Format("/api/FormCellDependency/{0}", FormCellDependencyId.ToString());

                // Create the http web request.
                var request = (HttpWebRequest)WebRequest.Create(Url + query);
                request.Headers.Add(HttpRequestHeader.Authorization, "Basic " + Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(Username + ":" + Drowssap)));
                request.Method = "DELETE";

                // execute the request.
                using (var response = (HttpWebResponse)request.GetResponse())
                {
                    if (response != null)
                    {
                        var responseStream = response.GetResponseStream();
                        var streamReader   = new System.IO.StreamReader(responseStream, System.Text.Encoding.UTF8);
                        var responseString = streamReader.ReadToEnd();

                        result = responseString.Length > 0 ? Newtonsoft.Json.JsonConvert.DeserializeObject <DeleteFormCellDependency>(responseString) : null;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("DeleteFormCellDependency: An unhandled exception occurred:[{0}]", ex.Message);

                return(result);
            }

            return(result);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        /// <remarks>args[0] = File path and name</remarks>
        /// <remarks>args[1] = url for Tax Form Catalog</remarks>
        /// <remarks>args[2] = user id for Tax Form Catalog</remarks>
        /// <remarks>args[3] = password for Tax Form Catalog</remarks>
        /// <remarks>args[4] = form master id to attach formCellDependencies</remarks>
        static void Main(string[] args)
        {
            List <InputData2> newDependencies = new List <InputData2>(); // = null;

            long updateFormMasterId = long.TryParse(args[4], out updateFormMasterId) ? updateFormMasterId : -1;

            if (args[0].Equals("d"))
            {
                List <FormCellDependency> currentDependencies = GetFormCellDependencies(updateFormMasterId, args[1], args[2], args[3]);
                Int64 deletedCount = 0;
                foreach (FormCellDependency fd in currentDependencies)
                {
                    DeleteFormCellDependency deleteResult = DeleteFormCellDependency(fd.FormCellDependencyId, args[1], args[2], args[3]);
                    if (deleteResult.Deleted)
                    {
                        deletedCount++;
                    }
                    else
                    {
                        Console.WriteLine(string.Format("Unable to delete formCellDependency [{0}] for FormMasterid [{1}].", fd.FormCellDependencyId.ToString(), updateFormMasterId.ToString()));
                    }
                }

                Console.WriteLine(string.Format("The application deleted [{0}] FormCellDependency records for FormMasterId [{1}].", deletedCount.ToString(), updateFormMasterId.ToString()));
            }
            else
            {
                //Populate object with source file
                using (FileStream fs = new FileStream(args[0], FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(fs, false))
                    {
                        WorkbookPart  workbookPart  = spreadsheetDocument.WorkbookPart;
                        WorksheetPart worksheetPart = workbookPart.WorksheetParts.First();
                        SheetData     sheetData     = worksheetPart.Worksheet.Elements <SheetData>().First();

                        foreach (Row row in sheetData.Elements <Row>())
                        {
                            InputData2    newDependency = new InputData2();
                            int           rowcolumn     = 1;
                            int           tempMonths    = -1;
                            List <String> firstRow      = new List <String>();

                            foreach (Cell c in row.Elements <Cell>())
                            {
                                switch (rowcolumn)
                                {
                                //New Format
                                case 1: newDependency.TaxFormCode = ReadExcelCell(c, workbookPart); break;

                                case 2: newDependency.SummaryLabel = ReadExcelCell(c, workbookPart); break;

                                case 3: newDependency.FieldName = ReadExcelCell(c, workbookPart) ?? null; break;

                                case 4: newDependency.CurrentPeriod = ReadExcelCell(c, workbookPart) ?? null; break;

                                case 5: newDependency.Months = int.TryParse(ReadExcelCell(c, workbookPart), out tempMonths) ? tempMonths : 0; break;

                                case 6: newDependency.PriorYear = ReadExcelCell(c, workbookPart); break;
                                }

                                rowcolumn++;
                            }

                            if (newDependency.TaxFormCode != "Form")
                            {
                                newDependencies.Add(newDependency);
                            }
                        }
                    }
                }

                List <FormCellDependency> recordsToAdd = new List <FormCellDependency>();
                int    totalRecords    = newDependencies.Count;
                string prevTaxFormCode = string.Empty;
                long   formMasterId    = 0;
                List <FormCellDependency> existingDependencies = GetFormCellDependencies(updateFormMasterId, args[1], args[2], args[3]);
                List <Annotation>         formAnnotations      = new List <Annotation>();
                List <SummaryLabel>       summaryLabels        = GetSummaryLabels(args[1], args[2], args[3]);


                // Create List of FormCellDependency records to add
                foreach (InputData2 item in newDependencies)
                {
                    if (!item.TaxFormCode.Equals(prevTaxFormCode))
                    {
                        formMasterId    = GetFormMasterId(item.TaxFormCode, args[1], args[2], args[3]);
                        prevTaxFormCode = item.TaxFormCode;
                        if (formMasterId > 0)
                        {
                            formAnnotations = GetAnnotations(formMasterId, args[1], args[2], args[3]);
                        }
                        else
                        {
                            Console.WriteLine(string.Format("Unable to find a formmaster record for taxformcode [{0}].", item.TaxFormCode));
                        }
                    }

                    if (formMasterId > 0)
                    {
                        try
                        {
                            FormCellDependency dependency   = null;
                            Annotation         annotation   = formAnnotations.Any() ? formAnnotations.Where(a => a.AnnotationName == item.FieldName).FirstOrDefault() : null;
                            SummaryLabel       summaryLabel = summaryLabels.Any() ? summaryLabels.Where(a => a.SummaryLabelCode == item.SummaryLabel || a.Description == item.SummaryLabel).FirstOrDefault() : null;
                            if (annotation == null)
                            {
                                if (summaryLabel == null)
                                {
                                    Console.WriteLine(string.Format("AddFormCellDependencyFromExcel:  Unable to find summary label [{0}] or field name [{1}] on tax form [{2}].", item.SummaryLabel, item.FieldName, item.TaxFormCode));
                                }
                                else
                                {
                                    dependency = existingDependencies.Any() ? existingDependencies.Where(d => d.SummaryLabelId == summaryLabel.SummaryLabelId && !d.AnnotationId.HasValue && d.FormMasterOptionId == formMasterId).FirstOrDefault() : null;
                                }
                            }
                            else
                            {
                                if (summaryLabel == null)
                                {
                                    dependency = existingDependencies.Any() ? existingDependencies.Where(d => d.AnnotationId == annotation.AnnotationId && !d.SummaryLabelId.HasValue && d.FormMasterOptionId == formMasterId).FirstOrDefault() : null;
                                }
                                else
                                {
                                    dependency = existingDependencies.Any() ? existingDependencies.Where(d => d.SummaryLabelId == summaryLabel.SummaryLabelId && d.AnnotationId == annotation.AnnotationId && d.FormMasterOptionId == formMasterId).FirstOrDefault() : null;
                                }
                            }
                            if (summaryLabel != null || annotation != null)
                            {
                                FormCellDependency dependencyToAdd = new FormCellDependency();
                                dependencyToAdd.FormCellDependencyId = dependency == null ? -1 : dependency.FormCellDependencyId;
                                dependencyToAdd.FormMasterId         = updateFormMasterId;
                                dependencyToAdd.FormMasterOptionId   = formMasterId;
                                dependencyToAdd.AnnotationId         = annotation == null ? null : (long?)annotation.AnnotationId;
                                dependencyToAdd.SummaryLabelId       = summaryLabel == null ? null : (long?)summaryLabel.SummaryLabelId;
                                dependencyToAdd.IncludeCurrentPeriod = item.CurrentPeriod.ToUpper() == "1" ? true : false;
                                dependencyToAdd.MonthsAgo            = item.Months;
                                dependencyToAdd.PriorYearEndFiscal   = item.PriorYear.ToUpper() == "1" ? true : false;
                                dependencyToAdd.CreatedDate          = System.DateTime.UtcNow;
                                dependencyToAdd.CreatedUserId        = 0;
                                dependencyToAdd.ModifiedDate         = System.DateTime.UtcNow;
                                dependencyToAdd.ModifiedUserId       = 0;
                                recordsToAdd.Add(dependencyToAdd);
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(string.Format("AddFormCellDependencyFromExcel: An error occurred [{0}] while processing TaxFormCode [{1}] and summary label [{2}] and field [{3}].", ex.Message, item.TaxFormCode, item.SummaryLabel, item.FieldName));
                        }
                    }
                }


                // insert records to FormCellDependency
                int recordsInserted = 0;
                int recordsUpdated  = 0;
                int recordsErrored  = 0;
                if (recordsToAdd.Count > 0)
                {
                    recordsInserted = UpdateFormCellDepencencies(recordsToAdd, args[1], args[2], args[3], out recordsUpdated, out recordsErrored);
                }
                Console.WriteLine(string.Format("AddFormCellDependencyFromExcel: {0} records inserted and {1} records updated out of {2} total records.  There were {3} records that resulted in an error. ", recordsInserted.ToString(), recordsUpdated.ToString(), totalRecords.ToString(), recordsErrored.ToString()));
            }
        }