Пример #1
0
        /// <summary>
        /// An item was added.
        /// </summary>
        public override void ItemAdded(SPItemEventProperties properties)
        {
            SPWeb      web  = properties.Web;
            SPListItem item = properties.ListItem;

            item["textUsers"] = String.Empty;

            SPFieldUserValueCollection userValues = new SPFieldUserValueCollection(web, item["manyUsers"].ToString());

            string userValuesString = String.Empty;

            using (SPSite site = properties.Site)
            {
                SPServiceContext serviceContext = SPServiceContext.GetContext(site);
                try
                {
                    UserProfileManager userProfileManager = new UserProfileManager(serviceContext);

                    foreach (SPFieldUserValue userValue in userValues)
                    {
                        var userProfile = userProfileManager.GetUserProfile(userValue.User.LoginName);
                        userValuesString += "'" + userProfile["WorkEmail"] + "',";
                    }
                }
                catch
                {
                    //Empty
                }
            }

            string queryString = "SELECT "
                                 + " d.Name as Dep, "
                                 + " e.FName, "
                                 + " p.Name as Pos "
                                 + " FROM Departments d "
                                 + " LEFT JOIN KPlan kp ON kp.DepartmentId = d.Id "
                                 + " LEFT JOIN Emploees e ON kp.id = e.KP_Id "
                                 + " LEFT JOIN Positions p ON kp.PositionId = p.Id "
                                 + " WHERE "
                                 + " e.EMail in (" + userValuesString.TrimEnd(',') + ")";


            using (var manager = new ManagerSQL(properties.Web))
            {
                List <Dictionary <string, string> > result = manager.SelectAll(queryString.Replace(@"\\", @"\"));
                for (int i = 0; i < result.Count; i++)
                {
                    item["textUsers"] += String.Format("{0} / {1} / {2}; ", result[i]["FName"], result[i]["Dep"], result[i]["Pos"]);
                }
            }

            item.Update();
        }
Пример #2
0
        private void load(String Path)
        {
            if (File.Exists(Path))
            {
                StreamReader streamReader = new StreamReader(Path);
                String       s;
                int          tempStart;
                int          tempStop;
                do
                {
                    s = streamReader.ReadLine();
                    if (s != null)
                    {
                        tempStart = s.IndexOf(" \"");
                        tempStop  = s.IndexOf("\" ");

                        if (s.IndexOf("DataBase") != -1)
                        {
                            Database = s.Substring(tempStart + 2, tempStop - tempStart - 2);
                        }

                        else if (s.IndexOf("Address") != -1)
                        {
                            Address = s.Substring(tempStart + 2, tempStop - tempStart - 2);
                        }

                        else if (s.IndexOf("User") != -1)
                        {
                            User = s.Substring(tempStart + 2, tempStop - tempStart - 2);
                        }

                        else if (s.IndexOf("Password") != -1)
                        {
                            Password = s.Substring(tempStart + 2, tempStop - tempStart - 2);
                        }
                    }
                } while (s != null);
                streamReader.Close();
            }
            else
            {
                Debug.WriteLine("Error reading configuration file");
            }
            sql = new ManagerSQL(Address, Database, User, Password);
            sql.connect();
            sql.querry("Select * from dbo.Products");
        }
Пример #3
0
 /// <summary>
 /// Permet de se connecter à la base de donnée
 /// </summary>
 public DataBaseConnect()
 {
     Base = new ManagerSQL();
      Base.Connexion();
 }