protected override object CreateInstance(Type itemType) { System.Collections.IList list = GetObjectsFromInstance(this.Context.Instance); if (list.Count <= 0) { return(null); } if (list[0].GetType() == typeof(TableData) && itemType == typeof(TableAxisData)) { TableData table = (TableData)list[0]; foreach (DefaultAxis item in Enum.GetValues(typeof(DefaultAxis))) { if (!table.dicTableAxisItem.ContainsKey(item.ToString())) { TableAxisData newAxis = new TableAxisData(item.ToString()); table.dicTableAxisItem.Add(item.ToString(), newAxis); return(newAxis); } } } if (list[0].GetType() == typeof(TableData) && itemType == typeof(TablePosItem)) { TableData table = (TableData)list[0]; if (null == table) { return(null); } int index = 0; string strTemp = "NewItem_"; while (true) { if (!table.dicTablePosItem.ContainsKey(strTemp + index.ToString())) { TablePosItem newPoint = new TablePosItem(); newPoint.Name = strTemp + index.ToString(); table.dicTablePosItem.Add(newPoint.Name, newPoint); return(newPoint); } index++; } } return(null); //return base.CreateInstance(itemType); }
protected internal bool AddNewPoint() { try { string strNewName = ""; if (!GetNewPointName(ref strNewName) || !TableManage.docTable.dicTableData.ContainsKey(_strCurrTable)) { throw new Exception(); } TablePosItem posItem = new TablePosItem(strNewName); posItem.ActiveX = true; posItem.ActiveY = true; posItem.ActiveZ = true; posItem.ActiveU = true; posItem.ActiveA = true; posItem.ActiveB = true; posItem.ActiveC = true; posItem.ActiveD = true; DataGridViewRow row = new DataGridViewRow(); DataGridViewTextBoxCell nameCell = new DataGridViewTextBoxCell(); DataGridViewCheckBoxCell isUseCell = new DataGridViewCheckBoxCell(); DataGridViewComboBoxCell elementCell = new DataGridViewComboBoxCell(); DataGridViewTextBoxCell posCellX = new DataGridViewTextBoxCell(); DataGridViewTextBoxCell posCellY = new DataGridViewTextBoxCell(); DataGridViewTextBoxCell posCellZ = new DataGridViewTextBoxCell(); DataGridViewTextBoxCell posCellU = new DataGridViewTextBoxCell(); DataGridViewTextBoxCell posCellA = new DataGridViewTextBoxCell(); DataGridViewTextBoxCell posCellB = new DataGridViewTextBoxCell(); DataGridViewTextBoxCell posCellC = new DataGridViewTextBoxCell(); DataGridViewTextBoxCell posCellD = new DataGridViewTextBoxCell(); DataGridViewCheckBoxCell activeCellX = new DataGridViewCheckBoxCell(); DataGridViewCheckBoxCell activeCellY = new DataGridViewCheckBoxCell(); DataGridViewCheckBoxCell activeCellZ = new DataGridViewCheckBoxCell(); DataGridViewCheckBoxCell activeCellU = new DataGridViewCheckBoxCell(); DataGridViewCheckBoxCell activeCellA = new DataGridViewCheckBoxCell(); DataGridViewCheckBoxCell activeCellB = new DataGridViewCheckBoxCell(); DataGridViewCheckBoxCell activeCellC = new DataGridViewCheckBoxCell(); DataGridViewCheckBoxCell activeCellD = new DataGridViewCheckBoxCell(); DataGridViewCheckBoxCell moveRelCell = new DataGridViewCheckBoxCell(); DataGridViewComboBoxCell moveModeCell = new DataGridViewComboBoxCell(); DataGridViewTextBoxCell remarkCell = new DataGridViewTextBoxCell(); nameCell.Value = strNewName; isUseCell.Value = posItem.IsUse; posCellX.Value = posItem.PosX; posCellY.Value = posItem.PosY; posCellZ.Value = posItem.PosZ; posCellU.Value = posItem.PosU; posCellA.Value = posItem.PosA; posCellB.Value = posItem.PosB; posCellC.Value = posItem.PosC; posCellD.Value = posItem.PosD; activeCellX.Value = posItem.ActiveX; activeCellY.Value = posItem.ActiveY; activeCellZ.Value = posItem.ActiveA; activeCellU.Value = posItem.ActiveU; activeCellA.Value = posItem.ActiveA; activeCellB.Value = posItem.ActiveB; activeCellC.Value = posItem.ActiveC; activeCellD.Value = posItem.ActiveD; moveRelCell.Value = posItem.MoveRel; remarkCell.Value = posItem.Remarks; moveModeCell.DataSource = Enum.GetNames(typeof(PointMoveMode)); moveModeCell.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing; moveModeCell.Value = posItem.MoveMode.ToString(); elementCell.DataSource = Enum.GetNames(typeof(Element)); elementCell.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing; elementCell.Value = posItem.TrgElement.ToString(); row.Cells.Add(nameCell); row.Cells.Add(isUseCell); row.Cells.Add(elementCell); row.Cells.Add(posCellX); row.Cells.Add(posCellY); row.Cells.Add(posCellZ); row.Cells.Add(posCellU); row.Cells.Add(posCellA); row.Cells.Add(posCellB); row.Cells.Add(posCellC); row.Cells.Add(posCellD); row.Cells.Add(activeCellX); row.Cells.Add(activeCellY); row.Cells.Add(activeCellZ); row.Cells.Add(activeCellU); row.Cells.Add(activeCellA); row.Cells.Add(activeCellB); row.Cells.Add(activeCellC); row.Cells.Add(activeCellD); row.Cells.Add(moveRelCell); row.Cells.Add(moveModeCell); row.Cells.Add(remarkCell); dataGridView1.Rows.Add(row); TableManage.docTable.dicTableData[_strCurrTable].dicTablePosItem.Add(posItem.Name, posItem); TableManage.docTable.dicTableData[_strCurrTable].ListTablePosItems.Add(posItem); } catch (Exception ex) { MessageBox.Show("Add new item unsuccessful!\r\n" + ex.ToString(), "", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification); return(false); } return(true); }
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e) { try { dataGridView1.EndEdit(); if (e.RowIndex >= TableManage.docTable.dicTableData[_strCurrTable].ListTablePosItems.Count) { return; } string strName = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString(); string strOldName = TableManage.docTable.dicTableData[_strCurrTable].ListTablePosItems[e.RowIndex].Name; string strMoveMode = dataGridView1["ColumnMoveMode", e.RowIndex].Value.ToString().Trim(); if (e.ColumnIndex == 0 && !UniqueCheck(1, strName)) { throw new Exception(); } TablePosItem posItem = TableManage.docTable.dicTableData[_strCurrTable].ListTablePosItems[e.RowIndex]; double dTemp = 0.00; string strTemp = ""; List <double> listPos = new List <double>(); for (int index = 0; index < 8; index++) { strTemp = dataGridView1.Rows[e.RowIndex].Cells[index + 3].Value.ToString(); if (!double.TryParse(strTemp, out dTemp)) { MessageBox.Show("The value type should be double type !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification); throw new Exception(); } listPos.Add(dTemp); } posItem.Name = strName; posItem.IsUse = Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells[1].EditedFormattedValue); posItem.TrgElement = (Element)Enum.Parse(typeof(Element), dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString(), false); posItem.PosX = listPos[0]; posItem.PosY = listPos[1]; posItem.PosZ = listPos[2]; posItem.PosU = listPos[3]; posItem.PosA = listPos[4]; posItem.PosB = listPos[5]; posItem.PosC = listPos[6]; posItem.PosD = listPos[7]; posItem.ActiveX = Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells[11].EditedFormattedValue); posItem.ActiveY = Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells[12].EditedFormattedValue); posItem.ActiveZ = Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells[13].EditedFormattedValue); posItem.ActiveU = Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells[14].EditedFormattedValue); posItem.ActiveA = Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells[15].EditedFormattedValue); posItem.ActiveB = Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells[16].EditedFormattedValue); posItem.ActiveC = Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells[17].EditedFormattedValue); posItem.ActiveD = Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells[18].EditedFormattedValue); posItem.MoveRel = Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells[19].EditedFormattedValue); posItem.MoveMode = (PointMoveMode)Enum.Parse(typeof(PointMoveMode), dataGridView1.Rows[e.RowIndex].Cells[20].Value.ToString(), false); posItem.Remarks = dataGridView1.Rows[e.RowIndex].Cells[21].Value.ToString(); TableManage.docTable.dicTableData[_strCurrTable].dicTablePosItem.Remove(strOldName); TableManage.docTable.dicTableData[_strCurrTable].dicTablePosItem.Add(strName, TableManage.docTable.dicTableData[_strCurrTable].ListTablePosItems[e.RowIndex]); } catch (Exception) { MessageBox.Show("Modefine unsuccessful.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification); ShowPosItems(); } }