コード例 #1
0
        public dynamic GetEmployeeDetails(int pageLength, String AccountName, String AccountEmail, int pageIndex, string sConstring)
        {
            DataSet ds = new DataSet();

            ODAl.AdminAccess rptObj = new ODAl.AdminAccess(sConstring);

            UD.TablePreferences EmployeeTablePreferences = new UD.TablePreferences("", "", true, false);
            Dictionary <string, UD.TablePreferences> EmployeeDictionary = new Dictionary <string, UD.TablePreferences>();

            EmployeeDictionary.Add("Employees", EmployeeTablePreferences);

            ds = rptObj.GetEmployeeDetails(pageLength, AccountName, AccountEmail, pageIndex);
            if (ds == null)
            {
                responseObj.Add(new JProperty("Success", "false"));
                responseObj.Add(new JProperty("Message", "Data Base Error"));
            }
            else
            {
                helper.ParseDataSet(ds, EmployeeDictionary);
                responseObj = helper.GetDataSetJobj;
            }

            return(responseObj);
        }
コード例 #2
0
        public JObject GetProfileDetails(int id, string conString)
        {
            DataSet ds = new DataSet();

            ODAl.AdminAccess rptObj = new ODAl.AdminAccess(conString);

            UD.TablePreferences EmployeeTablePreferences = new UD.TablePreferences("", "", true, false);
            Dictionary <string, UD.TablePreferences> EmployeeDictionary = new Dictionary <string, UD.TablePreferences>();

            EmployeeDictionary.Add("Employees", EmployeeTablePreferences);

            ds = rptObj.GetProfileDetails(id);
            if (ds == null)
            {
                responseObj.Add(new JProperty("Success", "false"));
                responseObj.Add(new JProperty("Message", "Data Base Error"));
            }
            else
            {
                helper.ParseDataSet(ds, EmployeeDictionary);
                responseObj = helper.GetDataSetJobj;
            }

            return(responseObj);
        }
