示例#1
0
        public List <TuKhoaTraVe> getTuKhoaPhuong(string tukhoa)
        {
            try
            {
                connect();

                string query = "SELECT * FROM TUKHOAPHUONG";
                adapter = new SqlDataAdapter(query, connection);
                DataSet dataset = new DataSet();
                adapter.Fill(dataset);
                ArrayList          ls  = ConvertDataSetToArrayList(dataset);
                List <TuKhoaTraVe> arr = new List <TuKhoaTraVe>();
                //List<int> dem = new List<int>();

                foreach (Object o in ls)
                {
                    TuKhoaTraVe      tk = new TuKhoaTraVe();
                    TuKhoaPhuong     tt = (TuKhoaPhuong)o;
                    ApproximatString A  = new ApproximatString(tt.TuKhoaPhuong1);
                    int C = A.SoSanh(tukhoa);
                    if (C != -1)
                    {
                        if (arr.Count == 0)
                        {
                            tk.ma    = tt.MaPhuong;
                            tk.saiso = C;
                            tk.bang  = 4;
                            arr.Add(tk);
                        }
                        else
                        {
                            for (int i = 0; i < arr.Count; i++)
                            {
                                if (arr[i].saiso > C)
                                {
                                    tk.ma    = tt.MaPhuong;
                                    tk.saiso = C;
                                    tk.bang  = 4;
                                    if (arr[i].ma != tt.MaPhuong)
                                    {
                                        arr.Insert(i, tk);
                                    }
                                    else
                                    {
                                        arr[i] = tk;
                                    }
                                    i = arr.Count;
                                }
                            }
                        }
                    }
                }
                disconnect();
                return(arr);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
示例#2
0
        protected override object GetDataFromDataRow(DataTable dt, int i)
        {
            TuKhoaPhuong tkp = new TuKhoaPhuong();

            tkp.MaTuKhoaPhuong = (int)dt.Rows[i]["MaTuKhoaPhuong"];
            tkp.TuKhoaPhuong1  = dt.Rows[i]["TuKhoaPhuong"].ToString();
            tkp.MaPhuong       = (int)dt.Rows[i]["MaPhuong"];
            return((object)tkp);
        }
示例#3
0
 public bool insertTuKhoaPhuong(TuKhoaPhuong tkp)
 {
     try
     {
         connect();
         string insertCommand = "INSERT INTO TUKHOAPHUONG VALUES( N'" +
                                tkp.TuKhoaPhuong1 + "'," + tkp.MaPhuong + ")";
         executeNonQuery(insertCommand);
         disconnect();
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }