Esempio n. 1
0
        public void execute(SPSite site, string data)
        {
            WebAppId = site.WebApplication.Id;

            using (SqlConnection cn = CreateConnection())
            {
                try
                {
                    cn.Open();
                    bool liveHours = false;
                    bool.TryParse(EPMLiveCore.CoreFunctions.getConfigSetting(site.RootWeb, "EPMLiveTSLiveHours"), out liveHours);

                    //string[] tsuids = data.Split(',');

                    //foreach(string tsuidData in tsuids)
                    {
                        //if (actualWork != "")
                        //{
                        if (!liveHours)
                        {
                            sErrors = SharedFunctions.processActualWork(cn, TSUID.ToString(), site, true, true);
                        }
                        //}
                    }

                    if (sErrors != "")
                    {
                        bErrors = true;
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    if (site != null)
                    {
                        site.Dispose();
                    }
                    data = null;
                }
            }
        }
        public void execute(SPSite site, string data)
        {
            DataTable dtItems = null;
            int       userid  = 0;

            WebAppId = site.WebApplication.Id;
            using (SqlConnection cn = CreateConnection())
            {
                try
                {
                    cn.Open();
                    try
                    {
                        WorkList = site.RootWeb.Lists["My Work"];
                    }
                    catch { }

                    XmlDocument docTimesheet = new XmlDocument();
                    docTimesheet.LoadXml(data);

                    using (SqlCommand cmd = new SqlCommand("SELECT     dbo.TSUSER.USER_ID FROM         dbo.TSUSER INNER JOIN dbo.TSTIMESHEET ON dbo.TSUSER.TSUSERUID = dbo.TSTIMESHEET.TSUSER_UID WHERE TS_UID=@tsuid", cn))
                    {
                        cmd.Parameters.AddWithValue("@tsuid", base.TSUID);
                        using (SqlDataReader dr = cmd.ExecuteReader())
                        {
                            if (dr.Read())
                            {
                                userid = dr.GetInt32(0);
                            }
                        }
                    }

                    //bool SaveAndSubmit = false;
                    //try
                    //{
                    //    SaveAndSubmit = bool.Parse(docTimesheet.FirstChild.Attributes["SaveAndSubmit"].Value);
                    //}
                    //catch { }

                    bool liveHours = false;

                    bool.TryParse(EPMLiveCore.CoreFunctions.getConfigSetting(site.RootWeb, "EPMLiveTSLiveHours"), out liveHours);

                    if (userid != 0)
                    {
                        SPUser user = TimesheetAPI.GetUser(site.RootWeb, userid.ToString());

                        if (user.ID != userid)
                        {
                            bErrors = true;
                            sErrors = "You do not have access to edit that timesheet.";
                        }
                        else
                        {
                            using (SqlCommand cmd1 = new SqlCommand("update TSQUEUE set percentcomplete=1 where TSQUEUE_ID=@QueueUid", cn))
                            {
                                cmd1.Parameters.AddWithValue("@queueuid", QueueUid);
                                cmd1.ExecuteNonQuery();
                            }

                            TimesheetSettings settings = new TimesheetSettings(site.RootWeb);

                            DataSet dsItems = new DataSet();

                            SPUser editUser = site.RootWeb.AllUsers.GetByID(base.userid);

                            using (var cache = SaveDataJobExecuteCache.InitializeCache(site))
                            {
                                using (SqlCommand cmd2 = new SqlCommand("SELECT * FROM TSITEM WHERE TS_UID=@tsuid", cn))
                                {
                                    cmd2.Parameters.AddWithValue("@tsuid", base.TSUID);
                                    using (SqlDataAdapter da = new SqlDataAdapter(cmd2))
                                    {
                                        da.Fill(dsItems);
                                        dtItems = dsItems.Tables[0];

                                        XmlNodeList ndItems = docTimesheet.FirstChild.SelectNodes("Item");

                                        float percent = 0;
                                        float count   = 0;
                                        float total   = ndItems.Count;

                                        using (SqlCommand cmd3 = new SqlCommand("update TSQUEUE set percentcomplete=2 where TSQUEUE_ID=@QueueUid",
                                                                                cn))
                                        {
                                            cmd3.Parameters.AddWithValue("@queueuid", QueueUid);
                                            cmd3.ExecuteNonQuery();
                                        }

                                        string preloadErrors;
                                        var    preloadHasErrors =
                                            cache.PreloadListItems(ndItems.Cast <XmlNode>().Select(i => new SaveDataJobExecuteCache.ListItemInfo
                                        {
                                            WebId      = iGetAttribute(i, "WebID"),
                                            ListId     = iGetAttribute(i, "ListID"),
                                            ListItemId = iGetAttribute(i, "ItemID")
                                        }), out preloadErrors);
                                        if (preloadHasErrors)
                                        {
                                            bErrors  = true;
                                            sErrors += preloadErrors;
                                        }

                                        foreach (XmlNode ndItem in ndItems)
                                        {
                                            string worktype = "";

                                            try
                                            {
                                                worktype = ndItem.Attributes["WorkTypeField"].Value;
                                            }
                                            catch
                                            {
                                            }

                                            ProcessItemRow(ndItem, dtItems, cn, site, settings, liveHours, worktype == settings.NonWorkList);

                                            count++;
                                            float pct = count / total * 98;

                                            if (pct >= percent + 10)
                                            {
                                                using (SqlCommand cmd4 =
                                                           new SqlCommand("update TSQUEUE set percentcomplete=@pct where TSQUEUE_ID=@QueueUid", cn))
                                                {
                                                    cmd4.Parameters.AddWithValue("@queueuid", QueueUid);
                                                    cmd4.Parameters.AddWithValue("@pct", pct);
                                                    cmd4.ExecuteNonQuery();
                                                }

                                                percent = pct;
                                            }
                                        }
                                    }
                                }

                                if (liveHours)
                                {
                                    sErrors += processProjectWork(cn, TSUID.ToString(), site, true, false);
                                }
                            }
                        }
                    }
                    else
                    {
                        bErrors = true;
                        sErrors = "Timesheet does not exist";
                    }
                }
                catch (Exception ex)
                {
                    bErrors = true;
                    sErrors = "Error: " + ex.ToString();
                }
                finally
                {
                    if (dtItems != null)
                    {
                        dtItems.Dispose();
                    }
                    if (site != null)
                    {
                        site.Dispose();
                    }
                    data = null;
                }
            }
        }