Esempio n. 1
0
        private DataGridView getDynamicGridRows(DataGridView grdlistShowDemo)
        {
            try
            {
                List <leaveob> lvaob = new List <leaveob>();
                leaveob        lva   = new leaveob();
                cmbListYear.SelectedItem = cmbLeaveYear.SelectedItem;
                List <employeeposting> EMPList = LeaveOBDB.getEmployeePostingListForLeaveOB();
                grdlistShowDemo.Rows.Clear();
                foreach (employeeposting empPost in EMPList)
                {
                    if (empPost.empID == 2)
                    {
                        int a = 0;
                    }
                    int           bal        = 0;
                    int           leavetaken = 0;
                    int           total      = 0;
                    int           val        = 0;
                    List <string> strList    = new List <string>();
                    strList.Add(empPost.empID.ToString());
                    strList.Add(empPost.empName);
                    strList.Add(empPost.officeName);
                    LeaveApproveDB lvAppDB = new LeaveApproveDB();
                    LeaveOBDB      lobDB   = new LeaveOBDB();
                    List <leaveob> lobList = lobDB.getLeaveOBDetails(empPost.empID.ToString(), Convert.ToInt32(cmbListYear.SelectedItem));
                    grdlistShowDemo.Rows.Add();
                    grdlistShowDemo.Rows[grdlistShowDemo.RowCount - 1].Cells["EmployeeID"].Value   = empPost.empID.ToString();
                    grdlistShowDemo.Rows[grdlistShowDemo.RowCount - 1].Cells["EmployeeName"].Value = empPost.empName;
                    grdlistShowDemo.Rows[grdlistShowDemo.RowCount - 1].Cells["Office"].Value       = empPost.officeName;
                    DataGridViewColumnCollection collection = grdlistShowDemo.Columns;
                    List <leaveob> officemax   = lobDB.getOfficeMax(empPost.officeID);
                    int            prevYear    = Convert.ToInt32(cmbListYear.SelectedItem);
                    List <leaveob> lobListPrev = lobDB.getLeaveOBDetailsnew(empPost.empID.ToString(), prevYear);

                    //Gives Carry Forward LEave Types
                    LeaveSettingsdb lvDB       = new LeaveSettingsdb();
                    List <Leave>    carryAvail = lvDB.getLeaveTypeList().Where(w => w.CarryForward == 1).ToList();

                    foreach (DataGridViewColumn col in collection)
                    {
                        leavetaken = 0;
                        string leaveColID = (LeaveDict.FirstOrDefault(pair => col.Name == pair.Key.Replace(" ", ""))).Key;
                        if (leaveColID != null)
                        {
                            leaveob             lob      = lobList.FirstOrDefault(listItem => listItem.LeaveID == leaveColID);
                            List <leaveapprove> lvremain = lobDB.getLeaveRemainYearWise(empPost.empID.ToString(), leaveColID, prevYear);
                            foreach (leaveapprove lv in lvremain)
                            {
                                leavetaken += lv.leavepending;
                                leavetaken += 1;
                            }
                            int     prevLVAvail = 0;
                            leaveob lobPrev     = lobListPrev.FirstOrDefault(leave => leave.LeaveID == leaveColID);
                            if (lobPrev != null)
                            {
                                prevLVAvail = lobPrev.LeaveCount;
                            }
                            bal = prevLVAvail - leavetaken;

                            leaveob offmax = officemax.FirstOrDefault(leave => leave.LeaveID == leaveColID);
                            if (offmax != null)
                            {
                                total = bal + offmax.maxdays;
                            }
                            else
                            {
                                total = bal;
                            }
                            if (lob != null)
                            {
                                Leave lvCarry = carryAvail.FirstOrDefault(lv => lv.leaveID == leaveColID);

                                if (lvCarry != null) // carry forward 1
                                {
                                    //int finaltotal = total + lob.LeaveCount;
                                    if (lvCarry.MaxAccrual > total)
                                    {
                                        grdlistShowDemo.Rows[grdlistShowDemo.RowCount - 1].Cells[col.Name].Value = total;
                                        val = total;
                                    }
                                    else
                                    {
                                        grdlistShowDemo.Rows[grdlistShowDemo.RowCount - 1].Cells[col.Name].Value = lvCarry.MaxAccrual;
                                        val = lvCarry.MaxAccrual;
                                    }
                                }
                                else
                                {
                                    if (offmax != null)
                                    {
                                        grdlistShowDemo.Rows[grdlistShowDemo.RowCount - 1].Cells[col.Name].Value = offmax.maxdays;
                                        val = offmax.maxdays;
                                    }
                                    else
                                    {
                                        grdlistShowDemo.Rows[grdlistShowDemo.RowCount - 1].Cells[col.Name].Value = lob.LeaveCount;
                                        val = lob.LeaveCount;
                                    }
                                }
                            }
                            else
                            {
                                Leave lvCarry = carryAvail.FirstOrDefault(lv => lv.leaveID == leaveColID);

                                if (lvCarry != null) // carry forward 1
                                {
                                    if (lvCarry.MaxAccrual > total)
                                    {
                                        grdlistShowDemo.Rows[grdlistShowDemo.RowCount - 1].Cells[col.Name].Value = total;
                                        val = total;
                                    }
                                    else
                                    {
                                        grdlistShowDemo.Rows[grdlistShowDemo.RowCount - 1].Cells[col.Name].Value = lvCarry.MaxAccrual;
                                        val = lvCarry.MaxAccrual;
                                    }
                                }
                                else
                                {
                                    if (offmax != null)
                                    {
                                        grdlistShowDemo.Rows[grdlistShowDemo.RowCount - 1].Cells[col.Name].Value = offmax.maxdays;
                                        val = offmax.maxdays;
                                    }
                                    else
                                    {
                                        grdlistShowDemo.Rows[grdlistShowDemo.RowCount - 1].Cells[col.Name].Value = 0;
                                        val = 0;
                                    }
                                }
                            }
                            lva            = new leaveob();
                            lva.EmployeeID = empPost.empID.ToString();
                            lva.LeaveID    = leaveColID;
                            lva.LeaveCount = val;
                            lvaob.Add(lva);
                        }
                    }
                }
                insert(lvaob);
            }
            catch (Exception ex)
            {
            }
            return(grdlistShowDemo);
        }
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)
            {
            }
        }
