Exemplo n.º 1
0
        private void FillVoiceAndNotes(ExcelWorksheet VoiceAndNotesSheet, ArcoOrder Orderdetail)
        {
            VoiceAndNotesSheet.Select();
            Regex regEx = new Regex("{{.*?}}");
            IEnumerable <ExcelRangeBase> _foundranges = VoiceAndNotesSheet.Cells.Where(fil => fil.Value != null).Where(fil => regEx.IsMatch(fil.Value.ToString()));

            Type _type = Orderdetail.VoiceNotesnPics.GetType();

            foreach (ExcelRangeBase _foundrange in _foundranges)
            {
                String _membername = ((String)_foundrange.Value).Replace("{{", String.Empty).Replace("}}", String.Empty);
                try
                {
                    _foundrange.Value = _type.GetProperty(_membername).GetValue(Orderdetail.VoiceNotesnPics, null);
                }
                catch (Exception ex)
                {
                    _foundrange.Value = "Member Name not found";
                }
            }
            regEx = new Regex("[[ImageList]]");
            ExcelRangeBase _imgrange = VoiceAndNotesSheet.Cells.Where(fil => fil.Value != null).Where(fil => regEx.IsMatch(fil.Value.ToString())).FirstOrDefault();

            if (_foundranges != null)
            {
                if (Orderdetail.VoiceNotesnPics.ImageAttachments.Count > 0)
                {
                    int    _imgcount  = 1;
                    String _imagelist = String.Empty;
                    Orderdetail.VoiceNotesnPics
                    .ImageAttachments
                    .ForEach(img =>
                    {
                        _imagelist = String.Concat(_imagelist,
                                                   String.Format("{0}_Image_{1}.jpeg", Orderdetail.OrderFramework.SalesOrderNumber, _imgcount++),
                                                   "\n");
                    });
                    _imgrange.Value = _imagelist;
                }
                else
                {
                    _imgrange.Value = String.Empty;
                }
            }
            VoiceAndNotesSheet.Select("A1");
        }
Exemplo n.º 2
0
        public void FillInboundAndPackaging(ExcelWorksheet InboundAndPackagingSheet, ArcoOrder Orderdetail)
        {
            InboundAndPackagingSheet.Select();
            Regex regEx = new Regex("{{.*?}}");
            IEnumerable <ExcelRangeBase> _foundranges = InboundAndPackagingSheet.Cells.Where(fil => fil.Value != null).Where(fil => regEx.IsMatch(fil.Value.ToString()));

            Type _type = Orderdetail.InboundnPackaging.GetType();

            foreach (ExcelRangeBase _foundrange in _foundranges)
            {
                String _membername = ((String)_foundrange.Value).Replace("{{", String.Empty).Replace("}}", String.Empty);
                try
                {
                    _foundrange.Value = _type.GetProperty(_membername).GetValue(Orderdetail.InboundnPackaging, null);
                }
                catch (Exception ex)
                {
                    _foundrange.Value = "Member Name not found";
                }
            }
            InboundAndPackagingSheet.Select("A1");
        }
Exemplo n.º 3
0
        private void CreateExcelDocument(ArcoOrder OrderDetail, String FileName)
        {
            String       _TemplateFileName = "ARCOeCardTemplateV3.xlsm";
            String       _TemplatePath     = String.Format(@"{0}\{1}", AppDomain.CurrentDomain.GetData("DataDirectory").ToString(), _TemplateFileName);
            FileInfo     _templatefileinfo = new FileInfo(_TemplatePath);
            FileInfo     _targetfileinfo   = new FileInfo(FileName);
            ExcelPackage _excel            = new ExcelPackage(_targetfileinfo, _templatefileinfo);

            ExcelWorksheet _ordersheet = _excel.Workbook.Worksheets["OrderFramework"];
            ExcelWorksheet _InboundAndPackagingSheet = _excel.Workbook.Worksheets["Inbound&Packaging"];
            ExcelWorksheet _VoiceAndNotesSheet       = _excel.Workbook.Worksheets["Voice&Notes"];
            ExcelWorksheet _specandrepairsheet       = _excel.Workbook.Worksheets["Specification&Repairs"];

            FillOrderSheet(_ordersheet, OrderDetail);

            FillInboundAndPackaging(_InboundAndPackagingSheet, OrderDetail);

            _specandrepairsheet.Name = "Specification&Repairs-1";
            if (OrderDetail.SpecificationRepairs.Count > 1)
            {
                for (int idx = 1; idx < OrderDetail.SpecificationRepairs.Count; idx++)
                {
                    _excel.Workbook.Worksheets.Add(String.Format("Specification&Repairs-{0}", idx + 1),
                                                   _excel.Workbook.Worksheets[String.Format("Specification&Repairs-{0}", idx)]);
                }
            }
            List <ExcelWorksheet> _specssheets = _excel.Workbook.Worksheets.Where(fil => fil.Name.StartsWith("Specification&Repairs-")).ToList();
            int _specidx = 0;

            _specssheets.ForEach(item =>
            {
                FillSpecsAndReapirs(item, OrderDetail.SpecificationRepairs[_specidx++]);
            });

            FillVoiceAndNotes(_VoiceAndNotesSheet, OrderDetail);
            _excel.Workbook.Worksheets.MoveToEnd("Voice&Notes");
            _ordersheet.Select();
            _excel.Save();
        }
