Пример #1
0
        private void btnView_Click(object sender, EventArgs e)
        {
            try
            {
                grdDriverJobsList.Columns.Clear();


                string   Err    = string.Empty;
                DateTime?dtFrom = dtpFromDate.Value.ToDateTimeorNull();
                DateTime?dtTill = dtpTillDate.Value.ToDateTimeorNull();


                int sameDay = dtFrom.Value.Date == dtTill.Value.Date?1:0;

                using (TaxiDataContext db = new TaxiDataContext())
                {
                    var list = db.stp_DriverJobsList(dtFrom, dtTill, sameDay).ToList();


                    if (list.Count > 0)
                    {
                        //var list2 = (list.AsEnumerable().OrderBy(item => item.DriverNo, new NaturalSortComparer<string>())).ToList();
                        var drivernolist = list.Select(args => new { args.DriverId, args.DriverNo, args.DriverName, args.VehicleType }).Distinct().ToList();

                        var driverJobslist = list.Select(args => new { args.DriverId, args.DriverNo, args.DriverName, args.VehicleType, args.FareRate, args.Id, args.PaymentTypeId }).Distinct().ToList();



                        int DrvCount = list.Select(c => c.DriverNo).Distinct().Count();
                        int Column   = (DrvCount + 1);
                        int rows     = 8 + list.Count;
                        grdDriverJobsList.RowCount = rows;


                        grdDriverJobsList.ColumnCount     = Column;
                        grdDriverJobsList.Columns[0].Name = "heading";

                        for (int x = 0; x < drivernolist.Count; x++)
                        {
                            grdDriverJobsList.Columns[x + 1].Name = drivernolist[x].DriverId.ToStr();
                        }

                        grdDriverJobsList.Columns[0].Width = 20;

                        for (int i = 0; i < 8; i++)
                        {
                            if (i == 0)
                            {
                                grdDriverJobsList.Rows[i].Cells[0].Value = "Name";

                                for (int j = 1; j <= drivernolist.Count; j++)
                                {
                                    grdDriverJobsList.Rows[i].Cells[j].Value = drivernolist[j - 1].DriverName;
                                }
                            }
                            else if (i == 1)
                            {
                                grdDriverJobsList.Rows[i].Cells[0].Value = "Number";

                                for (int j = 1; j <= drivernolist.Count; j++)
                                {
                                    grdDriverJobsList.Rows[i].Cells[j].Value = drivernolist[j - 1].DriverNo;
                                }
                            }
                            else if (i == 2)
                            {
                                grdDriverJobsList.Rows[i].Cells[0].Value = "Vehicle";

                                for (int j = 1; j <= drivernolist.Count; j++)
                                {
                                    grdDriverJobsList.Rows[i].Cells[j].Value = drivernolist[j - 1].VehicleType;
                                }
                            }
                            else if (i == 3)
                            {
                                grdDriverJobsList.Rows[i].Cells[0].Value = "Start";

                                string startTime = "???";
                                for (int j = 1; j <= drivernolist.Count; j++)
                                {
                                    startTime = list.Where(c => c.DriverId == drivernolist[j - 1].DriverId).FirstOrDefault().StartTime.ToStr();

                                    if (startTime.Length > 0 && startTime != "???")
                                    {
                                        startTime = startTime.Substring(startTime.LastIndexOf(' ') + 1);
                                    }
                                    else
                                    {
                                        startTime = "???";
                                    }

                                    grdDriverJobsList.Rows[i].Cells[j].Value = startTime;
                                }
                            }

                            else if (i == 4)
                            {
                                grdDriverJobsList.Rows[i].Cells[0].Value = "Finish";

                                //for (int j = 1; j <= drivernolist.Count; j++)
                                //{

                                //    grdDriverJobsList.Rows[i].Cells[j].Value = "???";

                                //}

                                string endTime = "???";
                                for (int j = 1; j <= drivernolist.Count; j++)
                                {
                                    endTime = list.Where(c => c.DriverId == drivernolist[j - 1].DriverId).FirstOrDefault().EndTime.ToStr();

                                    if (endTime.Length > 0 && endTime != "???")
                                    {
                                        endTime = endTime.Substring(endTime.LastIndexOf(' ') + 1);
                                    }
                                    else
                                    {
                                        endTime = "???";
                                    }



                                    grdDriverJobsList.Rows[i].Cells[j].Value = endTime;
                                }
                            }
                            else if (i == 5)
                            {
                                grdDriverJobsList.Rows[i].Cells[0].Value = "Total";

                                for (int j = 1; j <= drivernolist.Count; j++)
                                {
                                    grdDriverJobsList.Rows[i].Cells[j].Value = list.Where(c => c.DriverId == drivernolist[j - 1].DriverId).Sum(c => c.FareRate).ToDecimal();
                                }
                            }
                            else if (i >= 7)
                            {
                                for (int a = 0; a < drivernolist.Count; a++)
                                {
                                    int cnt = 1;
                                    foreach (var item in driverJobslist.Where(c => c.DriverId == drivernolist[a].DriverId))
                                    {
                                        grdDriverJobsList.Rows[6 + cnt].Cells[0].Value = cnt;

                                        grdDriverJobsList.Rows[6 + cnt].Cells[a + 1].Value = item.FareRate;
                                        grdDriverJobsList.Rows[6 + cnt].Cells[a + 1].Tag   = item.PaymentTypeId;
                                        //      grdDriverJobsList.Rows[i].Cells[j].Value = list.Where(c => c.Id1 == drivernolist[j - 1].Id1).Sum(c => c.FareRate).ToDecimal();
                                        cnt++;
                                    }
                                }
                            }
                        }

                        SetDefaultColumnSettings();
                    }
                }
            }
            catch
            {
            }
        }