Esempio n. 1
0
 public Boolean themTour(Object.Tour tour, int giaNL, int giaNLgiam, string hanGiamNL, int giaTE, int giaTEgiam, string hanGiamTE)
 {
     return(tourModel.themTour(tour, giaNL, giaNLgiam, hanGiamNL, giaTE, giaTEgiam, hanGiamTE));
 }
Esempio n. 2
0
        public Boolean themTour(Object.Tour tour, int giaNL, int giaNLgiam, string hanGiamNL, int giaTE, int GiaTEgiam, string hanGiamTE)
        {
            Debug.WriteLine("them tour: ");
            try
            {
                SqlCommand cmd = new SqlCommand("sp_themtour", cn.connect());
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@tieude", tour.TieuDe);
                cmd.Parameters.AddWithValue("@mota", tour.MoTa);
                cmd.Parameters.AddWithValue("@noikhoihanh", tour.NoiKhoiHanh);
                cmd.Parameters.AddWithValue("@thoigian", tour.TongThoiGian);
                //  cmd.Parameters.AddWithValue("@ngaykhoihanh", tour.NgayKhoiHanh);
                cmd.Parameters.AddWithValue("@nhomtour", tour.MaNhomTour);
                cmd.Parameters.AddWithValue("@manv", tour.MaNV);
                cmd.Parameters.AddWithValue("@socho", tour.SoCho);
                cmd.Parameters.AddWithValue("@ngaytao", tour.NgayTao);
                cmd.Parameters.AddWithValue("@imatour", SqlDbType.Int).Direction = ParameterDirection.Output;
                //cnn.Open();
                cmd.ExecuteNonQuery();
                String     idMaTour = cmd.Parameters["@imatour"].Value.ToString(); Debug.WriteLine("id tour: " + idMaTour);
                SqlCommand cmd2     = new SqlCommand("sp_themGiave", cn.connect());
                cmd2.CommandType = CommandType.StoredProcedure;
                cmd2.Parameters.AddWithValue("@matour", idMaTour);
                cmd2.Parameters.AddWithValue("@gianl", giaNL);
                cmd2.Parameters.AddWithValue("@giagiamnl", giaNLgiam);
                cmd2.Parameters.AddWithValue("@hanGiamNL", hanGiamNL);
                cmd2.Parameters.AddWithValue("@giate", giaTE);
                cmd2.Parameters.AddWithValue("@giagiamte", GiaTEgiam);
                cmd2.Parameters.AddWithValue("@hanGiamTE", hanGiamTE);
                int k1 = cmd2.ExecuteNonQuery();

                for (int i = 0; i < tour.DsNgayKhoiHanh.Count(); i++)
                {
                    try
                    {
                        SqlCommand cmd3 = new SqlCommand("sp_themThoiGianKhoiHanh", cn.connect());
                        cmd3.CommandType = CommandType.StoredProcedure;
                        cmd3.Parameters.AddWithValue("@imatour", idMaTour);
                        cmd3.Parameters.AddWithValue("@ngay", tour.DsNgayKhoiHanh[i]);
                        cmd3.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("Error " + ex.Message);
                    }
                }
                string query = "insert into tblhinhanh(iMaTour,sDuongDan) values (";
                for (int i = 0; i < tour.DsAnh.Count(); i++)
                {
                    if ((i + 1) == tour.DsAnh.Count())
                    {
                        query += idMaTour + ",'" + tour.DsAnh[i] + "')";
                    }
                    else
                    {
                        query += idMaTour + ",'" + tour.DsAnh[i] + "'),(";
                    }
                }
                Debug.WriteLine("Query : " + query);
                try
                {
                    SqlCommand cmdAnh = new SqlCommand(query, cn.connect());
                    cmdAnh.CommandType = CommandType.Text;
                    cmdAnh.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Error " + ex.Message);
                }

                //   int k = cmd3.ExecuteNonQuery();


                if (k1 > 0)
                {
                    //Response.Write("<script language=javascript>alert('OKK');</script>");
                    return(true);
                }
                else
                {
                    //Response.Write("<script language=javascript>alert('Rrror');</script>");
                    return(false);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("messeage: loi " + ex.Message);
                return(false);
            }
        }