Esempio n. 3
0
 private void ListFilteredLeave(int opt)
 {
     try
     {
         DateTime dtfrom = dtFrom.Value;
         DateTime dtto   = dtTo.Value;
         grdList.Rows.Clear();
         grdList.Columns.Clear();
         grdList.Columns.Add("EmployeeID", "EmployeeID");
         grdList.Columns.Add("EmployeeName", "Employee Name");
         grdList.Columns.Add("ApplicationDate", "Application Date");
         grdList.Columns.Add("LeaveType", "Leave Type");
         grdList.Columns.Add("NoofDays", "No Of Days");
         grdList.Columns["ApplicationDate"].Visible = false;
         grdList.Columns["ApplicationDate"].DefaultCellStyle.Format = "dd-MM-yyyy";
         grdList.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
         LeaveApproveDB lvdb = new LeaveApproveDB();
         if (opt == 1 || opt == 3 || opt == 4)
         {
             grdList.Columns.Add("FromDate", "From");
             grdList.Columns.Add("ToDate", "To");
             grdList.Columns.Add("PresentStatus", "Present Status");
             if (opt == 1)
             {
                 grdList.Columns.Add("ForwardedTo", "Forwarded To");
             }
             else if (opt == 3)
             {
                 grdList.Columns.Add("ForwardedTo", "Cancelled By");
             }
             else if (opt == 4)
             {
                 grdList.Columns.Add("ForwardedTo", "Rejected By");
             }
             grdList.Columns["FromDate"].DefaultCellStyle.Format = "dd-MM-yyyy";
             grdList.Columns["ToDate"].DefaultCellStyle.Format   = "dd-MM-yyyy";
             grdList.Columns["PresentStatus"].Width = 200;
             grdList.Columns["ForwardedTo"].Width   = 120;
             grdList.Columns["EmployeeName"].Width  = 160;
             List <leaveapprove> leaveactnpending = lvdb.getActionPending(dtfrom.Date, dtto.Date, opt).OrderBy(x => Convert.ToInt32(x.EmployeeID)).ToList();
             foreach (leaveapprove ap in leaveactnpending)
             {
                 grdList.Rows.Add();
                 grdList.Rows[grdList.Rows.Count - 1].Cells["EmployeeID"].Value      = Convert.ToInt32(ap.EmployeeID);
                 grdList.Rows[grdList.Rows.Count - 1].Cells["EmployeeName"].Value    = ap.EmployeeName;
                 grdList.Rows[grdList.Rows.Count - 1].Cells["ApplicationDate"].Value = ap.CreateTime;
                 grdList.Rows[grdList.Rows.Count - 1].Cells["LeaveType"].Value       = ap.leaveid;
                 grdList.Rows[grdList.Rows.Count - 1].Cells["NoofDays"].Value        = ap.noofdays;
                 grdList.Rows[grdList.Rows.Count - 1].Cells["FromDate"].Value        = ap.fromdate;
                 grdList.Rows[grdList.Rows.Count - 1].Cells["ToDate"].Value          = ap.todate;
                 grdList.Rows[grdList.Rows.Count - 1].Cells["PresentStatus"].Value   = presentstatus(ap.status, ap.documentStatus, ap.leavestatus);
                 grdList.Rows[grdList.Rows.Count - 1].Cells["ForwardedTo"].Value     = ap.ForwardUser;
             }
         }
         else if (opt == 2)
         {
             grdList.Columns.Add("SanctionedFromDate", "Sanctioned From");
             grdList.Columns.Add("SanctionedToDate", "Sanctioned To");
             grdList.Columns.Add("Approver", "Approver");
             grdList.Columns["SanctionedFromDate"].DefaultCellStyle.Format = "dd-MM-yyyy";
             grdList.Columns["SanctionedToDate"].DefaultCellStyle.Format   = "dd-MM-yyyy";
             grdList.Columns["Approver"].Width           = 170;
             grdList.Columns["EmployeeName"].Width       = 200;
             grdList.Columns["SanctionedFromDate"].Width = 120;
             grdList.Columns["SanctionedToDate"].Width   = 120;
             List <leaveapprove> leaveApprve = lvdb.getApprovedLeave(dtfrom.Date, dtto.Date).OrderBy(x => Convert.ToInt32(x.EmployeeID)).ToList();
             foreach (leaveapprove ap in leaveApprve)
             {
                 grdList.Rows.Add();
                 grdList.Rows[grdList.Rows.Count - 1].Cells["EmployeeID"].Value         = Convert.ToInt32(ap.EmployeeID);
                 grdList.Rows[grdList.Rows.Count - 1].Cells["EmployeeName"].Value       = ap.EmployeeName;
                 grdList.Rows[grdList.Rows.Count - 1].Cells["ApplicationDate"].Value    = ap.CreateTime;
                 grdList.Rows[grdList.Rows.Count - 1].Cells["LeaveType"].Value          = ap.leaveid;
                 grdList.Rows[grdList.Rows.Count - 1].Cells["NoofDays"].Value           = ap.noofdays;
                 grdList.Rows[grdList.Rows.Count - 1].Cells["SanctionedFromDate"].Value = ap.sanctionedFrom;
                 grdList.Rows[grdList.Rows.Count - 1].Cells["SanctionedToDate"].Value   = ap.sanctionedTo;
                 grdList.Rows[grdList.Rows.Count - 1].Cells["Approver"].Value           = ap.ApproveUser;
                 if (ap.sanctionedTo.Date >= DateTime.Now.Date && ap.sanctionedFrom.Date <= DateTime.Now)
                 {
                     grdList.Rows[grdList.Rows.Count - 1].DefaultCellStyle.BackColor = Color.Yellow;
                 }
             }
         }
         if (grdList.RowCount >= 1)
         {
             grdList.SelectionMode        = DataGridViewSelectionMode.FullRowSelect;
             grdList.CurrentCell.Selected = false;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error in Report Leave Detail listing");
     }
 }