Exemplo n.º 1
0
        public void create(Nha_Dat n)

        {
            string sql = "insert tbl_NhaDat values( N'" + n.Image1 + "', '" + n.Image2 + "', '" + n.Image3 + "', '" + n.DanhMuc_Id + "', N'" + n.TieuDe + "', '" + n.Gia + "', '" + n.DienTich + "', N'" + n.MoTa + "', N'" + n.ChiTiet + "', N'" + n.DiaChi + "', N'" + n.LienHe + "',  '" + n.LuotXem + "', '" + n.status + "', '" + n.created_at + "') ";

            obj.ExecuteNonQuery(sql);
        }
Exemplo n.º 2
0
        public void update(Nha_Dat n, string id)
        {
            string sql = " update tbl_NhaDat set Image1 = '" + n.Image1 + "', Image2 = '" + n.Image2 + "', Image3 = '" + n.Image3 + "', DanhMuc_Id = '" + n.DanhMuc_Id + "', TieuDe = N'" + n.TieuDe + "', Gia = '" + n.Gia + "', DienTich = '" + n.DienTich + "', MoTa = N'" + n.MoTa + "', ChiTiet = N'" + n.ChiTiet + "', DiaChi = N'" + n.DiaChi + "',  LienHe = N'" + n.LienHe + "', status = '" + n.status + "' where id = '" + id + "' ";

            obj.ExecuteNonQuery(sql);
        }
Exemplo n.º 3
0
        protected void submit_click(object sender, EventArgs e)
        {
            Nha_Dat n = new Nha_Dat();

            n.DanhMuc_Id = listCategory.SelectedValue;
            n.TieuDe     = txtTieuDe.Text;
            n.DienTich   = txtDienTich.Text;
            n.MoTa       = txtMoTa.Text;
            n.ChiTiet    = txtChiTiet.Text;
            n.DiaChi     = txtDiachi.Text;
            n.Gia        = txtGia.Text;
            n.LienHe     = txtLienHe.Text;

            n.Image1     = "";
            n.Image2     = "";
            n.Image3     = "";
            n.LuotXem    = 0;
            n.status     = checkStatus.Checked;
            n.created_at = DateTime.Now;

            // begin: get image
            // Image1 --------------------------------------------------------------------------
            if (upload_image_1.HasFile)
            {
                string tenFile_1 = upload_image_1.FileName;
                // lấy kiểu dữ liệu ảnh
                string extension = System.IO.Path.GetExtension(tenFile_1);
                // kiểm tra đuôi file
                if (extension == ".jpg" || extension == ".png" || extension == ".gif")
                {
                    // url folder lưu ảnh
                    string path = Server.MapPath("~/assets/upload/NhaDat//");
                    // Lưu trong folder
                    upload_image_1.SaveAs(path + tenFile_1);
                    string url_img_1 = "~/assets/upload/NhaDat/" + tenFile_1;  //luu trong db
                    // gán đường dẫn để lưu vào DB
                    n.Image1 = url_img_1;
                }
            }

            // Image2 --------------------------------------------------------------------------
            if (upload_image_2.HasFile)
            {
                string tenFile_2 = upload_image_2.FileName;
                string extension = System.IO.Path.GetExtension(tenFile_2);

                if (extension == ".jpg" || extension == ".png" || extension == ".gif")
                {
                    string path = Server.MapPath("~/assets/upload/NhaDat//");
                    upload_image_2.SaveAs(path + tenFile_2);
                    string url_img_2 = "~/assets/upload/NhaDat/" + tenFile_2;
                    n.Image2 = url_img_2;
                }
            }

            // Image3 --------------------------------------------------------------------------
            if (upload_image_3.HasFile)
            {
                string tenFile_3 = upload_image_3.FileName;
                string extension = System.IO.Path.GetExtension(tenFile_3);

                if (extension == ".jpg" || extension == ".png" || extension == ".gif")
                {
                    string path = Server.MapPath("~/assets/upload/NhaDat//");
                    upload_image_3.SaveAs(path + tenFile_3);
                    string url_img_3 = "~/assets/upload/NhaDat/" + tenFile_3;
                    n.Image3 = url_img_3;
                }
            }
            // end: get image

            // CREATE
            obj.create(n);

            Response.Redirect("DanhSach_NhaDat.aspx");
            ClientScript.RegisterStartupScript(this.GetType(), "adasd", "a()", true);
        }
Exemplo n.º 4
0
        //submit
        protected void Submit_Click(object sender, EventArgs e)
        {
            Nha_Dat n = new Nha_Dat();

            n.TieuDe     = txtTieuDe.Text;
            n.ChiTiet    = txtChiTiet.Text;
            n.Gia        = txtGia.Text;
            n.DienTich   = txtDienTich.Text;
            n.DiaChi     = txtDiachi.Text;
            n.LienHe     = txtLienHe.Text;
            n.MoTa       = txtMoTa.Text;
            n.status     = checkStatus.Checked;
            n.DanhMuc_Id = listCategory.SelectedValue;

            n.Image1 = anh1;
            n.Image2 = anh2;
            n.Image3 = anh3;

            // Nếu có ảnh mới thì update, không thì giữ nguyên ảnh cũ
            // Image1 --------------------------------------------------------------------------
            if (upload_image_1.HasFile)
            {
                //xoa anh cu

                /*string directoryimg = Server.MapPath(anh1);
                 * System.IO.File.Delete(directoryimg);*/

                //them anh moi
                string tenFile_1 = upload_image_1.FileName;
                string extension = System.IO.Path.GetExtension(tenFile_1);
                if (extension == ".jpg" || extension == ".png" || extension == ".gif")
                {
                    string path = Server.MapPath("~/assets/upload/NhaDat//");
                    upload_image_1.SaveAs(path + tenFile_1);
                    string url_img_1 = "~/assets/upload/NhaDat/" + tenFile_1;  //luu trong db
                    n.Image1 = url_img_1;
                }
            }
            // Image2 --------------------------------------------------------------------------
            if (upload_image_2.HasFile)
            {
                //xoa anh cu

                /*string directoryimg = Server.MapPath(anh2);
                 * System.IO.File.Delete(directoryimg);*/

                string tenFile_2 = upload_image_2.FileName;
                string extension = System.IO.Path.GetExtension(tenFile_2);
                if (extension == ".jpg" || extension == ".png" || extension == ".gif")
                {
                    string path = Server.MapPath("~/assets/upload/NhaDat//");
                    upload_image_2.SaveAs(path + tenFile_2);
                    string url_img_2 = "~/assets/upload/NhaDat/" + tenFile_2;
                    n.Image2 = url_img_2;
                }
            }

            // Image3 --------------------------------------------------------------------------
            if (upload_image_3.HasFile)
            {
                //xoa anh cu

                /*string directoryimg = Server.MapPath(anh3);
                 * System.IO.File.Delete(directoryimg);*/

                string tenFile_3 = upload_image_3.FileName;
                string extension = System.IO.Path.GetExtension(tenFile_3);
                if (extension == ".jpg" || extension == ".png" || extension == ".gif")
                {
                    string path = Server.MapPath("~/assets/upload/NhaDat//");
                    upload_image_3.SaveAs(path + tenFile_3);
                    string url_img_3 = "~/assets/upload/NhaDat/" + tenFile_3;
                    n.Image3 = url_img_3;
                }
            }
            // end: get image

            string Id = Request.QueryString["Id"];

            obj.update(n, Id);
            Response.Redirect("DanhSach_NhaDat.aspx");
        }