Exemplo n.º 1
0
 public ActionResult CreateContacts(EmailAddress e)
 {
     if (ModelState.IsValid)
     {
         db.MyEntitiesEmailAddress.Add(e);
         db.SaveChanges();
         return(RedirectToAction("SentConfirmation"));
     }
     return(View());
 }
Exemplo n.º 2
0
        private void Salesman()
        {
            try
            {
                ContactsModel contact = new ContactsModel();
                contact.Database.ExecuteSqlCommand("truncate table [SalesTable]");
                contact.Database.ExecuteSqlCommand("truncate table [ProductTable]");

                contact.SaveChanges();
                contact.SalesTable.Add(new SalesTable()
                {
                    Salesman = "Bill", Pen = 33, Pencil = 32, Eraser = 56, Ruler = 45, Whiteout = 33, Quantity = (33 * 12 + 32 * 16 + 56 * 10 + 45 * 14 + 33 * 15)
                });
                contact.SalesTable.Add(new SalesTable()
                {
                    Salesman = "John", Pen = 77, Pencil = 33, Eraser = 68, Ruler = 45, Whiteout = 23, Quantity = (77 * 12 + 33 * 16 + 68 * 10 + 45 * 14 + 23 * 15)
                });
                contact.SalesTable.Add(new SalesTable()
                {
                    Salesman = "David", Pen = 43, Pencil = 55, Eraser = 43, Ruler = 67, Whiteout = 65, Quantity = (43 * 12 + 55 * 16 + 43 * 10 + 67 * 14 + 65 * 15)
                });

                contact.ProductTable.Add(new ProductTable()
                {
                    Products = "原子筆", Sum = 153, Quantity = 153 * 12
                });
                contact.ProductTable.Add(new ProductTable()
                {
                    Products = "鉛筆", Sum = 128, Quantity = 128 * 16
                });
                contact.ProductTable.Add(new ProductTable()
                {
                    Products = "橡皮擦", Sum = 167, Quantity = 167 * 10
                });
                contact.ProductTable.Add(new ProductTable()
                {
                    Products = "直尺", Sum = 157, Quantity = 157 * 14
                });
                contact.ProductTable.Add(new ProductTable()
                {
                    Products = "立可白", Sum = 121, Quantity = 121 * 15
                });

                contact.SaveChanges();
                list1 = contact.SalesTable.ToList();
                list2 = contact.ProductTable.ToList();
            }
            catch (Exception ex)
            {
                MessageBox.Show($"發生錯誤 {ex.ToString()}");
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            ContactsModel contacts = new ContactsModel();
            string        Filename = @"C:\Users\TSAI\Desktop\test03.txt";

            string[] Fileline = new string[] { };
            if (File.Exists(Filename))
            {
                Fileline = File.ReadAllLines(Filename);
            }
            else
            {
                Console.WriteLine("File does not exist.");
            }
            DateTime FileFlyingDay;
            DateTime FileBirthday;

            foreach (var i in Fileline)
            {
                if (i.Substring(0, 3) == "695" || i.Substring(0, 3) == "525")
                {
                    DateTime.TryParse(i.Substring(13, 4) + "/" + i.Substring(17, 2) + "/" + i.Substring(19, 2), out FileFlyingDay);
                    DateTime.TryParse(i.Substring(21, 4) + "/" + i.Substring(25, 2) + "/" + i.Substring(27, 2), out FileBirthday);
                    var FileTickNumber = i.Substring(0, 13);
                    contacts.TextTable.Add(new TextTable {
                        TickNumber = FileTickNumber, FlyingDay = FileFlyingDay, Birthday = FileBirthday
                    });
                }
            }
            contacts.SaveChanges();
            Console.ReadLine();
        }
Exemplo n.º 4
0
        private void button1_Click(object sender, EventArgs e)
        {
            RefuleTable refule = new RefuleTable()
            {
                Kilometer     = (double)(numericUpDown2.Value),
                Liter         = (double)(numericUpDown1.Value),
                RefuelingDate = dateTimePicker1.Value
            };

            try
            {
                ContactsModel contacts = new ContactsModel();
                contacts.RefuleTable.Add(refule);
                contacts.SaveChanges();
                Cleardata();
            }
            catch (Exception ex)
            { MessageBox.Show($"{ex}"); }
        }
Exemplo n.º 5
0
        private void button1_Click(object sender, EventArgs e)
        {
            RefuleTable data = new RefuleTable()
            {
                RefulingDate = dateTimePicker1.Value,
                Liter        = (float)numericUpDown1.Value,
                Kilometer    = (float)numericUpDown2.Value
            };

            try
            {
                ContactsModel context = new ContactsModel();
                context.RefuleTable.Add(data);
                context.SaveChanges();
                MessageBox.Show("存檔完成");
            }
            catch (Exception ex)
            { MessageBox.Show($"發生錯誤 {ex.ToString()}"); }
        }
Exemplo n.º 6
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            ContactsTable data = new ContactsTable()
            {
                RefuelingDate = dateTimePicker1.Value,
                Liter         = Convert.ToDouble(numericUpDown1.Value),
                Kilometer     = Convert.ToDouble(numericUpDown2.Value),
            };

            try
            {
                ContactsModel context = new ContactsModel();
                context.ContactsTable.Add(data);
                context.SaveChanges();
                list = context.ContactsTable.ToList();
                MessageBox.Show("存檔完成");
            }
            catch (Exception ex)
            { MessageBox.Show($"發生錯誤 {ex.ToString()}"); }
        }
