Beispiel #1
0
 private void InitializeModelEvent()
 {
     mEvent = new ModelEvent();
     mEvent.Read();
     curEvs = new List <InputEventItem>();
     refEvs = new List <ViewEventItem>();
 }
Beispiel #2
0
 private void InitializeModelEvent()
 {
     mEvent = new ModelEvent();
     mEvent.Read();
     viewEvList = new List <ViewEventItem>();
     viewList   = new List <ListItem>();
     BindListItem();
 }
Beispiel #3
0
        public static void NpgsqlDBImportEvent(ModelEvent mEvent)
        {
            string conn_str = "Server=localhost;Port=5432;User ID=xiao;Database=note;Password=xiao;Enlist=true";

            using (NpgsqlConnection conn = new NpgsqlConnection(conn_str))
            {
                //PostgreSQLへ接続
                conn.Open();
                int evid = GetLastId("event", 10000000, conn);
                int chid = GetLastId("event_item", 11000000, conn);

                List <ImportEventItem> orderList = new List <ImportEventItem>();
                foreach (var ev in mEvent.Items)
                {
                    if (ev.Name == "Memo")
                    {
                        string cmd_str2 = string.Format("insert into event (id, name, category, status, sorted) values ('{0}', '{1}', '{2}', '{3}', '{4}');",
                                                        ++evid, "Diary", QuoConv(ev.Category), "Regular", "Diary");
                        NpgsqlCommand cmd2 = new NpgsqlCommand(cmd_str2, conn);
                        var           rtn2 = cmd2.ExecuteNonQuery();
                        foreach (var child in ev.Items)
                        {
                            cmd_str2 = string.Format("insert into event_item (id, date, memo, time, parent_id) values ('{0}', '{1}', '{2}', '{3}', '{4}');",
                                                     ++chid, child.Date.ToString("yyyy-MM-dd"), "", child.Time, evid);
                            cmd2 = new NpgsqlCommand(cmd_str2, conn);
                            rtn2 = cmd2.ExecuteNonQuery();

                            cmd_str2 = string.Format("insert into diary (date, memo, length) values ('{0}', '{1}', '{2}');",
                                                     child.Date.ToString("yyyy-MM-dd"), QuoConv(child.Memo), child.Memo.Length);
                            cmd2 = new NpgsqlCommand(cmd_str2, conn);
                            rtn2 = cmd2.ExecuteNonQuery();
                        }
                        continue;
                    }

                    string cmd_str = string.Format("insert into event (id, name, category, status, sorted) values ('{0}', '{1}', '{2}', '{3}', '{4}');",
                                                   ++evid, QuoConv(ev.Name), QuoConv(ev.Category), QuoConv(ev.Status), "");
                    NpgsqlCommand cmd  = new NpgsqlCommand(cmd_str, conn);
                    var           rtn1 = cmd.ExecuteNonQuery();
                    foreach (var child in ev.Items)
                    {
                        orderList.Add(new ImportEventItem(child, evid));
                    }
                    Console.WriteLine("Insert success! {0}", ev.Name);
                }

                Comparison <ImportEventItem> comparison = new Comparison <ImportEventItem>
                                                              ((ImportEventItem x, ImportEventItem y) => {
                    return(x.Date.CompareTo(y.Date));
                });
                orderList.Sort(comparison);//1、Comparison<Person>

                foreach (var child in orderList)
                {
                    string cmd_str = string.Format("insert into event_item (id, date, memo, time, parent_id) values ('{0}', '{1}', '{2}', '{3}', '{4}');",
                                                   ++chid, child.Date.ToString("yyyy-MM-dd"), QuoConv(child.Memo), child.Time, child.parentId);
                    NpgsqlCommand cmd2 = new NpgsqlCommand(cmd_str, conn);
                    var           rtn2 = cmd2.ExecuteNonQuery();
                }
                Console.WriteLine("Insert Complete!");
                conn.Close();
            }
        }