protected void btnSaveServiceProvider_ServerClick(object sender, EventArgs e)
        {
            ServiceProviderObject obj = new ServiceProviderObject();

            obj.SP_Name = txtServiceProviderName.Value;
            obj.SP_address= txtServiceProviderAddress.Value;
            obj.Telephone = txtServiceProviderTelephone.Value;
            obj.Category = Convert.ToInt32(lstCategory.Value);
            obj.Disable = chkBoxModelDisable.Checked;

            ManageServiceProvider ManageServiceProviderObj = new ManageServiceProvider();

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

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

            obj.SP_Name = txtServiceProviderName.Value;
            obj.SP_address = txtServiceProviderAddress.Value;
            obj.Telephone = txtServiceProviderTelephone.Value;
            obj.Category = Convert.ToInt32(lstCategory.Items.FindByValue(lstCategory.Value).Value);
            obj.Disable = chkBoxModelDisable.Checked;

            ManageServiceProvider ServiceProviderObj = new ManageServiceProvider();

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

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

            Session.Remove("rowIndex");
        }
        public Boolean updateAServiceProvider(string connectionString, ServiceProviderObject serviceProviderObj, int rowIndex)
        {
            try
            {
                conn = DBUtility.createConnection(connectionString);
                SqlCommand cmdIns = DBUtility.PrepareSPCommand("sp_UpdateServiceProvider", insertParameters(serviceProviderObj), conn);
                cmdIns.Parameters.Add(new SqlParameter("@SP_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(ServiceProviderObject ServiceProviderObj)
        {
            List<SqlParameter> insertParamsArray = new List<SqlParameter>();

            insertParamsArray.Add(new SqlParameter("@SP_Name", ServiceProviderObj.SP_Name));
            insertParamsArray.Add(new SqlParameter("@category", ServiceProviderObj.Category));
            insertParamsArray.Add(new SqlParameter("@SP_Address", ServiceProviderObj.SP_address));
            insertParamsArray.Add(new SqlParameter("@Telephone", ServiceProviderObj.Telephone));
            insertParamsArray.Add(new SqlParameter("@Disable", ServiceProviderObj.Disable));

            return insertParamsArray;
        }
        public bool insert(ServiceProviderObject ServiceProviderObj, string connectionString)
        {
            try
            {
                conn = DBUtility.createConnection(connectionString);
                SqlCommand cmdIns = DBUtility.PrepareSPCommand("sp_InsertServiceProvider", insertParameters(ServiceProviderObj), 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();
            }
        }