1,881 views(since 2013/10/08)

2つ以上のList更新する方法(Client Object Model, Sharepoint Online(Office365), Silverlight, C#)

2つ以上のListの更新をする場合や削除してから追加する場合は少し複雑になりますのでサンプルを作ってみました。

以下の画面から検索ボタン(検索処理)を押したときの処理

以下の画面から保存ボタン(更新処理)、アイテム削除ボタン(削除処理)

削除処理、検索処理、更新処理のクラスです。

Adapter_CQuotation.cs

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using SP = Microsoft.SharePoint.Client;
using System.Collections.ObjectModel;

using System.Xml.Serialization;
using SilverlightProjectMain.Models.SharepointClient.Base;

namespace SilverlightProjectMain.Models.SharepointClient
{

    public class Adapter_CQuotation : Adapter_Base0100
    {
        ////////////////////////////////////////////////////////////////////////////
        ///  削除処理
        ////////////////////////////////////////////////////////////////////////////
        static public void AsyncDelete(Adapter_EventHandler adapter_EventHandler, int nID)
        {
            using (var clientContext = new SP.ClientContext(SP.ApplicationContext.Current.Url))
            {
                var list = clientContext.Web.Lists.GetByTitle("List_Quotation");
                //clientContext.Load(list);

                //削除処理
                SP.ListItem listItem = list.GetItemById(nID);
                listItem.DeleteObject();

                SP.ListItemCollection listItemsDetail = null;

                //明細行取得
                var listDetail = clientContext.Web.Lists.GetByTitle("List_QuotationDetail001");
                string strWhere = "<Where><Eq><FieldRef Name='PersonID' /><Value Type='Integer'>" + nID.ToString() + "</Value></Eq></Where>";
                listItemsDetail = GetItemsFromCAMLQuery(listDetail, strWhere);
                clientContext.Load(listItemsDetail);

                clientContext.ExecuteQueryAsync(
                    new SP.ClientRequestSucceededEventHandler(delegate(object o, SP.ClientRequestSucceededEventArgs successargs)
                    {
                        try
                        {
                            //明細行削除
                            {
                                foreach (var li in listItemsDetail)
                                {
                                    SP.ListItem item = listDetail.GetItemById(li.Id);
                                    item.DeleteObject();
                                }
                            }

                            clientContext.ExecuteQueryAsync(
                                    new SP.ClientRequestSucceededEventHandler(delegate(object o3, SP.ClientRequestSucceededEventArgs successargs3)
                                    {
                                        adapter_EventHandler(true, null);
                                    }),
                                    new SP.ClientRequestFailedEventHandler(delegate(object o3, SP.ClientRequestFailedEventArgs failedArgs)
                                    {
                                        adapter_EventHandler(false, new Exception(failedArgs.ErrorDetails + "   " + failedArgs.Message));
                                    }));
                        }
                        catch (Exception ex2)
                        {
                            adapter_EventHandler(false, ex2);
                        }

                    }),
                    new SP.ClientRequestFailedEventHandler(delegate(object o, SP.ClientRequestFailedEventArgs failedArgs)
                    {
                        adapter_EventHandler(false, new Exception(failedArgs.ErrorDetails + "   " + failedArgs.Message));
                    })
                );
            }
        }

        ////////////////////////////////////////////////////////////////////////////
        ///  取得処理
        ////////////////////////////////////////////////////////////////////////////
        //IDで検索(SPList.GetItemById)
        static public void AsyncDownload(Adapter_EventHandlerCollection<CQuotation, CQuotationDetail001> adapter_EventHandler, int nID)
        {
            AsyncDownload_Sub(adapter_EventHandler, SearchType.ID, nID, string.Empty);
        }

        //全件検索(SP.CamlQuery)
        static public void AsyncDownload(Adapter_EventHandlerCollection<CQuotation, CQuotationDetail001> adapter_EventHandler)
        {
            AsyncDownload_Sub(adapter_EventHandler, SearchType.All, int.MinValue, string.Empty);
        }

        //検索キーワードを含む(SP.CamlQuery)
        static public void AsyncDownload(Adapter_EventHandlerCollection<CQuotation, CQuotationDetail001> adapter_EventHandler, string strCustomerName)
        {
            AsyncDownload_Sub(adapter_EventHandler, SearchType.Type001, int.MinValue, strCustomerName);
        }

        static private void AsyncDownload_Sub(Adapter_EventHandlerCollection<CQuotation, CQuotationDetail001> adapter_EventHandler, SearchType searchType, int nID, string strCustomerName)
        {
            using (var clientContext = new SP.ClientContext(SP.ApplicationContext.Current.Url))
            {
                SP.List list = clientContext.Web.Lists.GetByTitle("List_Quotation");
                SP.List listDetail = null;

                //load不要
                //clientContext.Load(list);

                SP.ListItem listItem = null;
                SP.ListItemCollection listItems = null;

                SP.ListItemCollection listItemsDetail = null;

                string strWhere = string.Empty;
                string strOrderBy = string.Empty;

                switch (searchType)
                {
                    //IDで検索(SPList.GetItemById)
                    case SearchType.ID:
                        listItem = list.GetItemById(nID);

                        //明細行取得
                        listDetail = clientContext.Web.Lists.GetByTitle("List_QuotationDetail001");
                        strWhere = "<Where><Eq><FieldRef Name='PersonID' /><Value Type='Integer'>" + nID.ToString() + "</Value></Eq></Where>";
                        strOrderBy = "<OrderBy><FieldRef Name=\"No\"></FieldRef></OrderBy>";
                        listItemsDetail = GetItemsFromCAMLQuery(listDetail, strWhere, strOrderBy);
                        clientContext.Load(listItemsDetail);
                        break;

                    //全件検索(SP.CamlQuery)
                    case SearchType.All:
                        listItems = GetItemsFromCAMLQuery(list);
                        break;

                    //検索キーワードを含む(SP.CamlQuery)
                    case SearchType.Type001:
                        //完全一致;    column =‘SearchWord’
                        //listItems = GetItemsFromCAMLQuery(list, "<Where><Eq><FieldRef Name='CustomerName' /><Value Type='Text'>" + strCustomerName + "</Value></Eq></Where>");

                        //検索キーワードを含む: column like ‘%SearchWord%’
                        strWhere = "<Where><Contains><FieldRef Name='CustomerName' /><Value Type='Text'>" + strCustomerName + "</Value></Contains></Where>";
                        listItems = GetItemsFromCAMLQuery(list, strWhere);
                        break;
                    default:
                        throw new Exception("存在しないSearchTypeです。SearchType=" + searchType.ToString());
                        break;
                }

                if (SearchType.ID == searchType)
                {
                    //IDで検索(SPList.GetItemById)
                    clientContext.Load(listItem);

                }
                else
                {
                    //全件検索(SP.CamlQuery)
                    //検索キーワードを含む(SP.CamlQuery)
                    clientContext.Load(listItems);
                }

                clientContext.ExecuteQueryAsync(
                    new SP.ClientRequestSucceededEventHandler(delegate(object o, SP.ClientRequestSucceededEventArgs successargs)
                    {
                        var oc_CQuotations = new System.Collections.ObjectModel.ObservableCollection<CQuotation>();

                        if (SearchType.ID == searchType)
                        {
                            //IDで検索(SPList.GetItemById)
                            addObservableCollection(oc_CQuotations, listItem);

                            //明細を取得する。
                            var oc_CQuotationDetail001s = new System.Collections.ObjectModel.ObservableCollection<CQuotationDetail001>();

                            //全件検索(SP.CamlQuery)
                            //検索キーワードを含む(SP.CamlQuery)
                            foreach (var li in listItemsDetail)
                            {
                                addObservableCollection(oc_CQuotationDetail001s, li);
                            }

                            adapter_EventHandler(true, null, oc_CQuotations, oc_CQuotationDetail001s);

                        }
                        else
                        {
                            //全件検索(SP.CamlQuery)
                            //検索キーワードを含む(SP.CamlQuery)
                            foreach (var li in listItems)
                            {
                                addObservableCollection(oc_CQuotations, li);
                            }
                            adapter_EventHandler(true, null, oc_CQuotations, null);
                        }
                    }),
                    new SP.ClientRequestFailedEventHandler(delegate(object o, SP.ClientRequestFailedEventArgs failedArgs)
                    {
                        adapter_EventHandler(false, new Exception(failedArgs.ErrorDetails + "   " + failedArgs.Message), null, null);
                    })
                );
            }

        }

        static private void AsyncDownload_Sub_Detail001(Adapter_EventHandlerCollection<CQuotationDetail001> adapter_EventHandler, int nID)
        {
            try
            {
                using (var clientContext = new SP.ClientContext(SP.ApplicationContext.Current.Url))
                {
                    var list = clientContext.Web.Lists.GetByTitle("List_QuotationDetail001");

                    var strWhere = "<Where><Eq><FieldRef Name='PersonID' /><Value Type='Integer'>" + nID.ToString() + "</Value></Eq></Where>";
                    var strOrderBy = "<OrderBy><FieldRef Name='ID'></FieldRef></OrderBy>";

                    var listItems = GetItemsFromCAMLQuery(list, strWhere, strOrderBy);
                    clientContext.Load(listItems);

                    clientContext.ExecuteQueryAsync(
                        new SP.ClientRequestSucceededEventHandler(delegate(object o, SP.ClientRequestSucceededEventArgs successargs)
                        {
                            try
                            {
                                var oc_CQuotationDetail001s = new System.Collections.ObjectModel.ObservableCollection<CQuotationDetail001>();

                                //全件検索(SP.CamlQuery)
                                //検索キーワードを含む(SP.CamlQuery)
                                foreach (var li in listItems)
                                {
                                    addObservableCollection(oc_CQuotationDetail001s, li);
                                }

                                adapter_EventHandler(true, null, oc_CQuotationDetail001s);
                            }
                            catch (Exception ex2)
                            {
                                adapter_EventHandler(false, ex2, null);
                            }

                        }),
                        new SP.ClientRequestFailedEventHandler(delegate(object o, SP.ClientRequestFailedEventArgs failedArgs)
                        {
                            adapter_EventHandler(false, new Exception(failedArgs.ErrorDetails + "   " + failedArgs.Message), null);
                        })
                    );
                }
            }
            catch (Exception ex2)
            {
                adapter_EventHandler(false, ex2, null);
            }

        }

        static private void addObservableCollection(System.Collections.ObjectModel.ObservableCollection<CQuotation> oc_CQuotations, SP.ListItem listItem)
        {
            oc_CQuotations.Add(new CQuotation()
            {
                ID = (int)listItem["ID"],
                Approved = (bool)listItem["Approved"],
                InvoiceID = Static_Common.ListItemToString(listItem["InvoiceID"]),
                CustomerName = Static_Common.ListItemToString(listItem["CustomerName"]),
                CreateDate = Static_Common.ListItemToDateTime(listItem["CreateDate"]),
                Subject1 = Static_Common.ListItemToString(listItem["Subject1"]),
                Subject2 = Static_Common.ListItemToString(listItem["Subject2"]),
                Other1 = Static_Common.ListItemToString(listItem["Other1"]),
                Other2 = Static_Common.ListItemToString(listItem["Other2"]),
                Subtotal = Static_Common.ListItemToDecimal(listItem["SubTotal"]),
                ConsumptionTax = Static_Common.ListItemToDecimal(listItem["ConsumptionTax"]),
                TotalAmount = Static_Common.ListItemToDecimal(listItem["TotalAmount"]),
                //RowData = Static_Common.ListItemToString(listItem["RowData"]),
                Memo = Static_Common.ListItemToString(listItem["Memo"]),
            });

        }
        static private void addObservableCollection(System.Collections.ObjectModel.ObservableCollection<CQuotationDetail001> oc_CQuotationDetail001, SP.ListItem listItem)
        {
            oc_CQuotationDetail001.Add(new CQuotationDetail001()
            {
                ID = (int)listItem["ID"],
                PersonID = Static_Common.ListItemToInt(listItem["PersonID"]),
                No = Static_Common.ListItemToInt(listItem["No"]),
                Desc01 = Static_Common.ListItemToString(listItem["Desc01"]),
                Quantity = Static_Common.ListItemToInt(listItem["Quantity"]),
                unit = Static_Common.ListItemToString(listItem["unit"]),
                StandardPrice = Static_Common.ListItemToDecimal(listItem["StandardPrice"]),
                SalesPrice = Static_Common.ListItemToDecimal(listItem["SalesPrice"]),
                Amount = Static_Common.ListItemToDecimal(listItem["Amount"]),
                Memo = Static_Common.ListItemToString(listItem["Memo"]),
            });

        }

        ////////////////////////////////////////////////////////////////////////////
        ///  更新処理
        ////////////////////////////////////////////////////////////////////////////

        //明細行を削除・追加するために現在の明細行を取得する。
        static private SP.ListItemCollection _listItemsDetail = null;

        static public void AsyncUpload(Adapter_EventHandler<int> adapter_EventHandler, int nID, CQuotation cQuotation, ObservableCollection<CQuotationDetail001> oc_CQuotationDetail001)
        {
            using (var clientContext = new SP.ClientContext(SP.ApplicationContext.Current.Url))
            {
                SP.ListItem _listItem = null;
                //新規or更新
                {
                    var list = clientContext.Web.Lists.GetByTitle("List_Quotation");
                    //clientContext.Load(list);

                    if (0 == nID)
                    {
                        _listItem = list.AddItem(new SP.ListItemCreationInformation());
                    }
                    else
                    {
                        _listItem = list.GetItemById(nID);
                    }

                    _listItem["Approved"] = cQuotation.Approved;

                    _listItem["InvoiceID"] = cQuotation.InvoiceID;
                    _listItem["CustomerName"] = cQuotation.CustomerName;

                    _listItem["CreateDate"] = cQuotation.CreateDate;

                    _listItem["Subject1"] = cQuotation.Subject1;
                    _listItem["Subject2"] = cQuotation.Subject2;
                    _listItem["Other1"] = cQuotation.Other1;
                    _listItem["Other2"] = cQuotation.Other2;

                    _listItem["SubTotal"] = 0;
                    _listItem["ConsumptionTax"] = 0;
                    _listItem["TotalAmount"] = 0;

                    //_listItem["RowData"] = cQuotation.RowData;
                    _listItem["Memo"] = cQuotation.Memo;

                    _listItem.Update();

                    //Load GetItemByIdで取得したときには必要
                    clientContext.Load(_listItem);
                }

                //明細行取得
                {
                    var list = clientContext.Web.Lists.GetByTitle("List_QuotationDetail001");
                    clientContext.Load(list);
                    var strWhere = "<Where><Eq><FieldRef Name='PersonID' /><Value Type='Integer'>" + nID.ToString() + "</Value></Eq></Where>";
                    _listItemsDetail = GetItemsFromCAMLQuery(list, strWhere);
                    clientContext.Load(_listItemsDetail);

                }

                clientContext.ExecuteQueryAsync(
                    new SP.ClientRequestSucceededEventHandler(delegate(object o, SP.ClientRequestSucceededEventArgs successargs)
                    {
                        int nNewID = 0;
                        try
                        {
                            nNewID = _listItem.Id;
                            //明細行を取得する。
                            AsyncUpload_Sub_Detail001(
                                new Adapter_EventHandler(delegate(bool IsSuccess, Exception e2)
                                {
                                    adapter_EventHandler(IsSuccess, e2, nNewID);
                                }),
                                nNewID,
                                oc_CQuotationDetail001);
                        }
                        catch (Exception ex2)
                        {
                            adapter_EventHandler(false, ex2, nNewID);
                        }
                    }),
                    new SP.ClientRequestFailedEventHandler(delegate(object o, SP.ClientRequestFailedEventArgs failedArgs)
                    {
                        adapter_EventHandler(false, new Exception(failedArgs.ErrorDetails + "   " + failedArgs.Message), 0);
                    }));
            }
        }
        static private void AsyncUpload_Sub_Detail001(Adapter_EventHandler adapter_EventHandler, int nID, ObservableCollection<CQuotationDetail001> oc_CQuotationDetail001)
        {
            try
            {
                using (var clientContext = new SP.ClientContext(SP.ApplicationContext.Current.Url))
                {
                    var list = clientContext.Web.Lists.GetByTitle("List_QuotationDetail001");
                    //clientContext.Load(list);

                    //明細行削除
                    {
                        foreach (var li in _listItemsDetail)
                        {
                            SP.ListItem item = list.GetItemById(li.Id);
                            item.DeleteObject();
                        }
                    }

                    //明細行追加
                    {
                        SP.ListItem item = null;
                        for (int i = 0; i < oc_CQuotationDetail001.Count; i++)
                        {
                            item = list.AddItem(new SP.ListItemCreationInformation());
                            item["PersonID"] = nID;
                            item["No"] = oc_CQuotationDetail001[i].No;
                            item["Desc01"] = oc_CQuotationDetail001[i].Desc01;
                            item["Quantity"] = oc_CQuotationDetail001[i].Quantity;
                            item["unit"] = oc_CQuotationDetail001[i].unit;
                            item["StandardPrice"] = oc_CQuotationDetail001[i].StandardPrice;
                            item["SalesPrice"] = oc_CQuotationDetail001[i].SalesPrice;
                            item["Amount"] = oc_CQuotationDetail001[i].Amount;
                            item["Memo"] = oc_CQuotationDetail001[i].Memo;
                            item.Update();
                        }
                    }

                    clientContext.ExecuteQueryAsync(
                            new SP.ClientRequestSucceededEventHandler(delegate(object o3, SP.ClientRequestSucceededEventArgs successargs3)
                            {
                                adapter_EventHandler(true, null);
                            }),
                            new SP.ClientRequestFailedEventHandler(delegate(object o3, SP.ClientRequestFailedEventArgs failedArgs)
                            {
                                adapter_EventHandler(false, new Exception(failedArgs.ErrorDetails + "   " + failedArgs.Message));
                            }));

                }
            }
            catch (Exception ex2)
            {
                adapter_EventHandler(false, ex2);
            }

        }

    }

    // 表示するためのデータのクラス

    public class CQuotation : CData
    {
        public bool Approved { get; set; }
        [XmlElement(IsNullable = true)]//Nullデータの場合でもタグが省略されないようにする。
        public string InvoiceID { get; set; }
        [XmlElement(IsNullable = true)]//Nullデータの場合でもタグが省略されないようにする。
        public string CustomerName { get; set; }
        public DateTime CreateDate { get; set; }
        [XmlElement(IsNullable = true)]//Nullデータの場合でもタグが省略されないようにする。
        public string Subject1 { get; set; }
        [XmlElement(IsNullable = true)]//Nullデータの場合でもタグが省略されないようにする。
        public string Subject2 { get; set; }
        [XmlElement(IsNullable = true)]//Nullデータの場合でもタグが省略されないようにする。
        public string Other1 { get; set; }
        [XmlElement(IsNullable = true)]//Nullデータの場合でもタグが省略されないようにする。
        public string Other2 { get; set; }
        public decimal Subtotal { get; set; }
        public decimal ConsumptionTax { get; set; }
        public decimal TotalAmount { get; set; }
        //public string RowData { get; set; } 
        [XmlElement(IsNullable = true)]//Nullデータの場合でもタグが省略されないようにする。
        public string Memo { get; set; } 
    }

    // 表示するためのデータのクラス
    public class CQuotationDetail001 : CData
    {
        public int PersonID { get; set; }
        public int No { get; set; }
        [XmlElement(IsNullable = true)]//Nullデータの場合でもタグが省略されないようにする。
        public string Desc01 { get; set; }
        public decimal Quantity { get; set; }
        [XmlElement(IsNullable = true)]//Nullデータの場合でもタグが省略されないようにする。
        public string unit { get; set; }
        public decimal StandardPrice { get; set; }
        public decimal SalesPrice { get; set; }
        public decimal Amount { get; set; }
        [XmlElement(IsNullable = true)]//Nullデータの場合でもタグが省略されないようにする。
        public string Memo { get; set; }
    }
}

Adapter_Base0100.cs (Baseクラス)

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using SP = Microsoft.SharePoint.Client;
using System.Collections.ObjectModel;

namespace SilverlightProjectMain.Models.SharepointClient.Base
{
    //デリゲート
    public delegate void Adapter_EventHandler(bool IsSuccess, Exception e);
    public delegate void Adapter_EventHandler<Type>(bool IsSuccess, Exception e, Type typeData);
    public delegate void Adapter_EventHandlerCollection<Type>(bool IsSuccess, Exception e, System.Collections.ObjectModel.ObservableCollection<Type> observableCollection);
    public delegate void Adapter_EventHandlerCollection<Type1, Type2>(bool IsSuccess, Exception e, System.Collections.ObjectModel.ObservableCollection<Type1> observableCollection1, System.Collections.ObjectModel.ObservableCollection<Type2> observableCollection2);

    public class CData
    {
        public int ID { get; set; }
    }

    public class Adapter_Base0100
    {
        protected enum SearchType
        {
            ID,
            All,
            Type001,
            Type002,
            Type003,
            Type004,
            Type005
        }
        protected const int DEFAULT_ROWLIMIT = 30;

        //Sample 動作OKのCAML
        //var camlQuery = new SP.CamlQuery();
        //camlQuery.ViewXml = "<View><Query><Where><Eq><FieldRef Name='ID' /><Value Type='Integer'>1</Value></Eq></Where></Query></View>";
        //camlQuery.ViewXml = "<View><Query><Where><Eq><FieldRef Name='CustomerName' /><Value Type='Text'>111</Value></Eq></Where></Query></View>";
        //camlQuery.ViewXml = "<View><Query><Where><Contains><FieldRef Name='CustomerName' /><Value Type='Text'>111</Value></Contains></Where></Query></View>";

        //その他キーワード(StartWith, In)

        //listItems = list.GetItems(camlQuery);
        //clientContext.Load(listItems);

        static protected SP.ListItemCollection GetItemsFromCAMLQuery(SP.List list)
        {
            return GetItemsFromCAMLQuery(list, "", "");
        }
        static protected SP.ListItemCollection GetItemsFromCAMLQuery(SP.List list, string strWhere)
        {
            return GetItemsFromCAMLQuery(list, strWhere, "");
        }
        static protected SP.ListItemCollection GetItemsFromCAMLQuery(SP.List list, string strWhere, string strOrderBy)
        {
            var camlQuery = new SP.CamlQuery();

            string strTemp = "<View>";
            strTemp += "<Query>" + strWhere + "</Query> ";
            strTemp += "<RowLimit>" + DEFAULT_ROWLIMIT.ToString() + "</RowLimit>";
            strTemp += strOrderBy;
            strTemp += "</View>";

            camlQuery.ViewXml  = strTemp;
            return list.GetItems(camlQuery);
        }

    }

}

StaticCommon.cs

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using Microsoft.SharePoint.Client;
using SP = Microsoft.SharePoint.Client;
using System.Collections.ObjectModel;

namespace SilverlightProjectMain
{
    public static class Static_Common
    {

        //シリアル化
        public static string XmlSerializeToString(this object objectInstance)
        {
            var serializer = new System.Xml.Serialization.XmlSerializer(objectInstance.GetType());
            var sb = new System.Text.StringBuilder();

            using (System.IO.TextWriter writer = new System.IO.StringWriter(sb))
            {
                serializer.Serialize(writer, objectInstance);
            }

            return sb.ToString();
        }

        public static T XmlDeserializeFromString<T>(string objectData)
        {
            return (T)XmlDeserializeFromString(objectData, typeof(T));
        }

        private static object XmlDeserializeFromString(string objectData, Type type)
        {
            var serializer = new System.Xml.Serialization.XmlSerializer(type);
            object result;

            using (System.IO.TextReader reader = new System.IO.StringReader(objectData))
            {
                result = serializer.Deserialize(reader);
            }

            return result;
        }

        static public int ListItemToInt(object objectData)
        {
            if (null == objectData)
            {
                return 0;
            }
            else
            {
                return int.Parse(objectData.ToString());
            }
        }

        static public string ListItemToString(object objectData)
        {
            if (null == objectData)
            {
                return "";
            }
            else
            {
                return objectData.ToString();
            }
        }
        static public decimal ListItemToDecimal(object objectData)
        {
            if (null == objectData)
            {
                return 0;
            }
            else
            {
                return Decimal.Parse(objectData.ToString());
            }
        }
        static public DateTime ListItemToDateTime(object objectData)
        {
            if (null == objectData)
            {
                throw new Exception("Error; ListItemToDateTime; Data is Null");
            }
            else
            {
                return (DateTime)objectData;
            }
        }

        static public void ThrowExceptionBeginInvoke(Control control, bool IsSuccess, Exception e)
        {
            if (!IsSuccess)
            {
                //WIndows のイベントでないときに(例:コールバック)throwすると app.xaml.csでエラーウインドウがよびだせなくなる。
                control.Dispatcher.BeginInvoke(new Action(delegate() { throw e; }), null);
            }

        }
        static public void ThrowExceptionBeginInvoke(Control control, Exception ex)
        {
            //WIndows のイベントでないときに(例:コールバック)throwすると app.xaml.csでエラーウインドウがよびだせなくなる。
            control.Dispatcher.BeginInvoke(new Action(delegate() { throw ex; }), null);
        }

        static public Boolean ShowYesCancel(Control control, string strMesage)
        {
            MessageBoxResult result = MessageBox.Show(strMesage, Define.APPLICTION_TITLENAME, MessageBoxButton.OKCancel);

            if (MessageBoxResult.OK == result)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        static public void ShowNormal(Control control, string strMesage)
        {
            control.Dispatcher.BeginInvoke(new Action(delegate() { MessageBox.Show(strMesage, Define.APPLICTION_TITLENAME, MessageBoxButton.OK); }), null);
        }

        static public void EnableControlBeginInvoke(Control control, bool IsEnabled)
        {
            control.Dispatcher.BeginInvoke(new Action(delegate() { control.IsEnabled = IsEnabled; }), null);
        }
    }
}

Filed Under: Office365 App

About the Author

野呂清二(ご連絡はこちらまで (http://www.exceedone.co.jp/inquiry/)

Leave a Reply




If you want a picture to show with your comment, go get a Gravatar.