Beispiel #1
0
        private void btPEdit_Click(object sender, EventArgs e)
        {
            using (FrmSelectProperty f = new FrmSelectProperty(oPropertyCollection.ToArray()))
            {
                f.ShowDialog();
                if (f.DialogResult == System.Windows.Forms.DialogResult.OK)
                {
                    List <IItem> properties = f._Property.ToList();
                    //整理資料表
                    //移除不在新項目的欄位
                    for (int i = oPropertyCollection.Count; i-- > 0;)
                    {
                        if (!ItemFunction.ComparePropertyCollection(properties, oPropertyCollection[i]))
                        {
                            IItem  item  = oPropertyCollection[i];
                            string name  = item.Name + "[" + item.Unit + "]";
                            int    rowid = dgViewFormula.Rows.IndexOf(dgViewFormula.Rows.Cast <DataGridViewRow>().FirstOrDefault(r => r.Cells[0].Value.ToString() == name));
                            dgViewProperty.Rows.RemoveAt(rowid);
                            oPropertyCollection.RemoveAt(i);
                        }
                    }

                    //新增欄位於表格中
                    DataGridViewRow row;
                    for (int i = 0; i < properties.Count; i++)
                    {
                        if (oPropertyCollection.Count == 0 || !ItemFunction.ComparePropertyCollection(oPropertyCollection, properties[i]))
                        {
                            IItem  item = properties[i];
                            string name = item.Name + "[" + item.Unit + "]";
                            row = new DataGridViewRow();
                            row.Cells.Add(new DataGridViewTextBoxCell());
                            row.Cells[0].Value = item.ID;
                            row.Cells.Add(new DataGridViewTextBoxCell());
                            row.Cells[1].Value = name;
                            row.Cells.Add(new DataGridViewTextBoxCell());
                            row.Cells[2].Value = item.ProdType;
                            dgViewProperty.Rows.Insert(i, row);
                        }
                    }
                    oPropertyCollection = properties;
                }
            }
        }