Exemplo n.º 7
0
        private void button1_Click(object sender, EventArgs e)
        {
            ContactsTable data = new ContactsTable()// 先產生一筆資料 在記憶體裡 requir 一定要有資料
            {
                UserName = textBox1.Text.Trim(),
                Address  = textBox2.Text.Trim(),
                Phone    = textBox3.Text.Trim()
            };

            try
            {
                ContactsModel context = new ContactsModel(); //記憶體之間的橋樑
                context.ContactsTable.Add(data);
                context.SaveChanges();                       // 改變 資料
                MessageBox.Show("存檔完成");
                ClearTextBoxes();
            }
            catch (Exception ex)
            { MessageBox.Show($"發生錯誤{ex.ToString()}"); }//練習用 tostring出來 自己要看的
        }
Exemplo n.º 8
0
        private void button1_Click(object sender, EventArgs e)
        {
            ContactsTable data = new ContactsTable()
            {
                UserName = textBox1.Text.Trim(),
                Address  = textBox2.Text.Trim(),
                Phone    = textBox3.Text.Trim()
            };

            try
            {
                ContactsModel context = new ContactsModel();
                context.ContactsTable.Add(data);
                context.SaveChanges();
                MessageBox.Show("存檔完成");
                ClearTextBoxes();
            }
            catch (Exception ex)
            { MessageBox.Show($"發生錯誤 {ex.ToString()}"); }
        }
Exemplo n.º 9
0
        private void button1_Click(object sender, EventArgs e)
        {
            ContactsTable data = new ContactsTable()
            {
                RefuilingDate = dateTimePicker1.Value,
                Liter         = (double)numericUpDown1.Value,
                Kilometer     = (double)numericUpDown2.Value
            };

            try
            {
                ContactsModel model = new ContactsModel();
                model.ContactsTable.Add(data);
                model.SaveChanges();
                MessageBox.Show("存檔完成");
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("發生錯誤");
            }
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            var lines = File.ReadAllLines("test03.txt");
            // string i = string.Empty;
            CultureInfo zhtw = new CultureInfo("zh-tw");

            foreach (var i in lines)
            {
                if (i.Substring(0, 3) == "695" || i.Substring(0, 3) == "525")
                {
                    DateTime.TryParseExact(i.Substring(13, 8), "yyyyMMdd", zhtw, DateTimeStyles.None, out DateTime dateValue1);
                    DateTime.TryParseExact(i.Substring(21, 8), "yyyyMMdd", zhtw, DateTimeStyles.None, out DateTime dateValue2);
                    Table data = new Table()
                    {
                        TickNumber = i.Substring(0, 13),
                        FlyingDay  = dateValue1,
                        BirthDay   = dateValue2
                    };
                    try
                    {
                        ContactsModel context = new ContactsModel();
                        context.Table.Add(data);
                        context.SaveChanges();
                        Console.WriteLine($"{data.TickNumber}  {data.FlyingDay.ToString("yyyy/MM/dd")}  {data.BirthDay.ToString("yyyy/MM/dd")}");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("發生錯誤" + ex);
                    }
                }
            }
            // var list = new ContactsModel();
            // var list2 = list.Table.ToList();
            //foreach(var i in list2)
            // {
            //     Console.WriteLine(i.TickNumber + " " + i.FlyingDay + " " + i.BirthDay);
            // }
            Console.ReadLine();
        }
