コード例 #1
0
        private void processWssItem(string gr_id, SPWeb web, SPList list)
        {
            if (list.Title == EPMLiveCore.CoreFunctions.getConfigSetting(web, "EPMLiveTSNonWork"))
            {
                output += "<action type='updatewss' sid='" + gr_id + "' tid='" + gr_id + "'/>";
                return;
            }
            web.AllowUnsafeUpdates = true;
            web.Site.CatchAccessDeniedException = false;
            string status = "";
            string title  = "";
            string id     = "";

            try
            {
                status = Request[gr_id + "_!nativeeditor_status"].ToString();
            }
            catch { }
            try
            {
                title = Request[gr_id + "_title"].ToString();
            }
            catch { }
            try
            {
                id = Request[gr_id + "_itemid"].ToString();
            }
            catch { }

            int    counter  = 2;
            string curField = "";

            try
            {
                SPListItem li    = null;
                bool       added = false;
                try
                {
                    if (id != "0")
                    {
                        li = list.GetItemById(int.Parse(id));
                    }
                }
                catch { }
                if (status != "deleted")
                {
                    foreach (string strField in strFields)
                    {
                        curField = strField;
                        string columnName = gr_id + "_c" + counter.ToString();
                        if (list.Fields.ContainsField(strField))
                        {
                            SPField field = list.Fields.GetFieldByInternalName(strField);
                            curField = field.Title;
                            if (field.InternalName == "Title")
                            {
                            }
                            else
                            {
                                string val = Request[columnName].ToString();
                                if (!field.ReadOnlyField && (field.ShowInEditForm == null || field.ShowInEditForm.Value))
                                {
                                    if (val == "")
                                    {
                                        li[field.Id] = null;
                                    }
                                    else
                                    {
                                        switch (field.Type)
                                        {
                                        case SPFieldType.Calculated:
                                            break;

                                        case SPFieldType.User:
                                            if (field.TypeAsString == "UserMulti")
                                            {
                                                SaveHelper.HandleMultiUserCase(web, val, li, field);
                                            }
                                            else
                                            {
                                                string[] sUsers = val.Split('\n');
                                                if (sUsers.Length > 0)
                                                {
                                                    SPUser           u  = web.AllUsers[sUsers[0]];
                                                    SPFieldUserValue uv = new SPFieldUserValue(web, u.ID + ";#" + u.Name);
                                                    li[field.Id] = uv;
                                                }
                                            }
                                            break;

                                        case SPFieldType.Number:
                                            if (field.SchemaXml.Contains("Percentage=\"TRUE\""))
                                            {
                                                try
                                                {
                                                    double fval = double.Parse(val.Replace("%", "")) / 100;
                                                    val = fval.ToString();
                                                }
                                                catch { }
                                            }
                                            double fVal = 0;
                                            if (double.TryParse(val, out fVal))
                                            {
                                                li[field.Id] = fVal;
                                            }
                                            else
                                            {
                                                li[field.Id] = null;
                                            }
                                            break;

                                        case SPFieldType.Lookup:
                                            li[strField] = val.Replace("\n", ";#");
                                            break;

                                        case SPFieldType.MultiChoice:
                                            string[] choices = val.Split('\n');
                                            val = ";#";
                                            foreach (string choice in choices)
                                            {
                                                val += choice.Replace(";#", "\n").Split('\n')[0] + ";#";
                                            }
                                            li[strField] = val;
                                            break;

                                        case SPFieldType.URL:
                                            break;

                                        case SPFieldType.DateTime:
                                            DateTime dt = DateTime.Parse(val);
                                            li[strField] = dt;
                                            break;

                                        case SPFieldType.Choice:
                                            if (val != "")
                                            {
                                                li[strField] = val.Replace(";#", "\n").Split('\n')[0];
                                            }
                                            else
                                            {
                                                val = null;
                                            }
                                            break;

                                        default:
                                            li[strField] = val;
                                            break;
                                        }
                                        ;
                                    }
                                }
                            }
                        }
                        counter++;
                    }
                    curField = "";
                    li.Update();
                    //arrItems.Add(li.ParentList.ParentWeb.ID + "." + li.ParentList.ID + "." + li.ID, new string[1] { null });
                    //queueAllItems.Enqueue(li);
                    //hshSaveGroups.Add("." + li.ParentList.ID + "." + li.ID, gr_id);

                    //if(added)
                    //    output += "<action type='update' sid='" + gr_id + "' tid='." + li.ParentList.ID + "." + li.ID + "'/>";
                    //else
                    output += "<action type='updatewss' sid='" + gr_id + "' tid='" + gr_id + "'/>";
                }
            }
            catch (Exception ex)
            {
                if (curField != "")
                {
                    output += "<action type='error100' sid='" + gr_id + "'><![CDATA[Field: " + curField + "<br>Error: " + ex.Message + "]]></action>";
                }
                else
                {
                    output += "<action type='error100' sid='" + gr_id + "'><![CDATA[" + ex.Message + "]]></action>";
                }
            }
        }