예제 #1
0
        private void OnInit()
        {
            try
            {
                InitFields();

                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (var rsite = new SPSite(SPContext.Current.Site.ID))
                    {
                        using (var web = rsite.OpenWeb(SPContext.Current.Web.ID))
                        {
                            arrwpFields = ReflectionMethods.GetWorkPlannerStatusFields(web, list.Title);
                        }
                    }
                    try
                    {
                        if (list.Title == Resources)
                        {
                            isResList = true;
                            var site1 = SPContext.Current.Site;
                            if (site1.WebApplication.Features[new Guid(FeatureId2)] != null)
                            {
                                InitFeature2();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine(ex.ToString());
                    }
                });


                if (SPContext.Current.FormContext.FormMode != SPControlMode.Invalid)
                {
                    mode = SPContext.Current.FormContext.FormMode;
                }
                else
                {
                    try
                    {
                        mode = (SPControlMode)int.Parse(Page.Request[Mode]);
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine(ex.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.ToString());
            }
        }
        private static void ProcessMethod(SPItemEventProperties properties, SPWeb web, ref string newPercent, out string method)
        {
            method = ReflectionMethods.GetStatusMethod(web, properties.ListTitle);

            if (method == "1")
            {
                try
                {
                    var workDone      = float.Parse(properties.AfterProperties["ActualWork"].ToString());
                    var remainingWork = float.Parse(properties.AfterProperties["RemainingWork"].ToString());

                    newPercent = workDone == 0 && remainingWork == 0
                        ? "0"
                        : (workDone / (remainingWork + workDone)).ToString();
                }
                catch (Exception ex)
                {
                    Trace.TraceError("Exception Suppressed {0}", ex);
                }
            }

            if (method == "2")
            {
                try
                {
                    var Work  = float.Parse(SaveDataJobExecuteCache.GetListItem(properties)["Work"].ToString());
                    var rWork = float.Parse(properties.AfterProperties["RemainingWork"].ToString());

                    if (Work == 0)
                    {
                        newPercent = "0";
                    }
                    else
                    {
                        newPercent = ((Work - rWork) / Work).ToString();
                    }
                }
                catch (Exception ex)
                {
                    Trace.TraceError("Exception Suppressed {0}", ex);
                }
            }
        }