Esempio n. 1
0
        /// <summary>
        /// Load data attach to show in grid
        /// </summary>
        /// <returns></returns>
        public ActionResult CMS180_LoadGridAttachedDocList(string installationSlipNo, string maintenanceNo)
        {
            ICommonHandler   commonhandler = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
            ObjectResultData res           = new ObjectResultData();

            try
            {
                List <dtAttachFileForGridView> lstAttachedName = new List <dtAttachFileForGridView>();
                if (!string.IsNullOrEmpty(maintenanceNo))
                {
                    lstAttachedName.AddRange(commonhandler.GetAttachFileForGridView(maintenanceNo));
                }
                if (!string.IsNullOrEmpty(installationSlipNo))
                {
                    lstAttachedName.AddRange(commonhandler.GetAttachFileForGridView(installationSlipNo));
                    lstAttachedName.AddRange(commonhandler.GetAttachFileForGridView(installationSlipNo + "-COMPLETE"));
                }
                res.ResultData = CommonUtil.ConvertToXml <dtAttachFileForGridView>(lstAttachedName, "Common\\CMS180_AttachedDocList", CommonUtil.GRID_EMPTY_TYPE.SEARCH);
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
            }

            return(Json(res));
        }
        /// <summary>
        /// Load attach for show in grid attach
        /// </summary>
        /// <returns></returns>
        public ActionResult CTS230_LoadGridAttachedDocList()
        {
            ICommonHandler   commonhandler = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
            ObjectResultData res           = new ObjectResultData();

            try
            {
                List <dtAttachFileForGridView> lstAttachedName = commonhandler.GetAttachFileForGridView(GetCurrentKey());
                res.ResultData = CommonUtil.ConvertToXml <dtAttachFileForGridView>(lstAttachedName, "Installation\\ISS010_AttachedDocList", CommonUtil.GRID_EMPTY_TYPE.INSERT);
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
            }

            return(Json(res));
        }
        /// <summary>
        /// load attach file to grid attach
        /// </summary>
        /// <returns></returns>
        public ActionResult CTS260_LoadGridAttachedDocList()
        {
            ICommonHandler   commonhandler = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
            ObjectResultData res           = new ObjectResultData();

            try
            {
                CTS260_ScreenParameter         param           = GetScreenObject <CTS260_ScreenParameter>();
                List <dtAttachFileForGridView> lstAttachedName = commonhandler.GetAttachFileForGridView(param.strProjectCode);
                res.ResultData = CommonUtil.ConvertToXml <dtAttachFileForGridView>(lstAttachedName, "Contract\\CTS260_attach", CommonUtil.GRID_EMPTY_TYPE.INSERT);
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
            }

            return(Json(res));
        }
        /// <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"));
        }