Example #1
0
        private CRMCalendar GetSaveEntity()
        {
            var entity = new CRMCalendar();

            if (hidID.Value != "0")
            {
                entity            = svr.LoadById(hidID.Value);
                entity.ModifyDate = DateTime.Now;
                entity.ModifyUser = base.LoginUserID;
            }
            else
            {
                entity.CDate      = DateTime.Now;
                entity.CUser      = base.LoginUserID;
                entity.ModifyDate = DateTime.Now;
                entity.ModifyUser = base.LoginUserID;
            }
            entity.UserName = hidPerson.Value;
            entity.Status   = 0;// 0 =draft 1= approved 2=reject,9=finish
            if (ddlTaskTime.SelectedValue != "")
            {
                entity.TaskDate = DateTime.ParseExact(hidDay.Value + " " + ddlTaskTime.SelectedValue, "yyyyMMdd H:mm", null);
            }
            else
            {
                entity.TaskDate = DateTime.ParseExact(hidDay.Value, "yyyyMMdd", null);
            }
            if (string.IsNullOrEmpty(txtTask.Text.Trim()) == false)
            {
                entity.Task = txtTask.Text.Trim();
            }
            return(entity);
        }
Example #2
0
        public CRMCalendar Save(CRMCalendar entity)
        {
            if (this.dataCtx.Connection != null)
                if (this.dataCtx.Connection.State == ConnectionState.Closed)
                    this.dataCtx.Connection.Open();
            DbTransaction tran = this.dataCtx.Connection.BeginTransaction();
            dataCtx.Transaction = tran;

            try
            {
                var qry = from t in CRMCalendars
                          where t.ID == entity.ID
                          select t;
                var obj = qry.SingleOrDefault();
                if (obj != null)
                    this.CopyEntity(obj, entity);
                else
                    this.CRMCalendars.InsertOnSubmit(entity);

                this.dataCtx.SubmitChanges();
                tran.Commit();
                return entity;
            }
            catch (Exception ex)
            {
                tran.Rollback();
                throw ex;
            }
            finally
            {
                dataCtx.Connection.Close();
            }
        }
Example #3
0
        //按ID绑定或者按CustID和TypeID绑定
        private void BindData()
        {
            //bind entity
            CRMCalendar entity = null;

            if (hidID.Value != "0")
            {
                entity = (CRMCalendar)svr.LoadById(hidID.Value);
            }

            if (entity != null)
            {
                if (entity.Task != null)
                {
                    txtTask.Text = entity.Task;
                }

                if (entity.TaskDate != null)
                {
                    ddlTaskTime.Text = entity.TaskDate.ToString("%H:mm");
                }

                string approvalUserName = "";
                if (entity.ApprovalUser != null)
                {
                    approvalUserName = usrSvr.LoadById(entity.ApprovalUser.ToString()).UserName;
                }

                switch (entity.Status)
                {
                case 0:
                    lblStatus.Text = "";
                    break;

                case 1:
                    lblStatus.Text = approvalUserName + "审批通过√";
                    break;

                case 2:
                    lblStatus.Text = "被" + approvalUserName + "否决×";
                    break;

                default:
                    lblStatus.Text = "";
                    break;
                }
            }
        }
Example #4
0
        public CRMCalendar Save(CRMCalendar entity)
        {
            if (this.dataCtx.Connection != null)
            {
                if (this.dataCtx.Connection.State == ConnectionState.Closed)
                {
                    this.dataCtx.Connection.Open();
                }
            }
            DbTransaction tran = this.dataCtx.Connection.BeginTransaction();

            dataCtx.Transaction = tran;

            try
            {
                var qry = from t in CRMCalendars
                          where t.ID == entity.ID
                          select t;
                var obj = qry.SingleOrDefault();
                if (obj != null)
                {
                    this.CopyEntity(obj, entity);
                }
                else
                {
                    this.CRMCalendars.InsertOnSubmit(entity);
                }

                this.dataCtx.SubmitChanges();
                tran.Commit();
                return(entity);
            }
            catch (Exception ex)
            {
                tran.Rollback();
                throw ex;
            }
            finally
            {
                dataCtx.Connection.Close();
            }
        }
