private void ExecuteLoad(object obj)
 {
     if (obj != null)
     {
         byte id = Convert.ToByte(obj);
         if (!VTypeList.Any(x => x.VoucherId == id))
         {
             MessageBox.Show("Invalid Id.", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Exclamation);
             return;
         }
         SelectedVType = VTypeList.FirstOrDefault(x => x.VoucherId == id);
     }
     VType = new VoucherType
     {
         VoucherId             = SelectedVType.VoucherId,
         VoucherName           = SelectedVType.VoucherName,
         Rate                  = SelectedVType.Rate,
         RateStr               = SelectedVType.RateStr,
         Value                 = SelectedVType.Value,
         ValidStart            = SelectedVType.ValidStart,
         ValidEnd              = SelectedVType.ValidEnd,
         Validity              = SelectedVType.Validity,
         VehicleType           = SelectedVType.VehicleType,
         VoucherInfo           = SelectedVType.VoucherInfo,
         SkipVoucherGeneration = SelectedVType.SkipVoucherGeneration,
         NonVat                = SelectedVType.NonVat
     };
     SetAction(ButtonAction.Selected);
 }
 private void SaveVoucherType()
 {
     if (MessageBox.Show(string.Format(SaveConfirmText, "Voucher Type"), MessageBoxCaption, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
     {
         return;
     }
     try
     {
         using (SqlConnection Conn = new SqlConnection(GlobalClass.TConnectionString))
         {
             Conn.Open();
             using (SqlTransaction Tran = Conn.BeginTransaction())
             {
                 VType.VoucherId = Conn.ExecuteScalar <byte>("SELECT CAST(ISNULL(MAX(VoucherId), 0) + 1 AS TINYINT) FROM VoucherTypes", transaction: Tran);
                 if (VType.Save(Tran))
                 {
                     GlobalClass.SetUserActivityLog(Tran, "Voucher Type", "New", WorkDetail: "VoucherId : " + VType.VoucherId, Remarks: VType.VoucherName);
                     Tran.Commit();
                     MessageBox.Show("Voucher Type Saved Successfully.", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Information);
                     VTypeList.Add(new VoucherType
                     {
                         VoucherId             = VType.VoucherId,
                         VoucherName           = VType.VoucherName,
                         Rate                  = VType.Rate,
                         RateStr               = VType.RateStr,
                         Value                 = VType.Value,
                         ValidStart            = VType.ValidStart,
                         ValidEnd              = VType.ValidEnd,
                         Validity              = VType.Validity,
                         VoucherInfo           = VType.VoucherInfo,
                         SkipVoucherGeneration = VType.SkipVoucherGeneration,
                         NonVat                = VType.NonVat
                     });
                     ExecuteUndo(null);
                 }
                 else
                 {
                     MessageBox.Show("Voucher Type could not be Saved.", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                 }
             }
         }
     }
     catch (SqlException ex)
     {
         if (ex.Number == 2601)
         {
             MessageBox.Show("Entered Voucher name already exist in the database. Enter unique name and try again", 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);
     }
 }
 private void UpdateVoucherType()
 {
     if (MessageBox.Show(string.Format(UpdateConfirmText, "Voucher Type"), MessageBoxCaption, MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
     {
         return;
     }
     try
     {
         using (SqlConnection Conn = new SqlConnection(GlobalClass.TConnectionString))
         {
             Conn.Open();
             using (SqlTransaction tran = Conn.BeginTransaction())
             {
                 string Remarks = Newtonsoft.Json.JsonConvert.SerializeObject(Conn.Query <VoucherType>("SELECT VoucherId, VoucherName, VehicleType, Rate, Value, Validity, ValidStart, ValidEnd, VoucherInfo, SkipVoucherGeneration FROM VoucherTypes WHERE VoucherId = @VoucherId", VType, tran).First());
                 if (VType.Update(tran))
                 {
                     GlobalClass.SetUserActivityLog(tran, "Voucher Type", "Edit", WorkDetail: "VoucherId : " + VType.VoucherId, Remarks: Remarks);
                     tran.Commit();
                     MessageBox.Show("Voucher Type Updated Successfully.", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Information);
                     var Voucher = VTypeList.First(x => x.VoucherId == VType.VoucherId);
                     Voucher.VoucherName           = VType.VoucherName;
                     Voucher.Rate                  = VType.Rate;
                     Voucher.RateStr               = VType.RateStr;
                     Voucher.Value                 = VType.Value;
                     Voucher.ValidStart            = VType.ValidStart;
                     Voucher.ValidEnd              = VType.ValidEnd;
                     Voucher.Validity              = VType.Validity;
                     Voucher.VoucherInfo           = VType.VoucherInfo;
                     Voucher.SkipVoucherGeneration = VType.SkipVoucherGeneration;
                     Voucher.NonVat                = VType.NonVat;
                     ExecuteUndo(null);
                 }
                 else
                 {
                     MessageBox.Show("Voucher Type could not be updated.", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                     tran.Rollback();
                 }
             }
         }
     }
     catch (SqlException ex)
     {
         if (ex.Number == 2601)
         {
             MessageBox.Show("Entered Voucher name already exist in the database. Enter unique name and try again", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Hand);
         }
         else
         {
             MessageBox.Show(ex.Number + " : " + ex.Message, MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(GlobalClass.GetRootException(ex).Message, MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Exemplo n.º 4
0
        private void GenerateVouchers()
        {
            decimal    Total  = VSDetailList.Sum(x => x.Quantity);
            string     Status = "{0} of " + Total.ToString() + " Done";
            Dispatcher d      = Dispatcher.CurrentDispatcher;

            ThreadPool.QueueUserWorkItem(x =>
            {
                using (SqlConnection conn = new SqlConnection(GlobalClass.TConnectionString))
                {
                    conn.Open();
                    using (SqlTransaction tran = conn.BeginTransaction())
                    {
                        foreach (TParkingSalesDetails pSD in _VSDetailList)
                        {
                            VoucherType vt = VTypeList.First(y => y.VoucherId == pSD.ProdId && y.SkipVoucherGeneration == false);
                            for (int i = 1; i <= pSD.Quantity; i++)
                            {
                                Voucher v = new Voucher()
                                {
                                    BillNo      = pSD.BillNo,
                                    ExpDate     = CurDate.AddDays(vt.Validity),
                                    ValidStart  = vt.ValidStart,
                                    ValidEnd    = vt.ValidEnd,
                                    VoucherName = vt.VoucherName,
                                    Value       = vt.Value,
                                    Sno         = i,
                                    VoucherId   = vt.VoucherId,
                                    FYID        = GlobalClass.FYID
                                };
                                do
                                {
                                    v.Barcode = "#" + new Random().Next(1677215).ToString("X");
                                }while (tran.Connection.ExecuteScalar <int>("SELECT COUNT(*) FROM ParkingVouchers WHERE Barcode = @Barcode", v, transaction: tran) > 0);
                                v.Save(tran);
                                ParkingVouchers.Add(v);
                                d.BeginInvoke((Action)(() =>
                                {
                                    GenCount = string.Format(Status, ParkingVouchers.Count);
                                    Progress = ParkingVouchers.Count / Total * 100;
                                }));
                            }
                        }
                        tran.Commit();
                        PrintVouchers(_VSDetailList.First().BillNo, true, d);
                    }
                }
            });
        }
 private void ExecuteDelete(object obj)
 {
     if (MessageBox.Show(string.Format(DeleteConfirmText, "Voucher Type"), MessageBoxCaption, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
     {
         return;
     }
     try
     {
         using (SqlConnection Conn = new SqlConnection(GlobalClass.TConnectionString))
         {
             Conn.Open();
             using (SqlTransaction tran = Conn.BeginTransaction())
             {
                 string Remarks = Newtonsoft.Json.JsonConvert.SerializeObject(Conn.Query <VoucherType>("SELECT VoucherId, VoucherName, Rate, Value, Validity, ValidStart, ValidEnd, VoucherInfo, SkipVoucherGeneration FROM VoucherTypes WHERE VoucherId = @VoucherId", VType, tran).First());
                 if (VType.Delete(tran))
                 {
                     GlobalClass.SetUserActivityLog(tran, "Voucher Type", "Delete", WorkDetail: "VoucherId : " + VType.VoucherId, Remarks: Remarks);
                     tran.Commit();
                     MessageBox.Show("Voucher Type Deleted successfully.", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Information);
                     VTypeList.Remove(VTypeList.First(x => x.VoucherId == VType.VoucherId));
                     ExecuteUndo(null);
                 }
                 else
                 {
                     MessageBox.Show("Voucher Type could not be Deleted.", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                 }
             }
         }
     }
     catch (SqlException ex)
     {
         if (ex.Number == 547)
         {
             MessageBox.Show("Selected Voucher 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);
     }
 }
Exemplo n.º 6
0
 private async Task GenerateVouchers(SqlTransaction tran)
 {
     decimal Total  = VSDetailList.Sum(x => x.Quantity);
     string  Status = "{0} of " + Total.ToString() + " Done";
     await Task.Run(() =>
     {
         foreach (TParkingSalesDetails pSD in _VSDetailList)
         {
             VoucherType vt = VTypeList.FirstOrDefault(y => y.VoucherId == pSD.ProdId && y.SkipVoucherGeneration == false);
             if (vt != null)
             {
                 for (int i = 1; i <= pSD.Quantity; i++)
                 {
                     Voucher v = new Voucher()
                     {
                         BillNo      = pSD.BillNo,
                         ExpDate     = CurDate.AddDays(vt.Validity),
                         ValidStart  = vt.ValidStart,
                         ValidEnd    = vt.ValidEnd,
                         VoucherName = vt.VoucherName,
                         Value       = vt.Value,
                         Sno         = i,
                         VoucherId   = vt.VoucherId,
                         FYID        = GlobalClass.FYID
                     };
                     do
                     {
                         v.Barcode = "#" + new Random().Next(1677215).ToString("X");
                     }while (tran.Connection.ExecuteScalar <int>("SELECT COUNT(*) FROM ParkingVouchers WHERE Barcode = @Barcode", v, transaction: tran) > 0);
                     v.Save(tran);
                     ParkingVouchers.Add(v);
                     GenCount = string.Format(Status, ParkingVouchers.Count);
                     Progress = ParkingVouchers.Count / Total * 100;
                 }
             }
         }
     });
 }
Exemplo n.º 7
0
        private void ExecuteLoad(object obj)
        {
            try
            {
                using (SqlConnection conn = new SqlConnection(GlobalClass.TConnectionString))
                {
                    PIN.InDate = InDate;
                    PIN.InTime = InTime.ToString("hh:mm tt");
                    PIN.InMiti = nepDate.CBSDate(PIN.InDate);
                    PIN.VType  = VTypeList.First(x => x.VTypeID == PIN.VehicleType);

                    POUT.Rate_ID  = (int)conn.ExecuteScalar("SELECT RATE_ID FROM RATEMASTER WHERE IsDefault = 1");
                    POUT.OutDate  = _CurDate;
                    POUT.OutTime  = _CurTime;
                    POUT.OutMiti  = nepDate.CBSDate(POUT.OutDate);
                    POUT.Interval = GetInterval(PIN.InDate, POUT.OutDate, PIN.InTime, POUT.OutTime);
                    POUT.PID      = PIN.PID;

                    CalculateParkingCharge(conn, PIN.InDate.Add(DateTime.Parse(PIN.InTime).TimeOfDay), POUT.OutDate.Add(DateTime.Parse(POUT.OutTime).TimeOfDay), POUT.Rate_ID, PIN.VehicleType);
                    POUT.CashAmount = POUT.ChargedAmount;
                    if (POUT.CashAmount > GlobalClass.AbbTaxInvoiceLimit)
                    {
                        TaxInvoice           = true;
                        CanChangeInvoiceType = false;
                    }
                    else
                    {
                        CanChangeInvoiceType = true;
                    }
                    FocusedElement = (short)Focusable.CashAmount;
                    PoleDisplay.WriteToDisplay(POUT.ChargedAmount, PoleDisplayType.AMOUNT);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemplo n.º 8
0
        void updateUI()
        {
            try
            {
                using (SqlConnection conn = new SqlConnection(GlobalClass.DataConnectionString))
                {
                    var OcList = conn.Query("SELECT VehicleType, SUM(InFlag) - SUM(OutFlag) Occupency FROM ParkingAreaInOutlog L JOIN ParkingArea PA ON L.PA_ID = PA.PA_ID GROUP BY VehicleType");
                    foreach (dynamic d in OcList)
                    {
                        VTypeList.First(x => x.VTypeID == d.VehicleType).Occupency = d.Occupency;
                    }

                    var PaOcList = conn.Query("SELECT PA_ID, SUM(InFlag) - SUM(OutFlag) Occupency FROM ParkingAreaInOutlog GROUP BY PA_ID");
                    foreach (dynamic d in PaOcList)
                    {
                        PAOccupencyList.First(x => x.PA_ID == d.PA_ID).Occupency = d.Occupency;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(GlobalClass.GetRootException(ex).Message, MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }