Exemple #1
0
    protected void btnSaveAlloc_Click(object sender, EventArgs e)
    {
        try
        {
            FlyingFishClassesDataContext gg = new FlyingFishClassesDataContext();
            if (tbUnalloc.Text == "")
            {
                tbUnalloc.Text = "0.0";
            }

            Project proj = gg.Projects.Where(p => p.projId == Convert.ToInt32(Session["projID"].ToString())).First();
            proj.unallocated_dollars = Convert.ToDecimal(tbUnalloc.Text);
            gg.SubmitChanges();
            lblUnalloc2.Text = proj.unallocated_dollars.ToString();
            //divOriginalAlloc.Visible = true;
            lblUnalloc2.Visible    = true;
            btnSaveAlloc.Visible   = false;
            btnCancelAlloc.Visible = false;
            btnChangeAlloc.Visible = true;
            tbUnalloc.Visible      = false;
        }
        catch (Exception exception)
        {
            //  lblException.Text = exception.StackTrace;
        }
    }
Exemple #2
0
    protected void gvWorkPackages_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        // try
        //{
        string fullname2 = "";
        string fullname3 = "";

        try
        {
            string[] fullname = lblProjectManager2.Text.Split(' ');
            fullname2 = fullname[0].ToLower() + "_" + fullname[1].ToLower();
            fullname3 = fullname[0] + "_" + fullname[1];
        }
        catch (Exception exception)
        {
            fullname2 = "";
            fullname3 = "";
        }
        if (e.CommandName == "btnView")
        {
            int         row         = Convert.ToInt32(e.CommandArgument);
            GridViewRow selectedRow = gvWorkPackages.Rows[row];
            Session["wpID"] = selectedRow.Cells[0].Text;
            Response.Redirect("~/RE/ManageWorkPackage.aspx");
        }

        if (e.CommandName == "btnDeactivate")
        {
            FlyingFishClassesDataContext gg = new FlyingFishClassesDataContext();
            if (User.Identity.Name == fullname2 || User.Identity.Name == fullname3)
            {
                int         row         = Convert.ToInt32(e.CommandArgument);
                GridViewRow selectedRow = gvWorkPackages.Rows[row];
                WorkPackage workpackage = gg.WorkPackages.Where(wp => wp.wpId == selectedRow.Cells[0].Text).First();
                workpackage.isActive = 0;
                var wps =
                    from wp in ff.WorkPackages
                    where (wp.wpId.ToString().Contains(workpackage.wpId))
                    select wp;
                foreach (var wp in wps)
                {
                    wp.isActive = 0;
                    string s2 = wp.wpId;
                    gg.SubmitChanges();
                }
                gg.SubmitChanges();

                populateManageProject();
            }
            else
            {
                MessageBox.Show("You are not the project manager.");
            }
        }
        // }
        //catch (Exception exception)
        //{
        //lblException.Text = exception.StackTrace;
        //}
    }
Exemple #3
0
    /// <summary>
    /// populates the drop down list
    /// </summary>
    /// Note the session used be created here
    private void populateDdl()
    {
        FlyingFishClassesDataContext ff = new FlyingFishClassesDataContext();

        ddlProjectId.DataSource = ff.Projects.Select(p => new
        {
            ProjID      = p.projId,
            ProjectName = (p.projName + " (") + p.projId + ")"
        });
        ddlProjectId.DataValueField = "ProjId";
        ddlProjectId.DataTextField  = "ProjectName";
        ddlProjectId.DataBind();
    }
Exemple #4
0
    protected void ddlProjectId_SelectedIndexChanged(object sender, EventArgs e)
    {
        FlyingFishClassesDataContext ff = new FlyingFishClassesDataContext();
        int projId = Convert.ToInt32(ddlProjectId.SelectedValue);

        ddlWpId.DataSource = ff.WorkPackages.Where(p => p.projId == projId).Select(p => new
        {
            text  = p.wpId,
            value = p.wpId
        });
        ddlWpId.DataValueField = "value";
        ddlWpId.DataTextField  = "text";
        ddlWpId.DataBind();
    }
