Exemplo n.º 1
0
        public static void NpgsqlDBImportPerson(ModelPerson mPerson)
        {
            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();
                List <ImportEventItem> orderList = new List <ImportEventItem>();

                int evid     = GetLastId("event", 10000000, conn);
                int chid     = GetLastId("event_item", 11000000, conn);
                int personid = GetLastId("person", 21000000, conn);

                foreach (var item in mPerson.Items)
                {
                    string cmd_str = string.Format("insert into person (id, name, category, status, memo, name2, name3, address, input_date) values " +
                                                   "('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}');",
                                                   ++personid, QuoConv(item.Name), QuoConv(item.Category), QuoConv(item.Status), QuoConv(item.Memo),
                                                   QuoConv(item.Name2), QuoConv(item.Name3), QuoConv(item.Address), QuoConv(item.InputDate.ToString("yyyy-MM-dd")));
                    NpgsqlCommand cmd  = new NpgsqlCommand(cmd_str, conn);
                    var           rtn1 = cmd.ExecuteNonQuery();

                    cmd_str = string.Format("select Count(*) from event where name = '{0}' or name = '{1}' or name = '{2}' ", QuoConv(item.Name), QuoConv(item.Name2), QuoConv(item.Name3));
                    cmd     = new NpgsqlCommand(cmd_str, conn);
                    int rtnCount = 0;
                    using (NpgsqlDataReader dr = cmd.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            if (!dr.IsDBNull(0))
                            {
                                rtnCount = dr.GetInt32(0);
                            }
                        }
                    }
                    if (rtnCount > 0)
                    {
                        continue;
                    }

                    cmd_str = string.Format("insert into event (id, name, category, status, sorted) values ('{0}', '{1}', '{2}', '{3}', '{4}');",
                                            ++evid, QuoConv(item.Name), "Communicate", "Finished", "Person");
                    cmd     = new NpgsqlCommand(cmd_str, conn);
                    rtn1    = cmd.ExecuteNonQuery();
                    cmd_str = string.Format("insert into event_item (id, date, memo, time, parent_id) values ('{0}', '{1}', '{2}', '{3}', '{4}');",
                                            ++chid, QuoConv(item.InputDate.ToString("yyyy-MM-dd")), "", 0.1, evid);
                    cmd  = new NpgsqlCommand(cmd_str, conn);
                    rtn1 = cmd.ExecuteNonQuery();

                    Console.WriteLine("Insert success! {0}", item.Name);
                }

                Console.WriteLine("Insert Complete!");
                conn.Close();
            }
        }
Exemplo n.º 2
0
 private void InitializePerson()
 {
     mPerson = new ModelPerson();
     mPerson.Read();
     curGroup = new List <ViewPerson>();
 }