Ejemplo n.º 1
0
        public List <TuKhoaTraVe> getTuKhoaMaDuong(string tukhoa)
        {
            try
            {
                connect();

                string query = "SELECT * FROM TUKHOADUONG";
                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();
                    TuKhoaDuong      tt = (TuKhoaDuong)o;
                    ApproximatString A  = new ApproximatString(tt.TuKhoaDuong1);
                    int C = A.SoSanh(tukhoa);
                    if (C != -1)
                    {
                        if (arr.Count == 0)
                        {
                            tk.ma    = tt.MaDuong;
                            tk.saiso = C;
                            tk.bang  = 3;
                            arr.Add(tk);
                        }
                        else
                        {
                            for (int i = 0; i < arr.Count; i++)
                            {
                                if (arr[i].saiso > C)
                                {
                                    tk.ma    = tt.MaDuong;
                                    tk.saiso = C;
                                    tk.bang  = 3;
                                    if (arr[i].ma != tt.MaDuong)
                                    {
                                        arr.Insert(i, tk);
                                    }
                                    else
                                    {
                                        arr[i] = tk;
                                    }
                                    i = arr.Count;
                                }
                            }
                        }
                    }
                }
                disconnect();
                return(arr);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        protected override object GetDataFromDataRow(DataTable dt, int i)
        {
            TuKhoaDuong dl = new TuKhoaDuong();

            dl.MaTuKhoaDuong = (int)dt.Rows[i]["MaTuKhoaDuong"];
            dl.TuKhoaDuong1  = dt.Rows[i]["TuKhoaDuong"].ToString();
            dl.MaDuong       = dt.Rows[i].IsNull("MaDuong")? 0 : (int)dt.Rows[i]["MaDuong"];
            return((object)dl);
        }
Ejemplo n.º 3
0
        public bool insertTuKhoaDuong(TuKhoaDuong dl)
        {
            connect();
            try
            {
                string insertCommand = @"INSERT INTO TUKHOADUONG (TuKhoaDuong, MaDuong)
                                    VALUES (N'" + dl.TuKhoaDuong1 + "'," + dl.MaDuong + ")";

                executeNonQuery(insertCommand);
                disconnect();
                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }