Пример #1
0
 public DistanceCharge DistanceChargeIDatareader(IDataReader dr)
 {
     DistanceCharge obj = new DistanceCharge();
     obj.ID = (dr["ID"] is DBNull) ? string.Empty : dr["ID"].ToString();
     obj.Name = (dr["Name"] is DBNull) ? string.Empty : dr["Name"].ToString();
     obj.Charge = (dr["Charge"] is DBNull) ? string.Empty : dr["Charge"].ToString();
     obj.Description = (dr["Description"] is DBNull) ? string.Empty : dr["Description"].ToString();
     return obj;
 }
 public List<DistanceCharge> GetAllDistanceCharge()
 {
     List<DistanceCharge> list = new List<DistanceCharge>();
     using (SqlCommand cmd = GetCommand("getAllDistanceCharge", CommandType.StoredProcedure))
     {
         DistanceCharge distanceCharge = new DistanceCharge();
         using (SqlDataReader dr = ExeDataReader(cmd))
         {
             if (dr.HasRows)
             {
                 while (dr.Read())
                 {
                     list.Add(distanceCharge.DistanceChargeIDatareader(dr));
                 }
             }
         }
         distanceCharge = null;
     }
     return list;
 }
 protected void btnCreate_Click(object sender, EventArgs e)
 {
     if (checkName() && checkChargeFormat() && Page.IsValid)
     {
         DistanceCharge distanceCharge = new DistanceCharge();
         distanceCharge.Name = txtName.Text;
         distanceCharge.Charge = txtCharge.Text;
         distanceCharge.Description = txtDescription.Text;
         bool result = DistanceChargeBLL.InsertDistanceCharge(distanceCharge);
         if (result)
         {
             lblStatusCreate.Text = "Create Distance Charge successful!";
             Response.AddHeader("REFRESH", "2;URL=DistanceManagement.aspx");
         }
         else
         {
             lblStatusCreate.Text = "Can not create new Distance Charge!";
             return;
         }
     }
 }
 public List<DistanceCharge> GetDistanceChargeByID(string id)
 {
     List<DistanceCharge> list = new List<DistanceCharge>();
     using (SqlCommand cmd = GetCommand("getDistanceChargeByID", CommandType.StoredProcedure))
     {
         AddParameter(cmd, "@ID", Convert.ToInt32(id));
         DistanceCharge distanceCharge = new DistanceCharge();
         using (SqlDataReader dr = ExeDataReader(cmd))
         {
             if (dr.HasRows)
             {
                 while (dr.Read())
                 {
                     list.Add(distanceCharge.DistanceChargeIDatareader(dr));
                 }
             }
         }
         distanceCharge = null;
     }
     return list;
 }
        public bool InsertDistanceCharge(DistanceCharge distanceCharge)
        {
            using (SqlCommand cmd = GetCommand("insertDistanceCharge", CommandType.StoredProcedure))
            {
                AddParameter(cmd, "@Name", distanceCharge.Name);
                AddParameter(cmd, "@Charge", distanceCharge.Charge);
                AddParameter(cmd, "@Description", distanceCharge.Description);

                int result = ExeNonQuery(cmd);
                return result > 0;
            }
        }
 public static bool UpdateDistanceCharge(DistanceCharge distanceCharge)
 {
     return db.UpdateDistanceCharge(distanceCharge);
 }
 public static bool InsertDistanceCharge(DistanceCharge distanceCharge)
 {
     return db.InsertDistanceCharge(distanceCharge);
 }
 private void LoadDistanceCharge()
 {
     DistanceCharge distanceCharge = new DistanceCharge();
     distanceCharge = DistanceChargeBLL.GetDistanceChargeByID(distanceChargeID)[0];
     txtName.Text = distanceCharge.Name;
     txtCharge.Text = Convert.ToDecimal(distanceCharge.Charge).ToString("F");
     txtDescription.Text = distanceCharge.Description;
 }