public int UpdateEntry(EmployeeModel emp, string siteUrl, string ID)
        {
            try
            {
                using (MSC.ClientContext context = GetContext(siteUrl))
                {
                    MSC.List list = context.Web.Lists.GetByTitle("TIM_DailyAttendance");

                    MSC.ListItem listItem = null;

                    MSC.ListItemCreationInformation itemCreateInfo = new MSC.ListItemCreationInformation();
                    listItem = list.GetItemById(Convert.ToInt32(ID));

                    listItem["AttendanceDate"] = Convert.ToDateTime(emp.attendance_date).ToString("dd-MM-yyyy");
                    listItem["CheckinTime"]    = emp.checkin_time;
                    listItem["CheckoutTime"]   = emp.checkout_time;
                    listItem["Comment"]        = emp.comment;
                    listItem["EmpNo"]          = emp.empno;
                    listItem["Hours"]          = emp.hours;
                    listItem["EmpName"]        = emp.name;
                    listItem["EmpMail"]        = emp.office_email;
                    listItem.Update();
                    context.ExecuteQuery();
                }
            }
            catch (Exception ex)
            {
            }

            return(0);
        }
Exemple #2
0
        private void ProductEditorDialog_AddClosed(object sender, EventArgs e)
        {
            ProductEditor dialog = (ProductEditor)sender;

            // stop if they clicked cancel
            if (dialog.DialogResult == false)
            {
                return;
            }

            StatusBarPanel.BeginUpdateMessage("Creating new item...");

            SP.List products = Globals.ClientContext.Web.Lists.GetByTitle("Products");
            SP.ListItemCreationInformation newProductInfo = new SP.ListItemCreationInformation();

            SP.ListItem newProduct = products.AddItem(newProductInfo);
            newProduct["Title"] = dialog.ProductNameTextBox.Text;
            newProduct["Product_x0020_Number"] = dialog.ProductNumberTextBox.Text;
            newProduct["Price"] = dialog.ProductPriceTextBox.Text;
            SP.FieldLookupValue fieldValue = new SP.FieldLookupValue();
            foreach (SP.ListItem item in Globals.ProductCategories)
            {
                if (item["Title"].ToString() == ((SP.ListItem)dialog.ProductCategoryComboBox.SelectedItem)["Title"].ToString())
                {
                    fieldValue.LookupId = item.Id;
                }
            }
            newProduct["Category"] = fieldValue;

            newProduct.Update();
            Globals.ClientContext.ExecuteQuery();

            this.Dispatcher.BeginInvoke(new Action(OnProducteditorAddUIUpdater), DispatcherPriority.Normal);
        }
Exemple #3
0
        /// <summary>
        /// Adds a new item, then reloads the data.
        /// </summary>
        private void AddButton_Click(object sender, EventArgs e)
        {
            var creationInfo = new SP.ListItemCreationInformation();

            SP.ListItem newRecipe = RecipesList.AddItem(creationInfo);

            // get values from input fields
            newRecipe["Title"] = RecipeTitleTextBox.Text;
            newRecipe["Required_x0020_Time"] = TimeNumericUpDown.Value.ToString();
            newRecipe["Difficulty"]          = DifficultyComboBox.SelectedItem.ToString();

            var categories = new List <string>();

            foreach (var checkedCategory in CategoryCheckedListBox.CheckedItems)
            {
                categories.Add(checkedCategory.ToString());
            }

            newRecipe["Category"] = categories.ToArray();

            newRecipe.Update();
            Context.ExecuteQuery();

            LoadRecipes();
        }
Exemple #4
0
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            CLOM.ClientContext context = new CLOM.ClientContext(CLOM.ApplicationContext.Current.Url);

            CLOM.List taskList = context.Web.Lists.GetByTitle("Tasks");

            CLOM.ListItemCreationInformation itemCreateInfo = new CLOM.ListItemCreationInformation();
            CLOM.ListItem newItem = taskList.AddItem(itemCreateInfo);
            newItem["Title"]   = textBox1.Text;
            newItem["DueDate"] = calendar1.SelectedDate.Value.ToShortDateString();
            newItem.Update();

            context.ExecuteQueryAsync(ClientRequestSucceeded, ClientRequestFailed);
        }
        public override void InsertRecords(string tableName, IEnumerable <Record> records)
        {
            //ProcessBatchData not available in Client OM. Maybe can use custom solution similar to base class ADO.NET version
            //But first need to test - maybe this is already fast enough
            using (var context = GetClientContext(ConnectionDetails))
            {
                var site           = context.Web;
                var list           = context.Web.Lists.GetByTitle(tableName);
                var itemCreateInfo = new SP.ListItemCreationInformation();

                records.ForEach(record =>
                {
                    var listItem = list.AddItem(itemCreateInfo);

                    record.Fields.ForEach(field =>
                    {
                        if (field.Type == FieldType.DateTime)
                        {
                            listItem[field.Name] = field.GetValue <DateTime>().ToISO8601DateString();
                        }
                        else if (field.Type == FieldType.String)
                        {
                            string value = field.Value.ToString();
                            if (value.Length > 255)
                            {
                                value = value.Substring(0, 255);
                            }
                            listItem[field.Name] = field.Value.ToString();
                        }
                        else if (field.Type == FieldType.RichText)
                        {
                            listItem[field.Name] = field.Value.ToString();
                        }
                        else
                        {
                            listItem[field.Name] = field.Value;
                        }
                    });

                    listItem.Update();
                });
                context.ExecuteQuery();
            }
        }