コード例 #3
0
 /// <summary>
 /// Converts the data set to JSon/Xml object.
 /// </summary>
 /// <param name="ds">The DataSet.</param>
 /// <returns></returns>
 public void ParseDataSet(DataSet ds, Dictionary <string, TablePreferences> tablePreferences = null)
 {
     if (ds == null)
     {
         return;
     }
     try
     {
         TablePreferences currentTablePreferences     = null;
         string           childXmlElementNameForRows  = "";
         bool             columnValuesAsXmlAttributes = true;
         bool             singleRowAsSingleEntity     = true;
         string           currentTableRootName        = string.Empty;
         foreach (DataTable table in ds.Tables)
         {
             currentTablePreferences     = null;
             currentTableRootName        = string.Empty;
             childXmlElementNameForRows  = "";
             columnValuesAsXmlAttributes = true;
             singleRowAsSingleEntity     = true;
             if (tablePreferences != null && tablePreferences.ContainsKey(table.TableName))
             {
                 tablePreferences.TryGetValue(table.TableName, out currentTablePreferences);
                 if (currentTablePreferences != null)
                 {
                     currentTableRootName        = currentTablePreferences.RootName == null ? string.Empty : currentTablePreferences.RootName;
                     childXmlElementNameForRows  = currentTablePreferences.ChildElementNameForRows == null ? string.Empty : currentTablePreferences.ChildElementNameForRows;
                     columnValuesAsXmlAttributes = currentTablePreferences.ColumnValuesAsXmlAttributes;
                     singleRowAsSingleEntity     = currentTablePreferences.SingleRowAsSingleEntity;
                 }
             }
             if (table.TableName.Equals(Label.OUTPUT_PARAMETERS))
             {
                 foreach (DataColumn column in table.Columns)
                 {
                     this.CreateProperty(column.ColumnName, table.Rows[0][column.ColumnName], true);
                 }
             }
             else
             {
                 this._jArr = new JArray();
                 JObject    rowJObj          = new JObject();
                 XmlElement tableRootElement = null;
                 XmlElement tableRowElement  = null;
                 XmlElement columnElement    = null;
                 string     columnValue      = "";
                 if (this._isOutputXmlFormat)
                 {
                     tableRootElement = xmlDoc.CreateElement(currentTableRootName.Length > 0 ? currentTableRootName : table.TableName);
                 }
                 if (singleRowAsSingleEntity && table.Rows.Count == 1)
                 {
                     if (this._isOutputXmlFormat)
                     {
                         tableRootElement = xmlDoc.CreateElement(childXmlElementNameForRows.Length > 0 ?
                                                                 childXmlElementNameForRows : currentTableRootName.Length > 0 ? currentTableRootName : table.TableName);
                     }
                     rowJObj = new JObject();
                     if (table.Rows.Count > 0)
                     {
                         foreach (DataColumn column in table.Columns)
                         {
                             if (table.Rows[0][column.ColumnName] is DBNull || table.Rows[0][column.ColumnName] == null)
                             {
                                 columnValue = "";
                             }
                             else
                             {
                                 columnValue = table.Rows[0][column.ColumnName].ToString();
                             }
                             if (this._isOutputXmlFormat)
                             {
                                 if (columnValuesAsXmlAttributes)
                                 {
                                     tableRootElement.SetAttribute(column.ColumnName, columnValue);
                                 }
                                 else
                                 {
                                     columnElement           = xmlDoc.CreateElement(column.ColumnName);
                                     columnElement.InnerText = columnValue;
                                     tableRootElement.AppendChild(columnElement);
                                 }
                             }
                             else
                             {
                                 bool  boolResult  = false;
                                 int   intResult   = 0;
                                 float floatResult = 0;
                                 if (column.ColumnName.Equals(Label.SUCCESS, StringComparison.CurrentCultureIgnoreCase) || bool.TryParse(columnValue, out boolResult))
                                 {
                                     rowJObj.Add(new JProperty(column.ColumnName, boolResult));
                                 }
                                 else if (int.TryParse(columnValue, out intResult))
                                 {
                                     rowJObj.Add(new JProperty(column.ColumnName, intResult));
                                 }
                                 else if (float.TryParse(columnValue, out floatResult))
                                 {
                                     rowJObj.Add(new JProperty(column.ColumnName, columnValue));
                                 }
                                 else
                                 {
                                     rowJObj.Add(new JProperty(column.ColumnName, columnValue));
                                 }
                             }
                         }
                     }
                     if (this._isOutputXmlFormat)
                     {
                         rootElement.AppendChild(tableRootElement);
                     }
                     else
                     {
                         this._jObj.Add(new JProperty(childXmlElementNameForRows.Length > 0 ?
                                                      childXmlElementNameForRows :
                                                      currentTableRootName.Length > 0 ?
                                                      currentTableRootName : table.TableName,
                                                      rowJObj));
                     }
                 }
                 else
                 {
                     foreach (DataRow row in table.Rows)
                     {
                         rowJObj = new JObject();
                         if (tableRootElement != null && childXmlElementNameForRows.Length > 0)
                         {
                             tableRowElement = xmlDoc.CreateElement(childXmlElementNameForRows);
                         }
                         else if (tableRootElement != null)
                         {
                             tableRowElement = xmlDoc.CreateElement(currentTableRootName.Length > 0 ? currentTableRootName : table.TableName);
                         }
                         foreach (DataColumn column in table.Columns)
                         {
                             if (row[column.ColumnName] is DBNull || row[column.ColumnName] == null)
                             {
                                 columnValue = "";
                             }
                             else
                             {
                                 columnValue = row[column.ColumnName].ToString();
                             }
                             if (this._isOutputXmlFormat)
                             {
                                 if (columnValuesAsXmlAttributes)
                                 {
                                     tableRowElement.SetAttribute(column.ColumnName, columnValue);
                                 }
                                 else
                                 {
                                     columnElement           = xmlDoc.CreateElement(column.ColumnName);
                                     columnElement.InnerText = columnValue;
                                     tableRowElement.AppendChild(columnElement);
                                 }
                             }
                             else
                             {
                                 bool  boolResult  = false;
                                 int   intResult   = 0;
                                 float floatResult = 0;
                                 if (column.ColumnName.Equals(Label.SUCCESS, StringComparison.CurrentCultureIgnoreCase) || bool.TryParse(columnValue, out boolResult))
                                 {
                                     rowJObj.Add(new JProperty(column.ColumnName, boolResult));
                                 }
                                 else if (int.TryParse(columnValue, out intResult))
                                 {
                                     rowJObj.Add(new JProperty(column.ColumnName, intResult));
                                 }
                                 else if (float.TryParse(columnValue, out floatResult))
                                 {
                                     rowJObj.Add(new JProperty(column.ColumnName, floatResult));
                                 }
                                 else
                                 {
                                     rowJObj.Add(new JProperty(column.ColumnName, columnValue));
                                 }
                             }
                         }
                         if (this._isOutputXmlFormat)
                         {
                             tableRootElement.AppendChild(tableRowElement);
                         }
                         else
                         {
                             this._jArr.Add(rowJObj);
                         }
                     }
                     if (this._isOutputXmlFormat)
                     {
                         rootElement.AppendChild(tableRootElement);
                     }
                     else
                     {
                         this._jObj.Add(new JProperty(currentTableRootName.Length > 0 ? currentTableRootName : table.TableName, this._jArr));
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         //Utilities.Logger.Error(ex.ToString());
     }
     finally { }
 }