예제 #1
0
        protected override int ExecuteDelete(IDictionary keys, 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, "ExecuteDelete", 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);
                }

                DataRow rowDelete = null;

                WebDataSourceDeletingEventArgs eventArgs = new WebDataSourceDeletingEventArgs(keys, values);
                master.OnDeleting(eventArgs);

                if (table.PrimaryKey.Length > 0)
                {
                    object[] keysDelete = new object[table.PrimaryKey.Length];
                    for (int i = 0; i < table.PrimaryKey.Length; i++)
                    {
                        string columnName = table.PrimaryKey[i].ColumnName;
                        if (values.Contains(columnName))
                        {
                            keysDelete[i] = values[columnName];
                        }
                        else if (dataSource.RelationValues != null && dataSource.RelationValues.Contains(columnName))
                        {
                            keysDelete[i] = dataSource.RelationValues[columnName];
                        }
                        else
                        {
                            throw new EEPException(EEPException.ExceptionType.ColumnValueNotFound, dataSource.GetType(), dataSource.ID, columnName, null);
                        }
                    }
                    rowDelete = table.Rows.Find(keysDelete);
                }
                else
                {
                    #region All cells on row
                    string where = string.Empty;
                    IDictionaryEnumerator vs = values.GetEnumerator();
                    while (vs.MoveNext())
                    {
                        string name = vs.Key.ToString();
                        object value = vs.Value;
                        Type type = table.Columns[name].DataType;

                        if (where.Length > 0)
                            where += " and ";

                        if (value == null || value == DBNull.Value || value.ToString().Length == 0)
                            where += Quote(name) + " is null";
                        else
                            where += Quote(name) + "=" + Mark(type, TransformMarkerInColumnValue(type, value));
                    }
                    DataRow[] rowsDelete = table.Select(where);
                    if (rowsDelete.Length != 1)
                    {
                        return 0;
                    }
                    rowDelete = rowsDelete[0];
                    #endregion
                }
                if (rowDelete != null)
                {
                    rowDelete.Delete();
                }
                if (dataSource.AutoApply)
                {
                    if (string.IsNullOrEmpty(dataSource.MasterDataSource))
                    {
                        dataSource.ApplyUpdates();
                    }
                }
                return 1;
            }
        }
예제 #2
0
 public void OnDeleting(WebDataSourceDeletingEventArgs value)
 {
     WebDataSourceDeletingEventHandler handler = (WebDataSourceDeletingEventHandler)Events[EventDeleting];
     if ((handler != null) && (value is WebDataSourceDeletingEventArgs))
     {
         handler(this, (WebDataSourceDeletingEventArgs)value);
     }
 }