Ejemplo n.º 1
0
 private void UpdateParkingArea()
 {
     if (MessageBox.Show("Are you sure you want to Edit this Occupency Area?", MessageBoxCaption, MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
     {
         return;
     }
     try
     {
         using (SqlConnection Conn = new SqlConnection(GlobalClass.TConnectionString))
         {
             Conn.Open();
             using (SqlTransaction tran = Conn.BeginTransaction())
             {
                 if ((int)Conn.ExecuteScalar(string.Format("SELECT COUNT(PA_ID) FROM ParkingArea WHERE PA_NAME = '{0}' AND PA_ID <>{1}", PA.PA_Name, PA.PA_ID), transaction: tran) > 0)
                 {
                     MessageBox.Show("Occupency Area with same name already exist. Please enter another name and try again.", "Save Data", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                     return;
                 }
                 TParkingArea PArea = Conn.Query <TParkingArea>("SELECT * FROM ParkingArea WHERE PA_ID = @PA_ID", PA, tran).First();
                 PA.Update(tran);
                 GlobalClass.SetUserActivityLog(tran, "Occupency Area Setting", "Edit", WorkDetail: "PA_ID : " + PA.PA_ID, Remarks: Newtonsoft.Json.JsonConvert.SerializeObject(PArea));
                 tran.Commit();
             }
             MessageBox.Show("Occupency Area Updated Successfully.", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Information);
             var pa = PAList.First(x => x.PA_ID == PA.PA_ID);
             pa.Description  = PA.Description;
             pa.Capacity     = PA.Capacity;
             pa.PA_Name      = PA.PA_Name;
             pa.VehicleType  = PA.VehicleType;
             pa.FLOOR        = PA.FLOOR;
             pa.MinVacantLot = PA.MinVacantLot;
             pa.VType        = PA.VType;
             ExecuteUndo(null);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 2
0
 private void ExecuteDelete(object obj)
 {
     if (MessageBox.Show("You are about to delete selected Occupency Area. Do you really want to proceed?", MessageBoxCaption, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
     {
         return;
     }
     try
     {
         using (SqlConnection Conn = new SqlConnection(GlobalClass.TConnectionString))
         {
             Conn.Open();
             using (SqlTransaction tran = Conn.BeginTransaction())
             {
                 TParkingArea PArea = Conn.Query <TParkingArea>("SELECT * FROM ParkingArea WHERE PA_ID = @PA_ID", PA, tran).First();
                 PA.Delete(tran);
                 GlobalClass.SetUserActivityLog(tran, "Occupency Area Setting", "Delete", WorkDetail: "PA_ID : " + PA.PA_ID, Remarks: Newtonsoft.Json.JsonConvert.SerializeObject(PArea));
                 tran.Commit();
             }
             MessageBox.Show("Occupency Area Deleted successfully.", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Information);
             PAList.Remove(PAList.First(x => x.PA_ID == PA.PA_ID));
             ExecuteUndo(null);
         }
     }
     catch (SqlException ex)
     {
         if (ex.Number == 547)
         {
             MessageBox.Show("Selected occupency area type cannot be deleted because it has already been linked to another transaction.", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Hand);
         }
         else
         {
             MessageBox.Show(ex.Number + " : " + ex.Message, MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }