예제 #1
0
        public string SaveLogFile(string fileName, string deviceId)
        {
            string deviceFileName = string.Empty;

            try
            {
                var httpRequest = HttpContext.Current.Request;
                if (httpRequest.Files.Count > 0)
                {
                    FilelHelper fileHelper = new FilelHelper();
                    foreach (string file in httpRequest.Files)
                    {
                        string filePath = ConfigurationHelper.GetDeviceLogFilePath();
                        fileHelper.CreateDirectory(filePath);
                        var postedFile = httpRequest.Files[file];
                        deviceFileName = string.Format("{0}_{1}", deviceId, fileName);
                        if (File.Exists(Path.Combine(filePath, deviceFileName)))
                        {
                            fileHelper.DeleteFile(Path.Combine(filePath, deviceFileName));
                        }
                        postedFile.SaveAs(Path.Combine(filePath, deviceFileName));
                    }
                }
            }
            catch (Exception ex)
            {
                string details = string.Format("Method: {1} {0} Message: {2} {0} Stack Trace: {3}", System.Environment.NewLine, "SaveTicketImage", ex.Message, ex.StackTrace.ToString());
                smART.Common.MessageLogger.Instance.LogMessage(ex, details, Common.Priority.High, 0, System.Diagnostics.TraceEventType.Error, "Service Error", "Service");
            }
            return(deviceFileName);
        }
예제 #2
0
        public string SaveTicketImage(string fileName)
        {
            var docfiles = new List <string>();

            try {
                var httpRequest = HttpContext.Current.Request;
                if (httpRequest.Files.Count > 0)
                {
                    FilelHelper fileHelper = new FilelHelper();
                    foreach (string file in httpRequest.Files)
                    {
                        string docRefID        = Guid.NewGuid().ToString();
                        var    destinationPath = fileHelper.GetTempSourceDirByFileRefId(docRefID); // Path.Combine(Configuration.GetsmARTTempDocPath(), docRefID);
                        fileHelper.CreateDirectory(destinationPath);
                        var postedFile = httpRequest.Files[file];
                        postedFile.SaveAs(Path.Combine(destinationPath, fileName));
                        docfiles.Add(docRefID);
                    }
                }
            }
            catch (Exception ex) {
                ExceptionHandler.HandleException(ex, "An error occured in SaveTicketImage from device.");

                //string details = string.Format("Method: {1} {0} Message: {2} {0} Stack Trace: {3}", System.Environment.NewLine, "SaveTicketImage", ex.Message, ex.StackTrace.ToString());
                //smART.Common.MessageLogger.Instance.LogMessage(ex, details, Common.Priority.High, 0, System.Diagnostics.TraceEventType.Error, "Service Error", "Service");
            }
            return(docfiles.FirstOrDefault());
        }
예제 #3
0
        public string SaveTicketImage(String scaleId, string documentType)
        {
            var docfiles = new List <string>();

            try {
                int intScaleId = Convert.ToInt32(scaleId);
                if (intScaleId <= 0)
                {
                    throw new Exception("Invalid ticket id.");
                }

                int    intDocType = Convert.ToInt32(documentType);
                string fileName   = CommonHelper.GetFileNameByDocType(intDocType);
                if (string.IsNullOrEmpty(fileName))
                {
                    throw new Exception("Invalid document type.");
                }


                var httpRequest = HttpContext.Current.Request;
                if (httpRequest.Files.Count > 0)
                {
                    // Get scale
                    Scale scale = new ScaleLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()).GetByID(scaleId, new string[] { "Party_ID" });
                    if (scale == null)
                    {
                        throw new Exception("Given scale id not found in database.");
                    }

                    FilelHelper fileHelper = new FilelHelper();
                    foreach (string file in httpRequest.Files)
                    {
                        // Save file
                        string docRefID        = Guid.NewGuid().ToString();
                        var    destinationPath = fileHelper.GetSourceDirByFileRefId(docRefID); // Path.Combine(Configuration.GetsmARTTempDocPath(), docRefID);
                        fileHelper.CreateDirectory(destinationPath);
                        var postedFile = httpRequest.Files[file];
                        postedFile.SaveAs(Path.Combine(destinationPath, fileName));
                        docfiles.Add(docRefID);

                        // Add attachment
                        ScaleAttachments attachments = new ScaleAttachments();
                        attachments.Document_Name  = fileName;
                        attachments.Document_RefId = new Guid(docRefID);
                        attachments.Document_Size  = 0;
                        attachments.Document_Title = fileName;
                        attachments.Document_Type  = "jpeg";
                        attachments.Ref_Type       = intDocType;

                        attachments.Updated_By        = User.Identity.Name;
                        attachments.Created_By        = User.Identity.Name;
                        attachments.Created_Date      = DateTime.Now;
                        attachments.Last_Updated_Date = DateTime.Now;
                        attachments.Parent            = new Scale {
                            ID = intScaleId
                        };
                        attachments.Document_Path = destinationPath;

                        ScaleAttachmentsLibrary ScaleLibrary = new ScaleAttachmentsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        attachments.Document_Name = fileName;
                        ScaleAttachments scaleAttachment = ScaleLibrary.Add(attachments);

                        // Update file ref in party master
                        if (scale.Party_ID != null && scale.Party_ID.ID > 0)
                        {
                            PartyLibrary partyLib = new PartyLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                            Party        party    = partyLib.GetByID(scale.Party_ID.ID.ToString());
                            if (party != null)
                            {
                                SetPartyImageRefByDocType(intDocType, scaleAttachment.Document_RefId.ToString(), party);
                                partyLib.Modify(party);
                            }
                        }
                    }
                }
            }
            catch (Exception ex) {
                //string details = string.Format("Method: {1} {0} Message: {2} {0} Stack Trace: {3}", System.Environment.NewLine, "SaveTicketImage", ex.Message, ex.StackTrace.ToString());
                ExceptionHandler.HandleException(ex, "An error occured in SaveTicketImage utils.");
                //smART.Common.MessageLogger.Instance.LogMessage(ex, details, Common.Priority.High, 0, System.Diagnostics.TraceEventType.Error, "Service Error", "Service");
            }
            return(docfiles.FirstOrDefault());
        }
