コード例 #1
0
        protected void grDSSanPham_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "themThanhPham")
            {
                //TextBox txt1 = (TextBox)grDSSanPham.Rows[Convert.ToInt32(e.CommandArgument)].FindControl("txtSLThuc");

                GridViewRow row        = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
                int         rowindex   = row.RowIndex;
                TextBox     txtSoluong = (TextBox)row.FindControl("txtSLThuc");
                Label       lbTenTP    = (Label)row.FindControl("lbTenSP");
                Label       lbGia      = (Label)row.FindControl("lbGia");

                int maThanhPham = int.Parse(e.CommandArgument.ToString());
                int soluong     = 0;
                int.TryParse(txtSoluong.Text, out soluong);
                int    gia   = int.Parse(lbGia.Text);
                string tenTP = lbTenTP.Text;

                lbDSChon.Visible       = true;
                lbTextTongTien.Visible = true;
                lbTongTien.Visible     = true;
                lbDSSanpham.Visible    = true;
                grDSSanPham.Visible    = true;
                gridDSChon.Visible     = true;

                if (Session["dsThanhPhamChon"] == null)
                {
                    dsThanhPhamChon            = new List <DTOChiTietDH>();
                    Session["dsThanhPhamChon"] = dsThanhPhamChon;
                }
                else
                {
                    dsThanhPhamChon = (List <DTOChiTietDH>)Session["dsThanhPhamChon"];
                }

                bool trangthai = false;
                foreach (DTOChiTietDH t in dsThanhPhamChon)
                {
                    if (t.dtoSP.MaSP == maThanhPham)
                    {
                        t.SoLuong += soluong;
                        trangthai  = true;
                        break;
                    }
                }
                if (trangthai == false)
                {
                    DTOChiTietDH tp    = new DTOChiTietDH();
                    DTOSanPham   dtoSP = daoEntities.TimTheoMaSP(maThanhPham);
                    tp.dtoSP     = dtoSP;
                    tp.SoLuong   = soluong;
                    tp.ThanhTien = gia * soluong;
                    dsThanhPhamChon.Add(tp);
                }

                hienThanhPhamChon();
                TongTien();
            }
        }
コード例 #2
0
        protected void btnThemSP_Click(object sender, EventArgs e)
        {
            XemDSKho.Visible = true;
            DTOXuLyPhieuGiao dtoct = new DTOXuLyPhieuGiao();

            // DTODonDatHang dtoDH = new DTODonDatHang();

            dtoct.MaDH = lbMaDH.Text;
            DTOSanPham dtoSP = new DTOSanPham();

            dtoct.MaSP = int.Parse(ddTP.SelectedValue);
            // dtoSP.TenSP = ddTP.SelectedItem.ToString();

            //dtoct.dtoSP = dtoSP;
            //dtoct.dtoDH = dtoDH;

            //dtoSP.TenSP = ddTP.SelectedValue;
            dtoct.SoLuong = int.Parse(txtSoLuong.Text);

            dtoct.ThanhTien = int.Parse(lbgia.Text) * int.Parse(txtSoLuong.Text);


            //BLLXuLyDonHang bll = new BLLXuLyDonHang();
            //bll.ThemChiTietDH(dtoct);


            DTOKhoSP dtokho = new DTOKhoSP();

            dtokho.MaSP    = int.Parse(ddTP.SelectedValue);
            dtokho.Soluong = int.Parse(lbSLKho.Text) - int.Parse(txtSoLuong.Text);
            DAO_Entity dao = new DAO_Entity();

            dao.CapNhatSLKhoSP(dtokho);



            DAO_Entity daokh = new DAO_Entity();

            daokh.ThemPhieuGiaoHang(dtoct);
            Response.Redirect(Request.RawUrl);
        }