Пример #1
0
        /// <summary>
        /// Step2: Refresh Preivew Mappings Listbox.
        /// </summary>
        private void RefreshPreviewMappings()
        {
            this.ListBox_Step2_PreviewMap.Items.Clear();

            foreach (var mapKVP in MPController.CurrentTransaction.Mappings)
            {
                var     resourceType = MPController.GetResourceTypeByGid(mapKVP.Value);
                var     resourceStr  = "";
                DataRow dr;
                switch (resourceType)
                {
                case ResourceType.Human:
                    dr          = MPController.FindResourceDataRow(GlobalContext.ResourcesDataSet.Tables["human"], mapKVP.Value);
                    resourceStr = String.Format("[H] {0}: {1} {2}", dr["PersonId"], dr["FirstName"],
                                                dr["LastName"]);
                    break;

                case ResourceType.Agent:
                    dr          = MPController.FindResourceDataRow(GlobalContext.ResourcesDataSet.Tables["agent"], mapKVP.Value);
                    resourceStr = String.Format("[A] {0}", dr["Name"]);
                    break;

                case ResourceType.Group:
                    dr          = MPController.FindResourceDataRow(GlobalContext.ResourcesDataSet.Tables["group"], mapKVP.Value);
                    resourceStr = String.Format("[G] {0} ({1})", dr["Name"],
                                                MPController.ParseGroupType(dr["GroupType"]));
                    break;

                case ResourceType.Position:
                    dr = MPController.FindResourceDataRow(GlobalContext.ResourcesDataSet.Tables["position"], mapKVP.Value);
                    var belongTo    = dr["BelongToGroup"] as string;
                    var belongToStr = "";
                    if (belongTo != null)
                    {
                        var fetched = GlobalContext.ResourcesDataSet.Tables["group"].Rows.Cast <DataRow>()
                                      .FirstOrDefault(groupRow => groupRow["GlobalId"] as string == belongTo);
                        if (fetched != null)
                        {
                            belongToStr = $" (Group: {fetched["Name"]})";
                        }
                    }
                    resourceStr = String.Format("[P] {0}{1}", dr["Name"], belongToStr);
                    break;

                case ResourceType.Capability:
                    dr          = MPController.FindResourceDataRow(GlobalContext.ResourcesDataSet.Tables["capability"], mapKVP.Value);
                    resourceStr = String.Format("[C] {0}", dr["Name"]);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                this.ListBox_Step2_PreviewMap.Items.Add(String.Format("{0} => {1}", mapKVP.Key, resourceStr));
            }
        }
        /// <summary>
        /// Create a new mapping management form.
        /// </summary>
        public ManageMappingForm()
        {
            InitializeComponent();
            // Business Roles
            foreach (var br in MPController.CurrentTransaction.BusinessRoleList)
            {
                this.ListBox_BusinessRole.Items.Add(br);
            }
            // Mappings
            foreach (var mapItem in MPController.CurrentTransaction.Mappings)
            {
                this.CurrentMap.Add(mapItem);
            }
            foreach (var mapKVP in MPController.CurrentTransaction.Mappings)
            {
                var     resourceType = MPController.GetResourceTypeByGid(mapKVP.Value);
                var     resourceStr  = "";
                DataRow dr;
                switch (resourceType)
                {
                case ResourceType.Human:
                    dr = MPController.FindResourceDataRow(GlobalContext.ResourcesDataSet.Tables["human"],
                                                          mapKVP.Value);
                    resourceStr = String.Format("[H] {0}: {1} {2}", dr["PersonId"], dr["FirstName"],
                                                dr["LastName"]);
                    break;

                case ResourceType.Agent:
                    dr = MPController.FindResourceDataRow(GlobalContext.ResourcesDataSet.Tables["agent"],
                                                          mapKVP.Value);
                    resourceStr = String.Format("[A] {0}", dr["Name"]);
                    break;

                case ResourceType.Group:
                    dr = MPController.FindResourceDataRow(GlobalContext.ResourcesDataSet.Tables["group"],
                                                          mapKVP.Value);
                    resourceStr = String.Format("[G] {0} ({1})", dr["Name"],
                                                MPController.ParseGroupType(dr["GroupType"]));
                    break;

                case ResourceType.Position:
                    dr = MPController.FindResourceDataRow(GlobalContext.ResourcesDataSet.Tables["position"],
                                                          mapKVP.Value);
                    var belongTo    = dr["BelongToGroup"] as string;
                    var belongToStr = "";
                    if (belongTo != null)
                    {
                        var fetched = GlobalContext.ResourcesDataSet.Tables["group"].Rows.Cast <DataRow>()
                                      .FirstOrDefault(groupRow => groupRow["GlobalId"] as string == belongTo);
                        if (fetched != null)
                        {
                            belongToStr = $" (Group: {fetched["Name"]})";
                        }
                    }
                    resourceStr = String.Format("[P] {0}{1}", dr["Name"], belongToStr);
                    break;

                case ResourceType.Capability:
                    dr = MPController.FindResourceDataRow(GlobalContext.ResourcesDataSet.Tables["capability"],
                                                          mapKVP.Value);
                    resourceStr = String.Format("[C] {0}", dr["Name"]);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                this.ListBox_Mappings.Items.Add(String.Format("{0} => {1}", mapKVP.Key, resourceStr));
            }
            // refresh resource list
            this.RefreshLists(true, true, true, true, true);
            // filter ComboBoxs
            foreach (DataRow dataRow in GlobalContext.ResourcesDataSet.Tables["group"].Rows)
            {
                this.ComboBox_Step2_Filter_G.Items.Add($"{dataRow["Name"]}");
            }
            foreach (DataRow dataRow in GlobalContext.ResourcesDataSet.Tables["position"].Rows)
            {
                this.ComboBox_Step2_Filter_P.Items.Add($"{dataRow["Name"]}");
            }
            foreach (DataRow dataRow in GlobalContext.ResourcesDataSet.Tables["capability"].Rows)
            {
                this.ComboBox_Step2_Filter_C.Items.Add($"{dataRow["Name"]}");
            }
            // set finish flag
            this.initFinish = true;
        }