Esempio n. 1
0
        public void Set(ref Dictionary <string, dynamic> dict)
        {
            int CurrMID;

            foreach (var i in dict)
            {
                SqlCommand.CommandText = "if not exists( select * from Makes where ManName = \'" +
                                         i.Key + "\' ) INSERT into Makes( ManName ) VALUES ( \'" + i.Key + "\')";
                SqlCommand.ExecuteNonQuery();

                SqlCommand.CommandText = "select M_ID from Makes where ManName = \'" + i.Key + "\'";
                using (var reader = SqlCommand.ExecuteReader())
                {
                    reader.Read();
                    CurrMID = (int)reader.GetValue(0);
                }

                foreach (var j in i.Value)
                {
                    SqlCommand.CommandText = "if not exists( select * from Models where ModelName = \'" +
                                             j + "\' and Man_ID = " + CurrMID.ToString() + ") INSERT into Models( ModelName, Man_ID ) VALUES ( \'" +
                                             j + "\', " + CurrMID.ToString() + ")";
                    SqlCommand.ExecuteNonQuery();
                }
            }
        }
Esempio n. 2
0
        public void Get(ref Dictionary <string, dynamic> dict, bool bKeysOnly)
        {
            // if not specified, return all makes
            if (dict.Count == 0)
            {
                SqlCommand.CommandText = "select ManName from Makes";
                using (var reader = SqlCommand.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        dict.Add(String.Format("{0}", reader[0]), new List <string>());
                    }
                }
            }

            int CurrMID;

            if (!bKeysOnly)
            {
                foreach (var i in dict)
                {
                    SqlCommand.CommandText = "select M_ID from Makes where ManName = \'" + i.Key + "\'";
                    using (var reader = SqlCommand.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            CurrMID = (int)reader.GetValue(0);
                        }
                        else
                        {
                            break;
                        }
                    }

                    SqlCommand.CommandText = "select ModelName from Models where Man_ID = " + CurrMID.ToString();
                    using (var reader = SqlCommand.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            dict[i.Key].Add(String.Format("{0}", reader[0]));
                        }
                    }
                }
            }
        }