Example #5
0
        private async Task ProcessLuisIntent(CRMLuisModel.Intent intent, ITurnContext turnContext, RecognizerResult luisResult0, CancellationToken cancellationToken = default(CancellationToken))
        {
            var msgContext = turnContext as ITurnContext <IMessageActivity>;

            switch (intent)
            {
            case CRMLuisModel.Intent.Greet_Welcome:
                var usrState = await _userProfileStateAccessor.GetAsync(turnContext);

                if (usrState == null)
                {
                    usrState = new UserProfileState();
                }
                usrState.CurrentDialog = "mainDialog";
                await _userProfileStateAccessor.SetAsync(turnContext, usrState);

                if (msgContext != null)
                {
                    Logger.LogInformation($"[Inside the Greet.Welcome Intent] " + msgContext.Activity.AsMessageActivity()?.Text, msgContext.Activity.Conversation.Id);
                }
                var dialogResult = await Dialog.Run(turnContext, _mainDialogStateAccessor, cancellationToken);

                if (dialogResult.Result != null && !string.IsNullOrWhiteSpace(dialogResult.Result.ToString()))
                {
                    turnContext.Activity.Text = dialogResult.Result.ToString();
                    var luisResult = await _recognizer.RecognizeAsync <CRMLuisModel>(turnContext, cancellationToken);

                    var luisResultRaw = await _recognizer.RecognizeAsync(turnContext, cancellationToken);
                    await ProcessLuisIntent(luisResult.TopIntent().intent, turnContext, luisResultRaw, cancellationToken);
                }
                break;

            case CRMLuisModel.Intent.Accounts_Total:
                Logger.LogInformation($"[Inside the Accounts.Total Intent] " + msgContext.Activity.AsMessageActivity()?.Text, msgContext.Activity.Conversation.Id);
                await CrmLead.GetAccountCounts(await CrmDataConnection.GetAPI2(msgContext, _configuration, _userProfileStateAccessor), msgContext);

                break;

            case CRMLuisModel.Intent.Accounts_AllAccounts:
                Logger.LogInformation($"[Inside the Accounts.AllAccounts Intent] " + msgContext.Activity.AsMessageActivity()?.Text, msgContext.Activity.Conversation.Id);
                await CrmLead.GetAllAccountCounts(await CrmDataConnection.GetAPI2(msgContext, _configuration, _userProfileStateAccessor), msgContext);

                break;

            case CRMLuisModel.Intent.Accounts_Top5:
                Logger.LogInformation($"[Inside the Accounts.Top5 Intent] " + msgContext.Activity.AsMessageActivity()?.Text, msgContext.Activity.Conversation.Id);
                var count = GetNumber(luisResult0.Text);
                await CrmLead.GetTopAccounts(await CrmDataConnection.GetAPI2(msgContext, _configuration, _userProfileStateAccessor), msgContext, count);

                break;

            case CRMLuisModel.Intent.Products_Top5:
                Logger.LogInformation($"[Inside the Products.Top5 Intent] " + msgContext.Activity.AsMessageActivity()?.Text, msgContext.Activity.Conversation.Id);
                await CrmLead.GetTopProducts(await CrmDataConnection.GetAPI2(msgContext, _configuration, _userProfileStateAccessor), msgContext);

                break;

            case CRMLuisModel.Intent.Calendar_Event:
                var usrState1 = await _userProfileStateAccessor.GetAsync(turnContext);

                if (usrState1 == null)
                {
                    usrState1 = new UserProfileState();
                }
                usrState1.CurrentDialog = "graphDialog";
                await _userProfileStateAccessor.SetAsync(turnContext, usrState1);

                var dialogResult1 = await CalDialog.Run(turnContext, _calDialogStateAccessor, cancellationToken);

                if (dialogResult1 != null && dialogResult1.Status == DialogTurnStatus.Complete && luisResult0.GetTopScoringIntent().intent.ToLower() != "none")
                {
                    var crmCalendar = new CRMCalendar();
                    Logger.LogInformation($"[Inside the Calendar.Event Intent] " + msgContext.Activity.AsMessageActivity()?.Text, msgContext.Activity.Conversation.Id);
                    await crmCalendar.AddEventToCalendar(luisResult0, msgContext, cancellationToken, _userProfileStateAccessor, Logger);
                }
                break;

            case CRMLuisModel.Intent.Greet_Farewell:
                Logger.LogInformation($"[Inside the Greet.Farewell Intent] " + msgContext.Activity.AsMessageActivity()?.Text, msgContext.Activity.Conversation.Id);
                var botAdapter = (BotFrameworkAdapter)turnContext.Adapter;
                await botAdapter.SignOutUserAsync(turnContext, "crm", null, cancellationToken);

                await botAdapter.SignOutUserAsync(turnContext, "graph", null, cancellationToken);

                await turnContext.SendActivityAsync(MessageFactory.Text("b'bye \U0001F44B Take care"), cancellationToken);

                await turnContext.SendActivityAsync(MessageFactory.Text("You have been signed out."), cancellationToken);

                break;

            case CRMLuisModel.Intent.QueryProduct:
                var product = luisResult0.GetEntity <string>("Product_Name");
                Logger.LogInformation($"[Inside the QueryProduct Intent] " + msgContext.Activity.AsMessageActivity()?.Text, msgContext.Activity.Conversation.Id);
                await CrmLead.GetProductInfo(await CrmDataConnection.GetAPI2(msgContext, _configuration, _userProfileStateAccessor), msgContext, product);

                break;

            case CRMLuisModel.Intent.Lead_Registration:
                var leadDialogState = await _leadDialogStateAccessor.GetAsync(turnContext);

                if (leadDialogState == null || leadDialogState.DialogStack.Count == 0)
                {
                    await turnContext.SendActivityAsync(MessageFactory.Text($"A new Lead is now being registered in the system."), cancellationToken);
                }
                Logger.LogInformation($"[Inside the Lead.Registration Intent] " + msgContext.Activity.AsMessageActivity()?.Text, msgContext.Activity.Conversation.Id);
                var dialogResult2 = await MakeRootDialog(msgContext.Activity.ChannelId).Run(turnContext, _leadDialogStateAccessor, cancellationToken);

                if (dialogResult2 != null && dialogResult2.Result != null)
                {
                    if (dialogResult2.Result is LeadRegisterForm completedForm)
                    {
                        CrmLead.CreateNewLead(CrmDataConnection.GetAPIStaging(_configuration), completedForm);
                        await turnContext.SendActivityAsync(MessageFactory.Text($"The Lead has been registered in the System"), cancellationToken);
                    }
                }
                break;

            case CRMLuisModel.Intent.Report_ActiveCases:
                Logger.LogInformation($"[Inside the Report.ActiveCases Intent] " + msgContext.Activity.AsMessageActivity()?.Text, msgContext.Activity.Conversation.Id);
                var actionUrl3 = "https://app.powerbi.com/view?r=eyJrIjoiODk3ODQxNDgtMzU2Ni00YTRkLThjMGMtOTliMzNiMDBhMjc4IiwidCI6Ijc0YzNhNGIxLWEyYTUtNGU0OC05ZDdiLTQzNGYzNmQzMzVlZCIsImMiOjF9";
                await CrmLead.ShowReport(msgContext, actionUrl3, "Active Cases");

                break;

            case CRMLuisModel.Intent.Report_PerformanceKpi:
                Logger.LogInformation($"[Inside the Report.PerformanceKpi Intent] " + msgContext.Activity.AsMessageActivity()?.Text, msgContext.Activity.Conversation.Id);
                var actionUrl2 = "https://app.powerbi.com/view?r=eyJrIjoiZWVjODlhNjktZTcwYy00ZDU3LTllYjAtOTRlMjY1MTk0NGQwIiwidCI6Ijc0YzNhNGIxLWEyYTUtNGU0OC05ZDdiLTQzNGYzNmQzMzVlZCIsImMiOjF9";
                await CrmLead.ShowReport(msgContext, actionUrl2, "Org Performance KPIs");

                break;

            case CRMLuisModel.Intent.Report_SalesAnalytics:
                Logger.LogInformation($"[Inside the Report.SalesAnalytics Intent] " + msgContext.Activity.AsMessageActivity()?.Text, msgContext.Activity.Conversation.Id);
                var actionUrl1 = "https://app.powerbi.com/view?r=eyJrIjoiZTljNDg5MjctNjljYi00MTQ2LWJiMTktM2M1OTBkMzQ0OWVkIiwidCI6Ijc0YzNhNGIxLWEyYTUtNGU0OC05ZDdiLTQzNGYzNmQzMzVlZCIsImMiOjF9";
                await CrmLead.ShowReport(msgContext, actionUrl1, "Sales Analytics Reports");

                break;

            case CRMLuisModel.Intent.Report_SalesLeaderboard:
                Logger.LogInformation($"[Inside the Report.SalesLeaderboard Intent] " + msgContext.Activity.AsMessageActivity()?.Text, msgContext.Activity.Conversation.Id);
                var actionUrl = "https://app.powerbi.com/view?r=eyJrIjoiNzMxZmRlNjEtYmFkMy00NDMyLThlY2MtMzI3ZDc2ODE5MTdiIiwidCI6Ijc0YzNhNGIxLWEyYTUtNGU0OC05ZDdiLTQzNGYzNmQzMzVlZCIsImMiOjF9";
                await CrmLead.ShowReport(msgContext, actionUrl, "Sales Leaderboard Reports");

                break;

            case CRMLuisModel.Intent.SharePoint_TopLists:
                Logger.LogInformation($"[Inside the SharePoint.TopLists Intent] " + msgContext.Activity.AsMessageActivity()?.Text, msgContext.Activity.Conversation.Id);
                var count2   = GetNumber(luisResult0.Text);
                var siteName = luisResult0.GetEntity <string>("Site_Name");
                if (string.IsNullOrEmpty(siteName))
                {
                    siteName = "DBS";
                }
                string siteUrl = "https://atidan2.sharepoint.com/sites/myrazor";
                if (siteName.ToLower().Contains("dbs"))
                {
                    siteUrl += "/" + siteName;
                }
                if (siteName.ToLower().Contains("elwyn"))
                {
                    siteUrl += "/RazorPMO/Elwyn/ElwynCRM";
                }
                if (siteName.ToLower().Contains("elwyncrm"))
                {
                    siteUrl += "/RazorPMO/Elwyn/ElwynCRM";
                }
                await QuerySharePoint.GetTopLists(siteUrl, count2, msgContext, siteName, _configuration);

                break;

            case CRMLuisModel.Intent.SharePoint_ListItems:
                Logger.LogInformation($"[Inside the SharePoint.ListItems Intent] " + msgContext.Activity.AsMessageActivity()?.Text, msgContext.Activity.Conversation.Id);
                var count1   = GetNumber(luisResult0.Text);
                var listName = luisResult0.GetEntity <string>("List_Name");
                if (string.IsNullOrEmpty(listName))
                {
                    listName = "Documents";
                }
                if (listName.ToLower() == "status" || listName.ToLower() == "statusreports")
                {
                    listName = "Status Reports";
                }
                if (listName.ToLower() == "billing" || listName.ToLower() == "billingreports")
                {
                    listName = "Billing Reports";
                }
                await QuerySharePoint.GetListContents("https://atidan2.sharepoint.com/sites/myrazor/DBS", listName, count1, msgContext, _configuration);

                break;

            case CRMLuisModel.Intent.SharePoint_AddTask:
                Logger.LogInformation($"[Inside the SharePoint.AddTask Intent] " + msgContext.Activity.AsMessageActivity()?.Text, msgContext.Activity.Conversation.Id);
                await QuerySharePoint.AddTask("https://atidan2.sharepoint.com/sites/ManufacturingICS1", msgContext, _configuration, luisResult0);

                break;

            case CRMLuisModel.Intent.None:
            default:
                Logger.LogInformation($"[Inside the None Intent] " + msgContext.Activity.AsMessageActivity()?.Text, msgContext.Activity.Conversation.Id);
                await turnContext.SendActivityAsync(MessageFactory.Text($"Sorry, I did not understand you. \U0001F44D"), cancellationToken);

                await turnContext.SendActivityAsync(MessageFactory.Text($"I don't know what you want to do"), cancellationToken);

                break;
            }
        }
Example #6
0
 private CRMCalendar GetSaveEntity()
 {
     var entity = new CRMCalendar();
     if (hidID.Value != "0")
     {
         entity = svr.LoadById(hidID.Value);
         entity.ModifyDate = DateTime.Now;
         entity.ModifyUser = base.LoginUserID;
     }
     else
     {
         entity.CDate = DateTime.Now;
         entity.CUser = base.LoginUserID;
         entity.ModifyDate = DateTime.Now;
         entity.ModifyUser = base.LoginUserID;
     }
     entity.UserName = hidPerson.Value;
     entity.Status = 0;// 0 =draft 1= approved 2=reject,9=finish
     if(ddlTaskTime.SelectedValue!="")
         entity.TaskDate = DateTime.ParseExact(hidDay.Value+ " "+ ddlTaskTime.SelectedValue,"yyyyMMdd H:mm",null);
     else
         entity.TaskDate = DateTime.ParseExact(hidDay.Value , "yyyyMMdd", null);
     if (string.IsNullOrEmpty(txtTask.Text.Trim()) == false)
         entity.Task = txtTask.Text.Trim();
     return entity;
 }