Ejemplo n.º 1
0
        /// <summary>
        /// 已更新项.
        /// </summary>
        public void ItemUpdatedbak(SPItemEventProperties properties)
        {
            string nameField = properties.List.Fields.GetField("完成百分比").InternalName;
            string fType     = properties.List.Fields.GetField("活动类型").InternalName;
            string fDiDian   = properties.List.Fields.GetField("活动地点").InternalName;
            string fObject   = properties.List.Fields.GetField("活动对象").InternalName;
            string fStart    = properties.List.Fields.GetField("开始日期").InternalName;
            string fEnd      = properties.List.Fields.GetField("截止日期").InternalName;
            string fAssigned = properties.List.Fields.GetField("截止日期").InternalName;

            if (properties.ListItem["ParentID"] != null)
            {// sub level
                if (properties.ListItem[nameField].ToString() == "1")
                {
                    string             taskName   = properties.ListItem["Title"].ToString();
                    string             typeName   = properties.ListItem[fType].ToString();
                    string             diDianName = properties.ListItem[fDiDian].ToString();
                    string             objName    = properties.ListItem[fObject].ToString();
                    DateTime           start      = DateTime.Parse(properties.ListItem[fStart].ToString());
                    DateTime           end        = DateTime.Parse(properties.ListItem[fEnd].ToString());
                    SPUser[]           assignedTo = (SPUser[])properties.ListItem[fAssigned];
                    SPFieldLookupValue taskID     = new SPFieldLookupValue(properties.ListItem.ID, taskName);
                }
            }
            string fDoc = properties.List.Fields.GetField("文档对象").InternalName;//查阅项

            SPField f1 = properties.List.Fields.GetFieldByInternalName(fDoc);

            SPFieldLookup      field    = f1 as SPFieldLookup;
            string             lookList = field.LookupList;
            SPListItem         item     = properties.ListItem;
            SPFieldLookupValue fValue   = new SPFieldLookupValue(item[fDoc].ToString());

            string[] choices = Regex.Split(fValue.ToString(), ";#");
            string   docUrl  = GetDocUrl(properties.WebUrl, field.LookupWebId, field.LookupList, fValue.LookupId.ToString());

            this.EventFiringEnabled = false;
            item["Title"]           = properties.Web.Url;// +docUrl;// fValue.LookupId + "\\" + item[fDoc] + fValue.LookupValue;
            item.Update();
            this.EventFiringEnabled = true;
            //using (SPWeb targetSite = new SPSite(properties.WebUrl).AllWebs[field.LookupWebId])
            //{
            //    // Get the name of the list where this field gets information.
            //    SPList targetList = targetSite.Lists[new Guid(field.LookupList)];

            //    // Get the name of the field where this field gets information.
            //    SPField targetField = targetList.Fields.GetFieldByInternalName(field.LookupField);
            //    //this.EventFiringEnabled = false;
            //    //item["Title"] = targetList.Title + "\\" + item[fDoc] + targetField.Title;
            //    //item.Update();
            //    //this.EventFiringEnabled = true;
            //}
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Fixes the SP field type lookup.
        /// </summary>
        /// <param name="fileSpListItem">The file sp list item.</param>
        /// <param name="sourceValue">The source value.</param>
        /// <returns>Fixes the SPField type Lookup.</returns>
        private string FixSPFieldTypeLookup(SPListItem fileSpListItem, string sourceValue)
        {
            string s = "\t\tLookup(" + sourceValue + ")\tIsThisLookup? " + this.SPFieldTypeIsLookup + "\n";

            s += "\t\twas:" + fileSpListItem[this.ContextSPField.Id] + "\n";

            // process lookup columns (including multi-valued ones)
            List <string> lookupValueList = new List <string>();

            if (this.SPFieldTypeIsLookup)
            {
                s += "\t\tIsThisLookupupMulti? " + this.SPFieldLookupIsMultiValue + "\n";

                if (this.SPFieldLookupIsMultiValue)
                {
                    foreach (SPFieldLookupValue spFieldLookupValue in (fileSpListItem[this.FileSPField.Id] as SPFieldLookupValueCollection))
                    {
                        lookupValueList.Add(spFieldLookupValue.LookupValue);
                    }
                }
                else
                {
                    lookupValueList.Add(new SPFieldLookupValue(sourceValue).LookupValue);
                }
            }
            else
            {
                string[] strList = sourceValue.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                foreach (string str in strList)
                {
                    lookupValueList.Add(str);
                }
                s += "\t\tLookupElse ListCount:\t" + lookupValueList.Count + "\n";
            }

            // construct an SPFieldLookup object in the image of our field
            SPFieldLookup spFieldLookup = this.ContextSPField as SPFieldLookup;

            s += "\t\tspfield as spfield lookup multi? " + spFieldLookup.AllowMultipleValues + "\n";
            s += "\t\tlookupvaluelistcount:\t" + lookupValueList.Count + "\n";

            if (spFieldLookup.AllowMultipleValues)
            {
                SPFieldLookupValueCollection spFieldLookupValues = new SPFieldLookupValueCollection();

                foreach (string value in lookupValueList)
                {
                    // obtain the lookup value and its corresponding ID
                    SPFieldLookupValue lookupValue =
                        GetLookupValue(fileSpListItem.Web.Site.ID, spFieldLookup, value);

                    // lookup value found in the lookup list
                    if (lookupValue != null)
                    {
                        spFieldLookupValues.Add(lookupValue);
                    }
                }

                fileSpListItem[this.ContextSPField.Id] = spFieldLookupValues;
                s += "\t\tis_:" + spFieldLookupValues + "\n";
            }
            else if (lookupValueList.Count > 0)
            {
                // empty column values are "copied" as well
                if (String.IsNullOrEmpty(lookupValueList[0]))
                {
                    fileSpListItem[this.ContextSPField.Id] = String.Empty;
                    // continue;
                }

                // obtain the lookup value and its corresponding ID
                SPFieldLookupValue spFieldLookupValue =
                    GetLookupValue(fileSpListItem.Web.Site.ID, spFieldLookup, lookupValueList[0]);

                // lookup value found in the lookup list
                if (spFieldLookupValue != null)
                {
                    fileSpListItem[this.ContextSPField.Id] = spFieldLookupValue.ToString();
                }
                s += "\t\tis_:" + fileSpListItem[this.ContextSPField.Id] + "\n";
            }

            return(s);
        }
 public override string ToString()
 {
     return(m_fieldLookupValue.ToString());
 }
Ejemplo n.º 4
0
        private void MatchSPFieldTypeLookup(SPListItem targetSPListItem, SPField targetSPField,
                                            SPListItem sourceSPListItem, SPField sourceSPField, string sourceValue)
        {
            // process lookup columns (including multi-valued ones)
            List <string> valueList = new List <string>();

            if (sourceSPField.Type == SPFieldType.Lookup)
            {
                if ((sourceSPField as SPFieldLookup).AllowMultipleValues)
                {
                    SPFieldLookupValueCollection spFieldLookupValues =
                        sourceSPListItem[sourceSPField.Id] as SPFieldLookupValueCollection;

                    foreach (SPFieldLookupValue value in spFieldLookupValues)
                    {
                        valueList.Add(value.LookupValue);
                    }
                }
                else
                {
                    SPFieldLookupValue spFieldLookupValue = new SPFieldLookupValue(sourceValue);
                    valueList.Add(spFieldLookupValue.LookupValue);
                }
            }
            else
            {
                string[] strList = sourceValue.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

                foreach (string str in strList)
                {
                    valueList.Add(str);
                }
            }

            // construct an SPFieldLookup object in the image of our field
            SPFieldLookup spFieldLookup = targetSPField as SPFieldLookup;

            if (spFieldLookup.AllowMultipleValues)
            {
                SPFieldLookupValueCollection spFieldLookupValues = new SPFieldLookupValueCollection();

                foreach (string value in valueList)
                {
                    // obtain the lookup value and its corresponding ID
                    SPFieldLookupValue lookupValue =
                        GetLookupValue(targetSPListItem.Web.Site.ID, spFieldLookup, value);

                    // lookup value found in the lookup list
                    if (lookupValue != null)
                    {
                        spFieldLookupValues.Add(lookupValue);
                    }
                }

                targetSPListItem[targetSPField.Id] = spFieldLookupValues;
            }
            else if (valueList.Count > 0)
            {
                // empty column values are "copied" as well
                if (string.IsNullOrEmpty(valueList[0]))
                {
                    targetSPListItem[targetSPField.Id] = string.Empty;
                    // continue;
                }

                // obtain the lookup value and its corresponding ID
                SPFieldLookupValue spFieldLookupValue =
                    GetLookupValue(targetSPListItem.Web.Site.ID, spFieldLookup, valueList[0]);

                // lookup value found in the lookup list
                if (spFieldLookupValue != null)
                {
                    targetSPListItem[targetSPField.Id] = spFieldLookupValue.ToString();
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Generowanie formatek rozliczeniowych dla klienta
        /// </summary>
        /// <param name="properties"></param>
        internal static void Execute_GenFormRozlK(SPItemEventProperties properties, SPWeb web)
        {
            Debug.WriteLine("Execute_GenFromRozl");

            StringBuilder msg = new StringBuilder();

            SPListItem item = properties.ListItem;

            int okresId  = new SPFieldLookupValue(item["selOkres"].ToString()).LookupId;
            int klientId = new SPFieldLookupValue(item["selKlient"].ToString()).LookupId;

            Debug.WriteLine(string.Format("klientId={0}, okresId={1}", klientId.ToString(), okresId.ToString()));

            if (okresId > 0 && klientId > 0)
            {
                SPListItem klient = tabKlienci.Get_KlientById(web, klientId);
                if (klient != null && klient["enumStatus"] != null && klient["enumStatus"].ToString() == "Aktywny")
                {
                    msg.AppendFormat(@"<li>klient# {0} {1}</li>",
                                     klient.ID.ToString(),
                                     BLL.Tools.Get_Text(klient, "_NazwaPrezentowana"));

                    bool createKK = Get_Flag(item, "colDodajKartyKontrolne");

                    Debug.WriteLine("Case: " + klient.ContentType.Name);

                    switch (klient.ContentType.Name)
                    {
                    case "KPiR":
                        ZUS_Forms.Create(web, klientId, okresId, createKK);
                        PD_Forms.Create(web, klientId, okresId, createKK);
                        VAT_Forms.Create(web, klientId, okresId, createKK);
                        BR_Forms.Create(web, klientId, okresId, createKK);
                        Reminder_Forms.Create(web, klientId, okresId);
                        break;

                    case "KSH":
                        ZUS_Forms.Create(web, klientId, okresId, createKK);
                        PDS_Forms.Create(web, klientId, okresId, createKK);
                        VAT_Forms.Create(web, klientId, okresId, createKK);
                        BR_Forms.Create(web, klientId, okresId, createKK);
                        Reminder_Forms.Create(web, klientId, okresId);
                        break;

                    case "Firma":
                        PDS_Forms.Create(web, klientId, okresId, createKK);
                        break;

                    case "Osoba fizyczna":
                        ZUS_Forms.Create(web, klientId, okresId, createKK);
                        PD_Forms.Create(web, klientId, okresId, createKK);
                        PDS_Forms.Create(web, klientId, okresId, createKK);
                        VAT_Forms.Create(web, klientId, okresId, createKK);
                        break;

                    default:
                        break;
                    }
                }
            }

            // info o zakończeniu procesu
            string bodyHTML = string.Empty;

            if (msg.Length > 0)
            {
                bodyHTML = string.Format(@"<ul>{0}</ul>", msg.ToString());
            }

            string subject = string.Format(@"Generowanie formatek rozliczeniowych dla klienta");

            SPEmail.EmailGenerator.SendProcessEndConfirmationMail(subject, bodyHTML, web, item);
        }
        /// <summary>
        /// Generowanie formatek rozliczeniowych dla klienta
        /// </summary>
        /// <param name="properties"></param>
        internal static void Execute_GenFormRozlK(SPItemEventProperties properties, SPWeb web)
        {
            Debug.WriteLine("Execute_GenFromRozl");

            StringBuilder msg = new StringBuilder();

            SPListItem item = properties.ListItem;

            int okresId = new SPFieldLookupValue(item["selOkres"].ToString()).LookupId;
            int klientId = new SPFieldLookupValue(item["selKlient"].ToString()).LookupId;

            Debug.WriteLine(string.Format("klientId={0}, okresId={1}", klientId.ToString(), okresId.ToString()));

            if (okresId > 0 && klientId > 0)
            {
                SPListItem klient = tabKlienci.Get_KlientById(web, klientId);
                if (klient != null && klient["enumStatus"] != null && klient["enumStatus"].ToString() == "Aktywny")
                {
                    msg.AppendFormat(@"<li>klient# {0} {1}</li>",
                        klient.ID.ToString(),
                        BLL.Tools.Get_Text(klient, "_NazwaPrezentowana"));

                    bool createKK = Get_Flag(item, "colDodajKartyKontrolne");

                    Debug.WriteLine("Case: " + klient.ContentType.Name);

                    switch (klient.ContentType.Name)
                    {
                        case "KPiR":
                            ZUS_Forms.Create(web, klientId, okresId, createKK);
                            PD_Forms.Create(web, klientId, okresId, createKK);
                            VAT_Forms.Create(web, klientId, okresId, createKK);
                            BR_Forms.Create(web, klientId, okresId, createKK);
                            Reminder_Forms.Create(web, klientId, okresId);
                            break;
                        case "KSH":
                            ZUS_Forms.Create(web, klientId, okresId, createKK);
                            PDS_Forms.Create(web, klientId, okresId, createKK);
                            VAT_Forms.Create(web, klientId, okresId, createKK);
                            BR_Forms.Create(web, klientId, okresId, createKK);
                            Reminder_Forms.Create(web, klientId, okresId);
                            break;
                        case "Firma":
                            PDS_Forms.Create(web, klientId, okresId, createKK);
                            break;
                        case "Osoba fizyczna":
                            ZUS_Forms.Create(web, klientId, okresId, createKK);
                            PD_Forms.Create(web, klientId, okresId, createKK);
                            PDS_Forms.Create(web, klientId, okresId, createKK);
                            VAT_Forms.Create(web, klientId, okresId, createKK);
                            break;

                        default:
                            break;
                    }
                }
            }

            // info o zakończeniu procesu
            string bodyHTML = string.Empty;

            if (msg.Length > 0)
            {
                bodyHTML = string.Format(@"<ul>{0}</ul>", msg.ToString());
            }

            string subject = string.Format(@"Generowanie formatek rozliczeniowych dla klienta");
            SPEmail.EmailGenerator.SendProcessEndConfirmationMail(subject, bodyHTML, web, item);

        }