Пример #1
0
        public static string UploadtoSAP()
        {
            int errCode = 0;

            try
            {
                Regex rx = new Regex("^[0-9]{5}$", RegexOptions.Compiled | RegexOptions.IgnoreCase);

                foreach (var file_path in
                         Directory
                         .EnumerateFiles(@"F:\apinvoice", "*.pdf")
                         .Where(x => rx.IsMatch(Path.GetFileNameWithoutExtension(x))))
                {
                    SAPbobsCOM.Company      oCompany = CompanyConnection("1");
                    SAPbobsCOM.Attachments2 oAtt     = (SAPbobsCOM.Attachments2)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oAttachments2);
                    oAtt.Lines.SourcePath    = @"F:\apinvoice";
                    oAtt.Lines.FileName      = Path.GetFileNameWithoutExtension(file_path);
                    oAtt.Lines.FileExtension = "pdf";
                    int iErr     = oAtt.Add();
                    int AttEntry = 0;
                    if (iErr == 0)
                    {
                        AttEntry = int.Parse(oCompany.GetNewObjectKey());
                        var apinvoice = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseInvoices);
                        if (apinvoice.GetByKey(Convert.ToInt32(Path.GetFileNameWithoutExtension(file_path))) == true)
                        {
                            apinvoice.AttachmentEntry = AttEntry;
                            errCode = apinvoice.Update();
                        }
                    }
                    if (iErr != 0)
                    {
                        (oCompany).GetLastError(out lErrCode, out sErrMsg);
                    }
                }
            }

            catch (Exception Ex)
            {
                sErrMsg = Ex.ToString();
            }


            return(errCode.ToString());
        }
Пример #2
0
        public async Task <IActionResult> CreateBoardMeeting(MeetingVM VM)
        {
            int    IsAttchInserted = -1;
            string strMessage      = "incorrect inputs provided.";

            SAPEntity.Instance.InitializeCompany();
            if (SAPEntity.Company.Connected)
            {
                ActivitiesService oActSrv = (ActivitiesService)SAPEntity.Company.GetCompanyService().GetBusinessService(ServiceTypes.ActivitiesService);
                Activity          oAct    = (Activity)oActSrv.GetDataInterface(ActivitiesServiceDataInterfaces.asActivity);
                ActivityParams    oParams;
                oAct.CardCode     = VM.cardcode;
                oAct.Activity     = BoActivities.cn_Task;
                oAct.ActivityType = 2;

                if (VM.cntctcode > 0)
                {
                    oAct.ContactPersonCode = VM.cntctcode;
                }

                DateTime StartDate = DateTime.ParseExact(VM.str_startdate, "dd/MM/yyyy", null);
                DateTime CloseDate = DateTime.ParseExact(VM.str_enddate, "dd/MM/yyyy", null);

                oAct.ActivityDate = StartDate;
                oAct.Duration     = (CloseDate - StartDate).TotalDays;
                oAct.DurationType = BoDurations.du_Days;
                if (!String.IsNullOrEmpty(VM.time))
                {
                    oAct.UserFields.Item("U_Time").Value = VM.time;
                }
                if (VM.assignesto.HasValue && VM.assignesto.Value > 0)
                {
                    oAct.HandledBy = VM.assignesto.Value;
                }
                oAct.Notes   = VM.notes;
                oAct.Details = VM.details;

                if (VM.files != null && VM.files.Count() > 0)
                {
                    SAPbobsCOM.Attachments2 SAPAttachment = (SAPbobsCOM.Attachments2)SAPEntity.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oAttachments2);
                    foreach (var FL in VM.files)
                    {
                        if (!string.IsNullOrEmpty(FL))
                        {
                            SAPAttachment.Lines.SetCurrentLine((SAPAttachment.Lines.Count) - 1);
                            string FileName = System.IO.Path.GetFileName(FL);
                            string FileExt  = System.IO.Path.GetExtension(FileName);
                            FileExt = FileExt.Replace('.', ' ').Trim();
                            SAPAttachment.Lines.SourcePath    = @"H:\Upload";
                            SAPAttachment.Lines.FileName      = FileName;
                            SAPAttachment.Lines.FileExtension = Path.GetExtension(FileExt);
                            SAPAttachment.Lines.Add();
                        }
                    }

                    if (VM.files.Count() > 0)
                    {
                        IsAttchInserted = SAPAttachment.Add();
                        if (IsAttchInserted == 0)
                        {
                            string ObjCode;
                            SAPEntity.Company.GetNewObjectCode(out ObjCode);
                            oAct.AttachmentEntry = Convert.ToInt32(ObjCode);
                        }
                        else
                        {
                            strMessage = SAPEntity.Company.GetLastErrorDescription();
                        }
                    }
                }


                oParams = oActSrv.AddActivity(oAct);
                long singleActCode = oParams.ActivityCode;
                if (singleActCode > 0)
                {
                    return(StatusCode(201));
                }
            }

            return(BadRequest("incorrect inputs provided."));
        }
