Click here to Skip to main content
15,889,116 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.6K   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.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using JohnKenedy.DataAccess;
using JohnKenedy.Samples;

namespace MenuMakanan
{
    public partial class MenuFoodDetail : Form
    {
        public MFoodEntity Header { get; set; }
        public MIngredientsEntityCollection Detail { get; set; }

        public MenuFoodDetail()
        {
            InitializeComponent();
        }

        private void MenuFoodDetail_Load(object sender, EventArgs e)
        {
            LoadData();
        }

        private void LoadData()
        {
            dataGridView1.AutoGenerateColumns = false;
            if (Header == null)
            {
                txtName.ReadOnly = false;

                DataAccessLayer.Manager.DALLayer.OpenConnectionTryClose();

                MIngredientsEntityCollection _col = new MIngredientsEntityCollection();
                _col.GetDataBy(null, new List<KeyValuePair<string, object>> { new KeyValuePair<string, object>("FoodNo", 0 )}, null);
                dataGridView1.DataSource = _col.LastSelectTable;

                DataAccessLayer.Manager.DALLayer.CloseConnection();
            }
            else
            {
                txtName.ReadOnly = true;
                txtName.Text = Header.Filler.GetColumnValueNotNull("Name").ToString();
                txtPrice.Text = Header.Filler.GetColumnValueNotNull("Price").ToString();
                bool _foodType = (bool) Header.Filler.GetColumnValueNotNull("IsFoodOrDrink");
                if (_foodType) radioButton1.Checked = true;
                else radioButton2.Checked = true;

                DataAccessLayer.Manager.DALLayer.OpenConnectionTryClose();

                Detail = Header.GetHeaderDetailMIngredientsEntityCollectionByPrimaryKey();
                dataGridView1.DataSource = Detail.LastSelectTable;

                DataAccessLayer.Manager.DALLayer.CloseConnection();
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSaveSetting_Click(object sender, EventArgs e)
        {
            DataAccessLayer.Manager.DALLayer.OpenConnectionTryClose();

            DataAccessLayer.Manager.DALLayer.BeginTransaction();
            try
            {
                MFoodEntity _header = Header;
                if (Header == null)
                {
                    _header = new MFoodEntity();
                }
                _header.Filler.AddColumnValue("Name", txtName.Text);
                _header.Filler.AddColumnValue("SellPrice", Convert.ToDecimal(txtPrice.Text));
                _header.Filler.AddColumnValue("IsFoodOrDrink", radioButton1.Checked);

                if (Convert.ToInt32(_header.Filler.GetColumnValueNotNull("FoodNo")) == 0)
                {
                    _header.InsertIdentity();
                }
                else
                {
                    _header.Update();
                }

                DataTable _table = (DataTable)dataGridView1.DataSource;
                MIngredientsEntityCollection _entityCollection = new MIngredientsEntityCollection();
                _entityCollection.SetDataByTable(_table);

                foreach (MIngredientsEntity _item in _entityCollection)
                {
                    if (Convert.ToInt32(_item.Filler.GetColumnValueNotNull("IngredientsNo")) == 0)
                    {
                        _item.InsertHeaderDetailMIngredientsIdentityToHeader(_header);
                    }
                    else
                    {
                        _item.UpdateHeaderDetailMIngredientsToHeader(_header);
                    }
                }
                if (_entityCollection.Collection.Count > 0)
                    _entityCollection[0].SortAbleMIngredientsNormalizeSortOrder(new object[] { Convert.ToInt32(_header.Filler.GetColumnValueNotNull("FoodNo")) });

                DataAccessLayer.Manager.DALLayer.CommitTransaction();
                MessageBox.Show("Data has been saved successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                DataAccessLayer.Manager.DALLayer.RollbackTransaction();
                MessageBox.Show("Error occur wheren storing information : " + ex.Message, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            DataAccessLayer.Manager.DALLayer.CloseConnection();
        }
    }
}

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