public void InitializeComponent()
 {
     if (_contentLoaded)
     {
         return;
     }
     _contentLoaded = true;
     System.Windows.Application.LoadComponent(this, new System.Uri("/StudBusApp;component/Views/%D0%9A%D0%BE%D0%BF%D0%B8%D1%8F%20%D0%A1%D1%82%D1%83%D" +
                                                                   "0%B4%D0%B5%D0%BD%D1%82%D1%8B.xaml", System.UriKind.Relative));
     this.LayoutRoot              = ((System.Windows.Controls.Grid)(this.FindName("LayoutRoot")));
     this.PageScrollViewer        = ((System.Windows.Controls.ScrollViewer)(this.FindName("PageScrollViewer")));
     this.ContentStackPanel       = ((System.Windows.Controls.StackPanel)(this.FindName("ContentStackPanel")));
     this.HeaderText              = ((System.Windows.Controls.TextBlock)(this.FindName("HeaderText")));
     this.студентDomainDataSource = ((System.Windows.Controls.DomainDataSource)(this.FindName("студентDomainDataSource")));
     this.группаDomainDataSource  = ((System.Windows.Controls.DomainDataSource)(this.FindName("группаDomainDataSource")));
     this.grid1             = ((System.Windows.Controls.Grid)(this.FindName("grid1")));
     this.кодTextBox        = ((System.Windows.Controls.TextBox)(this.FindName("кодTextBox")));
     this.кодГруппыComboBox = ((System.Windows.Controls.ComboBox)(this.FindName("кодГруппыComboBox")));
     this.фИОTextBox        = ((System.Windows.Controls.TextBox)(this.FindName("фИОTextBox")));
     this.button2           = ((System.Windows.Controls.Button)(this.FindName("button2")));
     this.button3           = ((System.Windows.Controls.Button)(this.FindName("button3")));
     this.студентDataGrid   = ((System.Windows.Controls.DataGrid)(this.FindName("студентDataGrid")));
     this.кодColumn         = ((System.Windows.Controls.DataGridTextColumn)(this.FindName("кодColumn")));
     this.кодГруппыColumn   = ((System.Windows.Controls.DataGridTextColumn)(this.FindName("кодГруппыColumn")));
     this.фИОColumn         = ((System.Windows.Controls.DataGridTextColumn)(this.FindName("фИОColumn")));
     this.button1           = ((System.Windows.Controls.Button)(this.FindName("button1")));
     this.dataField1        = ((System.Windows.Controls.DataField)(this.FindName("dataField1")));
 }
 public void InitializeComponent()
 {
     if (_contentLoaded)
     {
         return;
     }
     _contentLoaded = true;
     System.Windows.Application.LoadComponent(this, new System.Uri("/StudBusApp;component/Views/%D0%9E%D1%86%D0%B5%D0%BD%D0%BA%D0%B8.xaml", System.UriKind.Relative));
     this.LayoutRoot                       = ((System.Windows.Controls.Grid)(this.FindName("LayoutRoot")));
     this.PageScrollViewer                 = ((System.Windows.Controls.ScrollViewer)(this.FindName("PageScrollViewer")));
     this.ContentStackPanel                = ((System.Windows.Controls.StackPanel)(this.FindName("ContentStackPanel")));
     this.HeaderText                       = ((System.Windows.Controls.TextBlock)(this.FindName("HeaderText")));
     this.группаDomainDataSource           = ((System.Windows.Controls.DomainDataSource)(this.FindName("группаDomainDataSource")));
     this.студентDomainDataSource          = ((System.Windows.Controls.DomainDataSource)(this.FindName("студентDomainDataSource")));
     this.дисциплинаDomainDataSource       = ((System.Windows.Controls.DomainDataSource)(this.FindName("дисциплинаDomainDataSource")));
     this.оценкаDomainDataSource           = ((System.Windows.Controls.DomainDataSource)(this.FindName("оценкаDomainDataSource")));
     this.кодComboBox                      = ((System.Windows.Controls.ComboBox)(this.FindName("кодComboBox")));
     this.кодComboBox1                     = ((System.Windows.Controls.ComboBox)(this.FindName("кодComboBox1")));
     this.оценкаDomainDataSourceLoadButton = ((System.Windows.Controls.Button)(this.FindName("оценкаDomainDataSourceLoadButton")));
     this.grid3 = ((System.Windows.Controls.Grid)(this.FindName("grid3")));
     this.кодСтудентаComboBox = ((System.Windows.Controls.ComboBox)(this.FindName("кодСтудентаComboBox")));
     this.оценка1TextBox      = ((System.Windows.Controls.TextBox)(this.FindName("оценка1TextBox")));
     this.button2             = ((System.Windows.Controls.Button)(this.FindName("button2")));
     this.button4             = ((System.Windows.Controls.Button)(this.FindName("button4")));
     this.button3             = ((System.Windows.Controls.Button)(this.FindName("button3")));
     this.оценкаDataGrid      = ((System.Windows.Controls.DataGrid)(this.FindName("оценкаDataGrid")));
     this.кодСтудентаColumn   = ((System.Windows.Controls.DataGridTextColumn)(this.FindName("кодСтудентаColumn")));
     this.оценка1Column       = ((System.Windows.Controls.DataGridTextColumn)(this.FindName("оценка1Column")));
     this.button1             = ((System.Windows.Controls.Button)(this.FindName("button1")));
     this.grid1 = ((System.Windows.Controls.Grid)(this.FindName("grid1")));
     this.grid2 = ((System.Windows.Controls.Grid)(this.FindName("grid2")));
     this.студентDomainDataSource1 = ((System.Windows.Controls.DomainDataSource)(this.FindName("студентDomainDataSource1")));
     this.dataField1 = ((System.Windows.Controls.DataField)(this.FindName("dataField1")));
 }
