first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

C# Code: Windows Forms Data Services; Songhay.WinForms.Web.DataServices; Internal DataSet Procedures; C-sharp

#region Internal DataSet Procedures

internal enum DataPosition { First = 0, Next = 1, Previous = 2, Last = 3 }

internal static void DataSetCancel(DataSet TargetDataSet,ClientMessage Message) { try { TargetDataSet.RejectChanges(); MessageBox.Show(String.Concat("All of your changes have been rejected. ", "Previous edits since last Save will not be saved to the server."), Message.MainForm.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch(Exception Ex) { Message.DataErr(); MessageBox.Show(Ex.Message); } }

internal static void DataSetPosition(DataSet TargetDataSet, DataView EditView,DataPosition EnumPosition,ClientMessage Message) { try { switch(EnumPosition) { case DataPosition.First: Message.MainForm.BindingContext[EditView].Position = 0; DataSetPosition(TargetDataSet,EditView,Message); Message.ReadyToEdit(); break;

        case DataPosition.Next:
            Message.MainForm.BindingContext[EditView].Position += 1;
            DataSetPosition(TargetDataSet,EditView,Message);
            Message.ReadyToEdit();
            break;
        
        case DataPosition.Previous:
            Message.MainForm.BindingContext[EditView].Position -= 1;
            DataSetPosition(TargetDataSet,EditView,Message);
            Message.ReadyToEdit();
            break;
        
        case DataPosition.Last:
            Message.MainForm.BindingContext[EditView].Position 
                = Message.MainForm.BindingContext[EditView].Count - 1;
            DataSetPosition(TargetDataSet,EditView,Message);
            Message.ReadyToEdit();
            break;
    }
}
catch(Exception Ex)
{
    Message.ClientErr();
    Message.MainStatusPanel.Text = Ex.Message;
    MessageBox.Show(Ex.Message);
}

}

internal static void DataSetPosition(DataSet TargetDataSet, DataView EditView,ClientMessage Message) { if(Message.MainForm.BindingContext[EditView].Count > 0) { Message.EditStatusPanel.Text = String.Format("Data Row {0} of {1}", (Message.MainForm.BindingContext[EditView].Position + 1).ToString(), Message.MainForm.BindingContext[EditView].Count.ToString());

    if(TargetDataSet.HasChanges())
    {
        DataSet ds = TargetDataSet.GetChanges();
        string msg = "";
        foreach(DataTable table in ds.Tables)
        {
            if(table.Rows.Count > 1)
                msg += String.Format("{0}: {1} changes. ",
                    table.TableName,table.Rows.Count);

            if(table.Rows.Count == 1)
                msg += String.Format("{0}: 1 change. ",
                    table.TableName);
        }
        Message.ServerStatusPanel.Text = msg;
    }
    else
    {
        Message.ServerStatusPanel.Text
            = "No new changes to client-side data.";
    }
}
else
{
    Message.EditStatusPanel.Text = "        ";
    Message.ServerStatusPanel.Text = "        ";
}

}

internal static void DataSetUpdate(SqlDataAdapter TargetSQLDataAdapter, DataSet TargetDataSet, DataTable TargetDataTable, bool UpdateDBMS, bool PromptToLoseChanges, ClientMessage Message) { //Stop any current edits. Message.MainForm.BindingContext[TargetDataTable].EndCurrentEdit();

if(TargetDataSet.HasChanges())
{
    if(PromptToLoseChanges)
    {
        if(MessageBox.Show("Do you want to save your changes?",
            Message.MainForm.Text, MessageBoxButtons.YesNo,
            MessageBoxIcon.Question)
            == DialogResult.No) return;
    }
}

//Clone target data set. 
DataSet dsTmp = null;
try
{
    dsTmp = TargetDataSet.Clone();
}
catch(System.Exception Ex)
{
    MessageBox.Show(Ex.Message);
}

//Merge with empty clone. FUNKYKB: Does this test schema integrity?
try
{
    TargetDataSet.Merge(dsTmp);
}
catch(System.Exception Ex)
{
    MessageBox.Show(Ex.Message);
}

//Update server.
if(UpdateDBMS)
{
    try
    {
        Message.Saving();
        TargetSQLDataAdapter.Update(TargetDataSet);
    }
    catch(System.Exception Ex)
    {
        Message.DataErr();
        Message.MainStatusPanel.Text = Ex.Message;
        MessageBox.Show(Ex.Message);
    }
}

//Save and clear all changes.
TargetDataSet.AcceptChanges();

}

#endregion

mod date: 2004-06-30T04:00:57.000Z