Exemple #1
0
        public ActionResult TransactionItemsGridViewPartialAddNew([ModelBinder(typeof(DevExpressEditorsBinder))] Models.Items item)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    // Insert here a code to insert the new item in your model
                    unitOfWork.ItemsRepo.Insert(item);
                    unitOfWork.Save();
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }
            else
            {
                ViewData["EditError"] = "Please, correct all errors.";
                ViewData["Model"]     = item;
            }

            var model = unitOfWork.ItemsRepo.Get();

            return(PartialView("_TransactionItemsGridViewPartial", model));
        }
Exemple #2
0
 public static Items Deserialize()
 {
     Items myItems = new Items();
     XmlSerializer deserializer = new XmlSerializer(typeof(Items));
     TextReader reader = new StreamReader("outputItem.xml");
     object obj = deserializer.Deserialize(reader);
     myItems = (Items)obj;
     reader.Close();
     return myItems;
 }
Exemple #3
0
 public static Items GetItemsFromString(string s)
 {
     Items items = new Items();
     List<string> stringItems = new List<string>();
     stringItems = s.GetProperties();
     foreach (string item in stringItems)
     {
         items.CurItems.Add(Item.GetItemFromString(item));
     }
     return items;
 }
Exemple #4
0
        public ActionResult TransactionItemsGridViewPartialUpdate([ModelBinder(typeof(DevExpressEditorsBinder))] Models.Items item, [ModelBinder(typeof(DevExpressEditorsBinder))] Items oldModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    unitOfWork.ItemsRepo.Update(item);
                    unitOfWork.Save();
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }
            else
            {
                ViewData["EditError"] = "Please, correct all errors.";
            }
            var model = unitOfWork.ItemsRepo.Get();

            return(PartialView("_TransactionItemsGridViewPartial", model));
        }
Exemple #5
0
        public static Items Reading()
        {
            Items items = new Items();
            List<Item> itemsList = new List<Item>();
            bool b = true;
            while (b)
            {
                Console.WriteLine("Press (1) to read from *.txt, (2) - DataBase or (3) to Deserialize");
                string s = Console.ReadLine();
                int command;
                if (int.TryParse(s, out command))
                {
                    switch (command)
                    {
                        case 1:
                            using (StreamReader sr = File.OpenText("output.txt"))
                            {
                                string sRead = "";
                                List<string> stringItems = new List<string>();
                                while ((sRead = sr.ReadLine()) != null)
                                {
                                    stringItems.Add(sRead);
                                }
                                foreach (string item in stringItems)
                                {
                                    items = Items.GetItemsFromString(item);
                                }
                                Console.WriteLine(items);
                            }
                            break;
                        case 2:
                            string db1 = ConfigurationManager.AppSettings["connectionString"];
                            DataAccessManager daM = new DataAccessManager(db1);
                            items.CurItems = daM.GetItems();
                            break;
                        case 3:
                            items = Deserialize();
                            break;
                        default:
                            break;
                    }
                }

                bool exit = false;
                while (!exit)
                {
                    Console.WriteLine("Press (1) to exit from Writing or (2) to continue");
                    s = Console.ReadLine();
                    if (int.TryParse(s, out command))
                    {
                        switch (command)
                        {
                            case 1:
                                b = false;
                                exit = true;
                                break;
                            case 2:
                                exit = true;
                                break;
                            default:
                                continue;
                        }
                    }
                }
            }
            items.CurItems = itemsList;
            return items;
        }
Exemple #6
0
        static void SetData(Items myItems)
        {
            Item myItem1 = new Item();
            Position pos1 = new Position();
            Position pos2 = new Position();
            Job job = new Job();

            pos1.Latitude = 200;
            pos1.Longitude = 300;
            pos1.Accuracy = 5;
            pos1.Date = DateTime.Now;

            pos2.Latitude = 400;
            pos2.Longitude = 500;
            pos2.Accuracy = 6;
            pos2.Date = DateTime.Now;

            job.Time = DateTime.Now;
            job.Description = "some text";
            job.Phone = "7777";
            job.UserId = 1;

            myItem1.Id = 1;
            myItem1.FirstName = "Robin";
            myItem1.LastName = "Good";
            myItem1.PositionHistory.Add(pos1);
            myItem1.PositionHistory.Add(pos2);
            myItem1.JobHistory.Add(job);

            myItems.CurItems.Add(myItem1);
            myItems.CurItems.Add(myItem1);
        }
