Esempio n. 1
0
        protected override int ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues)
        {
            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.PropertyNotSupported, dataSource.GetType(), dataSource.ID, "ExecuteUpdate", 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 rowUpdate = null;

                WebDataSourceUpdatingEventArgs eventArgs = new WebDataSourceUpdatingEventArgs(keys, values, oldValues);
                master.OnUpdating(eventArgs);

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

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

                        if (value == null || value == DBNull.Value || value.ToString() == "")
                            where += Quote(name) + " is null";
                        else
                            where += Quote(name) + "=" + Mark(type, TransformMarkerInColumnValue(type, value));
                    }
                    #endregion
                    DataRow[] rowUpdates = table.Select(where);
                    if (rowUpdates.Length != 1)
                    {
                        return 0;
                    }
                    rowUpdate = rowUpdates[0];

                }
                if (rowUpdate == null)
                {
                    return 0;
                }
                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)
                        {
                            rowUpdate[i] = values[table.Columns[i].ColumnName];
                        }
                        else
                        {
                            rowUpdate[i] = DBNull.Value;
                        }
                    }
                }

                if (dataSource.AutoApply)
                {
                    if (string.IsNullOrEmpty(dataSource.MasterDataSource))
                    {
                        dataSource.ApplyUpdates();
                    }
                }
                return 1;
            }
        }
Esempio n. 2
0
 public void OnUpdating(WebDataSourceUpdatingEventArgs value)
 {
     WebDataSourceUpdatingEventHandler handler = (WebDataSourceUpdatingEventHandler)Events[EventUpdating];
     if ((handler != null) && (value is WebDataSourceUpdatingEventArgs))
     {
         handler(this, (WebDataSourceUpdatingEventArgs)value);
     }
 }