Example #1
0
        /// <summary>
        /// Updates a FormMaster record given the FormMaster Object
        /// </summary>
        /// <param name="TaxFormCode"></param>
        /// <param name="Url"></param>
        /// <param name="Username"></param>
        /// <param name="Drowssap"></param>
        /// <returns></returns>
        private static bool UpdateFormMaster(FormMaster updatedFormMaster, string Url, string Username, string Drowssap)
        {
            string     payload            = string.Empty;
            string     query              = string.Empty;
            FormMaster responseFormMaster = new FormMaster();

            try
            {
                payload = JsonConvert.SerializeObject(updatedFormMaster);
                byte[] buf = Encoding.UTF8.GetBytes(payload);

                query = string.Format("/api/FormMaster/{0}", updatedFormMaster.FormMasterId.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        = "PUT";
                request.ContentLength = buf.Length;
                request.ContentType   = "application/json; charset=utf-8";
                request.GetRequestStream().Write(buf, 0, buf.Length);

                // 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();
                        if (response.StatusCode == HttpStatusCode.OK)
                        {
                            responseFormMaster = responseString.Length > 0 ? Newtonsoft.Json.JsonConvert.DeserializeObject <FormMaster>(responseString) : null;
                        }
                        else
                        {
                            Console.WriteLine("8: UpdateForMMaster: Unable to update FormMaster for TaxFormCode [{0}] due to an unhandled exception:[{1}]", updatedFormMaster.TaxFormCode, responseString);
                            return(false);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("7: UpdateForMMaster: Unable to update FormMaster for TaxFormCode [{0}] due to an unhandled exception:[{1}]", updatedFormMaster.TaxFormCode, ex.Message);
                return(false);
            }

            return(true);
        }
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>
        static void Main(string[] args)
        {
            List <InputData> FormGrossFromDetails = new List <InputData>(); // = null;

            //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();
                    Int64         rowNumber     = 0;

                    foreach (Row row in sheetData.Elements <Row>())
                    {
                        rowNumber++;
                        InputData FormGrossFromDetail = new InputData();
                        int       rowcolumn           = 1;
                        if (rowNumber > 1)
                        {
                            foreach (Cell c in row.Elements <Cell>())
                            {
                                switch (rowcolumn)
                                {
                                case 1: FormGrossFromDetail.TaxFormCode = ReadExcelCell(c, workbookPart); break;
                                }

                                rowcolumn++;
                            }

                            FormGrossFromDetails.Add(FormGrossFromDetail);
                        }
                    }
                }
            }

            int totalRecords   = FormGrossFromDetails.Count;
            int recordsUpdated = 0;
            int recordsErrored = 0;

            foreach (InputData item in FormGrossFromDetails)
            {
                FormMaster currentFormMaster = GetFormMaster(item.TaxFormCode, args[1], args[2], args[3]);
                if (currentFormMaster == null)
                {
                    Console.WriteLine(string.Format("1: Unable to find a formmaster record for taxformcode [{0}].", item.TaxFormCode));
                }
                else
                {
                    try
                    {
                        currentFormMaster.GrossFromDetail = true;
                        bool updated = UpdateFormMaster(currentFormMaster, args[1], args[2], args[3]);
                        if (updated)
                        {
                            recordsUpdated++;
                        }
                        else
                        {
                            recordsErrored++;
                            Console.WriteLine(string.Format("2: Main: UpdateFormMaster was not successful updating the form master record while processing TaxFormCode [{0}].", item.TaxFormCode));
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(string.Format("4: Main: An error occurred [{0}] while processing TaxFormCode [{1}].", ex.Message, item.TaxFormCode));
                        recordsErrored++;
                    }
                }
            }

            Console.WriteLine(string.Format("5: Main: {0} records updated and {1} records errored out of {2} total records.", recordsUpdated.ToString(), recordsErrored.ToString(), totalRecords.ToString()));
            Console.ReadKey();
        }
Example #3
0
        /// <summary>
        /// obtains the formmaster for a given TaxFormCode
        /// </summary>
        /// <param name="TaxFormCode"></param>
        /// <param name="Url"></param>
        /// <param name="Username"></param>
        /// <param name="Drowssap"></param>
        /// <returns></returns>
        private static FormMaster GetFormMaster(string TaxFormCode, string Url, string Username, string Drowssap)
        {
            FormMaster formMaster = new FormMaster();
            string     query      = string.Empty;

            try
            {
                query = string.Format("/api/FormMaster/%7Bid%7D?taxFormCode={0}", TaxFormCode);

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

                // execute the request.
                using (var response1 = (HttpWebResponse)request1.GetResponse())
                {
                    if (response1 != null)
                    {
                        var responseStream1 = response1.GetResponseStream();
                        var streamReader1   = new System.IO.StreamReader(responseStream1, System.Text.Encoding.UTF8);
                        var responseString1 = streamReader1.ReadToEnd();

                        formMaster = responseString1.Length > 0 ? Newtonsoft.Json.JsonConvert.DeserializeObject <FormMaster>(responseString1) : null;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("7: GetFormMasterId 1: Unable to find TaxFormCode [{0}] due to an unhandled exception:[{1}]", TaxFormCode, ex.Message);
            }


            try
            {
                if (formMaster == null)
                {
                    query = string.Format("/api/FormMaster/%7Bid%7D?legacyReturnName={0}", TaxFormCode);
                    var request2 = (HttpWebRequest)WebRequest.Create(Url + query);
                    request2.Headers.Add(HttpRequestHeader.Authorization, "Basic " + Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(Username + ":" + Drowssap)));

                    using (var response2 = (HttpWebResponse)request2.GetResponse())
                    {
                        if (response2 != null)
                        {
                            var responseStream2 = response2.GetResponseStream();
                            var streamReader2   = new System.IO.StreamReader(responseStream2, System.Text.Encoding.UTF8);
                            var responseString2 = streamReader2.ReadToEnd();

                            formMaster = responseString2.Length > 0 ? Newtonsoft.Json.JsonConvert.DeserializeObject <FormMaster>(responseString2) : null;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("8: GetFormMasterId 2: Unable to find LegacyReturnName [{0}] due to an unhandled exception:[{1}]", TaxFormCode, ex.Message);

                return(formMaster);
            }

            return(formMaster);
        }