Exemple #1
0
        public override void PopulateData()
        {
            try
            {
                int    RangeId  = ddlDateRange.SelectedValue.ToInt();
                int    DriverId = ddlDriver.SelectedValue.ToInt();
                string Error    = string.Empty;
                if (RangeId == 0)
                {
                    Error = "Required: Date Range";
                }

                if (!string.IsNullOrEmpty(Error))
                {
                    ENUtils.ShowMessage(Error);
                    return;
                }
                int idx = 0;
                int val = 0;


                int driverTypeId = optRent.Checked ? Enums.DRIVERTYPES.RENT : Enums.DRIVERTYPES.COMMISSION;

                using (TaxiDataContext db = new TaxiDataContext())
                {
                    var list = (from a in db.stp_GetDriverWeeklyRentHistory(RangeId, DriverId)
                                select new
                    {
                        a.Id,
                        a.TransId,
                        a.Active,
                        a.AccountBookings,
                        a.RentComm,
                        //  a.DriverName,
                        a.DriverNo,
                        a.DriverToPay,
                        a.OfficeToPay,
                        a.PreviousBalance,
                        IsPaid = a.IsPaid,
                        Paid = a.IsPaid != null && a.IsPaid == true ? "Paid" : "",
                        a.FromDate,
                        ToDate = a.TillDate,
                        PaidValue = a.IsPaid != null && a.IsPaid == true ? 1 : 0
                    }).ToList();
                    //var list = (from a in db.stp_DriverPaymentAccountBookings(driverTypeId, 115.00m)
                    //            select new
                    //              {
                    //                  a.Id,
                    //                  a.TransId,
                    //                  a.Active,
                    //                  a.AccountBookings,
                    //                  a.TotalRentCommission,
                    //                  a.DriverName,
                    //                  a.DriverNo,
                    //                  a.DriverToPay,
                    //                  a.OfficeToPay,
                    //                  a.PreviousBalance,
                    //                  IsPaid = a.IsWeeklyPaid,
                    //                  Paid = a.IsWeeklyPaid != null && a.IsWeeklyPaid == true ? "Paid" : "",
                    //                  a.FromDate,
                    //                  a.ToDate,
                    //                  PaidValue=a.IsWeeklyPaid != null && a.IsWeeklyPaid == true ?1:0

                    //              }).ToList();
                    if (list.Count == 0)
                    {
                        grdLister.RowCount = 0;
                        return;
                    }
                    var list2 = (list.AsEnumerable().OrderBy(item => item.DriverNo, new NaturalSortComparer <string>())).ToList();

                    idx = grdLister.CurrentRow != null ? grdLister.CurrentRow.Cells["Id"].Value.ToInt() : -1;
                    val = grdLister.TableElement.VScrollBar.Value;

                    grdLister.BeginUpdate();
                    grdLister.RowCount = list2.Count;
                    for (int i = 0; i < list2.Count; i++)
                    {
                        grdLister.Rows[i].Cells["Id"].Value       = list2[i].Id;
                        grdLister.Rows[i].Cells["TransId"].Value  = list2[i].TransId;
                        grdLister.Rows[i].Cells["Active"].Value   = list2[i].Active;
                        grdLister.Rows[i].Cells["DriverNo"].Value = list2[i].DriverNo;

                        grdLister.Rows[i].Cells["AccountBookings"].Value     = list2[i].AccountBookings;
                        grdLister.Rows[i].Cells["PaidAccountBookings"].Value = list2[i].IsPaid.ToBool() ? list2[i].AccountBookings : 0.00m;


                        grdLister.Rows[i].Cells["TotalRentCommission"].Value     = list2[i].RentComm;
                        grdLister.Rows[i].Cells["PaidTotalRentCommission"].Value = list2[i].IsPaid.ToBool() ? list2[i].RentComm : 0.00m;

                        grdLister.Rows[i].Cells["OfficeToPay"].Value     = list2[i].OfficeToPay;
                        grdLister.Rows[i].Cells["PaidOfficeToPay"].Value = list2[i].IsPaid.ToBool() ? list2[i].OfficeToPay : 0.00m;


                        grdLister.Rows[i].Cells["DriverToPay"].Value     = list2[i].DriverToPay;
                        grdLister.Rows[i].Cells["PaidDriverToPay"].Value = list2[i].IsPaid.ToBool() ? list2[i].DriverToPay : 0.00m;

                        grdLister.Rows[i].Cells["PreviousBalance"].Value     = list2[i].PreviousBalance.ToDecimal();
                        grdLister.Rows[i].Cells["PaidPreviousBalance"].Value = list2[i].IsPaid.ToBool() && list2[i].PreviousBalance.ToDecimal() < 0 ? list2[i].PreviousBalance.ToDecimal() : 0.00m;


                        grdLister.Rows[i].Cells["IsPaid"].Value = list2[i].IsPaid.ToBool();

                        grdLister.Rows[i].Cells["Paid"].Value = list2[i].Paid.ToStr();

                        grdLister.Rows[i].Cells["FromDate"].Value  = list2[i].FromDate.ToDate();
                        grdLister.Rows[i].Cells["ToDate"].Value    = list2[i].ToDate.ToDate();
                        grdLister.Rows[i].Cells["PaidValue"].Value = list2[i].PaidValue.ToInt();
                        grdLister.Rows[i].Cells["Check"].Value     = false;
                    }


                    grdLister.EndUpdate();
                }



                SetDefaultColumnSettings();


                AddSummaries();
                UpdatePeriod();


                if (idx > 0)
                {
                    grdLister.CurrentRow = grdLister.Rows.FirstOrDefault(c => c.Cells["Id"].Value.ToInt() == idx);
                }


                if (grdLister.TableElement.VScrollBar.Maximum >= val)
                {
                    grdLister.TableElement.VScrollBar.Value = val;
                }
            }
            catch (Exception ex)
            {
                ENUtils.ShowMessage(ex.Message);
            }
        }