Exemplo n.º 4
0
        public IHttpActionResult PostOrder(ArcoOrder order)
        {
            if (Prenotes.CheckPreNoteSubmit(order.OrderFramework.PrenoteId))
            {
                return(Content(HttpStatusCode.Conflict, "Prenote already submitted"));
            }
            if (Prenotes.CheckPreNoteDelete(order.OrderFramework.PrenoteId))
            {
                return(Content(HttpStatusCode.NotFound, "Prenote Deleted"));
            }

            ArcoOrder _orderclonewithoutimages = new ArcoOrder()
            {
                InboundnPackaging    = order.InboundnPackaging,
                OrderFramework       = order.OrderFramework,
                SpecificationRepairs = order.SpecificationRepairs,
                VoiceNotesnPics      = new VoiceNotesnPics()
                {
                    BookingCompletionDate = order.VoiceNotesnPics.BookingCompletionDate,
                    ImageAttachments      = new List <string>(),
                    VoiceAndNotesComments = order.VoiceNotesnPics.VoiceAndNotesComments
                }
            };

            Log.Info(String.Format("Request received from:{0}/{1} with the following detail\r\n{2}",
                                   HttpContext.Current.Request.UserHostAddress,
                                   HttpContext.Current.Request.UserHostName,
                                   JsonConvert.SerializeObject(_orderclonewithoutimages)));
            try
            {
                String _CurrentYearFolder = String.Format(@"{0}\{1}",
                                                          ConfigurationManager.AppSettings["FileServerPath"].ToString(),
                                                          DateTime.Now.Year.ToString());
                if (!Directory.Exists(_CurrentYearFolder))//If Current year folder is not there create it
                {
                    Directory.CreateDirectory(_CurrentYearFolder);
                    Log.Info(String.Format("Year folder:{0} created", _CurrentYearFolder));
                }
                String pattern = @"[\\\/\:\*\?\""\<\>\|]";
                String _BillToCompanyWithLegalCharacters = Regex.Replace(order.OrderFramework.BilltoCompany,
                                                                         pattern,
                                                                         " ",
                                                                         RegexOptions.CultureInvariant);
                String _ClientFolder = String.Format(@"{0}\{1}-{2}",
                                                     _CurrentYearFolder,
                                                     _BillToCompanyWithLegalCharacters,
                                                     order.OrderFramework.CustomerNumberBillTo);

                if (!Directory.Exists(_ClientFolder))//If Customer folder under Current year folder is not there create it
                {
                    Directory.CreateDirectory(_ClientFolder);
                    Log.Info(String.Format("Client folder:{0} created", _ClientFolder));
                }

                String orderfolder = String.Format(@"{0}\{1}",
                                                   _ClientFolder,
                                                   order.OrderFramework.SalesOrderNumber);

                String filename = String.Format(@"{0}\{1}.json", orderfolder, order.OrderFramework.SalesOrderNumber);

                if (!Directory.Exists(orderfolder))
                {
                    Directory.CreateDirectory(orderfolder);
                    CreateExcelDocument(order, String.Format(@"{0}\{1}.xlsm", orderfolder, order.OrderFramework.SalesOrderNumber));
                    Log.Info(String.Format(@"Data file:{0}\{1}.xlsm created", orderfolder, order.OrderFramework.SalesOrderNumber));
                    //int _imgcounter = 1;
                    //order
                    //    .VoiceNotesnPics
                    //    .ImageAttachments
                    //    .ForEach(Attachment =>
                    //    {
                    //        String _imagefilename = String.Format(@"{0}\{3}_Image_{1}.{2}", orderfolder, _imgcounter++, "jpeg", order.OrderFramework.SalesOrderNumber);
                    //        if (SaveImage(Attachment, _imagefilename))
                    //        {
                    //            Log.Info(String.Format(@"Image {0} created", _imagefilename));
                    //        }
                    //        else
                    //        {}
                    //    });
                    String Folderpath = String.Format(@"{0}\{1}-{2}\{3}", DateTime.Now.Year.ToString(),
                                                      _BillToCompanyWithLegalCharacters,
                                                      order.OrderFramework.CustomerNumberBillTo,
                                                      order.OrderFramework.SalesOrderNumber);

                    if (order.OrderFramework.PrenoteId > 0)
                    {
                        List <Attachment> Attachments = Prenotes.getAttachmentforPrenote(order.OrderFramework.PrenoteId);

                        String _SourceFolder = String.Format(@"{0}", ConfigurationManager.AppSettings["AttachmentsPath"].ToString());

                        String _DestFolder = String.Format(@"{0}\{1}", orderfolder, "Prenote Attachments");

                        if (!Directory.Exists(_DestFolder))
                        {
                            Directory.CreateDirectory(_DestFolder);
                            Log.Info(String.Format("Prenote folder:{0} created", _DestFolder));
                        }

                        foreach (Attachment item in Attachments)
                        {
                            var SourcefilePath = String.Format(@"{0}\{1}", _SourceFolder, item.ReferenceName + "." + item.Type);
                            var DestfilePath   = String.Format(@"{0}\{1}", _DestFolder, item.FileName + "." + item.Type);
                            File.Copy(SourcefilePath, DestfilePath);
                        }

                        //String Folderpath = String.Format(@"{0}\{1}-{2}\{3}", DateTime.Now.Year.ToString(),
                        //                            _BillToCompanyWithLegalCharacters,
                        //                            order.OrderFramework.CustomerNumberBillTo,
                        //                            order.OrderFramework.SalesOrderNumber);



                        Prenotes.PrenoteBooked(order.OrderFramework.PrenoteId);
                        Prenotes.MapSalesOrder1(order.OrderFramework, Folderpath);
                    }
                    else
                    {
                        Prenotes.MapSalesOrder(order.OrderFramework, Folderpath);
                    }
                    SmtpClient  _emailclient = new SmtpClient();
                    MailMessage _message     = new MailMessage();
                    // _message.From = new MailAddress(ConfigurationManager.AppSettings["EmailFrom"].ToString());
                    MailAddressCollection _to          = new MailAddressCollection();
                    List <String>         _toaddresses = new List <String>(ConfigurationManager.AppSettings["EmailTo"].Split(';'));
                    _toaddresses.ForEach(_toaddress =>
                    {
                        _message.To.Add(new MailAddress(_toaddress));
                    });
                    _message.Subject = String.Format("Plant: {3} {0} - {1} Order {2}",
                                                     order.OrderFramework.BilltoCompany,
                                                     order.OrderFramework.CustomerNumberBillTo,
                                                     order.OrderFramework.SalesOrderNumber,
                                                     order.OrderFramework.SiteLocation);
                    _message.IsBodyHtml = true;
                    _message.Body       = String.Format("Please find below the detail in the following File server<BR><A HREF=\"{0}\">{0}</A>", orderfolder);
                    //_emailclient.Send(_message);
                    //Log.Info("Mail Sent.");
                    return(Content(HttpStatusCode.OK, "SUCCESS"));
                }
                else
                {
                    return(Content(HttpStatusCode.BadRequest, "Order already Exist"));
                }
            }
            catch (DbEntityValidationException ex)
            {
                foreach (var eve in ex.EntityValidationErrors)
                {
                    Log.Error(String.Format("Request received from:{0}/{1}",
                                            HttpContext.Current.Request.UserHostAddress,
                                            HttpContext.Current.Request.UserHostName), ex);
                    Log.Error(string.Format("Err @ UpdatePrenoteSystem: Method:{0}, Entity Type: {1}, Entity State: {2}", "PrenoteSalesOrder", eve.Entry.Entity.GetType().Name, eve.Entry.State));
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Log.Error(string.Format("Err @ UpdatePrenoteSystem: Method:{0}, {1}, {2}", "PrenoteSalesOrder", ve.PropertyName, ve.ErrorMessage));
                    }
                }
                Log.Error(String.Format("Request received from:{0}/{1}",
                                        HttpContext.Current.Request.UserHostAddress,
                                        HttpContext.Current.Request.UserHostName), ex);
                return(Content(HttpStatusCode.InternalServerError, String.Format("{0}\r\n{1}", ex.Message, ex.StackTrace)));
            }
            catch (Exception ex)
            {
                Log.Error(String.Format("Request received from:{0}/{1}",
                                        HttpContext.Current.Request.UserHostAddress,
                                        HttpContext.Current.Request.UserHostName), ex);
                return(Content(HttpStatusCode.InternalServerError, String.Format("{0}\r\n{1}", ex.Message, ex.StackTrace)));
            }
        }