OrderStatus.cs :  » Content-Management-Systems-CMS » mojoPortal » WebStore » Business » 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 » mojoPortal 
mojoPortal » WebStore » Business » OrderStatus.cs
using System;
using System.Data;
using WebStore.Data;

namespace WebStore.Business{
    /// <summary>
    /// Author:          Joe Audette
    /// Created:        2007-02-18
    /// Last Modified:      2008-04-06
    /// 
    /// The use and distribution terms for this software are covered by the 
    /// Common Public License 1.0 (http://opensource.org/licenses/cpl.php)  
    /// which can be found in the file CPL.TXT at the root of this distribution.
    /// By using this software in any fashion, you are agreeing to be bound by 
    /// the terms of this license.
    ///
    /// You must not remove this notice, or any other, from this software.
    /// </summary>
    public class OrderStatus
    {
        const string OrderStatusReceivedId = "0db28432-d9a9-423e-84f2-8a94db434643";
        const string OrderStatusFulfillableId = "70443443-f665-42c9-b69f-48cbf011a14b";
        const string OrderStatusFulfilledId = "67e92035-e8d0-4700-822b-a4002f2f1a15";

        public static Guid OrderStatusReceivedGuid
        {
            get { return new Guid(OrderStatusReceivedId); }
        }

        public static Guid OrderStatusFulfillableGuid
        {
            get { return new Guid(OrderStatusFulfillableId); }
        }

        public static Guid OrderStatusFulfilledGuid
        {
            get { return new Guid(OrderStatusFulfilledId); }
        }


        #region Constructors

        public OrderStatus(Guid languageGuid)
        {
            langGuid = languageGuid;
        }


        public OrderStatus(Guid statusGuid, Guid languageGuid)
        {
            
            GetOrderStatus(statusGuid);
            langGuid = languageGuid;
            GetDescription(statusGuid, languageGuid);
        }

        #endregion

        #region Private Properties

        private Guid guid = Guid.Empty;
        private int sort;
        private Guid langGuid = Guid.Empty;
        private Guid descriptionGuid = Guid.Empty;
        private string description = string.Empty;
        private Guid guidToUse = Guid.NewGuid();

        #endregion

        #region Public Properties

        public Guid Guid
        {
            get { return guid; }
            //set { guid = value; }
        }

        public Guid GuidToUse
        {
            get { return guidToUse; }
            set { guidToUse = value; }
        }
        public int Sort
        {
            get { return sort; }
            set { sort = value; }
        }

        public Guid LanguageGuid
        {
            get { return langGuid; }
            set { langGuid = value; }
        }

        public string Description
        {
            get { return description; }
            set { description = value; }
        }

        #endregion

        #region Private Methods

        private void GetOrderStatus(Guid guid)
        {
            IDataReader reader = DBOrderStatus.Get(guid);

            if (reader.Read())
            {
                this.guid = new Guid(reader["Guid"].ToString());
                this.sort = Convert.ToInt32(reader["Sort"]);

            }

            reader.Close();

        }

        private void GetDescription(
            Guid statusGuid,
            Guid languageGuid)
        {
            IDataReader reader = DBOrderStatus.GetDescription(
                statusGuid,
                languageGuid);

            if (reader.Read())
            {
                this.langGuid = new Guid(reader["LanguageGuid"].ToString());
                this.description = reader["Description"].ToString();

            }

            reader.Close();

        }

        private bool Create()
        {
            
            this.guid = guidToUse;

            int rowsAffected = DBOrderStatus.Add(
                this.guid,
                this.sort);

            return (rowsAffected > 0);

        }



        private bool Update()
        {
            return DBOrderStatus.Update(
                this.guid,
                this.sort);

        }

        private bool LanguageDescriptionExists()
        {
            bool result = false;

            IDataReader reader = DBOrderStatus.GetDescription(
                guid, langGuid);
            if (reader.Read())
            {
                result = true;
            }
            reader.Close();


            return result;
        }


        #endregion

        #region Public Methods


        public bool Save()
        {
            bool result = false;

            if (this.guid != Guid.Empty)
            {
                result = Update();
            }
            else
            {
                result = Create();
            }

            if (result)
            {
                if (LanguageDescriptionExists())
                {
                    DBOrderStatus.UpdateDescription(
                        guid,
                        langGuid,
                        description);
                }
                else
                {
                    DBOrderStatus.AddDescription(
                        guid,
                        langGuid,
                        Description);
                }
            }

            return result;
        }

        public bool Delete()
        {
            // TODO: check if any order have this status first
            //bool result = DBOrderStatus.DeleteOrderStatusDescription(guid,langGuid);
            bool result = DBOrderStatus.DeleteDescription(guid);

            result = DBOrderStatus.Delete(guid);

            return result;
        }


        #endregion

        #region Static Methods

        


        //public static IDataReader GetAll(Guid languageGuid)
        //{
        //    return DBOrderStatus.GetAll(languageGuid);
        //}

        public static DataTable GetAll(Guid languageGuid)
        {
            DataTable dataTable = new DataTable();
            dataTable.Columns.Add("Guid", typeof(Guid));
            dataTable.Columns.Add("Sort", typeof(int));
            dataTable.Columns.Add("Description", typeof(string));
           // dataTable.Columns.Add("TotalPages", typeof(int));

            IDataReader reader = DBOrderStatus.GetAll(languageGuid);
            while (reader.Read())
            {
                DataRow row = dataTable.NewRow();
                row["Guid"] = reader["Guid"];
                row["Sort"] = reader["Sort"];
                row["Description"] = reader["Description"];
                //row["TotalPages"] = Convert.ToInt32(reader["TotalPages"]);
                dataTable.Rows.Add(row);
            }

            reader.Close();

            return dataTable;

        }

        

        #endregion


    }

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