All pastes #525027 Raw Edit

Stuff

public text v1 · immutable
#525027 ·published 2007-05-31 07:26 UTC
rendered paste body
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Domain;

namespace Billing.admin
{
    public partial class TarifEditor : PageBase
    {
        private int tarifId;
        private Tarif tarif;

        protected override void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);

            if (Request.QueryString["id"] != null)
            {
                
                tarifId = Int32.Parse(Request.QueryString["id"]);
                                
                domain.Merge(manager.Load(typeof(Tarif), tarifId));
                tarif = domain.LoadObject<Tarif>(tarifId);

              
                

                if (Request.Params["btnOk"] != null)
                    Save();
                LoadData();
            }
            else
            {
                tarif = domain.NewObject<Tarif>();
               
                txtType.Visible = false;
                DropDownListTrafType.Visible = true;

                if (Request.Params["btnOk"] != null)
                    Save();
                else
                    Clear();               
            }

            
        }

        private void Save()
        {
            try
            {
                tarif.Name = txtName.Value;
                tarif.type = DropDownListTrafType.SelectedValue;

                tarif.Price = decimal.Parse(txtPrice.Value);
                tarif.Notes = txtNotes.Value;

                if (tarif.State() == DataRowState.Detached)
                    tarif.Add();

            }

            catch (Exception ex)
            {

               // catching
            }

            try
            {
               // int i = 0;
               // decimal d = 100 / i;

                manager.Update(domain.Changes(), new string[] { "Tarif" });
                Response.Redirect("TarifList.aspx", true);                
            }
            catch (Exception ex)
            {
              // catching
               
            }
           

        }

        private void Clear()
        {
            txtType.Text = null;
            txtName.Value = null;
            txtPrice.Value = null;
            txtNotes.Value = null;
            DropDownListTrafType.DataSource = null;
            DropDownListTrafType.DataBind();
        }

        private void LoadData()
        {
            txtName.Value = tarif.Name;
            txtPrice.Value = tarif.Price.ToString();
            txtNotes.Value = tarif.Notes;

            if (txtType.Text != null)
            {
                txtType.Text = tarif.type.ToString();
                
            }
        }
    }
}