private void cmbListYear_SelectedIndexChanged1(object sender, EventArgs e) { if (LeaveOBDB.checkfryear(Convert.ToInt32(cmbListYear.SelectedItem))) { MessageBox.Show("No OB created for this year!!!"); return; } grdPnlShowOB.Rows.Clear(); grdPnlShowOB = getDynamicGridRowsnw(grdPnlShowOB); grdPnlShowOB.Refresh(); }
private void btnSaveLeaveOB_Click(object sender, EventArgs e) { try { LeaveOBDB LODB = new LeaveOBDB(); if (cmbLeaveYear.SelectedIndex == -1) { MessageBox.Show("Fill year Combo"); return; } string empID = lblEmployeeiD.Text; int year = Convert.ToInt32(cmbLeaveYear.SelectedItem); if (!validateLeaveDetailGridRows()) { MessageBox.Show("Check Leave Count Details"); return; } List <leaveob> lobList = new List <leaveob>(); foreach (DataGridViewRow row in grdEmpWiseLeaveOB.Rows) { leaveob lvob = new leaveob(); //lvob.EmployeeID = lblEmployeeiD.Text; //lvob.year = Convert.ToInt32(cmbLeaveYear.SelectedItem); lvob.LeaveID = row.Cells["LeaveID"].Value.ToString(); lvob.LeaveCount = Convert.ToInt32(row.Cells["LeaveCount"].Value); lobList.Add(lvob); } if (LODB.insertLeaveOBDetail(lobList, empID, year)) { MessageBox.Show("Leave OB Detail Updated Sucessfully"); grdEmpWiseLeaveOB.Rows.Clear(); pnlShowLeaveOB.Visible = false; } else { MessageBox.Show("Fail to update Leave OB Detail"); } } catch (Exception) { MessageBox.Show("Failed Adding / Editing Leave OB Detail"); return; } }
private void fillGriddetailRow() { try { if (lblEmployeeiD.Text.Trim().Length == 0) { MessageBox.Show("Error : Employee ID is Empty"); return; } if (cmbLeaveYear.SelectedIndex == -1) { MessageBox.Show("select Leave Year"); return; } grdEmpWiseLeaveOB.Rows.Clear(); LeaveOBDB lobDB = new LeaveOBDB(); List <leaveob> lobList = lobDB.getLeaveOBDetails(lblEmployeeiD.Text, Convert.ToInt32(cmbLeaveYear.SelectedItem)); foreach (var item in LeaveDict) { string leaveGender = LeaveOBDB.getGenderForLeaveType(item.Key); string empGender = LeaveOBDB.getGenderForEmployee(lblEmployeeiD.Text); if (leaveGender.Equals("All") || leaveGender.Equals(empGender)) { grdEmpWiseLeaveOB.Rows.Add(); leaveob lob = lobList.FirstOrDefault(leave => leave.LeaveID == item.Key); grdEmpWiseLeaveOB.Rows[grdEmpWiseLeaveOB.RowCount - 1].Cells["LeaveID"].Value = item.Key; grdEmpWiseLeaveOB.Rows[grdEmpWiseLeaveOB.RowCount - 1].Cells["Description"].Value = item.Value; if (lob != null) { grdEmpWiseLeaveOB.Rows[grdEmpWiseLeaveOB.RowCount - 1].Cells["LeaveCount"].Value = lob.LeaveCount; } else { grdEmpWiseLeaveOB.Rows[grdEmpWiseLeaveOB.RowCount - 1].Cells["LeaveCount"].Value = "0"; } } } } catch (Exception ex) { MessageBox.Show("Error in Filling Leave OB Detail GridView"); } }
private void ListLeaveOB() { try { grdList.Rows.Clear(); List <employeeposting> EMPList = LeaveOBDB.getEmployeePostingListForLeaveOB(); foreach (employeeposting emp in EMPList) { grdList.Rows.Add(emp.empID, emp.empName, emp.officeName); } filterGridData(); } catch (Exception) { MessageBox.Show("Error in LeaveOB listing"); } //enableBottomButtons(); pnlList.Visible = true; }
private void cmbLeaveYear_SelectedIndexChanged(object sender, EventArgs e) { int year = Convert.ToInt32(cmbLeaveYear.SelectedItem); if (year > DateTime.Now.Year) { if (LeaveOBDB.checkfryear(year)) { showgrid(); pnlShowLeaveOB.Visible = false; } else { DialogResult dialog = MessageBox.Show("OB Already exists for this year, Are you sure you want to replace?", "Yes", MessageBoxButtons.YesNo); if (dialog == DialogResult.Yes) { if (LeaveOBDB.Delfryear(year)) { showgrid(); pnlShowLeaveOB.Visible = false; } else { MessageBox.Show("ERROR!! Deleting LeaveOB Row"); return; } } else { MessageBox.Show("Please select another year!!!"); //cmbLeaveYear.SelectedIndex = -1; return; } } } else if (cmbLeaveYear.SelectedIndex != -1) { MessageBox.Show("Leave OB cannot be Altered for this Year!!!"); cmbLeaveYear.SelectedIndex = -1; return; } }
private DataGridView getDynamicGridRows(DataGridView grdlistShowDemo) { try { List <employeeposting> EMPList = LeaveOBDB.getEmployeePostingListForLeaveOB(); foreach (employeeposting empPost in EMPList) { List <string> strList = new List <string>(); strList.Add(empPost.empID.ToString()); strList.Add(empPost.empName); strList.Add(empPost.officeName); 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; foreach (DataGridViewColumn col in collection) { string leaveColID = (LeaveDict.FirstOrDefault(pair => col.Name == pair.Key.Replace(" ", ""))).Key; if (leaveColID != null) { leaveob lob = lobList.FirstOrDefault(listItem => listItem.LeaveID == leaveColID); if (lob != null) { grdlistShowDemo.Rows[grdlistShowDemo.RowCount - 1].Cells[col.Name].Value = lob.LeaveCount; } else { grdlistShowDemo.Rows[grdlistShowDemo.RowCount - 1].Cells[col.Name].Value = 0; } } } } } catch (Exception ex) { } return(grdlistShowDemo); }
void insert(List <leaveob> lva) { try { int year = Convert.ToInt32(cmbLeaveYear.SelectedItem); LeaveOBDB LODB = new LeaveOBDB(); if (LODB.insertLeaveyearOBDetail(lva, year)) { MessageBox.Show("Leave Year OB Detail Updated Sucessfully"); cmbLeaveYear.SelectedIndex = -1; } else { MessageBox.Show("Fail to update Leave OB Detail"); } } catch (Exception ex) { } }
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); }
public void showgridnw() { try { btnExit.Visible = false; pnlShowOBList.Controls.Clear(); pnlShowOBList = new Panel(); pnlShowOBList.Location = new System.Drawing.Point(8, 17); pnlShowOBList.Name = "pnlShowOBList"; pnlShowOBList.Size = new System.Drawing.Size(1100, 490); lblYearSel = new Label(); lblYearSel.AutoSize = true; lblYearSel.Location = new System.Drawing.Point(25, 21); lblYearSel.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); lblYearSel.Name = "lblYearSel"; lblYearSel.Size = new System.Drawing.Size(62, 13); lblYearSel.Text = "Select Year"; pnlShowOBList.Controls.Add(lblYearSel); lblsearch = new Label(); lblsearch.AutoSize = true; lblsearch.Location = new System.Drawing.Point(839, 11); lblsearch.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); lblsearch.Name = "lblsearch"; lblsearch.Size = new System.Drawing.Size(46, 15); lblsearch.Text = "Search"; pnlShowOBList.Controls.Add(lblsearch); txtsearch = new TextBox(); txtsearch.AutoSize = true; txtsearch.Location = new System.Drawing.Point(890, 10); txtsearch.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); txtsearch.Name = "lblsearch"; txtsearch.Size = new System.Drawing.Size(176, 21); txtsearch.TextChanged += new System.EventHandler(this.txtSearchGrd_TextChanged); pnlShowOBList.Controls.Add(txtsearch); cmbListYear = new ComboBox(); cmbListYear.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; cmbListYear.FormattingEnabled = true; cmbListYear.Location = new System.Drawing.Point(100, 18); cmbListYear.Name = "cmbYear"; cmbListYear.Size = new System.Drawing.Size(121, 21); cmbListYear.Items.AddRange(LeaveOBDB.getyear().ToArray()); cmbListYear.SelectedIndex = cmbListYear.FindString(dt.Year.ToString()); cmbListYear.SelectedIndexChanged += new System.EventHandler(this.cmbListYear_SelectedIndexChanged1); pnlShowOBList.Controls.Add(cmbListYear); grdPnlShowOB = new DataGridView(); grdPnlShowOB.AllowUserToAddRows = false; grdPnlShowOB.AllowUserToDeleteRows = false; grdPnlShowOB.AllowUserToOrderColumns = true; grdPnlShowOB.RowHeadersVisible = false; grdPnlShowOB.ColumnHeadersDefaultCellStyle.BackColor = Color.LightBlue; grdPnlShowOB.EnableHeadersVisualStyles = false; grdPnlShowOB.EditMode = System.Windows.Forms.DataGridViewEditMode.EditProgrammatically; grdPnlShowOB.GridColor = System.Drawing.SystemColors.ActiveCaption; grdPnlShowOB.Location = new System.Drawing.Point(25, 48); grdPnlShowOB.Name = "grdPnlShowOB"; grdPnlShowOB.BackgroundColor = System.Drawing.SystemColors.GradientActiveCaption; grdPnlShowOB.BorderStyle = System.Windows.Forms.BorderStyle.None; //grdPnlShowOB.ColumnHeadersHeight = 25; grdPnlShowOB.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; grdPnlShowOB.Size = new System.Drawing.Size(1020, 373); List <DataGridViewColumn> col = getListOFColumn(); grdPnlShowOB.Columns.AddRange(col.ToArray()); grdPnlShowOB = getDynamicGridRowsnw(grdPnlShowOB); pnlShowOBList.Controls.Add(grdPnlShowOB); btnOBListClose = new Button(); btnOBListClose.Location = new System.Drawing.Point(25, 430); btnOBListClose.Name = "btnOBListClose"; btnOBListClose.Size = new System.Drawing.Size(75, 23); btnOBListClose.Text = "Close"; btnOBListClose.UseVisualStyleBackColor = true; btnOBListClose.Click += new System.EventHandler(this.btnOBListClose_Click); btnExportToExcel = new Button(); btnExportToExcel.Location = new System.Drawing.Point(112, 430); btnExportToExcel.Name = "btnExportToExcel"; btnExportToExcel.Size = new System.Drawing.Size(95, 23); btnExportToExcel.Text = "Export To Excel"; btnExportToExcel.UseVisualStyleBackColor = true; btnExportToExcel.Click += new System.EventHandler(this.btnExportToExcel_Click); pnlShowOBList.Controls.Add(btnOBListClose); pnlShowOBList.Controls.Add(btnExportToExcel); pnlUI.Controls.Add(pnlShowOBList); pnlShowOBList.Visible = true; pnlShowOBList.BringToFront(); } catch (Exception ex) { } }