using System; using System.Collections.Generic; using System.Text; using System.Data; namespace FrontEnd_Builder { /// <summary> /// Class that will build out Dataset to send over /// to the Webservice for rebuild. /// </summary> class Builder { #region "--PRIVATES--" /// <summary> /// Our dataset to send over to the webservice. /// </summary> private DataSet _dsToReturn ; #endregion #region "--PROPERTIES--" /// <summary> /// Gets our dataset to send over to the webservice. /// </summary> public DataSet pDataSet { get { return this._dsToReturn; } } #endregion #region "--CONSTRUCTORS--" /// <summary> /// Default Constructor /// </summary> public Builder() { BuildDataSet(); } #endregion #region "--METHODS--" /// <summary> /// Build Initial Dataset /// </summary> private void BuildDataSet() { //-- INSTANTIATE SET AND TABLE -- _dsToReturn = new DataSet("Object"); _dsToReturn.Tables.Add(new DataTable("Properties")); } /// <summary> /// Add a property to the dataset /// </summary> /// <param name="name">name of the property</param> /// <param name="value">value of the property</param> public void AddProperty(string name, string value) { string[] values = new string[_dsToReturn.Tables[0].Columns.Count + 1]; int i = 0; //-- DO WE ALREADY HAVE A ROW -- if (_dsToReturn.Tables[0].Rows.Count == 0) { //-- ADD COLUMN -- this._dsToReturn.Tables[0].Columns.Add(name); //-- SET VALUE -- values[0] = value; //-- ADD NEW ROW -- this._dsToReturn.Tables[0].Rows.Add(values); } else { //-- GRAB EXISTING VALUES -- for (i = 0; i < _dsToReturn.Tables[0].Columns.Count; i++) values[i] = _dsToReturn.Tables[0].Rows[0][i].ToString(); //-- ADD NEW VALUE AT THE END -- values[i] = value; //-- REMOVE CURRENT ROW -- this._dsToReturn.Tables[0].Rows.RemoveAt(0); //-- ADD COLUMN -- this._dsToReturn.Tables[0].Columns.Add(name); //-- ADD NEW ROW -- this._dsToReturn.Tables[0].Rows.Add(values); } } #endregion } }