Exemple #1
0
        public void UpdateRow(DataSet ds, int rowNr, bool isDataToImport)
        {
            var currentRow = ds.Tables[DataSetTableName.Data].Rows[rowNr];

            var rowHasContent = false;

            foreach (DataRow field in ds.Tables[DataSetTableName.Fields].Rows)
            {
                if (DataType.ByName(field[FieldsTableColumn.Type].ToString()).IsUserDefinedField)
                {
                    var strColumnName  = field[FieldsTableColumn.Title].ToString();
                    var strValueColumn = ((isDataToImport &&
                                           ds.Tables[DataSetTableName.Data].Columns.Contains(strColumnName +
                                                                                             DataTableColumn.
                                                                                             Appendix_Original))
                                              ? strColumnName + DataTableColumn.Appendix_Original
                                              : strColumnName);
                    rowHasContent = Convert.ToBoolean(currentRow[strValueColumn].AsString() != string.Empty);
                    if (rowHasContent)
                    {
                        break;
                    }
                }
            }

            var userDefinedRowId = Convert.ToInt32(currentRow[DataTableColumn.RowId]);
            var isNew            = isDataToImport || (userDefinedRowId == -1);

            if (isNew && rowHasContent)
            {
                //New entries need AddRow first
                userDefinedRowId = AddRow();
                currentRow[DataTableColumn.RowId] = userDefinedRowId;
            }

            if (rowHasContent)
            {
                var values = new Dictionary <int, string>();
                foreach (DataRow field in ds.Tables[DataSetTableName.Fields].Rows)
                {
                    var strColumnName  = field[FieldsTableColumn.Title].ToString();
                    var strValueColumn = ((!isDataToImport &&
                                           ds.Tables[DataSetTableName.Data].Columns.Contains(strColumnName +
                                                                                             DataTableColumn.
                                                                                             Appendix_Original))
                                              ? strColumnName + DataTableColumn.Appendix_Original
                                              : strColumnName);
                    if (ds.Tables[DataSetTableName.Data].Columns.Contains(strValueColumn))
                    {
                        values.Add(field[FieldsTableColumn.Id].AsInt(), currentRow[strValueColumn].AsString());
                    }
                }
                UpdateData(userDefinedRowId, values);
                if (!isDataToImport)
                {
                    TrackingController.OnAction(
                        isNew ? TrackingController.Trigger.New : TrackingController.Trigger.Update, userDefinedRowId, this);
                }
            }
            else
            {
                DeleteRow(userDefinedRowId);
            }
        }
Exemple #2
0
 /// -----------------------------------------------------------------------------
 /// <summary>
 ///   deletes a data row in the database
 /// </summary>
 /// <param name = "userDefinedRowId">ID of the row to be deleted</param>
 /// -----------------------------------------------------------------------------
 public void DeleteRow(int userDefinedRowId)
 {
     TrackingController.OnAction(TrackingController.Trigger.Delete, userDefinedRowId, this);
     DataProvider.Instance().DeleteRow(userDefinedRowId, ModuleId);
 }