Exemple #5
0
    private void CreateSessionVars()
    {
        FlyingFishClassesDataContext ff = new FlyingFishClassesDataContext();

        try
        {
            var qry = (from o in ff.EmployeeMemberships
                       join emp in ff.aspnet_Users on o.userId equals emp.UserId
                       where emp.UserName == User.Identity.Name
                       select o.empId).Single();

            Session["CurEmpId"] = qry.ToString();
            //Label1.Text += "\t" + Convert.ToString(Session["CurEmpId"]);

            System.DateTime  currentDate   = System.DateTime.Now;
            System.DateTime  actualQryDate = currentDate;
            System.DayOfWeek dayOfWeek     = currentDate.DayOfWeek;

            // trying to get the sunday of the week picked by the user
            switch (dayOfWeek.ToString())
            {
            case "Monday": actualQryDate = currentDate.AddDays(-1); break;

            case "Tuesday": actualQryDate = currentDate.AddDays(-2); break;

            case "Wednesday": actualQryDate = currentDate.AddDays(-3); break;

            case "Thursday": actualQryDate = currentDate.AddDays(-4); break;

            case "Friday": actualQryDate = currentDate.AddDays(-5); break;

            case "Saturday": actualQryDate = currentDate.AddDays(-6); break;

            default: break;
            }
            Session["CurrentDate"] = actualQryDate;
        }
        catch
        {
            Response.Redirect("~/Login.aspx");
        }
    }
    protected void btnSaveAlloc_Click(object sender, EventArgs e)
    {
        try
        {
            FlyingFishClassesDataContext gg = new FlyingFishClassesDataContext();
            if (tbUnalloc.Text == "")
                tbUnalloc.Text = "0.0";

            Project proj = gg.Projects.Where(p => p.projId == Convert.ToInt32(Session["projID"].ToString())).First();
            proj.unallocated_dollars = Convert.ToDecimal(tbUnalloc.Text);
            gg.SubmitChanges();
            lblUnalloc2.Text = proj.unallocated_dollars.ToString();
            //divOriginalAlloc.Visible = true;
            lblUnalloc2.Visible = true;
            btnSaveAlloc.Visible = false;
            btnCancelAlloc.Visible = false;
            btnChangeAlloc.Visible = true;
            tbUnalloc.Visible = false;
        }
        catch (Exception exception)
        {
          //  lblException.Text = exception.StackTrace;
        }
    }
