Example #1
0
        public ActionResult TestUploadFile(HttpPostedFileBase uploadedFile, string TempRelatedID)
        {
            if (uploadedFile != null)
            {
                int fileSize = uploadedFile.ContentLength;

                byte[] data;
                using (BinaryReader reader = new BinaryReader(uploadedFile.InputStream))
                {
                    data = reader.ReadBytes(uploadedFile.ContentLength);
                }
                string fileType = Path.GetExtension(uploadedFile.FileName);

                ICommonHandler        handler = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
                List <tbt_AttachFile> attach  = handler.InsertAttachFile(TempRelatedID,
                                                                         uploadedFile.FileName,
                                                                         fileType,
                                                                         fileSize,
                                                                         data,
                                                                         false);

                List <tbt_AttachFile> list = handler.GetAttachFile(TempRelatedID);

                ViewBag.AttachFileList = list;
            }
            return(View("Upload"));
        }
        /// <summary>
        /// Attach file
        /// </summary>
        /// <param name="fileSelect"></param>
        /// <param name="DocumentName"></param>
        /// <param name="k"></param>
        /// <returns></returns>
        public ActionResult CTS230_AttachFile(HttpPostedFileBase fileSelect, string DocumentName, string k)
        {
            ICommonHandler commonhandler = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
            MessageModel   outmsg        = null;

            try
            {
                byte[] fileData;
                if (fileSelect == null)
                {
                    outmsg = MessageUtil.GetMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0050, null);
                }
                else
                {
                    using (BinaryReader reader = new BinaryReader(fileSelect.InputStream))
                    {
                        var fList = commonhandler.GetAttachFileForGridView(GetCurrentKey());

                        var filterDupItem = from a in fList where a.FileName.ToUpper().Equals(DocumentName.ToUpper() + Path.GetExtension(fileSelect.FileName).ToUpper()) select a;

                        if (filterDupItem.Count() > 0)
                        {
                            // Docname duplicate
                            outmsg = MessageUtil.GetMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0115, new string[] { DocumentName });
                        }
                        else if (DocumentName == null || DocumentName == "")
                        {
                            string nparam = CommonUtil.GetLabelFromResource(MessageUtil.MODULE_CONTRACT, "CTS300", "lblDocumentName");
                            outmsg = MessageUtil.GetMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0007, new string[] { nparam });
                        }
                        else
                        {
                            fileData = reader.ReadBytes(fileSelect.ContentLength);

                            if (commonhandler.CanAttachFile(DocumentName, fileData.Length, Path.GetExtension(fileSelect.FileName), GetCurrentKey(), GetCurrentKey()))
                            {
                                DateTime currDate = DateTime.Now;
                                commonhandler.InsertAttachFile(GetCurrentKey()
                                                               , DocumentName
                                                               , Path.GetExtension(fileSelect.FileName)
                                                               , fileData.Length
                                                               , fileData
                                                               , false);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                outmsg         = new MessageModel();
                outmsg.Message = ((SECOM_AJIS.Common.Models.ApplicationErrorException)(ex)).ErrorResult.Message.Message;
                outmsg.Code    = CommonValue.SYSTEM_MESSAGE_CODE;
            }

            if (outmsg != null)
            {
                ViewBag.Message = outmsg.Message;
                ViewBag.MsgCode = outmsg.Code;
            }
            ViewBag.K = k;

            return(View("CTS230_Upload"));
        }