public SqlCommand[] InsertIntoEmpLevProfile(string EmpId, string LPakId, string JoiningDate, string userId, string strEmpTypeId)
    {
        try
        {
            i = 0;

            decimal LEntitled         = 0;
            string  IsLeaveOnJoinDate = "";

            DateTime           dtLeaveStDate = DateTime.Now;
            clsEmpLeaveProfile objEmpLevPro  = new clsEmpLeaveProfile();
            SqlCommand[]       cmd           = new SqlCommand[15];

            if (dtLeavePakMst.Rows.Count == 0)
            {
                dtLeavePakMst = SelectLeavePakMst(LPakId);
            }

            DataTable dtLeavePeriod = SelectLeavePeriod(LPakId);

            if (dtLeavePeriod.Rows.Count > 0)
            {
                dtLeaveStDate = Convert.ToDateTime(dtLeavePeriod.Rows[0]["LeaveStartPeriod"]);
            }

            DataTable dtLevProfile = objLeaveAppMgr.SelectEmpLeaveProfile(EmpId, "0");

            DataTable dtLeaveType = objLeaveMgr.SelectLeavePakDet(Convert.ToInt32(LPakId));

            if (dtLeavePakMst.Rows.Count > 0)
            {
                IsLeaveOnJoinDate = dtLeavePakMst.Rows[0]["IsLCalOnJoinDate"].ToString();
            }

            if (dtLeaveType.Rows.Count > 0)
            {
                if (dtLevProfile.Rows.Count > 0)
                {
                    foreach (DataRow LTRow in dtLeaveType.Rows)
                    {
                        LEntitled    = 0;
                        objEmpLevPro = new clsEmpLeaveProfile(EmpId, LTRow["LTypeId"].ToString().Trim(), Math.Round(LEntitled, 2).ToString(),
                                                              userId, Common.SetDateTime(DateTime.Now.ToString()));

                        cmd[i] = InsertIntoEmpLevPro(objEmpLevPro, "Y", "N");
                        i++;
                    }
                }
                else
                {
                    foreach (DataRow LTRow in dtLeaveType.Rows)
                    {
                        if (IsLeaveOnJoinDate == "Y")
                        {
                            LEntitled = 0;
                        }

                        objEmpLevPro = new clsEmpLeaveProfile(EmpId, LTRow["LTypeId"].ToString().Trim(), Math.Round(LEntitled, 2).ToString(),
                                                              userId, Common.SetDateTime(DateTime.Now.ToString()));

                        cmd[i] = InsertIntoEmpLevPro(objEmpLevPro, "N", "N");
                        i++;
                    }
                }
            }

            dtLeaveType.Rows.Clear();
            dtLevProfile.Rows.Clear();
            return(cmd);
        }
        catch (Exception ex)
        {
            throw (ex);
        }
    }