Exemple #7
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (User.Identity.IsAuthenticated)
        {
            FlyingFishClassesDataContext ff = new FlyingFishClassesDataContext();

            var empId = ff.EmployeeMemberships
                        .Where(a => a.userId == (Guid)Membership.GetUser().ProviderUserKey)
                        .Select(a => a.empId).Single();

            var sickDays = ff.Employees.Where(a => a.empId == empId)
                           .Select(a => a.sickDays).Single();

            var vacationDays = ff.Employees.Where(a => a.empId == empId)
                               .Select(a => a.vacationLeave).Single();

            lblSickDaysAmount.Text     = sickDays.ToString();
            lblVacationDaysAmount.Text = vacationDays.ToString();
        }
        else
        {
            Response.Redirect("~/Login.aspx");
        }
    }
 //Saves new P-Level to the Database
 protected void buttonPlevel_Click(object sender, EventArgs e)
 {
     using (FlyingFishClassesDataContext ff = new FlyingFishClassesDataContext()) {
         PersonLevel pl = new PersonLevel()
         {
             rate       = Convert.ToDecimal(tbRate.Text),
             pLevel     = tbPLevelID.Text,
             fiscalYear = Convert.ToInt32(lblFiscalYear.Text)
         };
         ff.PersonLevels.InsertOnSubmit(pl);
         try
         {
             ff.SubmitChanges();
         }
         catch (Exception ex) {
             ex.ToString();
             lblError.Text      = "PLevel ID already exists.";
             lblError.ForeColor = System.Drawing.Color.Red;
             return;
         }
         lblError.Text      = "P-Level added. Refresh page to see changes.";
         lblError.ForeColor = System.Drawing.Color.Green;
     }
 }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (User.Identity.IsAuthenticated)
        {
            FlyingFishClassesDataContext ff = new FlyingFishClassesDataContext();

            var empId = ff.EmployeeMemberships
                    .Where(a => a.userId == (Guid)Membership.GetUser().ProviderUserKey)
                    .Select(a => a.empId).Single();

            var sickDays = ff.Employees.Where(a => a.empId == empId)
                    .Select(a => a.sickDays).Single();

            var vacationDays = ff.Employees.Where(a => a.empId == empId)
                    .Select(a => a.vacationLeave).Single();

            lblSickDaysAmount.Text = sickDays.ToString();
            lblVacationDaysAmount.Text = vacationDays.ToString();
        }
        else
        {
            Response.Redirect("~/Login.aspx");
        }
    }
    protected void gvWorkPackages_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        // try
        //{
            string fullname2 = "";
            string fullname3 = "";
            try
            {
                string[] fullname = lblProjectManager2.Text.Split(' ');
                fullname2 = fullname[0].ToLower() + "_" + fullname[1].ToLower();
                fullname3 = fullname[0] + "_" + fullname[1];
            }
            catch (Exception exception)
            {
                fullname2 = "";
                fullname3 = "";
            }
            if (e.CommandName == "btnView")
            {
                int row = Convert.ToInt32(e.CommandArgument);
                GridViewRow selectedRow = gvWorkPackages.Rows[row];
                Session["wpID"] = selectedRow.Cells[0].Text;
                Response.Redirect("~/RE/ManageWorkPackage.aspx");
            }

            if (e.CommandName == "btnDeactivate")
            {
                FlyingFishClassesDataContext gg = new FlyingFishClassesDataContext();
                if (User.Identity.Name == fullname2 || User.Identity.Name == fullname3)
                {
                    int row = Convert.ToInt32(e.CommandArgument);
                    GridViewRow selectedRow = gvWorkPackages.Rows[row];
                    WorkPackage workpackage = gg.WorkPackages.Where(wp => wp.wpId == selectedRow.Cells[0].Text).First();
                    workpackage.isActive = 0;
                    var wps =
                        from wp in ff.WorkPackages
                        where (wp.wpId.ToString().Contains(workpackage.wpId))
                        select wp;
                    foreach (var wp in wps)
                    {
                        wp.isActive = 0;
                        string s2 = wp.wpId;
                        gg.SubmitChanges();
                    }
                    gg.SubmitChanges();

                    populateManageProject();
                }
                else
                    MessageBox.Show("You are not the project manager.");
            }
           // }
        //catch (Exception exception)
        //{
            //lblException.Text = exception.StackTrace;
        //}
    }
    protected void gvUnactiveWP_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        //try
        //{
            string fullname2 = "";
            string fullname3 = "";
            try
            {
                string[] fullname = lblProjectManager2.Text.Split(' ');
                fullname2 = fullname[0].ToLower() + "_" + fullname[1].ToLower();
                fullname3 = fullname[0] + "_" + fullname[1];
            }
            catch (Exception exception)
            {
                fullname2 = "";
                fullname3 = "";
            }

            if (e.CommandName == "btnView")
            {
                int row = Convert.ToInt32(e.CommandArgument);
                GridViewRow selectedRow = gvUnactiveWP.Rows[row];
                Session["wpID"] = selectedRow.Cells[0].Text;
                Response.Redirect("~/RE/ManageWorkPackage.aspx");
            }

            if (e.CommandName == "btnActivate")
            {

                if (User.Identity.Name == fullname2 || User.Identity.Name == fullname3)
                {
                    FlyingFishClassesDataContext gg = new FlyingFishClassesDataContext();
                    int row = Convert.ToInt32(e.CommandArgument);
                    GridViewRow selectedRow = gvUnactiveWP.Rows[row];
                    WorkPackage workpackage = gg.WorkPackages.Where(wp => wp.wpId == selectedRow.Cells[0].Text).First();
                    workpackage.isActive = 1;

                    string[] wpArray = workpackage.wpId.Split('.');
                    string s = "";
                    for (int j = wpArray.Length - 1; j > 1; j--)
                    {
                        for (int i = 0; i < j; i++)
                        {
                            if (i == j - 1)
                                s += wpArray[i];
                            else
                                s += wpArray[i] + ".";
                        }
                        var subwp =
                                    (from wp in gg.WorkPackages
                                     where (wp.wpId == s)
                                     select wp);
                        string s2 = subwp.First().wpId;
                        subwp.First().isActive = 1;
                        gg.SubmitChanges();
                        s = "";
                    }
                    gg.SubmitChanges();
                    populateManageProject();
                }
                else
                    MessageBox.Show("You are not the project manager.");
            }
        //}
        //catch (Exception exception)
           // {
            //lblException.Text = exception.StackTrace;
        //}
    }
    private void addTotalRow()
    {
        FlyingFishClassesDataContext ff = new FlyingFishClassesDataContext();
        DateTime CurrentDate = Convert.ToDateTime(Session["CurrentDate"].ToString());
        int empIdTemp = Convert.ToInt32(Session["CurEmpId"].ToString());

        var qry2 = from ts in ff.TimesheetEntries
                   where (ts.tsDate >= CurrentDate) && (ts.empId == Convert.ToInt32(empIdTemp))
                   select new
                   {
                       ProjID = ts.projId,
                       WpId = ts.wpId,
                       tsdate = ts.tsDate,
                       Sun = ts.sun,
                       Mon = ts.mon,
                       Tue = ts.tue,
                       Wed = ts.wed,
                       Thu = ts.thu,
                       Fri = ts.fri,
                       Sat = ts.sat,
                       Notes = ts.notes

                   };

        if (qry2.Count() == 0)
        {
            //gvStatus.DataSource = null;
            //gvStatus.DataBind();
            //lblResults.Visible = true;
            //divReportData.Visible = false;
            //return;
        }

        DataTable dt = new DataTable();
        dt.Columns.Add(new DataColumn("ProjID", typeof(System.String)));
        dt.Columns.Add(new DataColumn("WpID", typeof(System.String)));
        dt.Columns.Add(new DataColumn("Sat", typeof(System.String)));
        dt.Columns.Add(new DataColumn("Sun", typeof(System.String)));
        dt.Columns.Add(new DataColumn("Mon", typeof(System.String)));
        dt.Columns.Add(new DataColumn("Tue", typeof(System.String)));
        dt.Columns.Add(new DataColumn("Wed", typeof(System.String)));
        dt.Columns.Add(new DataColumn("Thur", typeof(System.String)));
        dt.Columns.Add(new DataColumn("Fri", typeof(System.String)));

        // dt.Columns.Add(new DataColumn("Notes", typeof(System.String)));

        foreach (var row in qry2)
        {
            DataRow dr = dt.NewRow();
            dr["ProjID"] = row.ProjID;
            dr["WpID"] = row.WpId;
            dr["Mon"] = row.Mon;
            dr["Tue"] = row.Tue;
            dr["Wed"] = row.Wed;
            dr["Thur"] = row.Thu;
            dr["Fri"] = row.Thu;
            dr["Sat"] = row.Sat;
            dr["Sun"] = row.Sun;
            //dr["Notes"] = row.Notes;

            dt.Rows.Add(dr);
        }

        double totMon = 0;
        double totTue = 0;
        double totWed = 0;
        double totThu = 0;
        double totFri = 0;
        double totSat = 0;
        double totSun = 0;

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            var b = dt.Rows[i][4].ToString();
            totMon += Convert.ToDouble(dt.Rows[i][4].ToString());
        }

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            var b = dt.Rows[i][5].ToString();
            totTue += Convert.ToDouble(dt.Rows[i][5].ToString());
        }

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            var b = dt.Rows[i][6].ToString();
            totWed += Convert.ToDouble(dt.Rows[i][6].ToString());
        }
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            var b = dt.Rows[i][7].ToString();
            totThu += Convert.ToDouble(dt.Rows[i][7].ToString());
        }

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            var b = dt.Rows[i][8].ToString();
            totFri += Convert.ToDouble(dt.Rows[i][8].ToString());
        }

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            var b = dt.Rows[i][2].ToString();
            totSat += Convert.ToDouble(dt.Rows[i][2].ToString());
        }

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            var b = dt.Rows[i][3].ToString();
            totSun += Convert.ToDouble(dt.Rows[i][3].ToString());
        }

        dt.Clear();

        // add the total row
        DataRow totalRow = dt.NewRow();
        totalRow["ProjID"] = "Total";
        totalRow["Mon"] = totMon;
        totalRow["Tue"] = totThu;
        totalRow["wed"] = totWed;
        totalRow["Thur"] = totThu;
        totalRow["Fri"] = totFri;
        totalRow["Sat"] = totSat;
        totalRow["Sun"] = totSun;

        dt.Rows.Add(totalRow);

        gvTotals.DataSource = dt;
        gvTotals.DataBind();
    }
