/// <summary> /// 停機主檔原因項的增刪變化 /// </summary> void BaseReasonItemChangeSelected(ItemSelected selected) { if (selected == null) { return; } ProjectBaseItemModel itemBaseReason = selected.Item as ProjectBaseItemModel; AddHaltReasonItem(itemBaseReason, selected.Selected); }
/// <summary> /// 根據數據源生成按鈕列表 /// </summary> /// <typeparam name="T"></typeparam> private void CreateButtonList() { try { PropertyInfo displayMember; PropertyInfo valueMember; if (DataSource != null && DataSource.Count > 0) { propertyInfos = DataSource[0].GetType().GetProperties(); displayMember = propertyInfos.SingleOrDefault(d => d.Name == DisplayMember); valueMember = propertyInfos.SingleOrDefault(d => d.Name == ValueMember); } else { return; } foreach (var src in DataSource) { GeneralButton btn = new GeneralButton(); btn.Enabled = this.ButtonEnabled; btn.Height = this.ButtonHeight; btn.Width = this.ButtonWidth; btn.Click += button_Click; ItemSelected item = new ItemSelected(); item.Selected = false; item.Item = src; object value = displayMember.GetValue(src, null); if (value != null) { btn.Text = value.ToString(); } btn.Tag = item; buttonList.Add(btn); } } catch (Exception ex) { throw ex; } }
/// <summary> /// 選中\取消選中的準備工作項 /// TODO:1、修改函數名稱,現名稱不夠準確;2、修改第二參數變為枚舉或布爾值 /// </summary> /// <param name="itemSelected">當前選中的準備工作項</param> /// <param name="type">選中或取消選中</param> private void AddToItemList(ItemSelected itemSelected, int type) { ProjectBaseItemModel itemPrepareSelected = itemSelected.Item as ProjectBaseItemModel; if (itemPrepareSelected == null) { ShowErrorMessage("該項準備工作項綁定內容異常。"); return; } ListViewItem[] listExistItems = this._projectPrepareWorkBase.ListViewSelectedItems.Items.Find(itemPrepareSelected.Code.Trim(), true); if (listExistItems != null && listExistItems.Length > 0) { if (type == -1)//移除 { this._projectPrepareWorkBase.ListViewSelectedItems.Items.Remove(listExistItems[0]); this.m_Controller.RemovePrepareItem(itemPrepareSelected.Code.Trim()); } } else { if (type == 1)//添加 { AddListviewItem(itemPrepareSelected); this.m_Controller.AddPrepareItem(itemPrepareSelected.Code.Trim()); } } this._projectPrepareWorkBase.LabelSelectedItemsCount.Text = string.Format(m_strTotalSelectedText, this._projectPrepareWorkBase.ListViewSelectedItems.Items.Count); }