Click here to Skip to main content
15,886,026 members
Articles / Database Development / SQL Server

.NET Installer that Automatically Installs SQL 2005 Express

Rate me:
Please Sign up or sign in to vote.
4.77/5 (23 votes)
28 Jul 2008GPL35 min read 153.4K   6.2K   133  
This project enables developer to create a setup package that automatically installs SQL 2005 Express and restores database to it
								using System;
                                using System.Collections.Generic;
                                using System.Data;
                                using System.Linq;
                                using System.Text;
								using JohnKenedy.DataAccess;

                                namespace JohnKenedy.Samples
                                {
                                    public class MUserEntity
                                    {
                                        #region Properties
                                        private string _TableName = "MUser";
                                        private DataAccessTableFiller _Filler = null;
                                        public DataAccessTableFiller Filler
                                        {
                                            get
                                            {
                                                return _Filler;
                                            }
                                        }
                                        
                                        public DataRow RowData
                                        {
											get
											{
												if (Filler != null) return Filler.RowData;
												return null;
											}
                                        }
                                        #endregion

                                        public MUserEntity()
                                        {
                                            _Filler = DataAccessLayer.Manager[_TableName].GetFiller();
                                        }

                                        public void SetDataByDataRow(DataRow _row)
                                        {
                                            Filler.SetColumnValueByDataRow(_row);
                                        }
                                        
                                        public MUserEntity GetFullDataByUniqueRow()
                                        {
											MUserEntityCollection _collection = new MUserEntityCollection();
											IList<IDbDataParameter> _parameters = new List<IDbDataParameter>();
											
											string _sql = Filler.GetWhereFilterByAll(ref _parameters);
											_collection.GetDataByWhere(null, _sql, _parameters.ToArray<IDbDataParameter>(), null);
											
											if (_collection.Collection.Count <= 0) return null;
											return _collection[0];
                                        }
                                        
                                        public MUserEntity GetFullDataByPrimaryKey()
                                        {
											MUserEntityCollection _collection = new MUserEntityCollection();
											IDbDataParameter[] _parameters = null;
											
											string _sql = Filler.GetWhereFilterByPrimaryKey(ref _parameters);
											_collection.GetDataByWhere(null, _sql, _parameters, null);
											
											if (_collection.Collection.Count <= 0) return null;
											return _collection[0];
                                        }
                                        
                                        public long InsertIdentity()
                                        {
											ModifyFillerLoginMUserEncryptPasswordColumn();
                                            IDbCommand _com = Filler.GetInsertStatementFilterIdentity();
                                            long _result = DataAccessLayer.Manager[_TableName].ExecuteNonQueryInsertIdentityValueFromCommand(_Filler);
                                            return _result;
                                        }

                                        public int Insert()
                                        {
											ModifyFillerLoginMUserEncryptPasswordColumn();
                                            IDbCommand _com = Filler.GetInsertStatementNoFilter();
                                            int _result = DataAccessLayer.Manager[_TableName].ExecuteNonQueryInsertFromCommand(_Filler);
                                            return _result;
                                        }

                                        public int Delete()
                                        {
                                            IDbCommand _com = Filler.GetDeleteStatementForAllFilter();
                                            int _result = DataAccessLayer.Manager[_TableName].ExecuteNonQueryDeleteFromCommand(_Filler);
                                            return _result;
                                        }

                                        public int DeletePrimaryKey()
                                        {
                                            IDbCommand _com = Filler.GetDeleteStatementForPrimaryKey();
                                            int _result = DataAccessLayer.Manager[_TableName].ExecuteNonQueryDeleteFromCommand(_Filler);
                                            return _result;
                                        }
                                        
                                        public int DeleteByWhere(string _sql, IDbDataParameter[] _parameters)
										{
											return DataAccessLayer.Manager[_TableName].ExecuteNonQueryDeleteFromWhere(_sql, _parameters);
										}

                                        public int Update()
                                        {
											
                                            IDbCommand _com = Filler.GetUpdateStatementFilterIdentity();
                                            int _result = DataAccessLayer.Manager[_TableName].ExecuteNonQueryUpdateFromCommand(_Filler);
                                            return _result;
                                        }
                                        
										#region LoginModuleExtend
										public void ModifyFillerLoginMUserEncryptPasswordColumn()
										{
											BusinessHash _hash = new BusinessHash(ServiceProviderEnum.MD5);
											_hash.Salt = "~M@k@N4n3N@K/";
											
											string _username = Filler.GetColumnValue("Username").ToString();
											string _password = Filler.GetColumnValue("Password").ToString();
											string _encPassword = _hash.Encrypt(_username.ToLower() + _password);
											
											Filler.AddColumnValue("Password", _encPassword);
										}
										
										public int InsertLoginMUserPassword()
										{
											ModifyFillerLoginMUserEncryptPasswordColumn();
											
											return Insert();
										}
										
										public bool IsLoginMUserValid(string _username, string _password)
										{
											BusinessHash _hash = new BusinessHash(ServiceProviderEnum.MD5);
											_hash.Salt = "~M@k@N4n3N@K/";
											_password = _hash.Encrypt(_username.ToLower() + _password);
											
											Filler.AddColumnValue("Username", _username);
											MUserEntity _item = GetFullDataByUniqueRow();
											if (_item == null) return false;
											object _pass = _item.Filler.GetColumnValue("Password");
											if (_pass == null) return false;
											if (_pass.ToString() == _password) return true;
											return false;
										}
										
										#endregion                            
                                    }
                                }

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer (Senior)
Singapore Singapore
I write code mostly in C#, VB.NET, PHP and Assembly.

Comments and Discussions