Esempio n. 1
0
        private void ListFilteredLeave(int opt, string officeID)
        {
            try
            {
                DateTime dttemp = DateTime.Now;
                grdList.Rows.Clear();
                grdList.Columns.Clear();
                LeaveReportDB       sdb       = new LeaveReportDB();
                List <leaveapprove> leavetype = new List <leaveapprove>();
                leavetype = sdb.getLeaveLimit();
                grdList.Columns.Add("EmployeeID", "EmployeeID");
                grdList.Columns.Add("EmployeeName", "Employee Name");
                grdList.Columns.Add("Office", "Office");
                grdList.Columns["EmployeeID"].Frozen   = true;
                grdList.Columns["EmployeeName"].Frozen = true;
                grdList.Columns["Office"].Frozen       = true;
                foreach (leaveapprove leave in leavetype)
                {
                    grdList.Columns.Add(leave.leaveid, leave.leaveid);
                    grdList.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                }
                grdList.Columns.Add("CO", "CO");
                List <leavereport> lvremain2 = sdb.getLeaveRemain2(opt, regional, officeID);
                var lvrmn = lvremain2.Where(W => W.status != 98 && W.status != 2).GroupBy(x => new { x.EmployeeID, x.leaveid })
                            .Select(g => new
                {
                    GroupName    = g.Key,
                    leavepending = g.Where(a => a.documentStatus == 99 && a.sanctionedTo.Year == dttemp.Year).Sum(s => s.leavepending + 1),
                    EmployeeName = g.First().EmployeeName,
                    officename   = g.First().officename,
                    EmployeeID   = g.First().EmployeeID,
                    leaveid      = g.First().leaveid
                });
                var lvrmn2 = lvrmn.GroupBy(G => G.EmployeeID).ToList();
                int i = 0, j = 0;
                try
                {
                    foreach (var GroupName in lvrmn2)
                    {
                        i = 1;
                        j = 1;
                        string tstr = "";
                        try
                        {
                            foreach (var itm in GroupName)
                            {
                                if (i == j)
                                {
                                    tstr = itm.ToString();
                                    j++;
                                    grdList.Rows.Add();
                                    grdList.Rows[grdList.Rows.Count - 1].Cells["EmployeeID"].Value   = itm.EmployeeID;
                                    grdList.Rows[grdList.Rows.Count - 1].Cells["EmployeeName"].Value = itm.EmployeeName;
                                    grdList.Rows[grdList.Rows.Count - 1].Cells["Office"].Value       = itm.officename;
                                    grdList.Rows[grdList.Rows.Count - 1].Cells[itm.leaveid.Replace(" ", "CL")].Value = Convert.ToInt32(itm.leavepending);
                                }
                                else
                                {
                                    grdList.Rows[grdList.Rows.Count - 1].Cells[itm.leaveid].Value = itm.leavepending;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Error 1 : ListFilteredLeave() - " + ex.ToString() + "\n" + tstr);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error 2 : ListFilteredLeave() - " + ex.ToString());
                }

                DataGridViewButtonColumn btn = new DataGridViewButtonColumn();
                grdList.Columns.Add(btn);
                btn.HeaderText = "Details";
                btn.Text       = "Details";
                btn.Name       = "Details";
                btn.UseColumnTextForButtonValue = true;
                if (grdList.Rows.Count != 0 && Main.itemPriv[1] == true && (Main.itemPriv[2] == true || Main.itemPriv[3] == true))
                {
                    btnExportToExcel.Visible = true;
                }
                else
                {
                    btnExportToExcel.Visible = false;
                }
                grdList.Visible    = true;
                pnlgrdList.Visible = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error 3 : ListFilteredLeave() - " + ex.ToString());
            }
        }
Esempio n. 2
0
        public void setleavedetailgrid(string empid)
        {
            try
            {
                double daysPending = 0;
                dgvLeaveDetails.Columns.Clear();
                LeaveApproveDB      ladb  = new LeaveApproveDB();
                LeaveReportDB       lvdb  = new LeaveReportDB();
                List <leaveapprove> lvob  = lvdb.getLeaveLimit();
                List <leaveapprove> lvapp = ladb.getLeaveLimit(empid);
                dgvLeaveDetails.Columns.Add("LeaveType", "LeaveType");
                dgvLeaveDetails.Columns["LeaveType"].Frozen = true;
                foreach (leaveapprove lv in lvapp)
                {
                    int row = dgvLeaveDetails.Rows.Count - 1;
                    dgvLeaveDetails.Columns.Add(lv.leaveid, lv.leaveid);
                    dgvLeaveDetails.Columns[lv.leaveid].SortMode = DataGridViewColumnSortMode.NotSortable;
                    dgvLeaveDetails.DefaultCellStyle.Alignment   = DataGridViewContentAlignment.MiddleCenter;
                }
                dgvLeaveDetails.Rows.Add();
                dgvLeaveDetails.Rows[dgvLeaveDetails.Rows.Count - 1].Cells["LeaveType"].Value = "Leave OB";
                for (int j = 1; j <= dgvLeaveDetails.ColumnCount - 1; j++)
                {
                    dgvLeaveDetails.Rows[dgvLeaveDetails.Rows.Count - 1].Cells[j].Value = 0;
                }
                foreach (leaveapprove lv in lvapp)
                {
                    dgvLeaveDetails.Rows[dgvLeaveDetails.Rows.Count - 1].Cells[lv.leaveid].Value = lv.maxdays;
                }

                dgvLeaveDetails.Rows.Add();
                dgvLeaveDetails.Rows[dgvLeaveDetails.Rows.Count - 1].Cells["LeaveType"].Value = "Leave Taken";
                for (int j = 1; j <= dgvLeaveDetails.ColumnCount - 1; j++)
                {
                    dgvLeaveDetails.Rows[dgvLeaveDetails.Rows.Count - 1].Cells[j].Value = 0;
                }
                foreach (leaveapprove lv1 in lvapp)
                {
                    daysPending = 0;

                    List <leaveapprove> lvremain = ladb.getLeaveRemain(empid, lv1.leaveid);
                    foreach (leaveapprove lv in lvremain)
                    {
                        daysPending += lv.leavepending;
                        daysPending += 1;
                    }
                    dgvLeaveDetails.Rows[dgvLeaveDetails.Rows.Count - 1].Cells[lv1.leaveid].Value = daysPending;
                }
                dgvLeaveDetails.Rows.Add();
                dgvLeaveDetails.Rows[dgvLeaveDetails.Rows.Count - 1].Cells["LeaveType"].Value = "Current Balance";
                for (int j = 1; j <= dgvLeaveDetails.ColumnCount - 1; j++)
                {
                    for (int i = 0; i <= dgvLeaveDetails.RowCount - 1; i++)
                    {
                        if (i == 2)
                        {
                            if (dgvLeaveDetails.Columns[j].HeaderText != "CO")
                            {
                                dgvLeaveDetails.Rows[i].Cells[j].Value = Convert.ToDouble(dgvLeaveDetails.Rows[i - 2].Cells[j].Value) - Convert.ToDouble(dgvLeaveDetails.Rows[i - 1].Cells[j].Value);
                            }
                            else
                            {
                                dgvLeaveDetails.Rows[i].Cells[j].Value = Convert.ToDouble(dgvLeaveDetails.Rows[i - 2].Cells[j].Value);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }