예제 #1
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);
            }
        }
예제 #2
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());
        }