Exemple #7
0
        static void Main(string[] args)
        {
            Items myItems = new Items();
            SetData(myItems);
            bool mainProg = true;
            while (mainProg)
            {
                Console.WriteLine("Enter number (1) for reading or (2) for writing");
                string s = Console.ReadLine();
                int command;
                if(int.TryParse(s, out command))
                {
                    switch (command)
                    {
                        case 1:
                            myItems = Reading();
                            break;
                        case 2:
                             Writing(myItems);
                            break;
                        default:
                            continue;
                    }
                }
                bool exit = false;
                while (!exit)
                {
                    Console.WriteLine("Press (1) to exit or (2) to continue");
                    s = Console.ReadLine();
                    if (int.TryParse(s, out command))
                    {
                        switch (command)
                        {
                            case 1:
                                mainProg = false;
                                exit = true;
                                break;
                            case 2:

                                exit = true;
                                break;
                            default:
                                continue;
                        }
                    }
                }

            }
        }
Exemple #8
0
        public static void Writing(Items items)
        {
            bool b = true;
            while (b)
            {
                Console.WriteLine("Press (1) to write in *.txt, (2) - in DataBase or (3) to Serialize");
                string s = Console.ReadLine();
                int command;
                if (int.TryParse(s, out command))
                {
                    switch (command)
                    {
                        case 1:
                            using (StreamWriter sw = File.AppendText("output.txt"))
                            {
                                sw.WriteLine(items);
                            }
                            break;
                        case 2:
                            string db1 = ConfigurationManager.AppSettings["connectionString"];
                            DataAccessManager daM = new DataAccessManager(db1);
                            foreach(Item item in items.CurItems)
                            {
                                daM.InsertItem(item);
                            }
                            break;
                        case 3:
                            Serialize(items);
                            break;
                        default:
                            break;
                    }
                }

                bool exit = false;
                while (!exit)
                {
                    Console.WriteLine("Press (1) to exit from Writing or (2) to continue");
                    s = Console.ReadLine();
                    if (int.TryParse(s, out command))
                    {
                        switch (command)
                        {
                            case 1:
                                b = false;
                                exit = true;
                                break;
                            case 2:
                                exit = true;
                                break;
                            default:
                                continue;
                        }
                    }
                }
            }
        }
Exemple #9
0
 public static void Serialize(Items items)
 {
     XmlSerializer serialiser = new XmlSerializer(typeof(Items));
     using (TextWriter writer = new StreamWriter("outputItem.xml"))
     {
         serialiser.Serialize(writer, items);
     }
 }
        public List<Item> GetItems()
        {
            string sqlString = @"SELECT *
                                 FROM Item";

            List<Item> result = new List<Item>();

            using (var conn = new SqlConnection(connectionString))
            {
                SqlCommand sqlCommand = new SqlCommand(sqlString, conn);

                try
                {
                    conn.Open();
                    SqlDataReader reader = sqlCommand.ExecuteReader();

                    while (reader.Read())
                    {
                        Item item = new Item();
                        item.Id = Convert.ToInt32(reader[0].ToString());
                        item.FirstName = reader[1].ToString();
                        item.LastName = reader[2].ToString();
                        item.PositionHistory = GetPositionsById(item.Id);
                        item.JobHistory = GetJobsById(item.Id);
                        result.Add(item);
                    }
                }
                catch (Exception e)
                {
                    throw;
                }
            }
            Items items = new Items();
            items.CurItems = result;
            Console.WriteLine(items);

            return result;
        }