Exemple #6
0
 public static SP.ListItem AddItemToList(SP.ClientContext context, SP.List list, Dictionary <string, string> item)
 {
     try
     {
         SP.ListItemCreationInformation itemCreationInfo = new SP.ListItemCreationInformation();
         SP.ListItem newItem = list.AddItem(itemCreationInfo);
         foreach (KeyValuePair <string, string> entry in item)
         {
             newItem[entry.Key] = entry.Value;
         }
         newItem.Update();
         context.Load(newItem);
         context.ExecuteQuery();
         return(newItem);
     }
     catch (Exception e)
     {
         MessageBox.Show($"Error in SharepointMethods.AddItemToList: {e}");
         return(null);
     }
 }
        protected void lvCommesse_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            int itemIndex = ((ListViewDataItem)e.Item).DisplayIndex;

            // Extract the key and cast it to its data type.
            DataKey key = ((ListView)sender).DataKeys[itemIndex];
            string idCommessa = key.Values["Id"].ToString();
            string titolo = key.Values["Titolo"] as string;

            using (var clientContext = TokenHelper.GetClientContextWithContextToken(AppUrl, ContextToken, Request.Url.Authority))
            {
                SP.List oList = clientContext.Web.Lists.GetByTitle("RegistrazioneAttivita");

                //Aggiorno l'ultima commessa
                var lastItem = LeggiUltimaAttivita();
                if (lastItem != null)
                {
                    // Lo devo rileggere perchè l'ho caricato con un altro contesto
                    lastItem = oList.GetItemById(lastItem.Id);
                    lastItem["DataFine"] = DateTime.Now;

                    lastItem.Update();
                    clientContext.ExecuteQuery();

                }

                //Aggiungo quella nuova
                var spCreationInfo = new SP.ListItemCreationInformation();
                var attivitaItem = oList.AddItem(spCreationInfo);
                attivitaItem["Title"] = titolo;
                attivitaItem["Commessa"] = idCommessa;
                attivitaItem["DataInizio"] = DateTime.Now;

                attivitaItem.Update();

                clientContext.ExecuteQuery();

                VisualizzaAttivita(attivitaItem);
            }
        }
        public int AddItem(string ListName, TEntity Item)
        {
            try
            {
                SP.Web  web  = context.Web;
                SP.List list = web.Lists.GetByTitle(ListName);
                SP.ListItemCreationInformation createInfo = new SP.ListItemCreationInformation();
                SP.ListItem item = list.AddItem(createInfo);

                var properties = typeof(TEntity).GetProperties();

                foreach (var property in properties)
                {
                    if (property.PropertyType == typeof(bool?))
                    {
                        item[property.Name] = property.GetValue(Item) != null?property.GetValue(Item) : -1;
                    }
                    else if (property.Name != "ID" && property.Name != "Created" && property.Name != "Author")
                    {
                        item[property.Name] = property.GetValue(Item);
                    }
                }

                item.Update();
                context.Load(item);
                context.ExecuteQuery();

                return(item.Id);
            }
            catch (InvalidCastException ex)
            {
                throw new Exception(ex.Message + ". Data model types are invalid, please verify that models are strongly typed and match the SharePoint list column types.", new InvalidCastException());
            }
            catch (Exception ex)
            {
                Debug.Write(ex.Message);
                throw new Exception("Error getting SharePoint list data: " + ex.Message);
            }
        }
        public static void UpdateStatus(int ID, string siteUrl, string ListName)
        {
            using (MSC.ClientContext context = CustomSharePointUtility.GetContext(siteUrl))
            {
                if (context != null)
                {
                    MSC.List     list     = context.Web.Lists.GetByTitle(ListName);
                    MSC.ListItem listItem = null;

                    MSC.ListItemCreationInformation itemCreateInfo = new MSC.ListItemCreationInformation();
                    listItem = list.GetItemById(ID);

                    listItem["SystemUpdated"] = "Yes";
                    listItem.Update();
                    try
                    {
                        context.ExecuteQuery();
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
        }
Exemple #10
0
        public void Upload()
        {
            try
            {
                using (context = new MSC.ClientContext(sharePointSite))
                {
                    SecureString s = new SecureString();
                    //s.
                    MSC.SharePointOnlineCredentials cred = new MSC.SharePointOnlineCredentials(ConfigurationManager.AppSettings["UsrName"], getPassword(ConfigurationManager.AppSettings["PassWord"]));
                    context.Credentials = cred;
                    var list = context.Web.Lists.GetByTitle(documentLibraryName);
                    context.Load(list);

                    var root = list.RootFolder;
                    context.Load(root);
                    context.ExecuteQuery();

                    // ADDITION
                    string SourceDocPath = ConfigurationManager.AppSettings["SourceDocsPath"];

                    DirectoryInfo         dInfo       = new DirectoryInfo(SourceDocPath);
                    FileInfo[]            ListofFiles = dInfo.GetFiles();
                    List <linkIdentifier> listofLinks = new List <linkIdentifier>();
                    XmlDocument           doc         = new XmlDocument();
                    doc.Load("Links.xml");
                    XmlNodeList listXml = doc.GetElementsByTagName("link");
                    foreach (XmlNode n1 in listXml)
                    {
                        linkIdentifier id = new linkIdentifier();
                        id.rowIndex  = Convert.ToInt32(n1["rowIndex"].InnerText);
                        id.colIndex  = Convert.ToInt32(n1["colIndex"].InnerText);
                        id.SheetName = n1["SheetName"].InnerText;
                        listofLinks.Add(id);
                    }

                    foreach (FileInfo fileInstance in ListofFiles)
                    {
                        bool   IsgoodLink = false;
                        string path       = fileInstance.FullName;

                        Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
                        Workbook wb = excel.Workbooks.Open(path);

                        //***********************LINK CHECK*****************************************
                        //Read the first cell
                        foreach (linkIdentifier identifier in listofLinks)
                        {
                            Worksheet excelSheet = wb.Sheets[identifier.SheetName];
                            string    test       = excelSheet.Cells[identifier.rowIndex, identifier.colIndex].Formula;

                            test = test.Split(',')[0].TrimEnd("\"".ToCharArray());
                            String[] pathList = test.Split('/');

                            try
                            {
                                if (test.Contains(".aspx"))
                                {
                                    //LinkCheck(test);
                                    IsgoodLink = CheckLink(pathList, cred);
                                }
                                else
                                {
                                    IsgoodLink = CheckLink(pathList, cred);
                                }
                            }
                            catch (MSC.ServerException e)
                            {
                                if (e.ServerErrorTypeName == "System.IO.FileNotFoundException")
                                {
                                    IsgoodLink = false;
                                }
                                wb.Close();
                                IsgoodLink = false;
                            }
                            if (IsgoodLink == false)
                            {
                                Console.WriteLine("File {0} is having deadlinks.", fileInstance.Name);
                                wb.Close();
                                return;
                            }
                        }
                        wb.Close();
                        //***********************LINK CHECK*****************************************


                        string tempdir = fileInstance.Name;
                        tempdir = tempdir.Substring("2019.craft ".Length);
                        tempdir = tempdir.Trim(' ');
                        tempdir = tempdir.Remove((tempdir.Length - ".xlsm".Length));
                        String ParentDirectoryName = tempdir.Split('-')[0];
                        ParentDirectoryName = ParentDirectoryName.Trim();
                        string ChildDirectoryName = tempdir.Split('-')[1];
                        ChildDirectoryName = ChildDirectoryName.Trim();
                        try
                        {
                            MSC.ListItemCreationInformation information = new MSC.ListItemCreationInformation();
                            string targetFolder = ConfigurationManager.AppSettings["RootFolder"];
                            if (ConfigurationManager.AppSettings["Testing"] == "1")
                            {
                                targetFolder = ConfigurationManager.AppSettings["RootFolderTest"];
                            }
                            ;
                            information.FolderUrl = list.RootFolder.ServerRelativeUrl + targetFolder + ParentDirectoryName;
                            MSC.Folder parentFolder = list.RootFolder.Folders.Add(information.FolderUrl);
                            context.Load(parentFolder);
                            context.ExecuteQuery();
                            information.FolderUrl = information.FolderUrl + "/" + ChildDirectoryName;

                            MSC.Folder childDirectory = list.RootFolder.Folders.Add(information.FolderUrl);
                            context.Load(childDirectory);
                            context.ExecuteQuery();


                            if (IsgoodLink)
                            {
                                string     filePath       = fileInstance.FullName;
                                FileStream documentStream = System.IO.File.OpenRead(filePath);
                                byte[]     info           = new byte[documentStream.Length];
                                documentStream.Read(info, 0, (int)documentStream.Length);
                                string fileURL = information.FolderUrl + "/" + fileInstance.Name;

                                MSC.FileCreationInformation fileCreationInformation = new MSC.FileCreationInformation();
                                fileCreationInformation.Overwrite = true;
                                fileCreationInformation.Content   = info;
                                fileCreationInformation.Url       = fileURL;
                                try
                                {
                                    Microsoft.SharePoint.Client.File f = context.Web.GetFileByServerRelativeUrl(fileURL);
                                    context.Load(f);
                                    context.ExecuteQuery();
                                    f.CheckOut();
                                }
                                catch (Microsoft.SharePoint.Client.ServerException ex)
                                {
                                    if (ex.ServerErrorTypeName == "System.IO.FileNotFoundException")
                                    {
                                        Console.WriteLine("File is not found for Checkout");
                                    }
                                }
                                Microsoft.SharePoint.Client.File uploadFile = list.RootFolder.Files.Add(fileCreationInformation);


                                uploadFile.CheckIn("Improvement Plan", MSC.CheckinType.MajorCheckIn);

                                context.Load(uploadFile, w => w.MajorVersion, w => w.MinorVersion);
                                context.ExecuteQuery();
                                Console.WriteLine("Document {0} is uploaded and checked in into SharePoint", fileURL);
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                new EventLog().WriteEntry(ex.Message, EventLogEntryType.Error);
                return;
            }
        }
Exemple #11
0
        public static bool EmailDataPlant(PurchaseOrder updationList, string siteUrl, string listName)
        {
            bool retValue = false;

            try
            {
                using (MSC.ClientContext context = CustomSharePointUtility.GetContext(siteUrl))
                {
                    //List<Mailing> varx = new List<Mailing>();

                    MSC.List list = context.Web.Lists.GetByTitle(listName);

                    MSC.ListItem listItem = null;

                    MSC.ListItemCreationInformation itemCreateInfo = new MSC.ListItemCreationInformation();
                    listItem = list.AddItem(itemCreateInfo);

                    var obj = new Object();

                    var _To      = "";
                    var _Body    = "";
                    var _Subject = "";

                    _To = updationList.CurrentApprover;


                    _Subject = "Gentle Reminder";
                    _Body   += "Dear User, <br><br>This is to inform you that below request is pending for your Approval.";
                    _Body   += "<br><b>Workflow Name :</b> Purchase Order ";
                    _Body   += "<br><b>Voucher No :</b>  " + updationList.POReferenceNumber;
                    _Body   += "<br><b>Date of Creation :</b>  " + updationList.Created;
                    _Body   += "<br><b>Employee : </b> " + updationList.Author;

                    _Body += "<br><b>Department :</b> " + updationList.DepartmentName;
                    _Body += "<br><b>Location :</b> " + updationList.LocationName;
                    _Body += "<br><b>PO No : </b> " + updationList.PONumber;
                    _Body += "<br><b> PO Amount : </b> " + updationList.POCost;
                    _Body += "<br><b> Material Details : </b> " + updationList.MaterialDetails;

                    if (updationList.NewStatus == "1")
                    {
                        _Body += "<br><b>Status :</b> Pending With Purchase Head";
                    }
                    else if (updationList.NewStatus == "2")
                    {
                        _Body += "<br><b>Status :</b> Pending With Plant Head";
                    }


                    _Body += "<br><h3>Kindly provide your approval</h3>";
                    _Body += "<br><h3>For Approval Please Click in the below link</h3>";
                    if (updationList.NewStatus == "1")
                    {
                        ///       _Body += "<br><a href=\"https://aparindltd.sharepoint.com/PurchaseOrder/SitePages/PendingWithApprover.aspx\">View Link</a>";
                    }
                    else if (updationList.NewStatus == "2")
                    {
                        ///      _Body += "<br><a href=\"https://aparindltd.sharepoint.com/PurchaseOrder/SitePages/PendingWithManagingDirector.aspx\">View Link</a>";
                    }

                    listItem["ToUser"]      = _To;
                    listItem["SubjectDesc"] = _Subject;
                    listItem["BodyDesc"]    = _Body;

                    if (_To != "")
                    {
                        listItem.Update();
                    }
                    try
                    {
                        context.ExecuteQuery();
                        retValue = true;
                    }
                    catch (Exception ex)
                    {
                        CustomSharePointUtility.WriteLog(string.Format("Error in  InsertUpdate_EmployeeMaster ( context.ExecuteQuery();): Error ({0}) ", ex.Message));
                        return(false);
                        //continue;
                    }
                }
            }

            catch (Exception ex)
            {
                CustomSharePointUtility.WriteLog(string.Format("Error in  InsertUpdate_EmployeeMaster: Error ({0}) ", ex.Message));
            }
            return(retValue);
        }
Exemple #12
0
        public static bool EmailData(PurchaseOrder updationList, string FunctionalHeadEmail, string PurchaseHead, string PlantHead, string MD, string siteUrl, string listName)
        {
            bool retValue = false;

            try
            {
                using (MSC.ClientContext context = CustomSharePointUtility.GetContext(siteUrl))
                {
                    //List<Mailing> varx = new List<Mailing>();

                    MSC.List list = context.Web.Lists.GetByTitle(listName);
                    //for (var i = 0; i < updationList.Count; i++)
                    //{
                    //var updateList = updationList.Skip(i).Take(1).ToList();
                    //if (updateList != null && updateList.Count > 0)
                    //{
                    //    foreach (var updateItem in updateList)
                    //    {
                    MSC.ListItem listItem = null;

                    MSC.ListItemCreationInformation itemCreateInfo = new MSC.ListItemCreationInformation();
                    listItem = list.AddItem(itemCreateInfo);

                    var obj = new Object();
                    //Mailing data = new Mailing();

                    //var _From = "";
                    var _To = "";
                    //var _Cc = "";
                    var _Body    = "";
                    var _Subject = "";
                    if (updationList.ApprovalStatus == "Submitted" && updationList.LocationType == "Office")
                    {
                        _To = FunctionalHeadEmail;
                    }
                    else if (updationList.ApprovalStatus == "Approved By Functional Head" && updationList.LocationType == "Office")
                    {
                        _To = MD;
                    }
                    else if (updationList.ApprovalStatus == "Submitted" && updationList.LocationType == "Plant")
                    {
                        _To = PurchaseHead;
                    }
                    else if (updationList.ApprovalStatus == "Approved By Purchase Head" && updationList.LocationType == "Plant")
                    {
                        _To = PlantHead;
                    }
                    else if (updationList.ApprovalStatus == "Approved By Plant Head" && Convert.ToInt32(updationList.POCost) > 50000 && updationList.LocationType == "Plant")
                    {
                        _To = MD;
                    }

                    _Subject = "Gentle Reminder";
                    _Body   += "Dear User, <br><br>This is to inform you that below request is pending for your Approval.";
                    _Body   += "<br><b>Workflow Name :</b> Purchase Order ";
                    _Body   += "<br><b>Voucher No :</b>  " + updationList.POReferenceNumber;
                    _Body   += "<br><b>Date of Creation :</b>  " + updationList.Created;
                    _Body   += "<br><b>Employee : </b> " + updationList.Author;

                    _Body += "<br><b>Department :</b> " + updationList.DepartmentName;
                    _Body += "<br><b>Location :</b> " + updationList.LocationName;
                    _Body += "<br><b>PO No : </b> " + updationList.PONumber;
                    _Body += "<br><b> PO Amount : </b> " + updationList.POCost;
                    _Body += "<br><b> Material Details : </b> " + updationList.MaterialDetails;

                    if (updationList.ApprovalStatus == "Submitted" && updationList.LocationType == "Office")
                    {
                        _Body += "<br><b>Status :</b> Pending With Functional Head";
                    }
                    else if (updationList.ApprovalStatus == "Approved By Functional Head" && updationList.LocationType == "Office")
                    {
                        _Body += "<br><b>Status :</b> Pending With MD";
                    }
                    else if (updationList.ApprovalStatus == "Submitted" && updationList.LocationType == "Plant")
                    {
                        _Body += "<br><b>Status :</b> Pending With Purchase Head";
                    }
                    else if (updationList.ApprovalStatus == "Approved By Purchase Head" && updationList.LocationType == "Plant")
                    {
                        _Body += "<br><b>Status :</b> Pending With Plant Head";
                    }
                    else if (updationList.ApprovalStatus == "Approved By Plant Head" && Convert.ToInt32(updationList.POCost) > 50000 && updationList.LocationType == "Plant")
                    {
                        _Body += "<br><b>Status :</b> Pending With MD";
                    }

                    _Body += "<br><h3>Kindly provide your approval</h3>";
                    _Body += "<br><h3>For Approval Please Click in the below link</h3>";
                    if (updationList.ApprovalStatus == "Submitted" && updationList.LocationType == "Office")
                    {
                        //         _Body += "<br><a href=\"https://aparindltd.sharepoint.com/PurchaseOrder/SitePages/PendingWithFunctionalHead.aspx\">View Link</a>";
                    }
                    else if (updationList.ApprovalStatus == "Approved By Functional Head" && updationList.LocationType == "Office")
                    {
                        //       _Body += "<br><a href=\"https://aparindltd.sharepoint.com/PurchaseOrder/SitePages/PendingWithMD.aspx\">View Link</a>";
                    }
                    else if (updationList.ApprovalStatus == "Submitted" && updationList.LocationType == "Plant")
                    {
                        //       _Body += "<br><a href=\"https://aparindltd.sharepoint.com/PurchaseOrder/SitePages/PendingWithPurchaseHead.aspx\">View Link</a>";
                    }
                    else if (updationList.ApprovalStatus == "Approved By Purchase Head" && updationList.LocationType == "Plant")
                    {
                        //     _Body += "<br><a href=\"https://aparindltd.sharepoint.com/PurchaseOrder/SitePages/PendingWithPlantHead.aspx\">View Link</a>";
                    }
                    else if (updationList.ApprovalStatus == "Approved By Plant Head" && updationList.LocationType == "Plant")
                    {
                        //      _Body += "<br><a href=\"https://aparindltd.sharepoint.com/PurchaseOrder/SitePages/PendingWithManagingDirector.aspx\">View Link</a>";
                    }

                    //data.MailTo = _From;
                    //data.MailTo = _To;
                    //data.MailCC = _Cc;
                    //data.MailSubject = _Subject;
                    //data.MailBody = _Body;
                    //varx.Add(data);
                    listItem["ToUser"]      = _To;
                    listItem["SubjectDesc"] = _Subject;
                    listItem["BodyDesc"]    = _Body;
                    if (_To != "")
                    {
                        listItem.Update();
                    }
                    try
                    {
                        context.ExecuteQuery();
                        retValue = true;
                    }
                    catch (Exception ex)
                    {
                        CustomSharePointUtility.WriteLog(string.Format("Error in  InsertUpdate_EmployeeMaster ( context.ExecuteQuery();): Error ({0}) ", ex.Message));
                        return(false);
                        //continue;
                    }
                }

                //        }
                //    }
                //}

                //}
            }

            catch (Exception ex)
            {
                CustomSharePointUtility.WriteLog(string.Format("Error in  InsertUpdate_EmployeeMaster: Error ({0}) ", ex.Message));
            }
            return(retValue);
        }
Exemple #13
0
        public static bool EmailData(List <Employee> PendingEmployee, string siteUrl, string listName)
        {
            bool retValue = false;

            try
            {
                using (MSC.ClientContext context = CustomSharePointUtility.GetContext(siteUrl))
                {
                    //List<Mailing> varx = new List<Mailing>();

                    MSC.List list = context.Web.Lists.GetByTitle(listName);

                    MSC.ListItem listItem = null;

                    MSC.ListItemCreationInformation itemCreateInfo = new MSC.ListItemCreationInformation();
                    listItem = list.AddItem(itemCreateInfo);


                    // MSC.UserCollection users = new MSC.UserCollection();
                    //MSC.FieldUserValue fieldUserValue = new MSC.FieldUserValue();


                    MSC.FieldUserValue[] userValueCollection = new MSC.FieldUserValue[PendingEmployee.Count];
                    for (var i = 0; i < PendingEmployee.Count; i++)
                    {
                        MSC.FieldUserValue fieldUserVal = new MSC.FieldUserValue();
                        fieldUserVal.LookupId = Convert.ToInt32(PendingEmployee[i].EmployeeID);
                        userValueCollection.SetValue(fieldUserVal, i);
                    }


                    //var _From = "";
                    var _To = "";
                    //var _Cc = "";
                    var _Body    = "";
                    var _Subject = "";

                    _To = "1247";

                    _Subject = "Sales Estimate is not submitted";
                    _Body   += "Dear User, <br><br>This is to inform you that still your Sales Estimate is not submitted kindly fill and submit on priority.<br><br>Kindly click on below link for submit estimate";
                    _Body   += "<br><a href=" + siteUrl + "/SitePages/NewRequest.aspx>Submit Estimate</ a>";



                    listItem["ToUser"]      = userValueCollection;
                    listItem["SubjectDesc"] = _Subject;
                    listItem["BodyDesc"]    = _Body;
                    listItem.Update();


                    try
                    {
                        context.ExecuteQuery();
                        retValue = true;
                    }
                    catch (Exception ex)
                    {
                        CustomSharePointUtility.WriteLog(string.Format("Error in  InsertUpdate_EmployeeMaster ( context.ExecuteQuery();): Error ({0}) ", ex.Message));
                        return(false);
                        //continue;
                    }
                }

                //        }
                //    }
                //}

                //}
            }

            catch (Exception ex)
            {
                CustomSharePointUtility.WriteLog(string.Format("Error in  InsertUpdate_EmployeeMaster: Error ({0}) ", ex.Message));
            }
            return(retValue);
        }
        public static bool EmailData(List <ITAssets> updationList, string siteUrl, string listName)
        {
            bool retValue = false;

            try
            {
                using (MSC.ClientContext context = CustomSharePointUtility.GetContext(siteUrl))
                {
                    //List<Mailing> varx = new List<Mailing>();

                    MSC.List list = context.Web.Lists.GetByTitle(listName);
                    for (var i = 0; i < updationList.Count; i++)
                    {
                        var updateList = updationList.Skip(i).Take(1).ToList();
                        if (updateList != null && updateList.Count > 0)
                        {
                            foreach (var updateItem in updateList)
                            {
                                MSC.ListItem listItem = null;

                                MSC.ListItemCreationInformation itemCreateInfo = new MSC.ListItemCreationInformation();
                                listItem = list.AddItem(itemCreateInfo);

                                var obj = new Object();
                                //Mailing data = new Mailing();

                                //var _From = "";
                                var _To = "";
                                //var _Cc = "";
                                var _Body    = "";
                                var _Subject = "";
                                if (updateItem.StatusId == "0")
                                {
                                    _To = updateItem.FunctionalHead;
                                }
                                else
                                {
                                    _To = updateItem.AssignedApprover;
                                }
                                _Subject = "Gentle Reminder"; // + updateItem.ExpVoucherNo + " Travel Voucher Approval is Pending
                                _Body   += "Dear User, <br><br>This is to inform you that below request is pending for your Approval.";
                                _Body   += "<br><b>Workflow Name :</b> IT Asset Requisition ";
                                _Body   += "<br><b>Request No :</b>  " + updateItem.RequisitionNo;
                                _Body   += "<br><b>Date of Requisition :</b>  " + updateItem.StartOn;
                                _Body   += "<br><b>Requested By  : </b> " + updateItem.EmployeeName;
                                _Body   += "<br><b>Location :</b> " + updateItem.Location;
                                _Body   += "<br><b>Department :</b> " + updateItem.Department;
                                _Body   += "<br><b>Designation :</b> " + updateItem.Designation;
                                _Body   += "<br><b>Buisness :</b> " + updateItem.Business;
                                _Body   += "<br><b>Reporting to  :</b> " + updateItem.ReportingTo;
                                if (updateItem.Asset == "Desktop")
                                {
                                    _Body += "<br><b>IT Asset Request for  :</b> " + updateItem.Asset;
                                }
                                else
                                {
                                    _Body += "<br><b>Based on Work Level  :</b> " + updateItem.Asset;
                                }

                                _Body += "<br><b>New Joinee Employee :</b> " + updateItem.NewJoineeEmpName;
                                _Body += "<br><b>New Employee designation :</b> " + updateItem.NewEmployeeDesignation;
                                _Body += "<br><b>Replacement Of :</b> " + updateItem.ReplacementEmployeeName;
                                if (updateItem.StatusId == "0")
                                {
                                    _Body += "<br><b>Status :</b> " + updateItem.Status;
                                }
                                else if (updateItem.StatusId == "1")
                                {
                                    _Body += "<br><b>Status :</b> " + updateItem.Status;
                                }
                                else if (updateItem.StatusId == "4")
                                {
                                    _Body += "<br><b>Status :</b> " + updateItem.Status;
                                }
                                else if (updateItem.StatusId == "5")
                                {
                                    _Body += "<br><b>Status :</b> " + updateItem.Status;
                                }
                                else if (updateItem.StatusId == "6")
                                {
                                    _Body += "<br><b>Status :</b> " + updateItem.Status;
                                }
                                else if (updateItem.StatusId == "7")
                                {
                                    _Body += "<br><b>Status :</b> " + updateItem.Status;
                                }
                                _Body += "<br><h3>Kindly provide your approval</h3>";
                                _Body += "<br><h3>For Approval Please Click in the below link</h3>";
                                if (updateItem.StatusId == "0")
                                {
                                    _Body += "<br><a href=\"https://aparindltd.sharepoint.com/ITAssetRequisition/SitePages/PendingForMe.aspx?StatusId=" + updateItem.StatusId + "&RequisitionNo=\">View Link</a>";
                                }
                                else if (updateItem.StatusId == "1")
                                {
                                    _Body += "<br><a href=\"https://aparindltd.sharepoint.com/ITAssetRequisition/SitePages/PendingForMe.aspx?StatusId=" + updateItem.StatusId + "&RequisitionNo=\">View Link</a>";
                                }
                                else if (updateItem.StatusId == "4")
                                {
                                    _Body += "<br><a href=\"https://aparindltd.sharepoint.com/ITAssetRequisition/SitePages/PendingForMe.aspx?StatusId=" + updateItem.StatusId + "&RequisitionNo=\">View Link</a>";
                                }
                                else if (updateItem.StatusId == "5")
                                {
                                    _Body += "<br><a href=\"https://aparindltd.sharepoint.com/ITAssetRequisition/SitePages/PendingForMe.aspx?StatusId=" + updateItem.StatusId + "&RequisitionNo=\">View Link</a>";
                                }
                                else if (updateItem.StatusId == "6")
                                {
                                    _Body += "<br><a href=\"https://aparindltd.sharepoint.com/ITAssetRequisition/SitePages/PendingForMe.aspx?StatusId=" + updateItem.StatusId + "&RequisitionNo=\">View Link</a>";
                                }
                                else if (updateItem.StatusId == "7")
                                {
                                    _Body += "<br><a href=\"https://aparindltd.sharepoint.com/ITAssetRequisition/SitePages/PendingForMe.aspx?StatusId=" + updateItem.StatusId + "&RequisitionNo=\">View Link</a>";
                                }
                                //data.MailTo = _From;
                                //data.MailTo = _To;
                                //data.MailCC = _Cc;
                                //data.MailSubject = _Subject;
                                //data.MailBody = _Body;
                                //varx.Add(data);
                                listItem["ToUser"]      = _To;
                                listItem["MailSubject"] = _Subject;
                                listItem["MailBody"]    = _Body;
                                listItem.Update();
                            }
                            try
                            {
                                context.ExecuteQuery();
                                retValue = true;
                            }
                            catch (Exception ex)
                            {
                                CustomSharePointUtility.WriteLog(string.Format("Error in  InsertUpdate_EmployeeMaster ( context.ExecuteQuery();): Error ({0}) ", ex.Message));
                                return(false);
                                //continue;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                CustomSharePointUtility.WriteLog(string.Format("Error in  InsertUpdate_EmployeeMaster: Error ({0}) ", ex.Message));
            }
            return(retValue);
        }
Exemple #15
0
        public void getLibraryData(string strSourceURL, string strTargetURL)
        {
            try
            {
                using (spClient.ClientContext sourceContext = new spClient.ClientContext(strSourceURL)) //Site URL of InfoPath Libray
                {
                    Web web = sourceContext.Web;
                    spClient.ListCollection listColl = web.Lists;
                    sourceContext.Load(listColl);
                    sourceContext.ExecuteQuery();
                    for (int Count = 0; Count < listColl.Count; Count++)
                    {
                        if (listColl[Count].Title.Equals(txtLibraryName.Text.Trim()))
                        {
                            ASMSlibraryExist = true;
                            break;
                        }
                    }
                    if (ASMSlibraryExist)
                    {
                        spClient.List      oList     = sourceContext.Web.Lists.GetByTitle(txtLibraryName.Text.Trim());
                        spClient.CamlQuery camlQuery = new spClient.CamlQuery();
                        camlQuery.ViewXml = "<Query><OrderBy><FieldRef Name='ID' /></OrderBy></Query>";
                        spClient.ListItemCollection collListItem = oList.GetItems(camlQuery);

                        sourceContext.Load(collListItem);
                        sourceContext.ExecuteQuery();

                        SecureString password = new SecureString();
                        foreach (char c in txtPassword.Text.Trim().ToCharArray())
                        {
                            password.AppendChar(c);
                        }
                        using (spClient.ClientContext descontext = new spClient.ClientContext(txtDesturl.Text.Trim()))
                        {
                            descontext.Credentials = new SharePointOnlineCredentials(txtUserName.Text.Trim(), password);
                            spClient.Web            oweb     = descontext.Web;
                            spClient.ListCollection listcoll = oweb.Lists;

                            spClient.List spList = descontext.Web.Lists.GetByTitle(txtlistName.Text);
                            spClient.ListItemCreationInformation itemCreateInfo = new spClient.ListItemCreationInformation();
                            descontext.Load(spList);
                            descontext.ExecuteQuery();

                            for (int i = 0; i < collListItem.Count; i++)
                            {
                                try
                                {
                                    spClient.ListItem oListItem = spList.AddItem(itemCreateInfo);
                                    sourceContext.Load(collListItem[i]);
                                    AddItemsIntoList(collListItem[i], descontext, collListItem, oListItem, spList);
                                }
                                catch (Exception ex)
                                {
                                    //   MessageBox.Show(ex.Message);
                                    streamWriter.WriteLine("\r\n\r\n----------------------------- Error -------------------------------");
                                    streamWriter.WriteLine("Error Message :" + ex.Message);
                                    streamWriter.WriteLine("Stack Trace :" + ex.StackTrace);
                                }
                            }
                            sourceContext.ExecuteQuery();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Library does not exist. Please give valid InfoPath Library Name. ");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                streamWriter.WriteLine("\r\n\r\n----------------------------- Error -------------------------------");
                streamWriter.WriteLine("Error Message :" + ex.Message);
                streamWriter.WriteLine("Stack Trace :" + ex.StackTrace);
            }
        }
Exemple #16
0
        //public static void sample()
        //{
        //    List<TravelVoucher> data = new List<TravelVoucher>();
        //  List<Mailing> mail=EmailData(data, "", "");
        //}

        public static bool EmailData(List <ExpenseVoucher> updationList, string siteUrl, string listName)
        {
            bool retValue = false;

            try
            {
                using (MSC.ClientContext context = CustomSharePointUtility.GetContext(siteUrl))
                {
                    //List<Mailing> varx = new List<Mailing>();

                    MSC.List list = context.Web.Lists.GetByTitle(listName);
                    for (var i = 0; i < updationList.Count; i++)
                    {
                        var updateList = updationList.Skip(i).Take(1).ToList();
                        if (updateList != null && updateList.Count > 0)
                        {
                            foreach (var updateItem in updateList)
                            {
                                MSC.ListItem listItem = null;

                                MSC.ListItemCreationInformation itemCreateInfo = new MSC.ListItemCreationInformation();
                                listItem = list.AddItem(itemCreateInfo);

                                var obj = new Object();
                                //Mailing data = new Mailing();

                                //var _From = "";
                                var _To = "";
                                //var _Cc = "";
                                var _Body    = "";
                                var _Subject = "";
                                if (updateItem.SequenceNo == "1")
                                {
                                    if (updateItem.CurrentApprove == "")
                                    {
                                        break;
                                    }
                                    else
                                    {
                                        _To = updateItem.CurrentApprove;
                                    }
                                }
                                else if (updateItem.SequenceNo == "3")
                                {
                                    if (updateItem.AccountUserApproved == "")
                                    {
                                        break;
                                    }
                                    else
                                    {
                                        _To = updateItem.AccountUserApproved;
                                    }
                                }
                                else
                                {
                                    _To = updateItem.AssignUser;
                                }
                                _Subject = "Gentle Reminder"; // + updateItem.ExpVoucherNo + " Travel Voucher Approval is Pending
                                _Body   += "Dear User, <br><br>This is to inform you that below request is pending for your Approval.";
                                _Body   += "<br><b>Workflow Name :</b> Expense Voucher ";
                                _Body   += "<br><b>Voucher No :</b>  " + updateItem.ExpVoucherNo;
                                _Body   += "<br><b>Date of Creation :</b>  " + updateItem.CreationDate;
                                _Body   += "<br><b>Employee : </b> " + updateItem.CreatorName;
                                _Body   += "<br><b>Designation :</b> " + updateItem.Designation;

                                _Body += "<br><b>Department :</b> " + updateItem.CreatorDepartment;
                                _Body += "<br><b>Location :</b> " + updateItem.CreatorLocation;
                                if (updateItem.SequenceNo == "1")
                                {
                                    _Body += "<br><b>Status :</b> Pending With Functional Head";
                                }
                                else if (updateItem.SequenceNo == "2")
                                {
                                    _Body += "<br><b>Status :</b> Pending With Intenal Audit";
                                }
                                else if (updateItem.SequenceNo == "3")
                                {
                                    _Body += "<br><b>Status :</b> Pending With Accounts";
                                }

                                _Body += "<br><h3>Kindly provide your approval</h3>";
                                _Body += "<br><h3>For Approval Please Click in the below link</h3>";

                                if (updateItem.SequenceNo == "1")
                                {
                                    _Body += "<br><a href=\"https://aparindltd.sharepoint.com/ExpenseVoucher/SitePages/PendingFunctionalHead.aspx\">View Link</a>";
                                }
                                else if (updateItem.SequenceNo == "2")
                                {
                                    _Body += "<br><a href=\"https://aparindltd.sharepoint.com/ExpenseVoucher/SitePages/Pending%20Request.aspx\">View Link</a>";
                                }
                                else if (updateItem.SequenceNo == "3")
                                {
                                    _Body += "<br><a href=\"https://aparindltd.sharepoint.com/ExpenseVoucher/SitePages/PendingRequestAccounts.aspx\">View Link</a>";
                                }

                                //data.MailTo = _From;
                                //data.MailTo = _To;
                                //data.MailCC = _Cc;
                                //data.MailSubject = _Subject;
                                //data.MailBody = _Body;
                                //varx.Add(data);
                                listItem["ToUser"]      = _To;
                                listItem["SubjectDesc"] = _Subject;
                                listItem["BodyDesc"]    = _Body;
                                listItem.Update();
                            }
                            try
                            {
                                context.ExecuteQuery();
                                retValue = true;
                            }
                            catch (Exception ex)
                            {
                                CustomSharePointUtility.WriteLog(string.Format("Error in  InsertUpdate_EmployeeMaster ( context.ExecuteQuery();): Error ({0}) ", ex.Message));
                                return(false);
                                //continue;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                CustomSharePointUtility.WriteLog(string.Format("Error in  InsertUpdate_EmployeeMaster: Error ({0}) ", ex.Message));
            }
            return(retValue);
        }
        //public static void sample()
        //{
        //    List<TravelVoucher> data = new List<TravelVoucher>();
        //  List<Mailing> mail=EmailData(data, "", "");
        //}

        public static bool EmailData(List <ManpowerRequisition> updationList, string siteUrl, string listName)
        {
            bool retValue = false;

            try
            {
                using (MSC.ClientContext context = CustomSharePointUtility.GetContext(siteUrl))
                {
                    //List<Mailing> varx = new List<Mailing>();

                    MSC.List list = context.Web.Lists.GetByTitle(listName);
                    for (var i = 0; i < updationList.Count; i++)
                    {
                        var updateList = updationList.Skip(i).Take(1).ToList();
                        if (updateList != null && updateList.Count > 0)
                        {
                            foreach (var updateItem in updateList)
                            {
                                MSC.ListItem listItem = null;

                                MSC.ListItemCreationInformation itemCreateInfo = new MSC.ListItemCreationInformation();
                                listItem = list.AddItem(itemCreateInfo);

                                var obj = new Object();
                                //Mailing data = new Mailing();

                                //var _From = "";
                                var _To = "";
                                //var _Cc = "";
                                var _Body    = "";
                                var _Subject = "";
                                if (updateItem.Status == "Pending With Functional Head")
                                {
                                    // _To = updateItem.FunctionalHead;
                                    _To = updateItem.CurrentApprover;
                                    if (_To == "")
                                    {
                                        break;
                                    }
                                }
                                else if (updateItem.Status == "Pending With HR Head")
                                {
                                    _To = updateItem.HRHead;
                                }
                                else if (updateItem.Status == "Confirmed By MD And Back to HR Head")
                                {
                                    _To = updateItem.HRHeadOnly;
                                }
                                else if (updateItem.Status == "Pending With MD")
                                {
                                    _To = updateItem.MDorJMD;
                                }
                                else if (updateItem.Status == "Pending With Recruiter")
                                {
                                    _To = updateItem.Recruiter;
                                }
                                _Subject = "Gentle Reminder"; // + updateItem.ExpVoucherNo + " Travel Voucher Approval is Pending
                                _Body   += "Dear User, <br><br>This is to inform you that below request is pending for your Approval.";
                                _Body   += "<br><b>Workflow Name :</b> Manpower Requisition ";
                                _Body   += "<br><b>Voucher No :</b>  " + updateItem.RequisitionNumber;
                                _Body   += "<br><b>Date of Creation :</b>  " + updateItem.CreatedTime;
                                _Body   += "<br><b>Employee : </b> " + updateItem.Author;
                                _Body   += "<br><b>Designation :</b> " + updateItem.Designation;
                                _Body   += "<br><b>Department :</b> " + updateItem.Department;
                                _Body   += "<br><b>Budgeted / Replacement Additional:</b> " + updateItem.AdditionalBudgets;
                                _Body   += "<br><b>Location :</b> " + updateItem.CreatorLocation;
                                _Body   += "<br><b>Replacement of :</b> " + updateItem.ReplacementEmployeeName;

                                if (updateItem.Status == "Pending With Functional Head")
                                {
                                    _Body += "<br><b>Pending With  :</b> " + updateItem.CurrentApproverName;
                                }
                                else if (updateItem.Status == "Pending With HR Head")
                                {
                                    _Body += "<br><b>Pending With  :</b> " + updateItem.HRHeadName;
                                }
                                else if (updateItem.Status == "Confirmed By MD And Back to HR Head")
                                {
                                    _Body += "<br><b>Pending With  :</b> " + updateItem.HRHeadOnlyName;
                                }
                                else if (updateItem.Status == "Pending With MD")
                                {
                                    _Body += "<br><b>Pending With  :</b> " + updateItem.MDorJMDName;
                                }
                                else if (updateItem.Status == "Pending With Recruiter")
                                {
                                    _Body += "<br><b>Pending With  :</b> " + updateItem.RecruiterName;
                                }


                                _Body += "<br><h3>Kindly provide your approval</h3>";
                                _Body += "<br><h3>For Approval Please Click in the below link</h3>";
                                if (updateItem.Status == "Pending With Functional Head")
                                {
                                    _Body += "<br><a href=\"https://aparindltd.sharepoint.com/ManpowerRequisition/SitePages/Pending%20With%20Functional%20Head.aspx\">View Link</a>";
                                }
                                else if (updateItem.Status == "Pending With HR Head")
                                {
                                    _Body += "<br><a href=\"https://aparindltd.sharepoint.com/ManpowerRequisition/SitePages/Pending%20With%20HR%20Head.aspx\">View Link</a>";
                                }
                                else if (updateItem.Status == "Confirmed By MD And Back to HR Head")
                                {
                                    _Body += "<br><a href=\"https://aparindltd.sharepoint.com/ManpowerRequisition/SitePages/Pending%20With%20HR%20Head.aspx\">View Link</a>";
                                }
                                else if (updateItem.Status == "Pending With MD")
                                {
                                    _Body += "<br><a href=\"https://aparindltd.sharepoint.com/ManpowerRequisition/SitePages/Pending%20With%20MD.aspx\">View Link</a>";
                                }
                                else if (updateItem.Status == "Pending With Recruiter")
                                {
                                    _Body += "<br><a href=\"https://aparindltd.sharepoint.com/ManpowerRequisition/SitePages/Pending%20With%20Recruiter.aspx\">View Link</a>";
                                }



                                listItem["ToUser"]      = _To;
                                listItem["SubjectDesc"] = _Subject;
                                listItem["BodyDesc"]    = _Body;
                                listItem.Update();
                            }
                            try
                            {
                                context.ExecuteQuery();
                                retValue = true;
                            }
                            catch (Exception ex)
                            {
                                CustomSharePointUtility.WriteLog(string.Format("Error in  InsertUpdate_EmployeeMaster ( context.ExecuteQuery();): Error ({0}) ", ex.Message));
                                return(false);
                                //continue;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                CustomSharePointUtility.WriteLog(string.Format("Error in  InsertUpdate_EmployeeMaster: Error ({0}) ", ex.Message));
            }
            return(retValue);
        }