Пример #3
0
        /// <summary>
        /// Generates a field based on a property type and a property name.
        /// </summary>
        /// <param name="propertyType">The type of the property.</param>
        /// <param name="propertyName">The name of the property.</param>
        /// <param name="bindingMode">The binding mode.</param>
        /// <param name="panel">The panel to insert the field into.</param>
        /// <returns>A value indicating whether or not the field was generated.</returns>
        private bool GenerateField(Type propertyType, string propertyName, BindingMode bindingMode, Panel panel)
        {
            // Create a new DataField for the property.
            DataField newField = new DataField();
            Control control = GetControlFromType(propertyType);
            DependencyProperty dependencyProperty = GetBindingPropertyFromType(propertyType);

            control.TabIndex = this.GetNextTabIndex();
            newField.Content = control;

            if (bindingMode == BindingMode.TwoWay && !string.IsNullOrEmpty(propertyName))
            {
                control.SetBinding(
                    dependencyProperty,
                    new Binding(propertyName)
                    {
                        Mode = BindingMode.TwoWay,
                        ValidatesOnExceptions = true,
                        NotifyOnValidationError = true,
                        Converter = propertyType.IsEnum ? new DataFormToStringConverter() : null
                    });
            }
            else
            {
                control.SetBinding(
                    dependencyProperty,
                    new Binding(propertyName)
                    {
                        Mode = BindingMode.OneWay,
                        Converter = propertyType.IsEnum ? new DataFormToStringConverter() : null
                    });

                newField.IsReadOnly = true;
            }

            // If there's no path, coerce the field to read-only mode and give it
            // a label of "value" (since otherwise it would be blank).
            if (string.IsNullOrEmpty(propertyName))
            {
                newField.IsReadOnly = true;
                newField.Label = propertyType.Name;
            }

            // Raise the AutoGeneratingField event in case the user wants to cancel or replace the
            // field being generated.
            DataFormAutoGeneratingFieldEventArgs e = new DataFormAutoGeneratingFieldEventArgs(propertyName, propertyType, newField);
            this.OnAutoGeneratingField(e);

            if (e.Cancel)
            {
                return false;
            }
            else
            {
                panel.Children.Add(e.Field);
                return true;
            }
        }
        private DefaultActivity CreateCRMActivity(string ActName, DataField dfEntityid, DataField dfEntityName, int x, ref int y)
        {

            DefaultActivity actCRMReview = WorkflowFactory.CreateActivity<DefaultActivity>(ActName + " Review", WizardNames.DefaultActivity);
            process.Activities.Add(actCRMReview);
            actCRMReview.MetaData = "Generated by K2 for Dynamics CRM 2011 Process Generation Tool";
            actCRMReview.ExpectedDuration = 1440;
            actCRMReview.Priority = 2;
            actCRMReview.Slots = 1;
            actCRMReview.Type = ActivityTypes.DestinationInstanceParralel;
            WorkflowHelpers.PositionActivity(actCRMReview, x, y);
            y += 100;

            DesignCRMClient.CRMClientEvent crmClientEvent = WorkflowFactory.CreateEvent<DesignCRMClient.CRMClientEvent>(ActName + " Review", WizardNames.CRMClientEvent);
            
            crmClientEvent.EventItem.CRMCustomSNParameter.Parts.Add("k2_sn");
            crmClientEvent.EventItem.CRMEntityId.Parts.Add(dfEntityid);
            crmClientEvent.EventItem.CRMEntityType.Parts.Add(dfEntityName);
            crmClientEvent.EventItem.CRMFunctionsSmartObject.Parts.Add("K2_CRM_Functions");
            crmClientEvent.EventItem.CRMOrganisation.Parts.Add("Denallix");

            // Add some destination users
            SimpleDestinationRule destinationRule = new SimpleDestinationRule();
            DestinationSet defaultDestinationSet = new DestinationSet();
            Destination destination1 = new Destination();
            destination1.Type = DestinationTypes.User;

            SourceCode.Workflow.Design.WorkflowContextFieldPart fpProcOrigName = new WorkflowContextFieldPart();
            fpProcOrigName.WfProps = "ProcessOriginatorName";
            fpProcOrigName.WorkflowContextProperty = WorkflowContextProperty.ProcessOriginatorName;

            destination1.Value = new K2Field(fpProcOrigName);

            defaultDestinationSet.Destinations.Add(destination1);
            destinationRule.DestinationSets.Add(defaultDestinationSet);
            actCRMReview.DestinationRule = destinationRule;
            destinationRule.ResolveQueuesToUsers = true;

            crmClientEvent.EventItem.TaskSubject.Parts.Add(new WorkflowContextFieldPart(WorkflowContextProperty.ProcessFolio));
            crmClientEvent.EventItem.TaskSubject.Parts.Add(" - ");
            crmClientEvent.EventItem.TaskSubject.Parts.Add(new WorkflowContextFieldPart(WorkflowContextProperty.ActivityInstanceName));

            crmClientEvent.EventItem.TaskDescription.Parts.Add(new WorkflowContextFieldPart(WorkflowContextProperty.ProcessFolio));
            crmClientEvent.EventItem.TaskDescription.Parts.Add(" - ");
            crmClientEvent.EventItem.TaskDescription.Parts.Add(new WorkflowContextFieldPart(WorkflowContextProperty.ActivityInstanceName));

            crmClientEvent.EventItem.TaskOwnerFQN.Parts.Add(new WorkflowContextFieldPart(WorkflowContextProperty.ActivityInstanceDestUserName));
            crmClientEvent.EventItem.ProcessName.Parts.Add(new WorkflowContextFieldPart(WorkflowContextProperty.ProcessName));
            crmClientEvent.EventItem.ActivityName.Parts.Add(new WorkflowContextFieldPart(WorkflowContextProperty.ActivityInstanceName));
            crmClientEvent.EventItem.TaskCategory.Parts.Add(new WorkflowContextFieldPart(WorkflowContextProperty.ProcessName));
            crmClientEvent.EventItem.TaskSubcategory.Parts.Add(new WorkflowContextFieldPart(WorkflowContextProperty.ActivityInstanceName));


            actCRMReview.SucceedingRule = new DesignCRMClient.CRMClientActivitySucceedingRule();
            crmClientEvent.SucceedingRule = new DesignCRMClient.CRMClientEventSucceedingRule();

            actCRMReview.Events.Add(crmClientEvent);

            // Add two actions for the client event
            EventAction approveAction = WorkflowFactory.CreateK2Object<EventAction>("Approve");
            approveAction.ActionItem = new DefaultOutcomeAction();
            EventAction declineAction = WorkflowFactory.CreateK2Object<EventAction>("Decline");
            declineAction.ActionItem = new DefaultOutcomeAction();
            crmClientEvent.Actions.Add(approveAction);
            crmClientEvent.Actions.Add(declineAction);


            // Find the default succeeding rule property wizard definition,
            // and replace it with the default outcome succeeding rule
            //PropertyWizardDefinition propWizDefSimple = WorkflowHelpers.FindOfType<SimpleSucceedingRulePropertyWizardDefinition>(actCRMReview.WizardDefinition.PropertyWizardDefinitions);
            //PropertyWizardDefinition propWizDefOutcome = WorkflowHelpers.FindOfType<OutcomeSucceedingRulePropertyWizardDefinition>(actCRMReview.WizardDefinition.PropertyWizardDefinitions);
            //if (propWizDefSimple != null && propWizDefOutcome == null)
            //{
            //    actCRMReview.WizardDefinition.PropertyWizardDefinitions.Remove(propWizDefSimple);
            //    actCRMReview.WizardDefinition.PropertyWizardDefinitions.Add(
            //        WorkflowFactory.CreatePropertyWizardDefinition(PropertyWizardNames.OutcomeSucceedingRule));
            //}
            
            SourceCode.Workflow.Design.Outcome.Common.GenerateDefaultOutcomesForActions(crmClientEvent);
            SourceCode.Workflow.Design.Outcome.Common.GenerateDefaultLinesForOutcomes(actCRMReview.SucceedingRule as DesignCRMClient.CRMClientActivitySucceedingRule);
            SourceCode.Workflow.Design.Outcome.Common.SyncActivityAndEventSucceedingRule(crmClientEvent);
            return actCRMReview;

        }
        private DefaultActivity CreateStatusActivity(string status, DataField dfEntityid, DataField dfEntityName, int x, ref int y)
        {
            DefaultActivity actUpdate = WorkflowFactory.CreateActivity<DefaultActivity>(status + " Update", WizardNames.DefaultActivity);
            process.Activities.Add(actUpdate);
            actUpdate.MetaData = "Generated by K2 for Dynamics CRM 2011 Process Generation Tool";
            actUpdate.ExpectedDuration = 5;
            actUpdate.Priority = 2;
            WorkflowHelpers.PositionActivity(actUpdate, x, y);
            y += 100;

            // Create Event
            var eventname = "Update Staus - " + status;
            var smoUpdateStatus = WorkflowFactory.CreateEvent<SmartObjectEvent>(eventname, WizardNames.SmartObjectEvent);

            // Configure Event
            var smoInputs = new Dictionary<string, K2Field>();
            smoInputs.Add("EntityId", K2FieldFactory.CreateK2Field(dfEntityid));
            smoInputs.Add("Entity", K2FieldFactory.CreateK2Field(dfEntityName));
            smoInputs.Add("State", K2FieldFactory.CreateK2Field(2));
            smoInputs.Add("Status", K2FieldFactory.CreateK2Field(6));

            var smoOutputs = new Dictionary<string, K2Field>();

            smoUpdateStatus.EventItem.Properties = CreateSmartFormatProperties(
                CRMFunctionsSmartObjectGuid,
                "SmartObject Server",
                "K2_CRM_Functions",
                "K2 CRM Functions",
                "SetStateStatus",
                "Set State Status",
                false,
                smoInputs,
                smoOutputs,
                "Integrated=True;IsPrimaryLogin=True;Authenticate=True;EncryptedPassword=False;Host=localhost;Port=5555");

            actUpdate.Events.Add(smoUpdateStatus);

            return actUpdate;
        }
        private DefaultActivity CreateStartActivity(string status, DataField dfEntityid, DataField dfEntityName, int x, ref int y)
        {
            DefaultActivity activity = WorkflowFactory.CreateActivity<DefaultActivity>("Set Value", WizardNames.DefaultActivity);
            process.Activities.Add(activity);
            activity.MetaData = "Generated by K2 for Dynamics CRM 2011 Process Generation Tool";
            activity.ExpectedDuration = 5;
            activity.Priority = 2;
            WorkflowHelpers.PositionActivity(activity, x, y);
            y += 100;

            return activity;
        }
        private void btnGenerateCRMProcess_Click(object sender, RoutedEventArgs e)
        {
            SourceCode.SmartObjects.Client.SmartObjectClientServer smoServer = new SmartObjectClientServer();
            smoServer.CreateConnection();
            smoServer.Connection.Open("Integrated=True;IsPrimaryLogin=True;Authenticate=True;EncryptedPassword=False;Host=localhost;Port=5555");

            SmartObject smoCRM = smoServer.GetSmartObject("Demo_K2_CRM_Functions");
            smoCRM.MethodToExecute = "GetAllEntities";

            SmartObjectList smoEntities = smoServer.ExecuteList(smoCRM);


            // get state status details
            CRMPicklist pl = new CRMPicklist();
//            pl.AttributeLogicalName = att.LogicalName;
            pl.EntityLogicalName = "lead";

            CRMPicklist cp = functions.CRMGetStateStatus(pl);

            int seq = 0;
            foreach (CRMPicklistOption plo in cp.Picklist.OrderBy(p => p.PicklistParentValue).OrderBy(p => p.PicklistValue))
            {
                StateStatus ss = new StateStatus();
                ss.State = plo.PicklistParentValue;
                ss.StateName = plo.PicklistParentLabel;
                ss.Status = plo.PicklistValue;
                ss.StatusName = plo.PicklistLabel;
                ss.Sequence = seq;
                seq++;
                CRMSS.Add(ss);
            }


            bool ActiveOnly = true;


            string nowish = DateTime.Now.ToString("yyyyMMddHHmmss");
            // Create new process
            process = WorkflowFactory.CreateProcess<DefaultProcess>(nowish, WizardNames.DefaultProcess);

            DataField dfEntityId = new DataField("Entity Id", "");
            DataField dfEntityName = new DataField("Entity Name", "");
            process.DataFields.Add(dfEntityId);
            process.DataFields.Add(dfEntityName);


            var dimensions = WorkflowHelpers.GetActivityDimensions(process.StartActivity);
            int x = Convert.ToInt32(Math.Round(dimensions.X + dimensions.Width + 40D));
            int y = Convert.ToInt32(dimensions.Y) + 100;

            DefaultActivity PrevStatAct = null;
            DefaultActivity PrevReviewAct = null;

            PrevStatAct = CreateStartActivity("", dfEntityId, dfEntityName, x, ref y);

            SourceCode.Workflow.Authoring.Line startLine = WorkflowFactory.CreateLine("StartLine"); 
            startLine.StartActivity = process.StartActivity;
            startLine.FinishActivity = PrevStatAct;
            process.Lines.Add(startLine);

            int c = 0;

            foreach (StateStatus ss in CRMSS.OrderBy(p => p.Sequence))
            {
                DefaultActivity act = CreateStatusActivity(ss.StateName + " - " + ss.StatusName, dfEntityId, dfEntityName, x, ref y);
                if (PrevReviewAct != null)
                {
                    PrevReviewAct.FinishLines[0].FinishActivity = act;
                }

                if (c == 0)
                {
                    SourceCode.Workflow.Authoring.Line firstline = WorkflowFactory.CreateLine("Firstline");
                    firstline.StartActivity = PrevStatAct;
                    firstline.FinishActivity = act;
                    process.Lines.Add(firstline);
                }
                c++;

                DefaultActivity act1 = null;
                if (!ActiveOnly || ActiveOnly && ss.State == 0)
                {
                    act1 = CreateCRMActivity(ss.StateName + " - " + ss.StatusName, dfEntityId, dfEntityName, x, ref y);

                    SourceCode.Workflow.Authoring.Line line = WorkflowFactory.CreateLine("Line " + ss.Sequence);
                    line.StartActivity = act;
                    line.FinishActivity = act1;
                    process.Lines.Add(line);

                    if (PrevStatAct != null)
                    {
                        act1.FinishLines[1].FinishActivity = PrevStatAct;
                    }
                }

                if (act1 == null && PrevStatAct.FinishLines.Count == 0)
                {
                    PrevReviewAct = null;
                    SourceCode.Workflow.Authoring.Line updateLine = WorkflowFactory.CreateLine("Update Line " + ss.Sequence);
                    updateLine.StartActivity = PrevStatAct;
                    updateLine.FinishActivity = act;
                    process.Lines.Add(updateLine);
                }


                if (act != null)
                {
                    WorkflowHelpers.AutoPositionLines(act.StartLines);
                    WorkflowHelpers.AutoPositionLines(act.FinishLines);
                }
                if (act1 != null)
                {
                    WorkflowHelpers.AutoPositionLines(act1.StartLines);
                    WorkflowHelpers.AutoPositionLines(act1.FinishLines);
                }

                PrevReviewAct = act1;
                PrevStatAct = act;
            }
            


            process.FinishRule = new DesignCRMClient.CRMClientProcessFinishRule();

            process.SaveAs(txtProcessPath.Text+nowish+".kprx");

            process = null;
        }
 /// <summary>
 /// Constructs a new instance of DataFormAutoGeneratingFieldEventArgs.
 /// </summary>
 /// <param name="propertyName">The name of the property for the field being generated.</param>
 /// <param name="propertyType">The type of the property for the field being generated.</param>
 /// <param name="field">The field being generated.</param>
 public DataFormAutoGeneratingFieldEventArgs(string propertyName, Type propertyType, DataField field)
 {
     this.Field = field;
     this.PropertyName = propertyName;
     this.PropertyType = propertyType;
 }