Exemplo n.º 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);
        }
Exemplo n.º 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());
        }
Exemplo n.º 3
0
        public JsonResult _SaveCustomerThumbImage(string scaleId, string documentRefId1, string documentRefId2)
        {
            try
            {
                // Save thumb image1
                if (!string.IsNullOrEmpty(documentRefId1))
                {
                    FilelHelper fileHelper = new FilelHelper();
                    string      filePath   = fileHelper.GetFilePathByFileRefId(documentRefId1);
                    if (System.IO.File.Exists(filePath))
                    {
                        Byte[] photoBytes = fileHelper.GetBytesFromFile(filePath);
                        SaveThumbScannerAttachment(Convert.ToInt32(scaleId), photoBytes, "Thumb-Image1", EnumAttachmentRefType.Thumbprint1, FileFormat.jpg, false);
                    }
                }

                // Save thumb image2
                if (!string.IsNullOrEmpty(documentRefId2))
                {
                    FilelHelper fileHelper = new FilelHelper();
                    string      filePath   = fileHelper.GetFilePathByFileRefId(documentRefId2);
                    if (System.IO.File.Exists(filePath))
                    {
                        Byte[] photoBytes = fileHelper.GetBytesFromFile(filePath);
                        SaveThumbScannerAttachment(Convert.ToInt32(scaleId), photoBytes, "Thumb-Image2", EnumAttachmentRefType.Thumbprint2, FileFormat.jpg, false);
                    }
                }
                return(Json(new { Sucess = "True" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { Sucess = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 4
0
 public JsonResult _SavePartyLicenceID(string scaleId, string licenseImageRefId)
 {
     try {
         bool result = false;
         if (!string.IsNullOrEmpty(licenseImageRefId))
         {
             ScaleAttachmentsLibrary scaleAttOps     = new ScaleAttachmentsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
             ScaleAttachments        scaleAttachment = scaleAttOps.GetScaleAttachmentByRefId(new Guid(licenseImageRefId));
             if (scaleAttachment != null)
             {
                 FilelHelper fileHelper = new FilelHelper();
                 string      imagePath  = fileHelper.GetFilePathByFileRefId(licenseImageRefId);
                 byte[]      imageBytes = fileHelper.GetBytesFromFile(imagePath);
                 SaveScaleIDCardAttachment(Convert.ToInt32(scaleId), imageBytes);
                 result = true;
             }
         }
         var data = new { Success = result };
         return(Json(data, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex) {
         string message = ex.Message;
         Common.MessageLogger.Instance.LogMessage(ex, ex.Message, Common.Priority.High, 0, System.Diagnostics.TraceEventType.Critical, "Scanner Error", "Scanner");
         throw ex;
     }
 }
Exemplo n.º 5
0
        protected override void SaveChildEntities(string[] childEntityList, Item entity)
        {
            foreach (string ChildEntity in childEntityList)
            {
                switch (ChildEntity)
                {
                    #region /* Case Statements - All child grids */

                case "ItemNotes":
                    if (Session[ChildEntity] != null)
                    {
                        ItemNotesLibrary        itemNotesLibrary = new ItemNotesLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        IEnumerable <ItemNotes> resultList       = (IList <ItemNotes>)Session[ChildEntity];
                        foreach (ItemNotes itemNote in resultList)
                        {
                            itemNote.Parent = new Item {
                                ID = entity.ID
                            };
                            //itemNote.Notes = System.Web.HttpUtility.HtmlDecode(itemNote.Notes);
                            itemNotesLibrary.Add(itemNote);
                        }
                    }
                    break;

                case "ItemAttachment":
                    if (Session[ChildEntity] != null)
                    {
                        ItemAttachmentLibrary        itemLibrary = new ItemAttachmentLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        IEnumerable <ItemAttachment> resultList  = (IList <ItemAttachment>)Session[ChildEntity];
                        string      destinationPath;
                        string      sourcePath;
                        FilelHelper fileHelper = new FilelHelper();
                        foreach (ItemAttachment item in resultList)
                        {
                            destinationPath    = fileHelper.GetSourceDirByFileRefId(item.Document_RefId.ToString());     // Path.Combine(Configuration.GetsmARTDocPath(), item.Document_RefId.ToString());
                            sourcePath         = fileHelper.GetTempSourceDirByFileRefId(item.Document_RefId.ToString()); // Path.Combine(Configuration.GetsmARTTempDocPath(), item.Document_RefId.ToString());
                            item.Document_Path = fileHelper.GetFilePath(sourcePath);
                            fileHelper.MoveFile(item.Document_Name, sourcePath, destinationPath);

                            item.Parent = new Item {
                                ID = entity.ID
                            };
                            itemLibrary.Add(item);
                        }
                    }
                    break;

                    #endregion
                }
            }
        }
Exemplo n.º 6
0
        protected override void SaveChildEntities(string[] childEntityList, Asset entity)
        {
            foreach (string ChildEntity in childEntityList)
            {
                switch (ChildEntity)
                {
                    #region /* Case Statements - All child grids */
                case "AssetAudit":
                    if (Session[ChildEntity] != null)
                    {
                        ILibrary <AssetAudit>    lib        = new AssetAuditLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        IEnumerable <AssetAudit> resultList = (IList <AssetAudit>)Session[ChildEntity];
                        foreach (AssetAudit result in resultList)
                        {
                            result.Asset = new Asset()
                            {
                                ID = entity.ID
                            };
                            lib.Add(result);
                        }
                    }
                    break;

                case "AssetAttachments":
                    if (Session[ChildEntity] != null)
                    {
                        AssetAttachmentsLibrary        lib        = new AssetAttachmentsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        IEnumerable <AssetAttachments> resultList = (IList <AssetAttachments>)Session[ChildEntity];
                        string      destinationPath;
                        string      sourcePath;
                        FilelHelper fileHelper = new FilelHelper();
                        foreach (AssetAttachments result in resultList)
                        {
                            destinationPath      = fileHelper.GetSourceDirByFileRefId(result.Document_RefId.ToString());
                            sourcePath           = fileHelper.GetTempSourceDirByFileRefId(result.Document_RefId.ToString());
                            result.Document_Path = fileHelper.GetFilePath(sourcePath);
                            fileHelper.MoveFile(result.Document_Name, sourcePath, destinationPath);
                            result.Parent = new Asset {
                                ID = entity.ID
                            };
                            lib.Add(result);
                        }
                    }
                    break;

                    #endregion
                }
            }
        }
Exemplo n.º 7
0
        public Guid SaveScaleIDCardAttachment(int Id, byte[] data)
        {
            Guid guid = SaveFile(data);

            ScaleAttachments attachments = new ScaleAttachments();

            attachments.Document_Name  = "LicenceID-Image.jpeg";
            attachments.Document_RefId = guid;
            attachments.Document_Size  = data.LongLength;
            attachments.Document_Title = "LicenceID-Image";
            attachments.Document_Type  = "jpeg";

            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 = Id
            };

            string destinationPath;
            string sourcePath;

            FilelHelper fileHelper = new FilelHelper();

            destinationPath = fileHelper.GetSourceDirByFileRefId(attachments.Document_RefId.ToString());     // Path.Combine(Configuration.GetsmARTDocPath(), Scale.Document_RefId.ToString());
            sourcePath      = fileHelper.GetTempSourceDirByFileRefId(attachments.Document_RefId.ToString()); // Path.Combine(Configuration.GetsmARTTempDocPath(), Scale.Document_RefId.ToString());

            attachments.Document_Path = fileHelper.GetFilePath(sourcePath);

            if (Id > 0)
            {
                fileHelper.MoveFile(attachments.Document_Name, sourcePath, destinationPath);
                ScaleAttachmentsLibrary ScaleLibrary = new ScaleAttachmentsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                ScaleLibrary.Add(attachments);
            }
            else
            {
                if (Session["ScaleAttachments"] == null)
                {
                    Session["ScaleAttachments"] = new List <ScaleAttachments>();
                }
                IList <ScaleAttachments> iList = (IList <ScaleAttachments>)Session["ScaleAttachments"];
                iList.Add(attachments);
            }
            return(guid);
        }
Exemplo n.º 8
0
        private void SaveAttachment(int Id, byte[] data, string fileName, EnumAttachmentRefType refType, FileFormat fileFormat)
        {
            Guid guid = SaveFile(data, fileName);

            ScaleAttachments attachments = new ScaleAttachments();

            attachments.Document_Name  = fileName;// "Thumb-Image.jpeg";
            attachments.Document_RefId = guid;
            attachments.Document_Size  = data.LongLength;
            attachments.Document_Title = fileName;
            attachments.Document_Type  = fileFormat.ToString();
            attachments.Ref_Type       = (int)refType;

            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 = Id
            };

            string destinationPath;
            string sourcePath;

            FilelHelper fileHelper = new FilelHelper();

            destinationPath = fileHelper.GetSourceDirByFileRefId(attachments.Document_RefId.ToString());     // Path.Combine(Configuration.GetsmARTDocPath(), Scale.Document_RefId.ToString());
            sourcePath      = fileHelper.GetTempSourceDirByFileRefId(attachments.Document_RefId.ToString()); // Path.Combine(Configuration.GetsmARTTempDocPath(), Scale.Document_RefId.ToString());

            attachments.Document_Path = fileHelper.GetFilePath(sourcePath);

            if (Id > 0)
            {
                fileHelper.MoveFile(attachments.Document_Name, sourcePath, destinationPath);
                ScaleAttachmentsLibrary ScaleLibrary = new ScaleAttachmentsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                attachments.Document_Name = fileName;
                ScaleAttachments scaleAttachment = ScaleLibrary.Add(attachments);
            }
            else
            {
                if (Session["ScaleAttachments"] == null)
                {
                    Session["ScaleAttachments"] = new List <ScaleAttachments>();
                }
                IList <ScaleAttachments> iList = (IList <ScaleAttachments>)Session["ScaleAttachments"];
                iList.Add(attachments);
            }
        }
Exemplo n.º 9
0
 public JsonResult _SaveCustomerImage(string scaleId, string documentRefId)
 {
     try
     {
         if (!string.IsNullOrEmpty(documentRefId))
         {
             FilelHelper fileHelper = new FilelHelper();
             string      filePath   = fileHelper.GetFilePathByFileRefId(documentRefId);
             if (System.IO.File.Exists(filePath))
             {
                 Byte[] photoBytes = fileHelper.GetBytesFromFile(filePath);
                 SaveScaleAttachment(Convert.ToInt32(scaleId), photoBytes, false);
             }
         }
         return(Json(new { Sucess = "True" }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         return(Json(new { Sucess = ex.Message }, JsonRequestBehavior.AllowGet));
     }
 }
Exemplo n.º 10
0
        protected override void SaveChildEntities(string[] childEntityList, Scale entity)
        {
            foreach (string ChildEntity in childEntityList)
            {
                switch (ChildEntity)
                {
                    #region /* Case Statements - All child grids */

                case "ScaleDetails":
                    if (Session[ChildEntity] != null)
                    {
                        ScaleDetailsLibrary        ScaleDetailsLibrary = new ScaleDetailsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        IEnumerable <ScaleDetails> resultList          = (IList <ScaleDetails>)Session[ChildEntity];
                        foreach (ScaleDetails scaleDetails in resultList)
                        {
                            scaleDetails.Scale = new Scale {
                                ID = entity.ID
                            };
                            ScaleDetailsLibrary.Add(scaleDetails);
                        }
                    }
                    break;

                case "ScaleNotes":
                    if (Session[ChildEntity] != null)
                    {
                        ScaleNotesLibrary        ScaleNotesLibrary = new ScaleNotesLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        IEnumerable <ScaleNotes> resultList        = (IList <ScaleNotes>)Session[ChildEntity];
                        foreach (ScaleNotes ScaleNote in resultList)
                        {
                            ScaleNote.Parent = new Scale {
                                ID = entity.ID
                            };
                            //itemNote.Notes = System.Web.HttpUtility.HtmlDecode(itemNote.Notes);
                            ScaleNotesLibrary.Add(ScaleNote);
                        }
                    }
                    break;

                case "ScaleAttachments":
                    if (Session[ChildEntity] != null)
                    {
                        ScaleAttachmentsLibrary        ScaleLibrary = new ScaleAttachmentsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        IEnumerable <ScaleAttachments> resultList   = (IList <ScaleAttachments>)Session[ChildEntity];
                        string      destinationPath;
                        string      sourcePath;
                        FilelHelper fileHelper = new FilelHelper();
                        foreach (ScaleAttachments Scale in resultList)
                        {
                            destinationPath     = fileHelper.GetSourceDirByFileRefId(Scale.Document_RefId.ToString());     // Path.Combine(Configuration.GetsmARTDocPath(), Scale.Document_RefId.ToString());
                            sourcePath          = fileHelper.GetTempSourceDirByFileRefId(Scale.Document_RefId.ToString()); // Path.Combine(Configuration.GetsmARTTempDocPath(), Scale.Document_RefId.ToString());
                            Scale.Document_Path = fileHelper.GetFilePath(sourcePath);
                            fileHelper.MoveFile(Scale.Document_Name, sourcePath, destinationPath);

                            Scale.Parent = new Scale {
                                ID = entity.ID
                            };
                            ScaleLibrary.Add(Scale);
                        }
                    }
                    break;
                //case "ScaleIDCardAttachments":
                //  if (Session[ChildEntity] != null) {
                //    ScaleIDCardAttachmentsLibrary ScaleLibrary = new ScaleIDCardAttachmentsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                //    IEnumerable<ScaleIDCardAttachments> resultList = (IList<ScaleIDCardAttachments>) Session[ChildEntity];
                //    string destinationPath;
                //    string sourcePath;
                //    FilelHelper fileHelper = new FilelHelper();
                //    foreach (ScaleIDCardAttachments Scale in resultList) {
                //      destinationPath = fileHelper.GetSourceDirByFileRefId(Scale.Document_RefId.ToString());// Path.Combine(Configuration.GetsmARTDocPath(), Scale.Document_RefId.ToString());
                //      sourcePath = fileHelper.GetTempSourceDirByFileRefId(Scale.Document_RefId.ToString()); // Path.Combine(Configuration.GetsmARTTempDocPath(), Scale.Document_RefId.ToString());
                //      Scale.Document_Path = fileHelper.GetFilePath(sourcePath);
                //      fileHelper.MoveFile(Scale.Document_Name, sourcePath, destinationPath);

                //      Scale.Parent = new Scale {
                //        ID = entity.ID
                //      };
                //      ScaleLibrary.Add(Scale);
                //    }
                //  }
                //  break;
                case "ScaleExpense":
                    if (Session[ChildEntity] != null)
                    {
                        ScaleExpenseLibrary           lib        = new ScaleExpenseLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        IEnumerable <ExpensesRequest> resultList = (IList <ExpensesRequest>)Session[ChildEntity];
                        foreach (ExpensesRequest exp in resultList)
                        {
                            exp.Reference = new Invoice {
                                ID = entity.ID
                            };
                            exp.Reference_Table = entity.GetType().Name;
                            exp.Reference_ID    = entity.ID;
                            lib.Add(exp);
                        }
                    }
                    break;

                    #endregion
                }
            }
        }
Exemplo n.º 11
0
        //[HttpPost]
        //public override ActionResult Save(Invoice entity)
        //{
        //    ModelState.Clear();

        //    // Need to find an easier way

        //    if (entity.ID == 0 && entity.Booking.ID == 0)
        //        ModelState.AddModelError("Booking", "Booking is required");
        //    if (entity.Net_Amt<= 0)
        //        ModelState.AddModelError("Net_Amt", "Net Amount is required");

        //    if (ModelState.IsValid)
        //    {
        //        if (entity.ID == 0)
        //        {
        //            entity = Library.Add(entity);

        //            // Also save all relevant child records in database
        //            if (ChildEntityList != null)
        //            {
        //                SaveChildEntities(ChildEntityList, entity);
        //                ClearChildEntities(ChildEntityList);
        //            }
        //        }
        //        else
        //        {
        //            Library.Modify(entity);
        //        }

        //        ModelState.Clear();
        //    }
        //    else
        //        return Display(entity);

        //    return Display(entity.ID.ToString());
        //}

        protected override void SaveChildEntities(string[] childEntityList, Invoice entity)
        {
            foreach (string ChildEntity in childEntityList)
            {
                switch (ChildEntity)
                {
                    #region /* Case Statements - All child grids */
                case "InvoiceExpense":
                    if (Session[ChildEntity] != null)
                    {
                        InvoiceExpenseLibrary         InvoiceExpenseLibrary = new InvoiceExpenseLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        IEnumerable <ExpensesRequest> resultList            = (IList <ExpensesRequest>)Session[ChildEntity];
                        foreach (ExpensesRequest InvoiceExpense in resultList)
                        {
                            if (InvoiceExpense.Reference_Table == new Model.Scale().GetType().Name || InvoiceExpense.Reference_Table == new Model.DispatcherRequest().GetType().Name)
                            {
                                InvoiceExpense.Payment = new PaymentReceipt {
                                    ID = 0
                                };
                                InvoiceExpense.Invoice = new Invoice {
                                    ID = entity.ID
                                };
                                InvoiceExpenseLibrary.Modify(InvoiceExpense, new string[] { "Paid_Party_To", "Payment", "Invoice" });
                            }
                            else
                            {
                                InvoiceExpense.Reference = new Invoice {
                                    ID = entity.ID
                                };
                                InvoiceExpense.Reference_Table = entity.GetType().Name;
                                InvoiceExpense.Reference_ID    = entity.ID;
                                InvoiceExpense.Invoice         = new Invoice {
                                    ID = entity.ID
                                };
                                InvoiceExpenseLibrary.Add(InvoiceExpense);
                            }
                        }
                    }
                    break;

                case "InvoiceNotes":
                    if (Session[ChildEntity] != null)
                    {
                        InvoiceNotesLibrary        InvoiceNotesLibrary = new InvoiceNotesLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        IEnumerable <InvoiceNotes> resultList          = (IList <InvoiceNotes>)Session[ChildEntity];
                        foreach (InvoiceNotes InvoiceNote in resultList)
                        {
                            InvoiceNote.Parent = new Invoice {
                                ID = entity.ID
                            };
                            InvoiceNotesLibrary.Add(InvoiceNote);
                        }
                    }
                    break;

                case "InvoiceAttachments":
                    if (Session[ChildEntity] != null)
                    {
                        InvoiceAttachmentsLibrary        InvoiceLibrary = new InvoiceAttachmentsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        IEnumerable <InvoiceAttachments> resultList     = (IList <InvoiceAttachments>)Session[ChildEntity];
                        string      destinationPath;
                        string      sourcePath;
                        FilelHelper fileHelper = new FilelHelper();
                        foreach (InvoiceAttachments Invoice in resultList)
                        {
                            destinationPath       = fileHelper.GetSourceDirByFileRefId(Invoice.Document_RefId.ToString());     // Path.Combine(Configuration.GetsmARTDocPath(), Invoice.Document_RefId.ToString());
                            sourcePath            = fileHelper.GetTempSourceDirByFileRefId(Invoice.Document_RefId.ToString()); // Path.Combine(Configuration.GetsmARTTempDocPath(), Invoice.Document_RefId.ToString());
                            Invoice.Document_Path = fileHelper.GetFilePath(sourcePath);
                            fileHelper.MoveFile(Invoice.Document_Name, sourcePath, destinationPath);

                            Invoice.Parent = new Invoice {
                                ID = entity.ID
                            };
                            InvoiceLibrary.Add(Invoice);
                        }
                    }
                    break;

                    #endregion
                }
            }
        }
Exemplo n.º 12
0
        public Ticket MapTicketFromRsmartTicket(Scale rsmartScale, IEnumerable <ScaleDetails> rsmartScaleDetails, IEnumerable <ScaleAttachments> rsmartScaleAttachments, AddressBook rsmartAddress, Ticket t)
        {
            FilelHelper fileHelper = new FilelHelper();

            // Ticket Details
            t.key = new TicketKey();
            t.key.ticketnumber   = rsmartScale.Scale_Ticket_No;
            t.key.ticketDateTime = rsmartScale.Created_Date.ToString();

            if (rsmartScale.Party_ID != null)
            {
                // Customer Details
                t.customer          = new Customer();
                t.customer.name     = rsmartScale.Party_ID.Party_Name;
                t.customer.idNumber = rsmartScale.Party_ID.License_No;
                string dobString = rsmartScale.Party_ID.Party_DOB;
                t.customer.phone = rsmartScale.Party_ID.Party_Phone1;


                DateTime dobDt;
                if (!string.IsNullOrEmpty(dobString) && smART.Common.DateTimeHelper.IsValidDate(dobString, out dobDt))
                {
                    t.customer.dob = dobDt.ToString();
                }
                //t.customer.dob = Convert .ToString(rsmartScale.Party_ID.Party_DOB);

                // Address details
                if (rsmartAddress != null)
                {
                    t.customer.address1   = rsmartAddress.Address1;
                    t.customer.city       = rsmartAddress.City;
                    t.customer.state      = rsmartAddress.State;
                    t.customer.postalCode = rsmartAddress.Zip_Code;
                }

                // Vehicle details
                t.customer.vehicle         = new Vehicle();
                t.customer.vehicle.color   = rsmartScale.Color;
                t.customer.vehicle.make    = rsmartScale.Make;
                t.customer.vehicle.model   = rsmartScale.Model;
                t.customer.vehicle.state   = rsmartScale.Plate_State;
                t.customer.vehicle.license = rsmartScale.Vehicle_Plate_No;
                t.customer.vehicle.year    = rsmartScale.Vehicle_Year;


                if (rsmartScaleAttachments != null && rsmartScaleAttachments.Count() > 0)
                {
                    List <Image> customerImageList = new List <Image>();

                    // Signature
                    ScaleAttachments signatureAttachment = rsmartScaleAttachments.FirstOrDefault(a => a.Ref_Type == (int)EnumAttachmentRefType.Signature);
                    if (signatureAttachment != null)
                    {
                        Image img = new Image();
                        img.imageData     = fileHelper.GetBytesFromFile(fileHelper.GetFilePathByFileRefId(signatureAttachment.Document_RefId.ToString()));
                        img.imageType     = ImageType.Jpeg;
                        img.imageCategory = ImageCategory.Signature;
                        customerImageList.Add(img);
                    }

                    // Thumb Print
                    ScaleAttachments thumbAttachment = rsmartScaleAttachments.FirstOrDefault(a => a.Ref_Type == (int)EnumAttachmentRefType.Thumbprint1);
                    if (thumbAttachment != null)
                    {
                        Image img = new Image();
                        img.imageData     = fileHelper.GetBytesFromFile(fileHelper.GetFilePathByFileRefId(thumbAttachment.Document_RefId.ToString()));
                        img.imageType     = ImageType.Jpeg;
                        img.imageCategory = ImageCategory.Thumbprint;
                        customerImageList.Add(img);
                    }

                    // Customer
                    ScaleAttachments customerAttachment = rsmartScaleAttachments.FirstOrDefault(a => a.Ref_Type == (int)EnumAttachmentRefType.Customer);
                    if (customerAttachment != null)
                    {
                        Image img = new Image();
                        img.imageData     = fileHelper.GetBytesFromFile(fileHelper.GetFilePathByFileRefId(customerAttachment.Document_RefId.ToString()));
                        img.imageType     = ImageType.Jpeg;
                        img.imageCategory = ImageCategory.Customer;
                        customerImageList.Add(img);
                    }

                    // Customer License Id
                    ScaleAttachments licenseAttachment = rsmartScaleAttachments.FirstOrDefault(a => a.Ref_Type == (int)EnumAttachmentRefType.DriverLicense);
                    if (licenseAttachment != null)
                    {
                        Image img = new Image();
                        img.imageData     = fileHelper.GetBytesFromFile(fileHelper.GetFilePathByFileRefId(licenseAttachment.Document_RefId.ToString()));
                        img.imageType     = ImageType.Jpeg;
                        img.imageCategory = ImageCategory.CustomerID;
                        customerImageList.Add(img);
                    }

                    // Vehicle
                    ScaleAttachments vehicleLicenseAttachment = rsmartScaleAttachments.FirstOrDefault(a => a.Ref_Type == (int)EnumAttachmentRefType.Vehicle);
                    if (vehicleLicenseAttachment != null)
                    {
                        Image img = new Image();
                        img.imageData     = fileHelper.GetBytesFromFile(fileHelper.GetFilePathByFileRefId(vehicleLicenseAttachment.Document_RefId.ToString()));
                        img.imageType     = ImageType.Jpeg;
                        img.imageCategory = ImageCategory.Vehicle;
                        customerImageList.Add(img);
                    }

                    // Cash Card
                    ScaleAttachments cashCardAttachment = rsmartScaleAttachments.FirstOrDefault(a => a.Ref_Type == (int)EnumAttachmentRefType.CashCard);
                    if (cashCardAttachment != null)
                    {
                        Image img = new Image();
                        img.imageData     = fileHelper.GetBytesFromFile(fileHelper.GetFilePathByFileRefId(cashCardAttachment.Document_RefId.ToString()));
                        img.imageType     = ImageType.Jpeg;
                        img.imageCategory = ImageCategory.Customer;
                        customerImageList.Add(img);
                    }
                    t.customer.images = new Image[] { };
                    t.customer.images = customerImageList.ToArray <Image>();
                }
            }

            if (rsmartScaleDetails != null && rsmartScaleDetails.Count() > 0)
            {
                // Item Details
                List <smART.Integration.LeadsOnline.LeadsOnlineWCF.Item> itemList = new List <smART.Integration.LeadsOnline.LeadsOnlineWCF.Item>();
                string clerk = ConfigurationHelper.GetClerk();
                foreach (var item in rsmartScaleDetails)
                {
                    smART.Integration.LeadsOnline.LeadsOnlineWCF.Item item1 = new smART.Integration.LeadsOnline.LeadsOnlineWCF.Item();
                    item1.description = item.Apply_To_Item.Long_Name;
                    item1.amount      = Convert.ToDouble(item.Amount);
                    item1.weight      = Convert.ToDouble(item.NetWeight);
                    item1.employee    = clerk;

                    // Item image
                    List <ScaleAttachments> itemAttachments = rsmartScaleAttachments.Where <ScaleAttachments>(s => s.Ref_ID == item.ID && s.Ref_Type == (int)EnumAttachmentRefType.Item).ToList(); //|| s.Document_Title == item.Apply_To_Item.Short_Name
                    if (itemAttachments != null && itemAttachments.Count() > 0)
                    {
                        List <Image> imageList = new List <Image>();
                        foreach (var itemAttach in itemAttachments)
                        {
                            Image itemImage = new Image();
                            itemImage.imageData     = fileHelper.GetBytesFromFile(fileHelper.GetFilePathByFileRefId(itemAttach.Document_RefId.ToString()));
                            itemImage.imageType     = ImageType.Jpeg;
                            itemImage.imageCategory = ImageCategory.Item;
                            imageList.Add(itemImage);
                        }
                        item1.images = new Image[] { };
                        item1.images = imageList.ToArray <Image>();
                    }
                    itemList.Add(item1);
                }

                t.items = new smART.Integration.LeadsOnline.LeadsOnlineWCF.Item[] { };
                t.items = itemList.ToArray <smART.Integration.LeadsOnline.LeadsOnlineWCF.Item>();
            }
            return(t);
        }
Exemplo n.º 13
0
        public JsonResult _SaveCustomerImages(string scaleId, string partyId)
        {
            try
            {
                if (!string.IsNullOrEmpty(partyId))
                {
                    // Get party
                    PartyLibrary          partyLib = new PartyLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                    smART.ViewModel.Party party    = partyLib.GetByID(partyId);
                    if (party != null)
                    {
                        FilelHelper fileHelper = new FilelHelper();
                        string      filePath;
                        // Save Customer Image
                        if (!string.IsNullOrEmpty(party.PhotoRefId))
                        {
                            filePath = fileHelper.GetFilePathByFileRefId(party.PhotoRefId);
                            if (System.IO.File.Exists(filePath))
                            {
                                Byte[] photoBytes = fileHelper.GetBytesFromFile(filePath);
                                SaveAttachment(Convert.ToInt32(scaleId), photoBytes, CommonHelper.GetFileNameByDocType((int)EnumAttachmentRefType.Customer), EnumAttachmentRefType.Customer, FileFormat.jpeg);
                            }
                        }
                        // Signature Image
                        if (!string.IsNullOrEmpty(party.SignatureImageRefId))
                        {
                            filePath = fileHelper.GetFilePathByFileRefId(party.SignatureImageRefId);
                            if (System.IO.File.Exists(filePath))
                            {
                                Byte[] photoBytes = fileHelper.GetBytesFromFile(filePath);
                                SaveAttachment(Convert.ToInt32(scaleId), photoBytes, CommonHelper.GetFileNameByDocType((int)EnumAttachmentRefType.Signature), EnumAttachmentRefType.Signature, FileFormat.bmp);
                            }
                        }
                        // Thumb Image
                        if (!string.IsNullOrEmpty(party.ThumbImage1RefId))
                        {
                            filePath = fileHelper.GetFilePathByFileRefId(party.ThumbImage1RefId);
                            if (System.IO.File.Exists(filePath))
                            {
                                Byte[] photoBytes = fileHelper.GetBytesFromFile(filePath);
                                SaveAttachment(Convert.ToInt32(scaleId), photoBytes, CommonHelper.GetFileNameByDocType((int)EnumAttachmentRefType.Thumbprint1), EnumAttachmentRefType.Thumbprint1, FileFormat.jpg);
                            }
                        }
                        // License Image
                        if (!string.IsNullOrEmpty(party.LicenseImageRefId))
                        {
                            filePath = fileHelper.GetFilePathByFileRefId(party.LicenseImageRefId);
                            if (System.IO.File.Exists(filePath))
                            {
                                Byte[] photoBytes = fileHelper.GetBytesFromFile(filePath);
                                SaveAttachment(Convert.ToInt32(scaleId), photoBytes, CommonHelper.GetFileNameByDocType((int)EnumAttachmentRefType.DriverLicense), EnumAttachmentRefType.DriverLicense, FileFormat.jpg);
                            }
                        }

                        // Vehicle Image
                        if (!string.IsNullOrEmpty(party.VehicleImageRegId))
                        {
                            filePath = fileHelper.GetFilePathByFileRefId(party.VehicleImageRegId);
                            if (System.IO.File.Exists(filePath))
                            {
                                Byte[] photoBytes = fileHelper.GetBytesFromFile(filePath);
                                SaveAttachment(Convert.ToInt32(scaleId), photoBytes, CommonHelper.GetFileNameByDocType((int)EnumAttachmentRefType.Vehicle), EnumAttachmentRefType.Vehicle, FileFormat.jpg);
                            }
                        }

                        // Cash Card Image
                        if (!string.IsNullOrEmpty(party.CashCardImageRefId))
                        {
                            filePath = fileHelper.GetFilePathByFileRefId(party.CashCardImageRefId);
                            if (System.IO.File.Exists(filePath))
                            {
                                Byte[] photoBytes = fileHelper.GetBytesFromFile(filePath);
                                SaveAttachment(Convert.ToInt32(scaleId), photoBytes, CommonHelper.GetFileNameByDocType((int)EnumAttachmentRefType.CashCard), EnumAttachmentRefType.CashCard, FileFormat.jpg);
                            }
                        }
                    }
                }
                return(Json(new { Sucess = "True" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { Sucess = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 14
0
        public HttpResponseMessage SaveTicket([FromBody] Ticket value)
        {
            try {
                if (value.Scale == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest));
                }

                // Start transaction.
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions {
                    IsolationLevel = IsolationLevel.ReadCommitted
                })) {
                    smART.ViewModel.Scale newScale = new Scale();

                    // Add new party if already exists
                    if (!string.IsNullOrEmpty(value.Scale.License_No))
                    {
                        PartyLibrary partyLib = new PartyLibrary(ConString);
                        Party        party    = partyLib.GetByLicenseNo(value.Scale.License_No);
                        if (party != null)
                        {
                            newScale.Party_ID = party;
                        }
                        else
                        {
                            // Add new party
                            party                   = new Party();
                            party.Party_Name        = value.Scale.Customer_Name;
                            party.Party_Short_Name  = value.Scale.Customer_Name;
                            party.License_No        = value.Scale.License_No;
                            party.Party_Type        = "Individual";
                            party.Created_By        = value.Scale.Created_By;
                            party.Updated_By        = value.Scale.Created_By;
                            party.Created_Date      = value.Scale.Created_Date;
                            party.Last_Updated_Date = value.Scale.Created_Date;
                            party.Active_Ind        = true;
                            party.IsActive          = true;
                            party.State             = !string.IsNullOrEmpty(value.Scale.Customer_State) ? value.Scale.Customer_State.ToString().Trim() : "";
                            party.ACLicense_ID      = value.Scale.Customer_ACLicense_ID;
                            party.Party_DOB         = value.Scale.Customer_DOB;
                            //string dobString = value.Scale.Customer_DOB;
                            //DateTime dobDt;
                            //if (smART.Common.DateTimeHelper.IsValidDate(dobString, out dobDt))
                            //    party.Party_DOB = dobDt;

                            party             = partyLib.Add(party);
                            newScale.Party_ID = party;

                            // Add new Address
                            AddressBook address = new AddressBook();
                            address.Address1          = value.Scale.Customer_Address;
                            address.City              = value.Scale.Customer_City;
                            address.State             = value.Scale.Customer_State;
                            address.Country           = value.Scale.Customer_Country;
                            address.Party             = party;
                            address.Created_By        = value.Scale.Created_By;
                            address.Updated_By        = value.Scale.Created_By;
                            address.Created_Date      = value.Scale.Created_Date;
                            address.Last_Updated_Date = value.Scale.Created_Date;
                            address.Primary_Flag      = true;
                            address.Active_Ind        = true;
                            address.Zip_Code          = value.Scale.Customer_Zip;
                            AddressBookLibrary addressLib = new AddressBookLibrary(ConString);
                            addressLib.Add(address);
                        }
                    }

                    // Save Scale
                    ScaleLibrary lib = new ScaleLibrary(ConString);
                    newScale.Ticket_Status = "Open";
                    newScale.QScale        = true;
                    newScale.Gross_Weight  = value.ScaleDetails.Sum(s => s.GrossWeight);
                    newScale.Tare_Weight   = value.ScaleDetails.Sum(s => s.TareWeight);;
                    newScale.Net_Weight    = value.ScaleDetails.Sum(s => s.NetWeight);
                    value.Scale.MapServiceEntityToServerEntity(newScale);
                    smART.ViewModel.Scale scale = lib.Add(newScale);

                    // Save scale detail
                    if (value.ScaleDetails != null)
                    {
                        ScaleDetailsLibrary libScaleDetail = new ScaleDetailsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        ItemLibrary         libItem        = new ItemLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        foreach (var item in value.ScaleDetails)
                        {
                            smART.ViewModel.ScaleDetails newScaleDetails = new smART.ViewModel.ScaleDetails();
                            newScaleDetails.Apply_To_Item = libItem.GetByID(item.Item_ID.ToString());
                            newScaleDetails.Item_Received = libItem.GetByID(item.Item_ID.ToString());
                            newScaleDetails.Scale         = scale;
                            item.MapServiceEntityToServerEntity(newScaleDetails);
                            ScaleDetails scaleDetails = libScaleDetail.Add(newScaleDetails);

                            // Set docuent related id if document is related to item
                            if (value.ScaleAttachments != null && value.ScaleAttachments.Count > 0)
                            {
                                Model.ScaleAttachments modelAttach = value.ScaleAttachments.Where(w => w.Document_RelatedID == item.ID).FirstOrDefault();
                                if (modelAttach != null && modelAttach.Document_RelatedTo == 1)
                                {
                                    modelAttach.Document_RelatedID = scaleDetails.ID;
                                }
                            }
                        }
                    }

                    // Save Max Ticket ID in Device Settings
                    DeviceSettingLibrary deviceLib      = new DeviceSettingLibrary(ConString);
                    DeviceSettings       deviceSettings = deviceLib.GetByUniueID(scale.Unique_ID.Value);
                    deviceSettings.MaxTicket_ID = value.Scale.ID;
                    deviceLib.Modify(deviceSettings);


                    // Save Attachments
                    if (value.ScaleAttachments != null)
                    {
                        ScaleAttachmentsLibrary libAttach  = new ScaleAttachmentsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        FilelHelper             fileHelper = new FilelHelper();

                        foreach (var item in value.ScaleAttachments)
                        {
                            smART.ViewModel.ScaleAttachments newScaleAttachment = new smART.ViewModel.ScaleAttachments();

                            // Save file
                            Guid   docRefId        = Guid.NewGuid();
                            string destinationPath = fileHelper.GetSourceDirByFileRefId(docRefId.ToString());
                            fileHelper.MoveFile(item.Document_Title, fileHelper.GetTempSourceDirByFileRefId(item.Document_Path), destinationPath);

                            // Save attachment
                            newScaleAttachment.Parent         = scale;
                            newScaleAttachment.Document_RefId = docRefId;
                            newScaleAttachment.Document_Path  = Path.Combine(destinationPath, item.Document_Title);
                            item.MapServiceEntityToServerEntity(newScaleAttachment);
                            libAttach.Add(newScaleAttachment);
                        }
                    }

                    // Complete transaction.
                    scope.Complete();
                }
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception ex) {
                ExceptionHandler.HandleException(ex, "An error occured in SaveTicket.");
                //string details = string.Format("Method: {1} {0} Message: {2} {0} Stack Trace: {3}", System.Environment.NewLine, "SaveTicket", ex.Message, ex.StackTrace.ToString());
                //smART.Common.MessageLogger.Instance.LogMessage(ex, details, Common.Priority.High, 0, System.Diagnostics.TraceEventType.Error, "Service Error", "Service");
                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }
        }
Exemplo n.º 15
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());
        }
Exemplo n.º 16
0
        protected override void SaveChildEntities(string[] childEntityList, PaymentReceipt entity)
        {
            foreach (string ChildEntity in childEntityList)
            {
                switch (ChildEntity)
                {
                    #region /* Case Statements - All child grids */

                case "PaymentDetails":
                    if (Session[ChildEntity] != null)
                    {
                        PaymentReceiptDetailsLibrary        library    = new PaymentReceiptDetailsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        IEnumerable <PaymentReceiptDetails> resultList = (IList <PaymentReceiptDetails>)Session[ChildEntity];
                        foreach (PaymentReceiptDetails PaymentReceiptDetails in resultList)
                        {
                            if (PaymentReceiptDetails.Apply_Amount > 0)
                            {
                                PaymentReceiptDetails.PaymentReceipt = new PaymentReceipt {
                                    ID = entity.ID
                                };
                                library.Add(PaymentReceiptDetails);
                            }
                        }
                    }
                    break;

                case "PaymentNotes":
                    if (Session[ChildEntity] != null)
                    {
                        PaymentReceiptNotesLibrary        PaymentReceiptNotesLibrary = new PaymentReceiptNotesLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        IEnumerable <PaymentReceiptNotes> resultList = (IList <PaymentReceiptNotes>)Session[ChildEntity];
                        foreach (PaymentReceiptNotes PaymentReceiptNote in resultList)
                        {
                            PaymentReceiptNote.Parent = new PaymentReceipt {
                                ID = entity.ID
                            };
                            //itemNote.Notes = System.Web.HttpUtility.HtmlDecode(itemNote.Notes);
                            PaymentReceiptNotesLibrary.Add(PaymentReceiptNote);
                        }
                    }
                    break;

                case "PaymentAttachments":
                    if (Session[ChildEntity] != null)
                    {
                        PaymentReceiptAttachmentsLibrary        PaymentReceiptLibrary = new PaymentReceiptAttachmentsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        IEnumerable <PaymentReceiptAttachments> resultList            = (IList <PaymentReceiptAttachments>)Session[ChildEntity];
                        string      destinationPath;
                        string      sourcePath;
                        FilelHelper fileHelper = new FilelHelper();
                        foreach (PaymentReceiptAttachments PaymentReceipt in resultList)
                        {
                            destinationPath = fileHelper.GetSourceDirByFileRefId(PaymentReceipt.Document_RefId.ToString());     // Path.Combine(Configuration.GetsmARTDocPath(), PaymentReceipt.Document_RefId.ToString());
                            sourcePath      = fileHelper.GetTempSourceDirByFileRefId(PaymentReceipt.Document_RefId.ToString()); // Path.Combine(Configuration.GetsmARTTempDocPath(), PaymentReceipt.Document_RefId.ToString());
                            PaymentReceipt.Document_Path = fileHelper.GetFilePath(sourcePath);
                            fileHelper.MoveFile(PaymentReceipt.Document_Name, sourcePath, destinationPath);

                            PaymentReceipt.Parent = new PaymentReceipt {
                                ID = entity.ID
                            };
                            PaymentReceiptLibrary.Add(PaymentReceipt);
                        }
                    }
                    break;

                case "PaymentExpense":
                    if (Session[ChildEntity] != null)
                    {
                        PaymentExpenseLibrary         lib        = new PaymentExpenseLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        IEnumerable <ExpensesRequest> resultList = (IList <ExpensesRequest>)Session[ChildEntity];
                        foreach (ExpensesRequest exp in resultList)
                        {
                            if (exp.Reference_Table == new Model.Scale().GetType().Name || exp.Reference_Table == new Model.DispatcherRequest().GetType().Name)
                            {
                                //ExpensesRequest scaleExp = lib.GetByID(exp.ID.ToString(), new string[] { "Paid_Party_To", "Payment" });
                                exp.Payment = new PaymentReceipt {
                                    ID = entity.ID
                                };
                                exp.Invoice = new Invoice {
                                    ID = 0
                                };
                                lib.Modify(exp, new string[] { "Paid_Party_To", "Payment", "Invoice" });
                            }
                            else
                            {
                                exp.Reference = new PaymentReceipt {
                                    ID = entity.ID
                                };
                                exp.Reference_Table = entity.GetType().Name;
                                exp.Reference_ID    = entity.ID;
                                exp.Payment         = new PaymentReceipt {
                                    ID = entity.ID
                                };
                                lib.Add(exp);
                            }
                        }
                    }
                    break;

                    #endregion
                }
            }
        }
Exemplo n.º 17
0
 public AttachmentGridController(string dbContextConnectionString, string sessionName, string[] includePredicates = null)
     : base(dbContextConnectionString, sessionName, includePredicates)
 {
     _fileHelper = new FilelHelper();
 }
Exemplo n.º 18
0
        private void SaveThumbScannerAttachment(int Id, byte[] data, string fileName, EnumAttachmentRefType refType, FileFormat fileFormat, bool updateParty = true)
        {
            Guid guid = SaveFile(data, string.Format("{0}.{1}", fileName, fileFormat.ToString()));

            ScaleAttachments attachments = new ScaleAttachments();

            attachments.Document_Name  = string.Format("{0}.{1}", fileName, fileFormat.ToString());// "Thumb-Image.jpeg";
            attachments.Document_RefId = guid;
            attachments.Document_Size  = data.LongLength;
            attachments.Document_Title = "Thumb-Image";
            attachments.Document_Type  = "jpeg";
            attachments.Ref_Type       = (int)refType;

            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 = Id
            };

            string destinationPath;
            string sourcePath;

            FilelHelper fileHelper = new FilelHelper();

            destinationPath = fileHelper.GetSourceDirByFileRefId(attachments.Document_RefId.ToString());     // Path.Combine(Configuration.GetsmARTDocPath(), Scale.Document_RefId.ToString());
            sourcePath      = fileHelper.GetTempSourceDirByFileRefId(attachments.Document_RefId.ToString()); // Path.Combine(Configuration.GetsmARTTempDocPath(), Scale.Document_RefId.ToString());

            attachments.Document_Path = fileHelper.GetFilePath(sourcePath);

            if (Id > 0)
            {
                fileHelper.MoveFile(attachments.Document_Name, sourcePath, destinationPath);
                ScaleAttachmentsLibrary ScaleLibrary = new ScaleAttachmentsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                attachments.Document_Name = string.Format("{0}.{1}", fileName, "jpg");
                ScaleAttachments scaleAttachment = ScaleLibrary.Add(attachments);

                if (updateParty)
                {
                    Scale        scale    = new ScaleLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()).GetByID(Id.ToString(), new string[] { "Party_ID" });
                    PartyLibrary partyLib = new PartyLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                    Party        party    = partyLib.GetByID(scale.Party_ID.ID.ToString());
                    if (party != null)
                    {
                        party.PhotoRefId = scaleAttachment.Document_RefId.ToString();
                        partyLib.Modify(party);
                    }
                }
            }
            else
            {
                if (Session["ScaleAttachments"] == null)
                {
                    Session["ScaleAttachments"] = new List <ScaleAttachments>();
                }

                IList <ScaleAttachments> iList = (IList <ScaleAttachments>)Session["ScaleAttachments"];
                iList.Add(attachments);
            }
        }
Exemplo n.º 19
0
        protected override void SaveChildEntities(string[] childEntityList, Booking entity)
        {
            foreach (string ChildEntity in childEntityList)
            {
                switch (ChildEntity)
                {
                    #region /* Case Statements - All child grids */

                case "Container":
                    if (Session[ChildEntity] != null)
                    {
                        ContainerLibrary        containerLibrary = new ContainerLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        IEnumerable <Container> resultList       = (IList <Container>)Session[ChildEntity];
                        foreach (Container continer in resultList)
                        {
                            continer.Booking = new Booking {
                                ID = entity.ID
                            };
                            containerLibrary.Add(continer);
                        }
                    }
                    break;

                case "BookingNotes":
                    if (Session[ChildEntity] != null)
                    {
                        BookingNotesLibrary        BookingNotesLibrary = new BookingNotesLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        IEnumerable <BookingNotes> resultList          = (IList <BookingNotes>)Session[ChildEntity];
                        foreach (BookingNotes BookingNote in resultList)
                        {
                            BookingNote.Parent = new Booking {
                                ID = entity.ID
                            };
                            //itemNote.Notes = System.Web.HttpUtility.HtmlDecode(itemNote.Notes);
                            BookingNotesLibrary.Add(BookingNote);
                        }
                    }
                    break;

                case "BookingAttachments":
                    if (Session[ChildEntity] != null)
                    {
                        BookingAttachmentsLibrary        BookingLibrary = new BookingAttachmentsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        IEnumerable <BookingAttachments> resultList     = (IList <BookingAttachments>)Session[ChildEntity];
                        string      destinationPath;
                        string      sourcePath;
                        FilelHelper fileHelper = new FilelHelper();
                        foreach (BookingAttachments Booking in resultList)
                        {
                            destinationPath       = fileHelper.GetSourceDirByFileRefId(Booking.Document_RefId.ToString());     // Path.Combine(Configuration.GetsmARTDocPath(), Booking.Document_RefId.ToString());
                            sourcePath            = fileHelper.GetTempSourceDirByFileRefId(Booking.Document_RefId.ToString()); // Path.Combine(Configuration.GetsmARTTempDocPath(), Booking.Document_RefId.ToString());
                            Booking.Document_Path = fileHelper.GetFilePath(sourcePath);
                            fileHelper.MoveFile(Booking.Document_Name, sourcePath, destinationPath);

                            Booking.Parent = new Booking {
                                ID = entity.ID
                            };
                            BookingLibrary.Add(Booking);
                        }
                    }
                    break;

                    #endregion
                }
            }
        }
Exemplo n.º 20
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);
            }
        }