Exemple #2
0
    protected void grLeavePakMst_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        GridView _gridView      = (GridView)sender;
        int      _selectedIndex = int.Parse(e.CommandArgument.ToString());
        string   _commandName   = e.CommandName;

        _gridView.SelectedIndex = _selectedIndex;
        switch (_commandName)
        {
        case ("DoubleClick"):
            this.OpenRecord();
            hfID.Value           = grLeavePakMst.DataKeys[_gridView.SelectedIndex].Values[0].ToString();
            txtLeavePakName.Text = grLeavePakMst.SelectedRow.Cells[1].Text;

            HiddenField hfPDesc = (HiddenField)grLeavePakMst.SelectedRow.Cells[2].FindControl("HfDesc");
            txtDescription.Text = hfPDesc.Value;

            HiddenField hfCalOnJD = (HiddenField)grLeavePakMst.SelectedRow.Cells[2].FindControl("HfCalOnJoinDate");
            chkLeavCalcOnJoining.Checked = (hfCalOnJD.Value == "Y" ? true : false);

            HiddenField hfIsOffDC = (HiddenField)grLeavePakMst.SelectedRow.Cells[2].FindControl("hfIsOffdayCounted");
            chkIsOffdayCounted.Checked = (hfIsOffDC.Value == "Y" ? true : false);

            string strEmpTypeStatus = grLeavePakMst.DataKeys[_gridView.SelectedIndex].Values[2].ToString();
            ddlEmploymentType.SelectedValue = string.IsNullOrEmpty(strEmpTypeStatus) == true ? "0" : strEmpTypeStatus;

            string strMonthFrom = grLeavePakMst.DataKeys[_gridView.SelectedIndex].Values[3].ToString();
            ddlMonthFrom.SelectedValue = string.IsNullOrEmpty(strMonthFrom) == true ? "0" : strMonthFrom;

            string strMonthTo = grLeavePakMst.DataKeys[_gridView.SelectedIndex].Values[4].ToString();
            ddlMonthTo.SelectedValue = string.IsNullOrEmpty(strMonthTo) == true ? "0" : strMonthTo;

            HiddenField hfIsActive = (HiddenField)grLeavePakMst.SelectedRow.Cells[2].FindControl("hfIsActive");
            chkInActive.Checked = (hfIsActive.Value == "Y" ? false : true);

            HiddenField hfISDefault = (HiddenField)grLeavePakMst.SelectedRow.Cells[2].FindControl("hfISDefault");
            chkIsDefault.Checked = (hfISDefault.Value == "Y" ? true : false);

            chkIsNextYear.Checked = (grLeavePakMst.DataKeys[_gridView.SelectedIndex].Values[5].ToString() == "Y" ? true : false);

            DataTable dtLeaveDet = objLeaveManager.SelectLeavePakDet(Convert.ToInt32(hfID.Value));
            if (dtLeaveDet.Rows.Count > 0)
            {
                grLeaveList.DataSource = dtLeaveDet;
                grLeaveList.DataBind();
                this.CheckSelectedGridField();
            }

            else
            {
                dtLeaveList            = objLeaveManager.SelectLeaveType(0);
                grLeaveList.DataSource = dtLeaveList;
                grLeaveList.DataBind();
            }

            this.EntryMode(true);
            this.TabContainer1.ActiveTabIndex = 0;
            this.TabContainer1.TabIndex       = 0;
            break;
        }
    }
    public SqlCommand[] InsertIntoLevProfile(string EmpId, string LPakId, string JoiningDate, string userId, string strEmpTypeId)
    {
        try
        {
            i = 0;
            decimal LeaveAvail        = 0;
            decimal LEntitled         = 0;
            decimal tempValue         = 0;
            string  IsLeaveOnJoinDate = "";

            DateTime           dtJoinDate;
            DateTime           dtLeaveStDate = DateTime.Now;
            clsEmpLeaveProfile objEmpLevPro  = new clsEmpLeaveProfile();
            SqlCommand[]       cmd           = new SqlCommand[15];

            if (dtLeavePakMst.Rows.Count == 0)
            {
                dtLeavePakMst = SelectLeavePakMst(LPakId);
            }

            DataTable dtLeavePeriod = SelectLeavePeriod(LPakId);

            if (dtLeavePeriod.Rows.Count > 0)
            {
                dtLeaveStDate = Convert.ToDateTime(dtLeavePeriod.Rows[0]["LeaveStartPeriod"]);
            }

            DataTable dtLevProfile = objLeaveAppMgr.SelectEmpLeaveProfile(EmpId, "0");

            DataTable dtLeaveType = objLeaveMgr.SelectLeavePakDet(Convert.ToInt32(LPakId));

            if (dtLeavePakMst.Rows.Count > 0)
            {
                IsLeaveOnJoinDate = dtLeavePakMst.Rows[0]["IsLCalOnJoinDate"].ToString();
            }

            if (dtLeaveType.Rows.Count > 0)
            {
                if (dtLevProfile.Rows.Count > 0)
                {
                    foreach (DataRow LTRow in dtLeaveType.Rows)
                    {
                        DataRow[] foundRows;
                        string    strExpr = "";
                        strExpr   = "LTypeId='" + LTRow["LTypeId"].ToString().Trim() + "'";
                        foundRows = dtLevProfile.Select(strExpr);
                        if (foundRows.Length > 0)
                        {
                            if (IsLeaveOnJoinDate == "Y")
                            {
                                LeaveAvail = 0;
                                if (LTRow["LTypeId"].ToString().Trim() == "2")
                                {
                                    if (LTRow["MaxLAmt"].ToString() != "0")
                                    {
                                        dtLeaveStDate = Convert.ToDateTime(dtLeavePeriod.Rows[0]["LeaveStartPeriod"]);
                                        if (JoiningDate == "")
                                        {
                                            dtJoinDate = dtLeaveStDate;
                                        }
                                        else
                                        {
                                            dtJoinDate = Convert.ToDateTime(JoiningDate);
                                        }

                                        if (dtJoinDate > dtLeaveStDate)
                                        {
                                            TimeSpan DateDiff  = dtJoinDate - dtLeaveStDate;
                                            string   strTotDay = ReturnTotalDay(DateDiff.ToString());
                                            tempValue  = (Convert.ToDecimal(LTRow["MaxLAmt"]) / 366);
                                            tempValue  = (tempValue * (366 - Convert.ToInt32(strTotDay)));
                                            LeaveAvail = Convert.ToDecimal(tempValue);
                                            LeaveAvail = Math.Round(LeaveAvail, 2);
                                            //LEntitled = LeaveAvail;

                                            char[]   strSpliter = { '.' };
                                            string[] arinfo     = new string[2];

                                            arinfo = LeaveAvail.ToString().Split(strSpliter);

                                            if (strEmpTypeId == "1")
                                            {
                                                LEntitled = LeaveAvail;// Convert.ToDecimal(arinfo[0]) + Convert.ToDecimal(arinfo[1].ToString());
                                            }
                                            else
                                            {
                                                //double dclJoinMonth = dtJoinDate.Month;
                                                //double dclBal = (12 - dclJoinMonth) * 1.16;

                                                //if (dtJoinDate.Day == 1)
                                                //    arinfo[1] = "1.16";
                                                //else if (dtJoinDate.Day > 1 && dtJoinDate.Day <= 7)
                                                //    arinfo[1] = ".87";
                                                //else if (dtJoinDate.Day > 7 && dtJoinDate.Day <= 14)
                                                //    arinfo[1] = ".58";
                                                //else if (dtJoinDate.Day > 14 && dtJoinDate.Day <= 21)
                                                //    arinfo[1] = ".29";
                                                //else if (dtJoinDate.Day > 21 && dtJoinDate.Day <= 31)
                                                //    arinfo[1] = "0";

                                                //dclBal = dclBal + Convert.ToDouble(arinfo[1]);
                                                LEntitled = 0;// Convert.ToDecimal(dclBal);
                                            }
                                        }
                                        else
                                        {
                                            LEntitled = Convert.ToDecimal(LTRow["MaxLAmt"]);
                                        }
                                    }
                                    else
                                    {
                                        LEntitled = Convert.ToDecimal(LTRow["MaxLAmt"]);
                                    }
                                }
                                else
                                {
                                    LEntitled = Convert.ToDecimal(LTRow["MaxLAmt"]);
                                }
                            }
                            else
                            {
                                LEntitled = Convert.ToDecimal(LTRow["MaxLAmt"]);
                            }

                            objEmpLevPro = new clsEmpLeaveProfile(EmpId, LTRow["LTypeId"].ToString().Trim(), LEntitled.ToString(),
                                                                  userId, Common.SetDateTime(DateTime.Now.ToString()));

                            cmd[i] = InsertIntoEmpLevPro(objEmpLevPro, "Y", "N");
                            i++;
                        }
                        #region Comment
                        //Add new record in LeaveProfile when dtLeaveType.Rows.count=0
                        ////else
                        ////{
                        ////    if (IsLeaveOnJoinDate == "Y")
                        ////    {
                        ////        LeaveAvail = 0;
                        ////        if (LTRow["MaxLAmt"].ToString() != "0")
                        ////        {
                        ////            dtLeaveStDate = Convert.ToDateTime(dtLeavePeriod.Rows[0]["LeaveStartPeriod"]);
                        ////            if (JoiningDate == "")
                        ////                dtJoinDate = dtLeaveStDate;
                        ////            else
                        ////                dtJoinDate = Convert.ToDateTime(JoiningDate);

                        ////            if (dtJoinDate > dtLeaveStDate)
                        ////            {
                        ////                TimeSpan DateDiff = dtJoinDate - dtLeaveStDate;
                        ////                string strTotDay = ReturnTotalDay(DateDiff.ToString());
                        ////                tempValue = (Convert.ToDecimal(LTRow["MaxLAmt"]) / 366);
                        ////                tempValue = (tempValue * (366 - Convert.ToInt32(strTotDay)));
                        ////                LeaveAvail = Convert.ToDecimal(tempValue);
                        ////                LEntitled = LeaveAvail;
                        ////            }
                        ////            else
                        ////                LEntitled = Convert.ToDecimal(LTRow["MaxLAmt"]);
                        ////        }
                        ////        else
                        ////            LEntitled = Convert.ToDecimal(LTRow["MaxLAmt"]);
                        ////    }
                        ////    else
                        ////        LEntitled = Convert.ToDecimal(LTRow["MaxLAmt"]);

                        ////    objEmpLevPro = new clsEmpLeaveProfile(EmpId, LTRow["LTypeId"].ToString().Trim(), LEntitled.ToString(),
                        ////       userId, Common.SetDateTime(DateTime.Now.ToString()));

                        ////    cmd[i] = InsertIntoEmpLevPro(objEmpLevPro, "N", "N");
                        ////    i++;
                        ////}
                        #endregion
                    }
                }
                else//(dtLevProfile.Rows.Count = 0)
                {
                    foreach (DataRow LTRow in dtLeaveType.Rows)
                    {
                        if (IsLeaveOnJoinDate == "Y")
                        {
                            LeaveAvail = 0;
                            if (LTRow["LTypeId"].ToString().Trim() == "2")
                            {
                                if (LTRow["MaxLAmt"].ToString() != "0")
                                {
                                    dtLeaveStDate = Convert.ToDateTime(dtLeavePeriod.Rows[0]["LeaveStartPeriod"]);
                                    if (JoiningDate == "")
                                    {
                                        dtJoinDate = dtLeaveStDate;
                                    }
                                    else
                                    {
                                        dtJoinDate = Convert.ToDateTime(JoiningDate);
                                    }

                                    if (dtJoinDate > dtLeaveStDate)
                                    {
                                        TimeSpan DateDiff  = dtJoinDate - dtLeaveStDate;
                                        string   strTotDay = ReturnTotalDay(DateDiff.ToString());
                                        tempValue  = (Convert.ToDecimal(LTRow["MaxLAmt"]) / 366);
                                        tempValue  = (tempValue * (366 - Convert.ToInt32(strTotDay)));
                                        LeaveAvail = Convert.ToDecimal(tempValue);
                                        LeaveAvail = Math.Round(LeaveAvail, 2);
                                        //LEntitled = LeaveAvail;

                                        char[]   strSpliter = { '.' };
                                        string[] arinfo     = new string[2];

                                        arinfo = LeaveAvail.ToString().Split(strSpliter);

                                        if (strEmpTypeId == "1")
                                        {
                                            LEntitled = LeaveAvail;//Convert.ToDecimal(arinfo[0]) + Convert.ToDecimal(arinfo[1].ToString());
                                        }
                                        else
                                        {
                                            //double dclJoinMonth = dtJoinDate.Month;
                                            //double dclBal = (12 - dclJoinMonth) * 1.16;

                                            //if (dtJoinDate.Day == 1)
                                            //    arinfo[1] = "1.16";
                                            //else if (dtJoinDate.Day > 1 && dtJoinDate.Day <= 7)
                                            //    arinfo[1] = ".87";
                                            //else if (dtJoinDate.Day > 7 && dtJoinDate.Day <= 14)
                                            //    arinfo[1] = ".58";
                                            //else if (dtJoinDate.Day > 14 && dtJoinDate.Day <= 21)
                                            //    arinfo[1] = ".29";
                                            //else if (dtJoinDate.Day > 21 && dtJoinDate.Day <= 31)
                                            //    arinfo[1] = "0";

                                            //dclBal = dclBal + Convert.ToDouble(arinfo[1]);
                                            //LEntitled = Convert.ToDecimal(dclBal);
                                            LEntitled = 0;
                                        }
                                    }
                                    else
                                    {
                                        LEntitled = Convert.ToDecimal(LTRow["MaxLAmt"]);
                                    }
                                }
                                else
                                {
                                    LEntitled = Convert.ToDecimal(LTRow["MaxLAmt"]);
                                }
                            }
                            else
                            {
                                LEntitled = Convert.ToDecimal(LTRow["MaxLAmt"]);
                            }
                        }
                        else
                        {
                            LEntitled = Convert.ToDecimal(LTRow["MaxLAmt"]);
                        }

                        objEmpLevPro = new clsEmpLeaveProfile(EmpId, LTRow["LTypeId"].ToString().Trim(), Math.Round(LEntitled, 2).ToString(),
                                                              userId, Common.SetDateTime(DateTime.Now.ToString()));

                        cmd[i] = InsertIntoEmpLevPro(objEmpLevPro, "N", "N");
                        i++;
                    }
                }
            }
            dtLeaveType.Rows.Clear();
            dtLevProfile.Rows.Clear();
            return(cmd);
        }
        catch (Exception ex)
        {
            throw (ex);
        }
    }