Example #1
0
        private void simpleButton9_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(@"Data Source=192.168.1.53,1433;Initial Catalog=QLKhoBB;User ID=sa;Password=123456789");

            con.Open();
            SqlCommand     cmd = new SqlCommand("select * from XuatKho where sohd  = '" + txtmahd.Text + "'", con);
            SqlDataAdapter da  = new SqlDataAdapter(cmd);
            DataTable      dt  = new DataTable();

            da.Fill(dt);
            con.Close();
            XtraReport2 rp = new XtraReport2();

            rp.DataSource = dt;
            rp.ShowPreviewDialog();
        }
Example #2
0
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            string    sqln = @"select MaVT, TenVT, Barcode ,Sum(Nhap) as tongnhhap , SUM(Xuat) as tongxuat, (SUM(Nhap) - SUM(Xuat)) as Ton from (select mavt as MaVT, tenvt as TenVT, barcode as Barcode, 0 as Nhap, 0 as Xuat From VatTu union Select N.mavt as MaVT, H.tenvt as TenVT,  N.barcodenhap as Barcode, Sum(N.slnhap) as Nhap, 0 as Xuat  From NhapKho N, VatTu H Where N.mavt = H.mavt Group By N.mavt, H.tenvt, N.barcodenhap having SUM(N.slnhap) > 0 union Select X.mavt as MaVT, H.tenvt as TenVT, X.barcodexuat as Barcode, 0 as Nhap, Sum(X.slxuat) as Xuat   From XuatKho X, VatTu H Where X.mavt = H.mavt Group By X.mavt, H.tenvt, X.barcodexuat having SUM(X.slxuat) > 0) as hangton where Barcode = '" + txtbarcode.Text + "' Group by MaVT, TenVT, Barcode";
            DataTable dat  = ConnectDB.getTable(sqln);

            if (dat.Rows.Count > 0 && Convert.ToInt64(dat.Rows[0]["Ton"].ToString()) >= Convert.ToInt64(txtslnhap.Text))
            {
                try
                {
                    if (validate())
                    {
                        DialogResult tb = XtraMessageBox.Show("Bạn có muốn in phiếu xuất mặt hàng này sau khi xuất kho không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (tb == DialogResult.Yes)
                        {
                            string sql2 = "insert into XuatKho values('" + txtmahd.Text.Trim() + "','" + txtmvt.Text + "','" + txtbarcode.Text + "','" + txtslnhap.Text + "','" + txtdvtinh.Text + "','" + Convert.ToDateTime(date_nhap.Text).ToString("MM/dd/yyyy HH:mm:ss") + "',N'" + cb_user.EditValue.ToString() + "',N'" + txtdvgiaonhan.Text + "',N'" + txtghichu.Text + "')";
                            if (ConnectDB.Query(sql2) == -1)
                            {
                                XtraMessageBox.Show("Xuất không thành công (T_T) !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                            else
                            {
                                XtraMessageBox.Show("Xuất kho thành công (^-^)!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                string sqll = "insert into LichSu values('" + userxuat + "',N'Xuất kho mặt hàng có: [Mã HĐ]:(" + txtmahd + ") ||[Mã hàng]:(" + txtmvt.Text + ") || [Barcode]:(" + txtbarcode.Text + ") || [Số lượng xuất]:(" + txtslnhap.Text + ") || [Đơn vị tính]:(" + txtdvtinh.Text + ") || [Ngày xuất]:(" + Convert.ToDateTime(date_nhap.Text).ToString("dd/MM/yyyy HH:mm:ss") + ") || [Người xuất]:(" + cb_user.EditValue.ToString() + ") || [Đơn vị giao nhận]:(" + txtdvgiaonhan.Text + ")','" + DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss") + "')";
                                ConnectDB.Query(sqll);
                                hien();
                            }
                            SqlConnection con = new SqlConnection(@"Data Source=192.168.1.53,1433;Initial Catalog=QLKhoBB;User ID=sa;Password=123456789");
                            con.Open();
                            SqlCommand     cmd = new SqlCommand("select * from XuatKho where sohd  = '" + txtmahd.Text + "'", con);
                            SqlDataAdapter da  = new SqlDataAdapter(cmd);
                            DataTable      dt  = new DataTable();
                            da.Fill(dt);
                            con.Close();
                            XtraReport2 rp = new XtraReport2();
                            rp.DataSource = dt;
                            rp.ShowPreviewDialog();
                        }
                        else
                        {
                            try
                            {
                                if (validate())
                                {
                                    string sql2 = "insert into XuatKho values('" + txtmahd.Text.Trim() + "','" + txtmvt.Text + "','" + txtbarcode.Text + "','" + txtslnhap.Text + "','" + txtdvtinh.Text + "','" + Convert.ToDateTime(date_nhap.Text).ToString("MM/dd/yyyy HH:mm:ss") + "',N'" + cb_user.EditValue.ToString() + "',N'" + txtdvgiaonhan.Text + "',N'" + txtghichu.Text + "')";

                                    if (ConnectDB.Query(sql2) == -1)
                                    {
                                        XtraMessageBox.Show("Xuất không thành công (T_T) !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                    }
                                    else
                                    {
                                        XtraMessageBox.Show("Xuất kho thành công (^-^)!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                        string sqll = "insert into LichSu values('" + userxuat + "',N'Xuất kho mặt hàng có: [Mã HĐ]:(" + txtmahd + ") ||[Mã hàng]:(" + txtmvt.Text + ") || [Barcode]:(" + txtbarcode.Text + ") || [Số lượng xuất]:(" + txtslnhap.Text + ") || [Đơn vị tính]:(" + txtdvtinh.Text + ") || [Ngày xuất]:(" + Convert.ToDateTime(date_nhap.Text).ToString("dd/MM/yyyy HH:mm:ss") + ") || [Người xuất]:(" + cb_user.EditValue.ToString() + ") || [Đơn vị giao nhận]:(" + txtdvgiaonhan.Text + ")','" + DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss") + "')";
                                        ConnectDB.Query(sqll);
                                        hien();
                                    }
                                }
                            }
                            catch
                            {
                                XtraMessageBox.Show("Không thể kết nối tới CSDL", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                        }
                    }
                }
                catch
                {
                    XtraMessageBox.Show("Không thể kết nối tới CSDL", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else
            {
                XtraMessageBox.Show("Mặt hàng này hiện trong kho còn ít hơn so với số lượng xuất!");
            }
        }