public bool createCustomer(object[] newData)
        {
            int serviceNo = 9999;
            bool hasService = false;

                //prepare inputdata for ServiceContract creation
                object[] serviceInput = new object[3];
                serviceInput[0] = newData[9];
                serviceInput[1] = newData[13];
                serviceInput[2] = newData[10];

                serviceNo = createServiceContract(serviceInput);

                hasService = true;

            using (servicebaseEntities cc = new servicebaseEntities())
            {
                try
                {
                    customers c = new customers();
                    c.cname = newData[0].ToString();
                    c.street = newData[1].ToString();
                    c.city = newData[2].ToString();
                    c.postcode = (int)newData[3];
                    c.email = newData[4].ToString();
                    c.phone = newData[5].ToString();
                    c.panelcount = newData[6].ToString();
                    c.color = newData[7].ToString();
                    c.inverter = newData[8].ToString();
                    c.paneltype = (String)newData[14];
                    c.serviceno = serviceNo;
                    c.hasservice = hasService;

                    cc.customers.Add(c);

                }
                catch
                {

                }
                cc.SaveChanges();
            }
            return true;
        }
        public int createServiceContract(object[] serviceData)
        {
            int lastSID = new int();
            int serviceContractID = new int();
            int serviceID = (Int32)serviceData[0];
            servicetypes selectedService = null;

                //Get numbers of servicecontract in DB
                using (servicebaseEntities lc = new servicebaseEntities())
                {
                    var query = (from l in lc.servicecontracts
                                     select l.sid).Count();
                    lastSID = query;

                    var query1 = (from st in lc.servicetypes
                                 where st.tid == serviceID
                                 select st).SingleOrDefault();
                    selectedService = query1;

                //calc enddate on selected service
                DateTime startDate = (DateTime)serviceData[2];
                DateTime endDate = startDate.AddMonths(selectedService.period);
                DateTime timeStamp = DateTime.Now.Date;
                serviceContractID = Convert.ToInt32(DateTime.Now.Year.ToString() + DateTime.Now.DayOfYear.ToString() + lastSID.ToString());

                    servicecontracts sc = new servicecontracts();
                    sc.sid = serviceContractID;
                    sc.servicetype = (Int32)serviceData[0];
                    sc.soldby = (String)serviceData[1];
                    sc.startdate = startDate.Date;
                    sc.enddate = endDate.Date;
                    sc.timestamp = timeStamp;
                    lc.servicecontracts.Add(sc);
                    lc.SaveChanges();
                    lc.Dispose();
                }

                return serviceContractID;
        }
        public bool updateCustomer(int userId, object[] newData, bool serviceChanged)
        {
            //int serviceNo = 0;
            //bool hasService = false;

            /*
            if (serviceChanged)
            {
                //prepare inputdata for ServiceContract creation
                object[] serviceInput = new object[3];
                serviceInput[0] = newData[9];
                serviceInput[1] = newData[13];
                serviceInput[2] = newData[10];

                serviceNo = createServiceContract(serviceInput);

                hasService = true;

                //serviceNo++;

            }
            */

            using (servicebaseEntities sdb = new servicebaseEntities())
            {
                try
                {
                    var query = (from c in sdb.customers
                                 where c.uId == userId
                                 select c).FirstOrDefault();

                    query.cname = newData[0].ToString();
                    query.email = newData[4].ToString();
                    query.phone = newData[5].ToString();
                    query.panelcount = newData[6].ToString();
                    query.inverter = newData[8].ToString();
                    //query.serviceno = serviceNo;
                    //query.hasservice = hasService;
                    //query.servicecontracts.servicetype = Int32.Parse(newData[5].ToString()) + 1;
                    //query.servicecontracts.soldby = newData[7].ToString();

                    sdb.SaveChanges();
                }
                catch
                {

                }
                finally
                {
                    sdb.Dispose();
                }

                return true;

            }
        }