Exemple #13
0
    private void addTotalRow()
    {
        FlyingFishClassesDataContext ff = new FlyingFishClassesDataContext();
        DateTime CurrentDate            = Convert.ToDateTime(Session["CurrentDate"].ToString());
        int      empIdTemp = Convert.ToInt32(Session["CurEmpId"].ToString());

        var qry2 = from ts in ff.TimesheetEntries
                   where (ts.tsDate >= CurrentDate) && (ts.empId == Convert.ToInt32(empIdTemp))
                   select new
        {
            ProjID = ts.projId,
            WpId   = ts.wpId,
            tsdate = ts.tsDate,
            Sun    = ts.sun,
            Mon    = ts.mon,
            Tue    = ts.tue,
            Wed    = ts.wed,
            Thu    = ts.thu,
            Fri    = ts.fri,
            Sat    = ts.sat,
            Notes  = ts.notes
        };


        if (qry2.Count() == 0)
        {
            //gvStatus.DataSource = null;
            //gvStatus.DataBind();
            //lblResults.Visible = true;
            //divReportData.Visible = false;
            //return;
        }

        DataTable dt = new DataTable();

        dt.Columns.Add(new DataColumn("ProjID", typeof(System.String)));
        dt.Columns.Add(new DataColumn("WpID", typeof(System.String)));
        dt.Columns.Add(new DataColumn("Sat", typeof(System.String)));
        dt.Columns.Add(new DataColumn("Sun", typeof(System.String)));
        dt.Columns.Add(new DataColumn("Mon", typeof(System.String)));
        dt.Columns.Add(new DataColumn("Tue", typeof(System.String)));
        dt.Columns.Add(new DataColumn("Wed", typeof(System.String)));
        dt.Columns.Add(new DataColumn("Thur", typeof(System.String)));
        dt.Columns.Add(new DataColumn("Fri", typeof(System.String)));

        // dt.Columns.Add(new DataColumn("Notes", typeof(System.String)));



        foreach (var row in qry2)
        {
            DataRow dr = dt.NewRow();
            dr["ProjID"] = row.ProjID;
            dr["WpID"]   = row.WpId;
            dr["Mon"]    = row.Mon;
            dr["Tue"]    = row.Tue;
            dr["Wed"]    = row.Wed;
            dr["Thur"]   = row.Thu;
            dr["Fri"]    = row.Thu;
            dr["Sat"]    = row.Sat;
            dr["Sun"]    = row.Sun;
            //dr["Notes"] = row.Notes;


            dt.Rows.Add(dr);
        }

        double totMon = 0;
        double totTue = 0;
        double totWed = 0;
        double totThu = 0;
        double totFri = 0;
        double totSat = 0;
        double totSun = 0;


        for (int i = 0; i < dt.Rows.Count; i++)
        {
            var b = dt.Rows[i][4].ToString();
            totMon += Convert.ToDouble(dt.Rows[i][4].ToString());
        }

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            var b = dt.Rows[i][5].ToString();
            totTue += Convert.ToDouble(dt.Rows[i][5].ToString());
        }

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            var b = dt.Rows[i][6].ToString();
            totWed += Convert.ToDouble(dt.Rows[i][6].ToString());
        }
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            var b = dt.Rows[i][7].ToString();
            totThu += Convert.ToDouble(dt.Rows[i][7].ToString());
        }

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            var b = dt.Rows[i][8].ToString();
            totFri += Convert.ToDouble(dt.Rows[i][8].ToString());
        }

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            var b = dt.Rows[i][2].ToString();
            totSat += Convert.ToDouble(dt.Rows[i][2].ToString());
        }

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            var b = dt.Rows[i][3].ToString();
            totSun += Convert.ToDouble(dt.Rows[i][3].ToString());
        }

        dt.Clear();

        // add the total row
        DataRow totalRow = dt.NewRow();

        totalRow["ProjID"] = "Total";
        totalRow["Mon"]    = totMon;
        totalRow["Tue"]    = totThu;
        totalRow["wed"]    = totWed;
        totalRow["Thur"]   = totThu;
        totalRow["Fri"]    = totFri;
        totalRow["Sat"]    = totSat;
        totalRow["Sun"]    = totSun;

        dt.Rows.Add(totalRow);

        gvTotals.DataSource = dt;
        gvTotals.DataBind();
    }
