Gran lavoro!
Ma manca ancora qualcosina!
Ho aggiunto pò di codice alla turca per permettere al "tuo" connector di funzionare anche con i parameter dell'sqldatasource:
Modificando la classe parameter.cs
private object _parent;
internal void ResetParent()
{
this._parent = null;
}
internal object CompareExchangeParent(object value, object comparand)
{
object obj1 = this._parent;
if (comparand == obj1)
{
this._parent = value;
}
return obj1;
}
Modificando la classe ParameterCollection.cs:
ho modificato i due metodi "getParameter" che permettono il recupero di un dbparameter contenuto nella collezione (contenuta nell'array _param).
Ho modificato inoltre i set parameter e l'addrange.
Non ho inserito nessun throw per ora, quindi occhio ;)
private bool _isDirty;
private static Type ItemType;
internal bool IsDirty
{
get
{
return this._isDirty;
}
set
{
this._isDirty = value;
}
}
private void RangeCheck(int index)
{
if ((index < 0) || (this._parms.Count > index))
{
//throw ADP.ParametersMappingIndex(index, this);
}
}
private void OnChange()
{
this.IsDirty = true;
}
private void ValidateType(object value)
{
if (value == null)
{
//throw ADP.ParameterNull("value", this, SqlParameterCollection.ItemType);
}
if (!MySqlParameterCollection.ItemType.IsInstanceOfType(value))
{
//throw ADP.InvalidParameterType(this, SqlParameterCollection.ItemType, value);
}
}
private void Validate(int index, object value)
{
if (value == null)
{
//throw ADP.ParameterNull("value", this, SqlParameterCollection.ItemType);
}
object obj1 = ((MySqlParameter)value).CompareExchangeParent(this, null);
if (obj1 != null)
{
if (this != obj1)
{
//throw ADP.ParametersIsNotParent(SqlParameterCollection.ItemType, this);
}
if (index != this.IndexOf(value))
{
//throw ADP.ParametersIsParent(SqlParameterCollection.ItemType, this);
}
}
if (((MySqlParameter)value).ParameterName.Length == 0)
{
string text1;
index = 1;
do
{
text1 = "Parameter" + index.ToString(CultureInfo.CurrentCulture);
index++;
}
while (-1 != this.IndexOf(text1));
((MySqlParameter)value).ParameterName = text1;
}
}
private void Replace(int index, object newValue)
{
this.ValidateType(newValue);
this.Validate(index, newValue);
MySqlParameter parameter1 = (MySqlParameter) this._parms[index];
this._parms[index] = (MySqlParameter)newValue;
parameter1.ResetParent();
}
public override void AddRange(Array values)
{
this.OnChange();
if (values == null)
{
// throw ADP.ArgumentNull("values");
}
foreach (object obj1 in values)
{
this.ValidateType(obj1);
}
foreach (MySqlParameter parameter1 in values)
{
this.Validate(-1, parameter1);
this._parms.Add(parameter1);
}
// throw new Exception("AddRange-The method or operation is not implemented.");
}
protected override DbParameter GetParameter(string parameterName)
{
// throw new Exception("GetParameter-The method or operation is not implemented.");
int num1 = this.IndexOf(parameterName);
if (num1 < 0)
{
// throw ADP.ParametersSourceIndex(parameterName, this, MySqlParameterCollection.ItemType);
throw new Exception("GetParameter: Index is not valid.");
}
return (DbParameter) this._parms[num1];
}
protected override DbParameter GetParameter(int index)
{
//throw new Exception("GetParameter-The method or operation is not implemented.");
this.RangeCheck(index);
return (DbParameter) this._parms[index];
}
protected override void SetParameter(string parameterName, DbParameter value)
{
// throw new Exception("SetParameter-The method or operation is not implemented.");
this.OnChange();
int num1 = this.IndexOf(parameterName);
if (num1 < 0)
{
//throw ADP.ParametersSourceIndex(parameterName, this, MySqlParameterCollection.ItemType);
}
this.Replace(num1, value);
}
protected override void SetParameter(int index, DbParameter value)
{
//throw new Exception("SetParameter-The method or operation is not implemented.");
this.OnChange();
this.RangeCheck(index);
this.Replace(index, value);
}
Ovviamente se qualcuno riesce a fare una cosa meno disgustosa è pregato di postare il codice ;)
Io ci ho messo un'oretta copiando alla bell'emmeglio da sql ;)
Cmq questo l'ho provato in un paio di situazioni e sembrerebbe funzionare (per esempio ho creato un calendario e un detailview agganciato ad un sqlDatasource con un parameter di questo tipo:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ProviderName="MySql.Data.MySqlClient"
SelectCommand="SELECT IDmopera, data, da, a from MANODOPERA WHERE data = ?data">
<SelectParameters>
<asp:ControlParameter ControlID="Calendar1" PropertyName="SelectedDate" Name="data" />
</SelectParameters>
</asp:SqlDataSource>
e funzia ;) (sia lodato gesù :P)
Ps: non sono ancora riuscito però a fargli funziare la possibilità di aggiungere o modificare i parametri da codice.
Cioè aggiungendo un codice del tipo:
MySqlParameter dayParam = new MySqlParameter("?data", day.Date);
dayParam.MySqlDbType = MySqlDbType.Date;
SqlDataSource1.SelectParameters.Add(dayParam);
Mi da questo errore:
Compiler Error Message: CS1502: The best overloaded method match for 'System.Web.UI.WebControls.ParameterCollection.Add(System.Web.UI.WebControls.Parameter)' has some invalid arguments