protected void btnSaveLocation_ServerClick(object sender, EventArgs e)
        {
            LocationObject obj = new LocationObject();

            obj.Location_Name = txtLocationName.Value;
            obj.Location_Description = txtLocationDescription.Value;
            obj.Disable = chkBoxLocationDisable.Checked;

            ManageLocation manageLocations = new ManageLocation();

            bool success = manageLocations.insert(obj, ConfigurationManager.ConnectionStrings["MVSSqlDev2008ConnectionString"].ConnectionString);

            if (success)
            {
                divSuccess.Visible = true;
            }
            else
                divFailure.Visible = true;
        }
        protected void btnSaveLocation_ServerClick(object sender, EventArgs e)
        {
            LocationObject obj = new LocationObject();

            obj.Location_Name = txtLocationName.Value;
            obj.Location_Description = txtLocationDescription.Value;
            obj.Disable = chkBoxLocationDisable.Checked;

            ManageLocation manageLocations = new ManageLocation();

            bool success = manageLocations.updateALocation(ConfigurationManager.ConnectionStrings["MVSSqlDev2008ConnectionString"].ConnectionString, obj, Convert.ToInt32(Session["rowIndex"]));

            if (success)
            {
                divSuccess.Visible = true;
            }
            else
                divFailure.Visible = true;

            Session.Remove("rowIndex");
        }
        public Boolean updateALocation(string connectionString, LocationObject locationObj, int rowIndex)
        {
            try
            {
                conn = DBUtility.createConnection(connectionString);
                SqlCommand cmdIns = DBUtility.PrepareSPCommand("sp_UpdateLocation", insertParameters(locationObj), conn);
                cmdIns.Parameters.Add(new SqlParameter("@Location_ID", rowIndex));

                int rowsUpdated = cmdIns.ExecuteNonQuery();

                cmdIns.Dispose();
                DBUtility.Close(conn);
                conn.Dispose();

                if (rowsUpdated > 0)
                {
                    return true;
                }
                else return false;

            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString(), ex);
            }
            finally
            {
                DBUtility.Close(conn);
                conn.Dispose();
            }
        }
        public List<SqlParameter> insertParameters(LocationObject locationObj)
        {
            List<SqlParameter> insertParamsArray = new List<SqlParameter>();

            insertParamsArray.Add(new SqlParameter("@Location_Name", locationObj.Location_Name));
            insertParamsArray.Add(new SqlParameter("@Location_Description", locationObj.Location_Description));
            insertParamsArray.Add(new SqlParameter("@Disable", locationObj.Disable));

            return insertParamsArray;
        }
        public bool insert(LocationObject LocationObj, string connectionString)
        {
            try
            {
                conn = DBUtility.createConnection(connectionString);
                SqlCommand cmdIns = DBUtility.PrepareSPCommand("sp_InsertLocation", insertParameters(LocationObj), conn);

                int rowsUpdated = cmdIns.ExecuteNonQuery();

                //    cmdIns.Parameters.Clear();
                //    cmdIns.CommandText = "SELECT @@IDENTITY";

                //    // Get the last inserted id.
                //    int insertID = Convert.ToInt32(cmdIns.ExecuteScalar());

                cmdIns.Dispose();
                DBUtility.Close(conn);
                conn.Dispose();
                if (rowsUpdated > 0)
                {
                    return true;
                }
                else return false;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString(), ex);
            }
            finally
            {
                DBUtility.Close(conn);
                conn.Dispose();
            }
        }