Exemple #14
0
    //-------------------------------------------------------------------------
    protected void btnCreateNewRecord_Click(object sender, EventArgs e)
    {
        FlyingFishClassesDataContext ff = new FlyingFishClassesDataContext();

        try
        {
            var qry = (from emp in ff.Employees
                       where emp.empId == Convert.ToInt32(Session["CurEmpId"])
                       select emp.approver).FirstOrDefault();


            TimesheetHeader tmp = new TimesheetHeader()
            {
                tsDate     = Convert.ToDateTime(Session["CurrentDate"]),
                empId      = Convert.ToInt32(Session["CurEmpId"]),
                status     = "SAVED",
                approvedBy = qry,
                comments   = "Comments"
            };


            var qry2 = (from th in ff.TimesheetHeaders
                        where th.empId == tmp.empId && th.tsDate == tmp.tsDate
                        select th).ToList();

            if (qry2.Count == 0)
            {
                ff.TimesheetHeaders.InsertOnSubmit(tmp);
                ff.SubmitChanges();
            }

            TimesheetEntry tmp2 = new TimesheetEntry()
            {
                tsDate = Convert.ToDateTime(Session["CurrentDate"]),
                empId  = Convert.ToInt32(Session["CurEmpId"]),
                projId = Convert.ToInt32(ddlProjectId.SelectedValue),
                wpId   = (ddlWpId.SelectedValue).ToString(),
                sun    = Convert.ToInt32(tbSun.Text),
                sat    = Convert.ToInt32(tbSat.Text),
                fri    = Convert.ToInt32(tbFri.Text),
                thu    = Convert.ToInt32(tbThu.Text),
                wed    = Convert.ToInt32(tbWed.Text),
                tue    = Convert.ToInt32(tbTue.Text),
                mon    = Convert.ToInt32(tbMon.Text),
                notes  = tbNote.Text
            };

            ff.TimesheetEntries.InsertOnSubmit(tmp2);
            ff.SubmitChanges();
            lblteSubmitSuccess.Text = "Submit has been saved.";
            divNewRecord.Visible    = false;
            btnNewRecord.Visible    = true;
            divtotal.Visible        = true;
            tbFri.Text  = String.Empty;
            tbMon.Text  = String.Empty;
            tbNote.Text = String.Empty;
            //tbProjectID.Text = String.Empty;
            tbSat.Text = String.Empty;
            tbSun.Text = String.Empty;
            tbThu.Text = String.Empty;
            tbTue.Text = String.Empty;
            tbWed.Text = String.Empty;
            //tbWpID.Text = String.Empty;
        }
        catch (Exception myException)
        {
            lblteSubmitSuccess.Text = "ENTRY ALREADY EXISTS";
            // Label1.Text = "You have sumbitted the record before, Cannot insert duplicate record into the database!!!";
        }
    }