Exemplo n.º 11
0
        private void InsertData()
        {
            try
            {
                ContactsModel context = new ContactsModel();

                context.Database.ExecuteSqlCommand("TRUNCATE TABLE [TicketFare]");

                context.SaveChanges();

                context.TicketFare.Add(new Models.TicketFare {
                    StartStation = "台北", EndStation = "新竹", TicketPrice = 177
                });
                context.TicketFare.Add(new Models.TicketFare {
                    StartStation = "台北", EndStation = "台中", TicketPrice = 375
                });
                context.TicketFare.Add(new Models.TicketFare {
                    StartStation = "台北", EndStation = "嘉義", TicketPrice = 598
                });
                context.TicketFare.Add(new Models.TicketFare {
                    StartStation = "台北", EndStation = "台南", TicketPrice = 738
                });
                context.TicketFare.Add(new Models.TicketFare {
                    StartStation = "台北", EndStation = "高雄", TicketPrice = 842
                });
                context.TicketFare.Add(new Models.TicketFare {
                    StartStation = "新竹", EndStation = "台中", TicketPrice = 197
                });
                context.TicketFare.Add(new Models.TicketFare {
                    StartStation = "新竹", EndStation = "嘉義", TicketPrice = 421
                });
                context.TicketFare.Add(new Models.TicketFare {
                    StartStation = "新竹", EndStation = "台南", TicketPrice = 560
                });
                context.TicketFare.Add(new Models.TicketFare {
                    StartStation = "新竹", EndStation = "高雄", TicketPrice = 755
                });
                context.TicketFare.Add(new Models.TicketFare {
                    StartStation = "台中", EndStation = "嘉義", TicketPrice = 224
                });
                context.TicketFare.Add(new Models.TicketFare {
                    StartStation = "台中", EndStation = "台南", TicketPrice = 363
                });
                context.TicketFare.Add(new Models.TicketFare {
                    StartStation = "台中", EndStation = "高雄", TicketPrice = 469
                });
                context.TicketFare.Add(new Models.TicketFare {
                    StartStation = "嘉義", EndStation = "台南", TicketPrice = 139
                });
                context.TicketFare.Add(new Models.TicketFare {
                    StartStation = "嘉義", EndStation = "高雄", TicketPrice = 245
                });
                context.TicketFare.Add(new Models.TicketFare {
                    StartStation = "台南", EndStation = "高雄", TicketPrice = 106
                });

                context.SaveChanges();

                Data = context.TicketFare.ToList();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 12
0
 public void TicketFare()
 {
     try
     {
         ContactsModel contacts = new ContactsModel();
         contacts.Database.ExecuteSqlCommand("truncate table [ContactsTable]");
         contacts.SaveChanges();
         contacts.ContactsTable.Add(new ContactsTable()
         {
             StartStation = "台北", EndStation = "新竹", Fare = 177
         });
         contacts.ContactsTable.Add(new ContactsTable()
         {
             StartStation = "台北", EndStation = "台中", Fare = 375
         });
         contacts.ContactsTable.Add(new ContactsTable()
         {
             StartStation = "台北", EndStation = "嘉義", Fare = 598
         });
         contacts.ContactsTable.Add(new ContactsTable()
         {
             StartStation = "台北", EndStation = "台南", Fare = 738
         });
         contacts.ContactsTable.Add(new ContactsTable()
         {
             StartStation = "台北", EndStation = "高雄", Fare = 842
         });
         contacts.ContactsTable.Add(new ContactsTable()
         {
             StartStation = "新竹", EndStation = "台中", Fare = 197
         });
         contacts.ContactsTable.Add(new ContactsTable()
         {
             StartStation = "新竹", EndStation = "嘉義", Fare = 421
         });
         contacts.ContactsTable.Add(new ContactsTable()
         {
             StartStation = "新竹", EndStation = "台南", Fare = 560
         });
         contacts.ContactsTable.Add(new ContactsTable()
         {
             StartStation = "新竹", EndStation = "高雄", Fare = 755
         });
         contacts.ContactsTable.Add(new ContactsTable()
         {
             StartStation = "台中", EndStation = "嘉義", Fare = 224
         });
         contacts.ContactsTable.Add(new ContactsTable()
         {
             StartStation = "台中", EndStation = "台南", Fare = 363
         });
         contacts.ContactsTable.Add(new ContactsTable()
         {
             StartStation = "台中", EndStation = "高雄", Fare = 469
         });
         contacts.ContactsTable.Add(new ContactsTable()
         {
             StartStation = "嘉義", EndStation = "台南", Fare = 139
         });
         contacts.ContactsTable.Add(new ContactsTable()
         {
             StartStation = "嘉義", EndStation = "高雄", Fare = 245
         });
         contacts.ContactsTable.Add(new ContactsTable()
         {
             StartStation = "台南", EndStation = "高雄", Fare = 106
         });
         contacts.SaveChanges();
         list = contacts.ContactsTable.ToList();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Exemplo n.º 13
0
        private void InsertMyData()
        {
            try
            {
                ContactsModel context = new ContactsModel();

                //var P_rows = context.Products.ToList();

                //foreach(var row in P_rows)
                //{
                //    context.Products.Remove(row);
                //}

                //var S_rows = context.Sales.ToList();

                //foreach(var row in S_rows)
                //{
                //    context.Sales.Remove(row);
                //}

                context.Database.ExecuteSqlCommand("TRUNCATE TABLE [Products]");
                context.Database.ExecuteSqlCommand("TRUNCATE TABLE [Sales]");

                context.SaveChanges();

                context.Products.Add(new Products {
                    Product_Name = "原子筆", Product_Price = 12
                });
                context.Products.Add(new Products {
                    Product_Name = "鉛筆", Product_Price = 16
                });
                context.Products.Add(new Products {
                    Product_Name = "橡皮擦", Product_Price = 10
                });
                context.Products.Add(new Products {
                    Product_Name = "直尺", Product_Price = 14
                });
                context.Products.Add(new Products {
                    Product_Name = "立可白", Product_Price = 15
                });

                context.Sales.Add(new Sales {
                    Name = "Bill", Product_Name = "原子筆", Product_Quantity = 33
                });
                context.Sales.Add(new Sales {
                    Name = "Bill", Product_Name = "鉛筆", Product_Quantity = 32
                });
                context.Sales.Add(new Sales {
                    Name = "Bill", Product_Name = "橡皮擦", Product_Quantity = 56
                });
                context.Sales.Add(new Sales {
                    Name = "Bill", Product_Name = "直尺", Product_Quantity = 45
                });
                context.Sales.Add(new Sales {
                    Name = "Bill", Product_Name = "立可白", Product_Quantity = 33
                });
                context.Sales.Add(new Sales {
                    Name = "Jhon", Product_Name = "原子筆", Product_Quantity = 77
                });
                context.Sales.Add(new Sales {
                    Name = "Jhon", Product_Name = "鉛筆", Product_Quantity = 33
                });
                context.Sales.Add(new Sales {
                    Name = "Jhon", Product_Name = "橡皮擦", Product_Quantity = 68
                });
                context.Sales.Add(new Sales {
                    Name = "Jhon", Product_Name = "直尺", Product_Quantity = 45
                });
                context.Sales.Add(new Sales {
                    Name = "Jhon", Product_Name = "立可白", Product_Quantity = 23
                });
                context.Sales.Add(new Sales {
                    Name = "David", Product_Name = "原子筆", Product_Quantity = 43
                });
                context.Sales.Add(new Sales {
                    Name = "David", Product_Name = "鉛筆", Product_Quantity = 55
                });
                context.Sales.Add(new Sales {
                    Name = "David", Product_Name = "橡皮擦", Product_Quantity = 43
                });
                context.Sales.Add(new Sales {
                    Name = "David", Product_Name = "直尺", Product_Quantity = 67
                });
                context.Sales.Add(new Sales {
                    Name = "David", Product_Name = "立可白", Product_Quantity = 65
                });

                context.SaveChanges();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 14
0
        private void InitialData()
        {
            try
            {
                ContactsModel data = new ContactsModel();
                data.Database.ExecuteSqlCommand("truncate table [SalesTable]");
                data.Database.ExecuteSqlCommand("truncate table [ProductTable]");

                data.SaveChanges();
                data.SalesTable.Add(new SalesTable()
                {
                    Salesman = "Bill", ProductItem = "原子筆", Quantity = 33
                });
                data.SalesTable.Add(new SalesTable()
                {
                    Salesman = "Bill", ProductItem = "鉛筆", Quantity = 32
                });
                data.SalesTable.Add(new SalesTable()
                {
                    Salesman = "Bill", ProductItem = "橡皮擦", Quantity = 56
                });
                data.SalesTable.Add(new SalesTable()
                {
                    Salesman = "Bill", ProductItem = "直尺", Quantity = 45
                });
                data.SalesTable.Add(new SalesTable()
                {
                    Salesman = "Bill", ProductItem = "立可白", Quantity = 33
                });

                data.SalesTable.Add(new SalesTable()
                {
                    Salesman = "John", ProductItem = "原子筆", Quantity = 77
                });
                data.SalesTable.Add(new SalesTable()
                {
                    Salesman = "John", ProductItem = "鉛筆", Quantity = 33
                });
                data.SalesTable.Add(new SalesTable()
                {
                    Salesman = "John", ProductItem = "橡皮擦", Quantity = 68
                });
                data.SalesTable.Add(new SalesTable()
                {
                    Salesman = "John", ProductItem = "直尺", Quantity = 45
                });
                data.SalesTable.Add(new SalesTable()
                {
                    Salesman = "John", ProductItem = "立可白", Quantity = 23
                });

                data.SalesTable.Add(new SalesTable()
                {
                    Salesman = "David", ProductItem = "原子筆", Quantity = 43
                });
                data.SalesTable.Add(new SalesTable()
                {
                    Salesman = "David", ProductItem = "鉛筆", Quantity = 55
                });
                data.SalesTable.Add(new SalesTable()
                {
                    Salesman = "David", ProductItem = "橡皮擦", Quantity = 43
                });
                data.SalesTable.Add(new SalesTable()
                {
                    Salesman = "David", ProductItem = "直尺", Quantity = 67
                });
                data.SalesTable.Add(new SalesTable()
                {
                    Salesman = "David", ProductItem = "立可白", Quantity = 65
                });

                data.ProductTable.Add(new ProductTable()
                {
                    Item = "原子筆", Price = 12
                });
                data.ProductTable.Add(new ProductTable()
                {
                    Item = "鉛筆", Price = 16
                });
                data.ProductTable.Add(new ProductTable()
                {
                    Item = "橡皮擦", Price = 10
                });
                data.ProductTable.Add(new ProductTable()
                {
                    Item = "直尺", Price = 14
                });
                data.ProductTable.Add(new ProductTable()
                {
                    Item = "立可白", Price = 15
                });

                data.SaveChanges();

                list1 = data.SalesTable.ToList();
                list2 = data.ProductTable.ToList();
            }
            catch (Exception ex)
            {
                MessageBox.Show($"發生錯誤{ex.ToString()}");
            }
        }