Пример #3
0
        public async Task <IActionResult> CreateSingleActivity(singlecomplianceviewmodel VM)
        {
            string strMessage = "incorrect inputs provided.";
            bool   IsCreate   = true;

            try
            {
                int IsAttchInserted = -1;
                SAPEntity.Instance.InitializeCompany();
                if (SAPEntity.Company.Connected)
                {
                    ActivitiesService oActSrv = (ActivitiesService)SAPEntity.Company.GetCompanyService().GetBusinessService(ServiceTypes.ActivitiesService);
                    Activity          oAct    = (Activity)oActSrv.GetDataInterface(ActivitiesServiceDataInterfaces.asActivity);
                    ActivityParams    oParams;
                    if (VM.clgcode > 0)
                    {
                        IsCreate             = false;
                        oParams              = (ActivityParams)oActSrv.GetDataInterface(ActivitiesServiceDataInterfaces.asActivityParams);
                        oParams.ActivityCode = VM.clgcode;
                        oAct = oActSrv.GetActivity(oParams);
                    }
                    oAct.CardCode = VM.cardcode;
                    if (VM.cntctcode > 0)
                    {
                        oAct.ContactPersonCode = VM.cntctcode;
                    }

                    oAct.Activity     = BoActivities.cn_Task;
                    oAct.ActivityType = VM.type;
                    oAct.Subject      = VM.subject;
                    if (VM.assignesto.HasValue && VM.assignesto.Value > 0)
                    {
                        oAct.HandledBy = VM.assignesto.Value;
                    }
                    oAct.Status   = VM.status;
                    oAct.Priority = VM.prcode == "0" ? BoMsgPriorities.pr_Low : VM.prcode == "1" ? BoMsgPriorities.pr_Normal : BoMsgPriorities.pr_High;
                    oAct.Details  = VM.details;
                    oAct.Notes    = VM.notes;
                    if (!string.IsNullOrEmpty(VM.str_startdate))
                    {
                        DateTime StartDate = DateTime.ParseExact(VM.str_startdate, "dd/MM/yyyy", null);
                        DateTime CloseDate = DateTime.ParseExact(VM.str_enddate, "dd/MM/yyyy", null);
                        oAct.ActivityDate = StartDate;
                        oAct.Duration     = (CloseDate - StartDate).TotalDays;
                        oAct.DurationType = BoDurations.du_Days;
                    }
                    if (VM.files != null && VM.files.Count() > 0)
                    {
                        SAPbobsCOM.Attachments2 SAPAttachment = (SAPbobsCOM.Attachments2)SAPEntity.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oAttachments2);
                        foreach (var FL in VM.files)
                        {
                            if (!string.IsNullOrEmpty(FL))
                            {
                                SAPAttachment.Lines.SetCurrentLine((SAPAttachment.Lines.Count) - 1);
                                string FileName = System.IO.Path.GetFileName(FL);
                                string FileExt  = System.IO.Path.GetExtension(FileName);
                                FileExt = FileExt.Replace('.', ' ').Trim();
                                SAPAttachment.Lines.SourcePath    = @"H:\Upload";
                                SAPAttachment.Lines.FileName      = FileName;
                                SAPAttachment.Lines.FileExtension = Path.GetExtension(FileExt);
                                SAPAttachment.Lines.Add();
                            }
                        }

                        if (VM.files.Count() > 0)
                        {
                            IsAttchInserted = SAPAttachment.Add();
                            if (IsAttchInserted == 0)
                            {
                                string ObjCode;
                                SAPEntity.Company.GetNewObjectCode(out ObjCode);
                                oAct.AttachmentEntry = Convert.ToInt32(ObjCode);
                            }
                            else
                            {
                                strMessage = SAPEntity.Company.GetLastErrorDescription();
                            }
                        }
                    }

                    if (IsCreate)
                    {
                        oAct.UserFields.Item("U_AddedBy").Value = User.Identity.Name;
                        oParams = oActSrv.AddActivity(oAct);
                        long singleActCode = oParams.ActivityCode;
                        if (singleActCode > 0)
                        {
                            return(StatusCode(201));
                        }

                        else
                        {
                            strMessage = SAPEntity.Company.GetLastErrorDescription();
                        }
                    }
                    else
                    {
                        oAct.UserFields.Item("U_UpdatedBy").Value = User.Identity.Name;
                        oActSrv.UpdateActivity(oAct);
                        strMessage = SAPEntity.Company.GetLastErrorDescription();
                        if (!string.IsNullOrWhiteSpace(strMessage))
                        {
                            return(BadRequest(strMessage));
                        }
                        else
                        {
                            return(StatusCode(201));
                        }
                    }
                }
            }
            catch (Exception E)
            {
                var tt = E.Message;
            }

            return(BadRequest(strMessage));
        }