Exemple #15
0
    protected void gvUnactiveWP_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        //try
        //{
        string fullname2 = "";
        string fullname3 = "";

        try
        {
            string[] fullname = lblProjectManager2.Text.Split(' ');
            fullname2 = fullname[0].ToLower() + "_" + fullname[1].ToLower();
            fullname3 = fullname[0] + "_" + fullname[1];
        }
        catch (Exception exception)
        {
            fullname2 = "";
            fullname3 = "";
        }

        if (e.CommandName == "btnView")
        {
            int         row         = Convert.ToInt32(e.CommandArgument);
            GridViewRow selectedRow = gvUnactiveWP.Rows[row];
            Session["wpID"] = selectedRow.Cells[0].Text;
            Response.Redirect("~/RE/ManageWorkPackage.aspx");
        }

        if (e.CommandName == "btnActivate")
        {
            if (User.Identity.Name == fullname2 || User.Identity.Name == fullname3)
            {
                FlyingFishClassesDataContext gg = new FlyingFishClassesDataContext();
                int         row         = Convert.ToInt32(e.CommandArgument);
                GridViewRow selectedRow = gvUnactiveWP.Rows[row];
                WorkPackage workpackage = gg.WorkPackages.Where(wp => wp.wpId == selectedRow.Cells[0].Text).First();
                workpackage.isActive = 1;

                string[] wpArray = workpackage.wpId.Split('.');
                string   s       = "";
                for (int j = wpArray.Length - 1; j > 1; j--)
                {
                    for (int i = 0; i < j; i++)
                    {
                        if (i == j - 1)
                        {
                            s += wpArray[i];
                        }
                        else
                        {
                            s += wpArray[i] + ".";
                        }
                    }
                    var subwp =
                        (from wp in gg.WorkPackages
                         where (wp.wpId == s)
                         select wp);
                    string s2 = subwp.First().wpId;
                    subwp.First().isActive = 1;
                    gg.SubmitChanges();
                    s = "";
                }
                gg.SubmitChanges();
                populateManageProject();
            }
            else
            {
                MessageBox.Show("You are not the project manager.");
            }
        }
        //}
        //catch (Exception exception)
        // {
        //lblException.Text = exception.StackTrace;
        //}
    }
    protected void ddlProjectId_SelectedIndexChanged(object sender, EventArgs e)
    {
        FlyingFishClassesDataContext ff = new FlyingFishClassesDataContext();
        int projId = Convert.ToInt32(ddlProjectId.SelectedValue);

        ddlWpId.DataSource = ff.WorkPackages.Where(p => p.projId == projId).Select(p => new
        {
            text = p.wpId,
            value = p.wpId

        });
        ddlWpId.DataValueField = "value";
        ddlWpId.DataTextField = "text";
        ddlWpId.DataBind();
    }
 /// <summary>
 /// populates the drop down list 
 /// </summary>
 /// Note the session used be created here 
 private void populateDdl()
 {
     FlyingFishClassesDataContext ff = new FlyingFishClassesDataContext();
     ddlProjectId.DataSource = ff.Projects.Select(p => new
     {
         ProjID = p.projId,
         ProjectName = (p.projName + " (") + p.projId + ")"
     });
     ddlProjectId.DataValueField = "ProjId";
     ddlProjectId.DataTextField = "ProjectName";
     ddlProjectId.DataBind();
 }
    private void CreateSessionVars()
    {
        FlyingFishClassesDataContext ff = new FlyingFishClassesDataContext();

        try
        {
            var qry = (from o in ff.EmployeeMemberships
                       join emp in ff.aspnet_Users on o.userId equals emp.UserId
                       where emp.UserName == User.Identity.Name
                       select o.empId).Single();

            Session["CurEmpId"] = qry.ToString();
            //Label1.Text += "\t" + Convert.ToString(Session["CurEmpId"]);

            System.DateTime currentDate = System.DateTime.Now;
            System.DateTime actualQryDate = currentDate;
            System.DayOfWeek dayOfWeek = currentDate.DayOfWeek;

            // trying to get the sunday of the week picked by the user
            switch (dayOfWeek.ToString())
            {
                case "Monday": actualQryDate = currentDate.AddDays(-1); break;
                case "Tuesday": actualQryDate = currentDate.AddDays(-2); break;
                case "Wednesday": actualQryDate = currentDate.AddDays(-3); break;
                case "Thursday": actualQryDate = currentDate.AddDays(-4); break;
                case "Friday": actualQryDate = currentDate.AddDays(-5); break;
                case "Saturday": actualQryDate = currentDate.AddDays(-6); break;
                default: break;
            }
            Session["CurrentDate"] = actualQryDate;

        }
        catch
        {
            Response.Redirect("~/Login.aspx");
        }
    }
    //-------------------------------------------------------------------------
    protected void btnCreateNewRecord_Click(object sender, EventArgs e)
    {
        FlyingFishClassesDataContext ff = new FlyingFishClassesDataContext();
        try
        {
            var qry = (from emp in ff.Employees
                       where emp.empId == Convert.ToInt32(Session["CurEmpId"])
                       select emp.approver).FirstOrDefault();

            TimesheetHeader tmp = new TimesheetHeader()
            {

                tsDate = Convert.ToDateTime(Session["CurrentDate"]),
                empId = Convert.ToInt32(Session["CurEmpId"]),
                status = "SAVED",
                approvedBy = qry,
                comments = "Comments"

            };

            var qry2 = (from th in ff.TimesheetHeaders
                        where th.empId == tmp.empId && th.tsDate == tmp.tsDate
                        select th).ToList();

            if (qry2.Count == 0)
            {
                ff.TimesheetHeaders.InsertOnSubmit(tmp);
                ff.SubmitChanges();
            }

            TimesheetEntry tmp2 = new TimesheetEntry()
            {
                tsDate = Convert.ToDateTime(Session["CurrentDate"]),
                empId = Convert.ToInt32(Session["CurEmpId"]),
                projId = Convert.ToInt32(ddlProjectId.SelectedValue),
                wpId = (ddlWpId.SelectedValue).ToString(),
                sun = Convert.ToInt32(tbSun.Text),
                sat = Convert.ToInt32(tbSat.Text),
                fri = Convert.ToInt32(tbFri.Text),
                thu = Convert.ToInt32(tbThu.Text),
                wed = Convert.ToInt32(tbWed.Text),
                tue = Convert.ToInt32(tbTue.Text),
                mon = Convert.ToInt32(tbMon.Text),
                notes = tbNote.Text

            };

            ff.TimesheetEntries.InsertOnSubmit(tmp2);
            ff.SubmitChanges();
            lblteSubmitSuccess.Text = "Submit has been saved.";
            divNewRecord.Visible = false;
            btnNewRecord.Visible = true;
            divtotal.Visible = true;
            tbFri.Text = String.Empty;
            tbMon.Text = String.Empty;
            tbNote.Text = String.Empty;
            //tbProjectID.Text = String.Empty;
            tbSat.Text = String.Empty;
            tbSun.Text = String.Empty;
            tbThu.Text = String.Empty;
            tbTue.Text = String.Empty;
            tbWed.Text = String.Empty;
            //tbWpID.Text = String.Empty;

        }
        catch (Exception myException)
        {
            lblteSubmitSuccess.Text = "ENTRY ALREADY EXISTS";
            // Label1.Text = "You have sumbitted the record before, Cannot insert duplicate record into the database!!!";

        }
    }