예제 #4
0
        public ActionResult SendEmail(string id)
        {
            string      destinationFilePath = string.Empty;
            FilelHelper fileHelper          = new FilelHelper();

            try
            {
                if (string.IsNullOrEmpty(id))
                {
                    throw new Exception("Email send failed due to Container# not found.");
                }

                ContainerLibrary containerLib = new ContainerLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                Container        container    = containerLib.GetByID(id, new string[] { "Booking.Sales_Order_No.Party" });

                if (container == null || container.Booking == null || container.Booking.Sales_Order_No == null || container.Booking.Sales_Order_No.Party == null)
                {
                    throw new Exception("Email send failed.");
                }

                IEnumerable <Contact> contacts = Helpers.ContactHelper.GetEmailContactsByPartyId(container.Booking.Sales_Order_No.Party.ID);
                if (contacts.Count() <= 0)
                {
                    throw new Exception("There is no email contact exists.");
                }

                NotificationDefinition notDef = new NotificationDefinition();
                notDef.ToRecipients = new System.Net.Mail.MailAddressCollection();
                foreach (var item in contacts)
                {
                    notDef.ToRecipients.Add(new System.Net.Mail.MailAddress(item.Email, item.ListText));
                }

                EmployeeHelper employeeHelper = new EmployeeHelper();
                Employee       employee       = employeeHelper.GetEmployeeByUsername(System.Web.HttpContext.Current.User.Identity.Name);
                if (employee == null || string.IsNullOrEmpty(employee.Email) || string.IsNullOrEmpty(employee.Email_Password))
                {
                    throw new Exception("Sender email and password is required.");
                }

                ScaleLibrary scaleLib = new ScaleLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                Scale        scale    = scaleLib.GetScalesByContainerId(container.ID);

                ScaleAttachmentsLibrary        scaleAttachLib   = new ScaleAttachmentsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                IEnumerable <ScaleAttachments> scaleAttachments = scaleAttachLib.GetAllByParentID(scale.ID);
                if (scaleAttachments == null || scaleAttachments.Count() <= 0)
                {
                    throw new Exception("There is no attachment found.");
                }

                destinationFilePath = Path.Combine(Path.GetTempPath(), container.ID.ToString());
                fileHelper.CreateDirectory(destinationFilePath);
                fileHelper.DeleteFiles(destinationFilePath);
                string imageFilePath = Path.Combine(destinationFilePath, "Images");
                fileHelper.CreateDirectory(imageFilePath);

                string zipFilePath = Path.Combine(destinationFilePath, container.ID.ToString() + ".zip");

                foreach (var item in scaleAttachments)
                {
                    string sourceFilePath    = fileHelper.GetFilePathByFileRefId(item.Document_RefId.ToString());
                    string imageFileFullPath = Path.Combine(imageFilePath, item.Document_Name);
                    System.IO.File.Copy(sourceFilePath, imageFileFullPath);
                }
                new smART.Common.FilelHelper().CreateZip(imageFilePath, zipFilePath);

                if (!fileHelper.FileExits(zipFilePath))
                {
                    throw new Exception("There is no attachment found.");
                }

                string xslPath     = Path.Combine(ConfigurationHelper.GetsmARTXslPath(), "ContainerEmailBody.xslt");
                string smtpAddress = ConfigurationHelper.GetsmARTSMTPServer();

                notDef.Attachments = new List <System.Net.Mail.Attachment>();
                notDef.Attachments.Add(new System.Net.Mail.Attachment(zipFilePath));
                notDef.DeliveryType            = EnumNotificationDeliveryType.Email;
                notDef.FormatType              = EnumFormatType.HTML;
                notDef.Sender                  = new System.Net.Mail.MailAddress(employee.Email, employee.Emp_Name);
                notDef.SMTPServer              = smtpAddress;
                notDef.SMTPServerCredentialID  = employee.Email;
                notDef.SMTPServerCredentialPwd = employee.Email_Password;
                notDef.Subject                 = "Booking#/Container#: " + container.Booking.Booking_Ref_No + "/" + container.Container_No;
                NotificationHelper.StartNotificationWF(id, container.Booking.Sales_Order_No.Party.Party_Name, PartyHelper.GetOrganizationName(), employee.Emp_Name, notDef, xslPath, NotificationWFCompleted, container.Booking.Booking_Ref_No, container.Booking.Sales_Order_No.ID.ToString());
                //return Display(command, container);
                if (_sendMail == true)
                {
                    return(Json(new { Sucess = "Email send sucessfully." }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new { Sucess = "Email send failed." }, JsonRequestBehavior.AllowGet));
                }
                //return Json(new { Sucess = "Email send sucessfully." }, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                //var script = @"ShowAlertMessage(""Send mail failed"");";
                //return JavaScript(script);
                return(Json(new { Sucess = ex.Message }, JsonRequestBehavior.AllowGet));
            }
            finally
            {
                //fileHelper.DeleteDirectory(destinationFilePath);
            }
        }