DbBase.cs :  » Content-Management-Systems-CMS » JMDCMS » JMD » Data » Common » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Content Management Systems CMS » JMDCMS 
JMDCMS » JMD » Data » Common » DbBase.cs
/*
  Copyright (C) 2007  Ajay Handa - jmdcms.com 
  This program is free software; 
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  License for more details.
  Some rights reserved. Please read License.txt for details.
  Removing above copyright message is a violation of license terms.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
//using JMD.Windows.Controls;
using System.Data;
using System.Xml;


namespace JMD.Data.Common{
    public class DbBase 
    {
        #region FIELDS
        private DbSql m_dbSql;
        private DataSet dsUI = new DataSet();
        private string m_TableName;
        #endregion FIELDS

        #region CONSTRUCTOR
        public DbBase()
        {
        }
        #endregion CONSTRUCTOR

        #region PROPERTIES
        /// dbSql
        /// <summary>
        /// Database Access Library
        /// </summary>
        public DbSql dbSql
        {
            get { return m_dbSql; }
            set { m_dbSql = value; }
        }
        public void Init(string TableName)
        {
            m_TableName = TableName;
        }

        #endregion PROPERTIES

        #region METHODS
        /// OpenUI(string Code, string ReturnDefault,
        ///    string OrderBy, string WhereCondition)
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Code"></param>
        /// <param name="ReturnDefault"></param>
        /// <param name="OrderBy"></param>
        /// <param name="WhereCondition"></param>
        /// <returns></returns>
        public DataSet OpenUI(string Code, string ReturnDefault,
            string OrderBy, string WhereCondition)
        {
            if ((string.Compare(OrderBy, string.Empty) != 0) && (string.Compare(WhereCondition, string.Empty)) != 0)
            {
                return OpenUI(new string[] { "ID", m_TableName, "*", "1", "20", string.Format(" And {0} ", WhereCondition), string.Format(" Order By {0} ", OrderBy) }, Code, ReturnDefault);
            }
            else if (string.Compare(OrderBy, string.Empty) != 0)
            {
                return OpenUI(new string[] { "ID", m_TableName, "*", "1", "20", " ", string.Format(" Order By {0} ", OrderBy) }, Code, ReturnDefault);
            }
            else if (string.Compare(WhereCondition, string.Empty) != 0)
            {
                return OpenUI(new string[] { "ID", m_TableName, "*", "1", "20", string.Format(" And {0} ", WhereCondition), " " }, Code, ReturnDefault);
            }
            else
            {
                return OpenUI(new string[] { "ID", m_TableName, "*", "1", "20", " ", " " }, Code, ReturnDefault);
            }
        }
        /// OpenUI(string[] Sql,
        ///    string Code, string ReturnDefault)
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Sql"></param>
        /// <param name="Code"></param>
        /// <param name="ReturnDefault"></param>
        /// <returns></returns>
        private DataSet OpenUI(string[] Sql,
            string Code, string ReturnDefault)
        {
            dsUI.Dispose();
            dsUI = new DataSet();
            dsUI = dbSql.Open(TSql.UI_Select_Sp, new string[] { m_TableName, Code, ReturnDefault });
            dsUI.Tables[0].TableName = "UI";
            dsUI.Tables[1].TableName = "UI_VIEW";
            dsUI.Tables[2].TableName = "UI_DISPLAY";
            dsUI.Tables[3].TableName = "UI_SORT";
            dsUI.Tables[4].TableName = "UI_FILTER";
            dsUI.Tables[5].TableName = "UI_COMMAND";
            DataTable dt;
            dt = dbSql.OpenTable(TSql.TablePaging, Sql);
            dt.TableName = "TblRecords";
            dsUI.Tables.Add(dt);
            return dsUI;
        }
        /// SaveUI(string UI_ID,
        ///    string Code, string Is_Default, string XML)
        /// <summary>
        /// 
        /// </summary>
        /// <param name="UI_ID"></param>
        /// <param name="Code"></param>
        /// <param name="Is_Default"></param>
        /// <param name="XML"></param>
        /// <returns></returns>
        public bool SaveUI(string UI_ID,
            string Code, string Is_Default, string XML)
        {
            dbSql.Open(TSql.UI_Save, new string[] { UI_ID, Code, Is_Default, XML });
            return true;
        }
        /// ToXML(DataTable Table)
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Table"></param>
        /// <returns></returns>
        public string ToXML(DataTable Table)
        {
            foreach (DataColumn dc in Table.Columns)
            {
                dc.ColumnMapping = MappingType.Attribute;
            }
            StringBuilder sb = new StringBuilder();
            XmlWriter xmlWriter = XmlWriter.Create(sb);
            Table.WriteXml(xmlWriter);
            return sb.ToString();
        }
        /// ToXML(DataSet dataSet)
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dataSet"></param>
        /// <returns></returns>
        public string ToXML(DataSet dataSet)
        {
            foreach (DataTable Table in dataSet.Tables)
            {
                foreach (DataColumn dc in Table.Columns)
                {
                    dc.ColumnMapping = MappingType.Attribute;
                }
            }
            StringBuilder sb = new StringBuilder();
            XmlWriter xmlWriter = XmlWriter.Create(sb);
            dataSet.WriteXml(xmlWriter);
            return sb.ToString();
        }
        /// GetNextNumber
        /// <summary>
        /// Return Next Maximum available number for the given table
        /// Always provide real table name and not view or sp name
        /// </summary>
        /// <param name="TableName">For which the number is required</param>
        /// <returns>Next Available Maximum Number</returns>
        public string GetNextNumber(string TableName)
        {
            DataTable dt;
            dt = dbSql.OpenTable(TSql.GetNextNumber, new string[] { TableName });
            return dt.Rows[0][0].ToString();
        }
        public string AssignValue(DataColumn dc, string Value)
        {
            return dc.DataType.FullName;
        }

        #endregion METHODS
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.