Exemplo n.º 1
0
        protected override void CreateChildControls()
        {
            tb.AddTimer();
            act        = new EPMLiveCore.Act(SPContext.Current.Web);
            activation = act.CheckFeatureLicense(EPMLiveCore.ActFeature.Timesheets);

            if (activation != 0)
            {
                return;
            }

            if (SPContext.Current.ViewContext.View != null)
            {
                try
                {
                    typeof(ListTitleViewSelectorMenu).GetField("m_wpSingleInit", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(Page.FindControl("ctl00$PlaceHolderPageTitleInTitleArea$ctl01$ctl00").Controls[1], true);
                }
                catch { }
                try
                {
                    typeof(ListTitleViewSelectorMenu).GetField("m_wpSingle", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(Page.FindControl("ctl00$PlaceHolderPageTitleInTitleArea$ctl01$ctl00").Controls[1], true);
                }
                catch { }
            }

            try
            {
                sPeriodId = Page.Request["NewPeriod"].ToString();
            }
            catch { }
            try
            {
                sUserId = Page.Request["Delegate"].ToString();
            }
            catch { }

            ///

            SPWeb web = SPContext.Current.Web;

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                settings = new TimesheetSettings(web);

                SqlConnection cn = new SqlConnection(EPMLiveCore.CoreFunctions.getConnectionString(web.Site.WebApplication.Id));
                cn.Open();

                SqlCommand cmd  = new SqlCommand("spTSGetPeriodsForSite", cn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@siteid", web.Site.ID);

                DataSet ds = new DataSet();

                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(ds);

                DataTable dtPeriods = ds.Tables[0];

                DataRow[] drCur = dtPeriods.Select("CurPeriod='1'");
                if (drCur.Length > 0)
                {
                    iCurPeriodId   = int.Parse(drCur[0]["period_id"].ToString());
                    sCurPeriodName = ((DateTime)drCur[0]["period_start"]).ToShortDateString() + " - " + ((DateTime)drCur[0]["period_end"]).ToShortDateString();
                }
                if (dtPeriods.Rows.Count > 0)
                {
                    if (sPeriodId == "")
                    {
                        DataRow[] dr = dtPeriods.Select("CurPeriod='1'");
                        if (dr.Length > 0)
                        {
                            sPeriodId   = dr[0]["period_id"].ToString();
                            sPeriodName = ((DateTime)dr[0]["period_start"]).ToShortDateString() + " - " + ((DateTime)dr[0]["period_end"]).ToShortDateString();
                            bIsCurrentTimesheetPeriod = true;
                        }
                        else
                        {
                            sPeriodId   = dtPeriods.Rows[dtPeriods.Rows.Count - 1]["period_id"].ToString();
                            sPeriodName = ((DateTime)dtPeriods.Rows[dtPeriods.Rows.Count - 1]["period_start"]).ToShortDateString() + " - " + ((DateTime)dtPeriods.Rows[dtPeriods.Rows.Count - 1]["period_end"]).ToShortDateString();
                        }
                    }
                    else
                    {
                        DataRow[] dr = ds.Tables[0].Select("period_id='" + sPeriodId + "'");
                        if (dr.Length > 0)
                        {
                            sPeriodName = ((DateTime)dr[0]["period_start"]).ToShortDateString() + " - " + ((DateTime)dr[0]["period_end"]).ToShortDateString();
                            try
                            {
                                if (dr[0]["curPeriod"].ToString() == "1")
                                {
                                    bIsCurrentTimesheetPeriod = true;
                                }
                            }
                            catch { }
                        }
                        else
                        {
                            DataRow[] dr2 = ds.Tables[0].Select("CurPeriod='1'");
                            if (dr2.Length > 0)
                            {
                                sPeriodId   = dr2[0]["period_id"].ToString();
                                sPeriodName = ((DateTime)dr2[0]["period_start"]).ToShortDateString() + " - " + ((DateTime)dr2[0]["period_end"]).ToShortDateString();
                                bIsCurrentTimesheetPeriod = true;
                            }
                            else
                            {
                                sPeriodId   = dtPeriods.Rows[dtPeriods.Rows.Count - 1]["period_id"].ToString();
                                sPeriodName = ((DateTime)dtPeriods.Rows[dtPeriods.Rows.Count - 1]["period_start"]).ToShortDateString() + " - " + ((DateTime)dtPeriods.Rows[dtPeriods.Rows.Count - 1]["period_end"]).ToShortDateString();
                            }
                        }
                    }

                    string itmpprev = "";
                    bool bNext      = false;

                    foreach (DataRow dr in dtPeriods.Rows)
                    {
                        sPeriodList += "," + dr["period_id"].ToString() + "|" + ((DateTime)dr["period_start"]).ToShortDateString() + " - " + ((DateTime)dr["period_end"]).ToShortDateString();

                        if (bNext)
                        {
                            bNext = false;

                            iNextPeriod = int.Parse(dr["period_id"].ToString());
                        }

                        if (dr["period_id"].ToString() == sPeriodId)
                        {
                            if (itmpprev != "")
                            {
                                iPreviousPeriod = int.Parse(itmpprev);
                            }
                            bNext = true;
                        }

                        itmpprev = dr["period_id"].ToString();
                    }

                    sPeriodList = sPeriodList.Trim(',');

                    TSNotes = settings.AllowNotes.ToString().ToLower();


                    cmd = new SqlCommand("SELECT TSTYPE_ID, TSTYPE_NAME FROM TSTYPE where SITE_UID=@siteid", cn);
                    cmd.Parameters.AddWithValue("@siteid", web.Site.ID);

                    SqlDataReader drTypes = cmd.ExecuteReader();
                    while (drTypes.Read())
                    {
                        int id = drTypes.GetInt32(0);

                        TSColType = 2;

                        TSTypeObject += ",T" + id + ": '" + drTypes.GetString(1) + "'";
                    }
                    drTypes.Close();


                    TSTypeObject = "{" + TSTypeObject.Trim(',') + "}";

                    ArrayList arrPeriods = TimesheetAPI.GetPeriodDaysArray(cn, settings, web, sPeriodId);

                    foreach (DateTime dtStart in arrPeriods)
                    {
                        TSCols += "\"P" + dtStart.Ticks + "\": true,";
                    }

                    foreach (DateTime dtStart in arrPeriods)
                    {
                        TSDCols += "\"P" + dtStart.Ticks + "\": \"" + settings.DayDef.Split('|')[(int)dtStart.DayOfWeek * 3 + 1] + "|" + settings.DayDef.Split('|')[(int)dtStart.DayOfWeek * 3 + 2] + "\",";
                    }

                    TSCols  = "{" + TSCols.Trim(',') + "}";
                    TSDCols = "{" + TSDCols.Trim(',') + "}";

                    if (GridType == 0)
                    {
                        SPUser user = TimesheetAPI.GetUser(web, sUserId);

                        cmd = new SqlCommand("SELECT submitted, approval_status, locked FROM TSTIMESHEET where SITE_UID=@siteid and period_id=@period and username=@username", cn);
                        cmd.Parameters.AddWithValue("@siteid", web.Site.ID);
                        cmd.Parameters.AddWithValue("@period", sPeriodId);
                        cmd.Parameters.AddWithValue("@username", user.LoginName);

                        SqlDataReader drTS = cmd.ExecuteReader();
                        if (drTS.Read())
                        {
                            //Locked
                            if (drTS.GetBoolean(2))
                            {
                                bTsLocked = true;
                            }

                            //Submitted
                            if (drTS.GetBoolean(0))
                            {
                                if (drTS.GetInt32(1) == 1)
                                {
                                    sStatus = "Approved";
                                    if (!settings.DisableApprovals)
                                    {
                                        bTsLocked = true;
                                    }
                                }
                                else if (drTS.GetInt32(1) == 2)
                                {
                                    sStatus = "Rejected";
                                }
                                else
                                {
                                    sStatus = "Submitted";
                                }
                            }
                        }
                        drTS.Close();
                    }
                    else
                    {
                        bTsLocked = true;
                    }


                    cn.Close();

                    bHasPeriods = true;
                }
            });



            sDataParam   = "<Param GridId=\"" + sFullGridId + "\" Period=\"" + sPeriodId + "\" UserId=\"" + sUserId + "\"/>";
            sLayoutParam = "<Param GridId=\"" + sFullGridId + "\" Period=\"" + sPeriodId + "\" UserId=\"" + sUserId + "\" Editable=\"" + iEditable + "\" GridType=\"" + GridType + "\"/>";

            sDataParam   = System.Web.HttpUtility.HtmlEncode(System.Web.HttpUtility.HtmlEncode(sDataParam));
            sLayoutParam = System.Web.HttpUtility.HtmlEncode(System.Web.HttpUtility.HtmlEncode(sLayoutParam));
            ///


            DataTable dtTsDelegates = EPMLiveCore.API.APITeam.GetResourcePool("<Resources FilterField=\"TimesheetDelegates\" FilterFieldValue=\"" + web.CurrentUser.Name + "\" ><Columns>SimpleColumns</Columns></Resources>", web);

            foreach (DataRow dr in dtTsDelegates.Rows)
            {
                if (sUserId == dr["SPID"].ToString())
                {
                    sCurrentDelegate = dr["Title"].ToString();
                }

                sDelegates += dr["SPID"].ToString() + "|" + dr["Title"].ToString() + "^";
            }

            sDelegates = sDelegates.Trim('^');

            string serviceUrl = ((SPContext.Current.Web.ServerRelativeUrl == "/")
                                     ? ""
                                     : SPContext.Current.Web.ServerRelativeUrl) + "/_vti_bin/Workengine.asmx";

            ScriptManager scriptManager = ScriptManager.GetCurrent(Page);

            if (scriptManager != null)
            {
                scriptManager.Services.Add(new ServiceReference(serviceUrl));
            }
            else
            {
                scriptManager = new ScriptManager();
                scriptManager.Services.Add(new ServiceReference(serviceUrl));

                Page.Form.Controls.Add(scriptManager);
            }

            views = TimesheetAPI.GetViews(web);

            tb.StopTimer();
        }
Exemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(System.Web.HttpUtility.HtmlDecode(Request["Data"]));

            string sPeriodId = doc.FirstChild.SelectSingleNode("//Cfg").Attributes["PeriodId"].Value;
            string tsuid     = doc.FirstChild.SelectSingleNode("//Cfg").Attributes["TimesheetUID"].Value;
            bool   submit    = false;

            try
            {
                submit = bool.Parse(doc.FirstChild.SelectSingleNode("//Cfg").Attributes["SaveAndSubmit"].Value);
            }
            catch { }

            TimesheetSettings settings = new TimesheetSettings(SPContext.Current.Web);

            XmlNodeList ndListItems = doc.FirstChild.SelectNodes("//B/I");

            XmlDocument docTimesheet = new XmlDocument();

            int userId = SPContext.Current.Web.CurrentUser.ID;

            if (!string.IsNullOrEmpty(Page.Request["Delegate"]))
            {
                SPUser user = TimesheetAPI.GetUser(SPContext.Current.Web, Page.Request["Delegate"]);
                userId = user.ID;
            }

            docTimesheet.LoadXml("<Timesheet TSUID=\"" + tsuid + "\" Editable=\"0\" SaveAndSubmit=\"" + submit.ToString() + "\" TimesheetOwnerID=\"" + userId + "\"/>");

            try
            {
                docTimesheet.FirstChild.Attributes["Editable"].Value = doc.FirstChild.SelectSingleNode("//Cfg").Attributes["GridEditable"].Value;
            }
            catch { }

            SqlConnection cn = null;

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                cn = new SqlConnection(EPMLiveCore.CoreFunctions.getConnectionString(SPContext.Current.Web.Site.WebApplication.Id));
                cn.Open();
            });



            SqlCommand cmd = new SqlCommand("SELECT * FROM TSTYPE where SITE_UID=@siteid", cn);

            cmd.Parameters.AddWithValue("@siteid", SPContext.Current.Site.ID);

            DataSet        ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(cmd);

            da.Fill(ds);

            DataTable dtTypes = ds.Tables[0];

            bool bTypes = false;

            if (dtTypes.Rows.Count > 0)
            {
                bTypes = true;
            }

            ArrayList arrPeriodDates    = TimesheetAPI.GetPeriodDaysArray(cn, settings, SPContext.Current.Web, sPeriodId);
            Hashtable arrPeriodDateCols = new Hashtable();

            foreach (DateTime dt in arrPeriodDates)
            {
                arrPeriodDateCols.Add("P" + dt.Ticks, dt.ToString("s"));
                if (bTypes)
                {
                    arrPeriodDateCols.Add("TSP" + dt.Ticks, dt.ToString("s"));
                }
            }

            cn.Close();

            foreach (XmlNode nd in ndListItems)
            {
                XmlNode ndRow      = docTimesheet.CreateNode(XmlNodeType.Element, "Item", docTimesheet.NamespaceURI);
                XmlNode ndRowHours = docTimesheet.CreateNode(XmlNodeType.Element, "Hours", docTimesheet.NamespaceURI);
                ndRow.AppendChild(ndRowHours);

                foreach (XmlAttribute attr in nd.Attributes)
                {
                    if (arrPeriodDateCols.Contains(attr.Name))
                    {
                        if (bTypes)
                        {
                            if (attr.Name.StartsWith("TS"))
                            {
                                JavaScriptSerializer a = new JavaScriptSerializer();
                                object o = a.DeserializeObject(attr.Value);

                                System.Collections.Generic.Dictionary <string, object> oo = (System.Collections.Generic.Dictionary <string, object>)o;

                                XmlNode ndDate = docTimesheet.CreateNode(XmlNodeType.Element, "Date", docTimesheet.NamespaceURI);

                                XmlAttribute attr1 = docTimesheet.CreateAttribute("Value");
                                attr1.Value = arrPeriodDateCols[attr.Name].ToString();
                                ndDate.Attributes.Append(attr1);

                                foreach (DataRow dr in dtTypes.Rows)
                                {
                                    try
                                    {
                                        XmlNode ndTime = docTimesheet.CreateNode(XmlNodeType.Element, "Time", docTimesheet.NamespaceURI);

                                        attr1       = docTimesheet.CreateAttribute("Hours");
                                        attr1.Value = oo["T" + dr["TSTYPE_ID"].ToString()].ToString();
                                        ndTime.Attributes.Append(attr1);

                                        attr1       = docTimesheet.CreateAttribute("Type");
                                        attr1.Value = dr["TSTYPE_ID"].ToString();
                                        ndTime.Attributes.Append(attr1);

                                        ndDate.AppendChild(ndTime);
                                    }
                                    catch { }
                                }

                                if (settings.AllowNotes)
                                {
                                    string notes = "";
                                    try
                                    {
                                        notes = oo["Notes"].ToString();
                                    }
                                    catch { }
                                    if (notes != "")
                                    {
                                        XmlNode ndNotes = docTimesheet.CreateNode(XmlNodeType.Element, "Notes", docTimesheet.NamespaceURI);
                                        ndNotes.InnerText = notes;
                                        ndDate.AppendChild(ndNotes);
                                    }
                                }

                                ndRowHours.AppendChild(ndDate);
                            }
                        }
                        else
                        {
                            XmlNode ndDate = docTimesheet.CreateNode(XmlNodeType.Element, "Date", docTimesheet.NamespaceURI);

                            XmlAttribute attr1 = docTimesheet.CreateAttribute("Value");
                            attr1.Value = arrPeriodDateCols[attr.Name].ToString();
                            ndDate.Attributes.Append(attr1);


                            XmlNode ndTime = docTimesheet.CreateNode(XmlNodeType.Element, "Time", docTimesheet.NamespaceURI);
                            ndDate.AppendChild(ndTime);

                            attr1       = docTimesheet.CreateAttribute("Hours");
                            attr1.Value = attr.Value;
                            ndTime.Attributes.Append(attr1);

                            if (settings.AllowNotes)
                            {
                                string notes = nd.Attributes["TS" + attr.Name].Value;
                                if (notes != "")
                                {
                                    XmlNode ndNotes = docTimesheet.CreateNode(XmlNodeType.Element, "Notes", docTimesheet.NamespaceURI);
                                    ndNotes.InnerText = notes;
                                    ndDate.AppendChild(ndNotes);
                                }
                            }

                            ndRowHours.AppendChild(ndDate);
                        }
                    }
                    else
                    {
                        XmlAttribute attr1 = docTimesheet.CreateAttribute(attr.Name);
                        attr1.Value = attr.Value;
                        ndRow.Attributes.Append(attr1);
                    }
                }

                docTimesheet.FirstChild.AppendChild(ndRow);
            }

            XmlDocument docRes = new XmlDocument();

            docRes.LoadXml(TimesheetAPI.SaveTimesheet(docTimesheet.OuterXml, SPContext.Current.Web));



            if (docRes.FirstChild.Attributes["Status"].Value == "0")
            {
                data = "<Grid><IO Result='" + docRes.FirstChild.Attributes["Status"].Value + "'/></Grid>";
            }
            else
            {
                data = "<Grid><IO Result='" + docRes.FirstChild.Attributes["Status"].Value + "' Message='" + docRes.FirstChild.InnerText + "'/></Grid>";
            }
        }