protected override int ExecuteInsert(IDictionary values) { WebDataSource dataSource = (WebDataSource)_owner; if (dataSource == null) { return 0; } WebDataSource master = dataSource.MasterWebDataSource; if (!string.IsNullOrEmpty(dataSource.SelectAlias) && !string.IsNullOrEmpty(dataSource.SelectCommand)) { throw new EEPException(EEPException.ExceptionType.MethodNotSupported, dataSource.GetType(), dataSource.ID, "ExecuteInsert", null); } else if (string.IsNullOrEmpty(_viewName)) { throw new EEPException(EEPException.ExceptionType.PropertyNull, dataSource.GetType(), dataSource.ID, "DataMember", null); } else if (master.InnerDataSet == null) { throw new EEPException(EEPException.ExceptionType.ControlNotInitial, dataSource.GetType(), dataSource.ID, "WebDataSource", null); } else { DataTable table = master.InnerDataSet.Tables[_viewName]; if (table == null) { throw new EEPException(EEPException.ExceptionType.PropertyInvalid, dataSource.GetType(), dataSource.ID, "DataMember", _viewName); } // 添加WebDataSource的Adding事件 WebDataSourceAddingEventArgs eventArgs = new WebDataSourceAddingEventArgs(values); master.OnAdding(eventArgs); DataRow rowInsert = table.NewRow(); for (int i = 0; i < table.Columns.Count; i++) { if (values.Contains(table.Columns[i].ColumnName)) { if (values[table.Columns[i].ColumnName] != null && values[table.Columns[i].ColumnName].ToString().Length > 0) { rowInsert[i] = values[table.Columns[i].ColumnName]; } } else if (dataSource.RelationValues != null && dataSource.RelationValues.Contains(table.Columns[i].ColumnName)) { rowInsert[i] = dataSource.RelationValues[table.Columns[i].ColumnName]; } } /*去除空行,不判断剩余行数, 因为肯定会加一笔,防止没有资料时,新增一笔主键相同的值报错*/ if (table.ExtendedProperties.Contains("Empty") && table.ExtendedProperties["Empty"].Equals("True")) { table.Rows.RemoveAt(0); table.ExtendedProperties["Empty"] = "False"; } /***********************************************************************************/ table.Rows.Add(rowInsert); if (dataSource.AutoApply) { if (string.IsNullOrEmpty(dataSource.MasterDataSource)) { if (dataSource.AutoApplyForInsert) { dataSource.ApplyUpdates(); } else { foreach (Control control in dataSource.Parent.Controls) { if (control is WebDataSource && (control as WebDataSource).MasterDataSource == dataSource.ID) { return 1; } } dataSource.ApplyUpdates(); } } } return 1; } }
public void OnAdding(WebDataSourceAddingEventArgs value) { WebDataSourceAddingEventHandler handler = (WebDataSourceAddingEventHandler)Events[EventAdding]; if ((handler != null) && (value is WebDataSourceAddingEventArgs)) { handler(this, (WebDataSourceAddingEventArgs)value); } }