using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TestKendoMenu.Models;
using Kendo.Mvc.Extensions;
using Kendo.Mvc.UI;
using System.IO;
using System.Data.OleDb;
using System.Data;
using System.Xml.Serialization;
using System.Xml;
using System.Globalization;

namespace TestKendoMenu.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/
        private T DeserializeObject<T>(string filename)
        {

            // Create an instance of the XmlSerializer specifying type and namespace.
            XmlSerializer serializer = new
            XmlSerializer(typeof(T));

            // A FileStream is needed to read the XML document.
            FileStream fs = new FileStream(filename, FileMode.Open);
            XmlReader reader = XmlReader.Create(fs);

            // Declare an object variable of the type to be deserialized.
            T i =            // Use the Deserialize method to restore the object's state.
                (T)serializer.Deserialize(reader);
            fs.Close();

            return i;
        }

        protected class DataType
        {
            public int Value { set; get; }
            public string Text { set; get; }

        }

        public ActionResult InterestCalculationWZ()
        {
            InterfaceModel iii = new InterfaceModel();

            string savedFileName = Path.Combine(Server.MapPath("~/App_Data"), Path.GetFileName("interfaceModel.xml"));

            List<DataType> monthNames = new List<DataType>();

            var culture = CultureInfo.GetCultureInfo("he-IL");
            DateTimeFormatInfo mi = DateTimeFormatInfo.GetInstance(culture);

            string[] names = mi.MonthNames;
            int counter = 1;
            foreach (string item in names)
            {
                if (item.Trim().Length != 0)
                {
                    DataType c = new DataType { Value = counter++, Text = item };
                    monthNames.Add(c);
                }

            }

            ViewBag.MonthNames = monthNames;

            iii = DeserializeObject<InterfaceModel>(savedFileName);


            // Send interface data
            return PartialView(iii);
        }

        public PartialViewResult DatePicker()
        {
            return PartialView();
        }
        public PartialViewResult ChooseInterface(int actionType)
        {

            ViewData["ActionType"] = actionType;
            //return PartialView(InterfaceDBManager.GetInterfaceListWithModel());
            return PartialView(new List<InterfaceModel>());


        }

        [OutputCache(Duration = 0, NoStore = true)]
        public ActionResult ReadInterfaceListView([DataSourceRequest] DataSourceRequest request)
        {

            var ifs = new List<InterfaceModel>() { new InterfaceModel { InterfaceId = 1, InterfaceName = "Testing", ViewName = "FileExportWizard" } };

            return Json(ifs.ToDataSourceResult(request));

        }

        public ActionResult Index()
        {

            return View();
        }

    }
}
