protected void btnXacNhan_Click(object sender, System.EventArgs e)
 {
     clsPhieuXuat oPhieuXuat = new clsPhieuXuat();
     oPhieuXuat.NhanVienLogon_Id = "3d2df69a-4d7c-4d78-a4a3-075a169a109d";
     oPhieuXuat.PhieuXuat_Id = sKey;
     oPhieuXuat.ChungTu = null;
     oPhieuXuat.KieuFile = "";
     oPhieuXuat.XacNhanPhieuXuat();
     lblThongBao.Text = "Xác nhận thành công!";
 }
Exemplo n.º 2
0
        public bool AddData(clsPhieuXuat phieuXuat)
        {
            _conn.CMD.CommandText = String.Format("INSERT [dbo].[tbPhieuXuat] (NgayLap,idCuaHang,idNhanVien,GhiChu,SoPhieuXuat"
                                                  + ",idLoaiPhieuXuat,idKhachHang,idChuyenHang,idNhaCungCap) "
                                                  + "VALUES (cast('{0}' as datetime),N'{1}',N'{2}',N'{3}',N'{4}',N'{5}',{6},{7},{8})"
                                                  , phieuXuat.NgayLap.ToString("yyyy-MM-dd hh:mm:ss.FFF")
                                                  , phieuXuat.IdCuaHang
                                                  , phieuXuat.IdNhanVien
                                                  , phieuXuat.GhiChu
                                                  , phieuXuat.SoPhieuXuat
                                                  , phieuXuat.IdLoaiPhieuXuat
                                                  , (phieuXuat.IdKhachHang != 0) ? "'" + phieuXuat.IdKhachHang.ToString() + "'" : "null"
                                                  , (phieuXuat.IdChuyenHang != 0) ? "'" + phieuXuat.IdChuyenHang.ToString() + "'" : "null"
                                                  , (phieuXuat.IdNhaCungCap != 0) ? "'" + phieuXuat.IdNhaCungCap.ToString() + "'" : "null"
                                                  );

            return(_conn.ExecuteCMD());
        }
Exemplo n.º 3
0
        public bool AddData(clsPhieuXuat phieuXuat)
        {
            DialogResult result = MessageBox.Show("Xác nhận tạo phiếu nhập " + GetNewMaPhieuXuatTraNhaCungCap() + " ?", "Xác nhận",
                                                  MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.No)
            {
                return(false);
            }
            ///them hoa don

            if (_mdlPhieuXuat.AddData(phieuXuat))
            {
                MessageBox.Show("Thêm thành công", "Thêm phiếu nhập", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //them chi tiet hoa don
                return(true);
            }
            else
            {
                MessageBox.Show("Thêm thất bại", "Thêm phiếu nhập", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(false);
        }
        private void bindData(int index)
        {
            try
            {
                //LAY DANH SACH CAC QUOC GIA RA
                dsGroup = new DataTable();
                dsPhieuNhapXuat = new DataTable();
                clsPhieuNhap objPhieuNhap = new clsPhieuNhap();
                clsPhieuXuat objPhieuXuat = new clsPhieuXuat();

                if (sLoaiPhieu == "0")
                {
                    objPhieuNhap.So_Phieu = sKey;
                    dsGroup = objPhieuNhap.Select_ChiTiet();
                    objPhieuNhap.PhieuNhap_Id = sPhieu_Id;
                    dsPhieuNhapXuat = objPhieuNhap.Select();
                    if (dsPhieuNhapXuat.Rows.Count > 0)
                    {
                        if (Convert.ToInt16(dsPhieuNhapXuat.Rows[0]["LoaiNhapXuat_Id"]) == 1)
                        {
                            txtLoaiNhapXuat.Text = "Phiếu nhập";
                        }
                        else
                        {
                            txtLoaiNhapXuat.Text = "Phiếu xuất";
                        }
                        txtSoPhieu.Text = dsPhieuNhapXuat.Rows[0]["so_phieu"].ToString();
                        txtLyDoNhap.Text = dsPhieuNhapXuat.Rows[0]["LyDoNhap"].ToString();
                        txtDienGiai.Text = dsPhieuNhapXuat.Rows[0]["Dien_Giai"].ToString();
                        dtpNgayNhapXuat.SelectedDate = Convert.ToDateTime(dsPhieuNhapXuat.Rows[0]["Ngay_Nhap"]);
                        if (dsPhieuNhapXuat.Rows[0]["DuAn_DanhRieng_Id"] == DBNull.Value)
                        {
                            txtDuAnDanhRieng.Text = "";
                        }
                        else
                        {
                            txtDuAnDanhRieng.Text = dsPhieuNhapXuat.Rows[0]["DuAn_DanhRieng_Id"].ToString();
                        }
                        txtNhanVienBan.Text = dsPhieuNhapXuat.Rows[0]["TenDayDu"].ToString();
                        txtNhanVienDoiTac.Text = dsPhieuNhapXuat.Rows[0]["TenDoiTac"].ToString();
                    }
                }
                else
                {
                    objPhieuXuat.So_Phieu = sKey;
                    dsGroup = objPhieuXuat.Select_ChiTiet();
                    objPhieuXuat.PhieuXuat_Id = sPhieu_Id;
                    dsPhieuNhapXuat = objPhieuXuat.Select();
                    if (dsPhieuNhapXuat.Rows.Count > 0)
                    {
                        if (Convert.ToInt16(dsPhieuNhapXuat.Rows[0]["LoaiNhapXuat_Id"]) == 1)
                        {
                            txtLoaiNhapXuat.Text = "Phiếu nhập";
                        }
                        else
                        {
                            txtLoaiNhapXuat.Text = "Phiếu xuất";
                        }
                        txtSoPhieu.Text = dsPhieuNhapXuat.Rows[0]["so_phieu"].ToString();
                        txtLyDoNhap.Text = dsPhieuNhapXuat.Rows[0]["LyDoXuat"].ToString();
                        txtDienGiai.Text = dsPhieuNhapXuat.Rows[0]["Dien_Giai"].ToString();
                        dtpNgayNhapXuat.SelectedDate = Convert.ToDateTime(dsPhieuNhapXuat.Rows[0]["Ngay_Xuat"]);
                        if (dsPhieuNhapXuat.Rows[0]["DuAn_Id"] == DBNull.Value)
                        {
                            txtDuAnDanhRieng.Text = "";
                        }
                        else
                        {
                            txtDuAnDanhRieng.Text = dsPhieuNhapXuat.Rows[0]["DuAn_Id"].ToString();
                        }
                        txtNhanVienBan.Text = dsPhieuNhapXuat.Rows[0]["TenDayDu"].ToString();
                        txtNhanVienDoiTac.Text = dsPhieuNhapXuat.Rows[0]["TenDoiTac"].ToString();
                    }
                }
                objPhieuNhap.So_Phieu = "0";

                m_grid.EditIndex = index;
                m_grid.DataSource = dsGroup;
                bool add = false;
                if (dsGroup.Rows.Count <= 0)
                {
                    dsGroup.Rows.Add(dsGroup.NewRow());
                    add = true;

                }
                //
                m_grid.DataBind();
                if (add)
                    m_grid.Rows[0].Visible = false;
                if (m_grid.Rows.Count > 0)
                {
                    string confirm = "return confirm('Bạn thật sự muốn xóa row này?')";

                    for (int i = 0; i < m_grid.Rows.Count; i++)
                    {
                        GridViewRow row = m_grid.Rows[i];
                        LinkButton lbutton1 = (LinkButton)row.FindControl("cmdDelete");
                        if (lbutton1 != null)
                        {
                            lbutton1.Visible = D_Option;
                            lbutton1.Attributes.Add("onclick", confirm);
                            //lbutton1.Enabled = D_Option;
                        }

                        LinkButton lbutton2 = (LinkButton)row.FindControl("cmdEdit");
                        if (lbutton2 != null)
                            lbutton2.Visible = U_Option;
                    }
                }

                //XET QUYETN CHO CHUC NANG INSERT
                GridViewRow row1 = m_grid.FooterRow;
                if (row1 != null)
                {
                    row1.Visible = I_Option;
                }
            }
            catch (Exception ex)
            {
            }
        }
        private void bindData(int index)
        {
            try
            {
                //LAY DANH SACH CAC QUOC GIA RA
                dsGroup = new DataTable();

                //Hiển thị tổng hợp
                clsPhieuXuat oPhieuXuat = new clsPhieuXuat();
                DataTable tblPhieuXuat = new DataTable();
                oPhieuXuat.PhieuXuat_Id = sKey;
                dsGroup = oPhieuXuat.Select_ThongTinThietBi();
                //
                tblPhieuXuat = oPhieuXuat.Select();
                if (tblPhieuXuat.Rows.Count > 0)
                {
                    txtSoPhieu.Text = tblPhieuXuat.Rows[0]["So_Phieu"].ToString();
                    dtpNgayNhap.SelectedDate = Convert.ToDateTime(tblPhieuXuat.Rows[0]["Ngay_Xuat"]);
                    txtNguoiNhan.Text = tblPhieuXuat.Rows[0]["NguoiXuat"].ToString();
                }

                m_grid.EditIndex = index;
                m_grid.DataSource = dsGroup;
                bool add = false;
                if (dsGroup.Rows.Count <= 0)
                {
                    dsGroup.Rows.Add(dsGroup.NewRow());
                    add = true;

                }
                //
                m_grid.DataBind();
                if (add)
                    m_grid.Rows[0].Visible = false;
                if (m_grid.Rows.Count > 0)
                {
                    string confirm = "return confirm('Bạn thật sự muốn xóa row này?')";

                    for (int i = 0; i < m_grid.Rows.Count; i++)
                    {
                        GridViewRow row = m_grid.Rows[i];
                        LinkButton lbutton1 = (LinkButton)row.FindControl("cmdDelete");
                        if (lbutton1 != null)
                        {
                            lbutton1.Visible = D_Option;
                            lbutton1.Attributes.Add("onclick", confirm);
                            //lbutton1.Enabled = D_Option;
                        }

                        LinkButton lbutton2 = (LinkButton)row.FindControl("cmdEdit");
                        if (lbutton2 != null)
                            lbutton2.Visible = U_Option;
                    }
                }

                //XET QUYETN CHO CHUC NANG INSERT
                GridViewRow row1 = m_grid.FooterRow;
                if (row1 != null)
                {
                    row1.Visible = I_Option;
                }
                //
                string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["SQLConn"].ToString();// "server='NgoQuangLua-PC'; uid=sa;pwd=sa; Database='QL'; trusted_connection=true;";
                System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(connectionString);
                string queryString = "select COUNT(*) sl_danhap from ThongTinThietBi a where a.PhieuXuat_Id='"+ sKey +"' and a.ThietBi_Id='"+ cboThietBi.SelectedValue +"'";
                sqlConnection.Open();
                SqlDataAdapter oAdap = new SqlDataAdapter(queryString, sqlConnection);

                DataTable tblTemp = new DataTable();
                oAdap.Fill(tblTemp);
                if (tblTemp.Rows.Count > 0)
                {
                    txtSoLuongDaCoChiTiet.Text = tblTemp.Rows[0]["sl_danhap"].ToString();
                    txtSoLuongCanNhapChiTiet.Text = (Convert.ToInt16(txtSoLuongNhapKho.Text == "" ? "0" : txtSoLuongNhapKho.Text) - Convert.ToInt16(txtSoLuongDaCoChiTiet.Text == "" ? "0" : txtSoLuongDaCoChiTiet.Text)).ToString();
                }
                else
                {
                    txtSoLuongDaCoChiTiet.Text = "0";
                    txtSoLuongCanNhapChiTiet.Text = (Convert.ToInt16(txtSoLuongNhapKho.Text == "" ? "0" : txtSoLuongNhapKho.Text) - Convert.ToInt16(txtSoLuongDaCoChiTiet.Text == "" ? "0" : txtSoLuongDaCoChiTiet.Text)).ToString();
                }

            }
            catch (Exception ex)
            {
            }
        }
        protected void m_grid_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                string commandName = e.CommandName;
                GridViewRow row = m_grid.FooterRow;

                if (commandName == "Insert")
                {
                    clsPhieuXuat oPhieuXuat = new clsPhieuXuat();
                    oPhieuXuat.NhanVienLogon_Id = "3d2df69a-4d7c-4d78-a4a3-075a169a109d";
                    oPhieuXuat.PhieuXuat_Id = sKey;
                    oPhieuXuat.ThongTinThietBi_Id = sThongTinThietBi_Id;

                    oPhieuXuat.InsertChiTietPhieuXuat();
                    bindData(-1);
                    sThongTinThietBi_Id = "";
                }
                else if (commandName == "TimKiem")
                {
                    string Ma_Serial = ((TextBox)row.FindControl("txtIMa_Serial")).Text;
                    string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["SQLConn"].ToString();// "server='NgoQuangLua-PC'; uid=sa;pwd=sa; Database='QL'; trusted_connection=true;";
                    System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(connectionString);
                    string queryString = "select * from ThongTinThietBi a where a.Ma_Serial='" + Ma_Serial + "' and a.trang_thai in (1,7)";
                    sqlConnection.Open();
                    SqlDataAdapter oAdap = new SqlDataAdapter(queryString, sqlConnection);

                    DataTable tblTemp = new DataTable();
                    oAdap.Fill(tblTemp);
                    if (tblTemp.Rows.Count > 0)
                    {
                        ((TextBox)row.FindControl("txtIMA_MAC")).Text = tblTemp.Rows[0]["Ma_MAC"].ToString();
                        ((TextBox)row.FindControl("txtIMA_DLK")).Text = tblTemp.Rows[0]["Ma_DLK"].ToString();
                        ((TextBox)row.FindControl("txtIMA_SLC")).Text = tblTemp.Rows[0]["Ma_SLC"].ToString();
                        sThongTinThietBi_Id = tblTemp.Rows[0]["ThongTinThietBi_Id"].ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                ltlAnnouncement.Text = "Khong them moi duoc du lieu. Vui long lien he voi quan tri<br>" + ex.Message;
            }
        }
        protected void m_grid_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            try
            {
                int id = e.RowIndex;
                m_grid.EditIndex = id;
                GridViewRow row = m_grid.Rows[id];

                string NhanVien_Logon_id = "3d2df69a-4d7c-4d78-a4a3-075a169a109d";
                string TenHangMuc = ((TextBox)row.FindControl("txtUHangMuc")).Text;
                string sSoLuong = ((TextBox)row.FindControl("txtUSoLuong")).Text;
                string sDonGia = ((TextBox)row.FindControl("txtUDonGia")).Text;

                double SoLuong = Convert.ToDouble(sSoLuong==""? "0": sSoLuong);
                double DonGia = Convert.ToDouble(sDonGia==""? "0": sDonGia);
                double TongTien = SoLuong * DonGia;
                double VAT = TongTien * 0.01;
                //double VAT = Convert.ToDouble(((TextBox)row.FindControl("txtIVAT")).Text);
                string sPhiCacLoai = ((TextBox)row.FindControl("txtUPhiCacLoai")).Text;
                string sGiamGia = ((TextBox)row.FindControl("txtUGiamGia")).Text;
                double PhiCacLoai = Convert.ToDouble(sPhiCacLoai==""? "0": sPhiCacLoai);
                double GiamGia = Convert.ToDouble(sGiamGia==""? "0": sGiamGia);
                double ThanhTien = TongTien + VAT + PhiCacLoai - GiamGia;
                //-------------
                string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["SQLConn"].ToString();
                System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(connectionString);
                SqlCommand cmd = new SqlCommand();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                cmd.CommandText = "select * from thanhpham where tenthanhpham=N'" + TenHangMuc + "'";
                cmd.Connection = sqlConnection;
                da = new SqlDataAdapter(cmd);
                da.Fill(ds);
                string ThanhPham_id = "";
                if (ds.Tables[0].Rows.Count > 0)
                {
                    ThanhPham_id = ds.Tables[0].Rows[0]["ThanhPham_Id"].ToString();
                }
                else
                {
                    ThanhPham_id = "";
                }
                ds = new DataSet();
                cmd.CommandText = "select * from thietbi where tenthietbi=N'" + TenHangMuc + "'";
                cmd.Connection = sqlConnection;
                da = new SqlDataAdapter(cmd);
                da.Fill(ds);
                string ThietBi_id = "";
                if (ds.Tables[0].Rows.Count > 0)
                {
                    ThietBi_id = ds.Tables[0].Rows[0]["ThietBi_Id"].ToString();
                }
                else
                {
                    ThietBi_id = "";
                }

                if (m_grid.DataKeys[id].Value.ToString() != "")
                {
                    clsPhieuXuat objPhieuXuat = new clsPhieuXuat();
                    objPhieuXuat.NhanVienLogon_Id = NhanVien_Logon_id;
                    objPhieuXuat.PhieuXuat_Id = sPhieuNhap_Id;
                    objPhieuXuat.ThietBi_Id = ThietBi_id;
                    objPhieuXuat.SoLuong = SoLuong;
                    objPhieuXuat.DonGia = DonGia;
                    objPhieuXuat.VAT = VAT;
                    objPhieuXuat.GiamGia = GiamGia;
                    objPhieuXuat.PhiCacLoai = PhiCacLoai;
                    string _result = objPhieuXuat.InsertChiTiet();

                }
            }
            catch (Exception ex)
            {
                ltlAnnouncement.Text = "Khong cap nhat duoc du lieu. Vui long lien he voi quan tri<br>" + ex.Message;
            }

            bindData(-1);
        }
        protected void btnGhi_Click(object sender, System.EventArgs e)
        {
            if (!bsua) //thêm mới
            {

                clsPhieuXuat oPhieuXuat = new clsPhieuXuat();
                byte[] productImage = FileUpload1.FileBytes;
                oPhieuXuat.NhanVienLogon_Id = "83e36d21-8607-4b6f-8dcc-4be0c0fd4ba5";
                oPhieuXuat.KeHoachNhapXuat_Id = sKey;
                oPhieuXuat.PhieuXuat_Id = sPhieuNhap_Id;
                oPhieuXuat.Ngay_Xuat = Convert.ToDateTime(dtpNgayNhapXuat.SelectedDate);
                oPhieuXuat.MaLoaiXuat_Id = cboMaLoaiNhap.SelectedValue;
                oPhieuXuat.LyDoXuat = txtLyDoNhap.Text;
                oPhieuXuat.Dien_Giai = txtDienGiai.Text;
                if (cboDuAn.SelectedIndex == 0)
                {
                    oPhieuXuat.DuAn_DanhRieng_Id = "";
                }
                else
                {
                    oPhieuXuat.DuAn_DanhRieng_Id = cboDuAn.SelectedValue;
                }
                oPhieuXuat.NhanVien_Xuat_Id = cboNhanVienNhapXuat.SelectedValue;
                oPhieuXuat.Ten_NhanVien_DoiTac = cboNhanVienDoiTac.Text;
                oPhieuXuat.NhanVien_DoiTac_Id = cboNhanVienDoiTac.SelectedValue;
                oPhieuXuat.ChungTu = productImage;
                oPhieuXuat.KieuFile = ".jpg";
                oPhieuXuat.So_Phieu = txtSoPhieu.Text;
                oPhieuXuat.Insert();
                lblThongBao.Text = "Tạo phiếu xuất thành công, mời bạn nhập chi tiết";
            }
            else //sửa
            {
                clsNhanVien oNhanVien = new clsNhanVien();
                //oNhanVien.NhanVien_Id = sKey;
                //oNhanVien.PhongBan_Id = cboPhongBan.SelectedValue.ToString();
                //oNhanVien.Ten = txtTen.Text;
                //oNhanVien.Ho = txtHo.Text;
                //oNhanVien.TenDayDu = txtTenDayDu.Text;
                //oNhanVien.DiaChi = txtDiaChi.Text;
                //oNhanVien.Tel = txtTel.Text;
                //oNhanVien.SubTel = txtSubTel.Text;
                //oNhanVien.Mobile = txtMobile.Text;
                //oNhanVien.HomePhone = "";
                //oNhanVien.Main_EMail = txtEmail.Text;
                //oNhanVien.Other_Email = txtOtherEmail.Text;
                //oNhanVien.ChucDanh = txtChucDanh.Text;
                //oNhanVien.GioiTinh = (byte)(cboGioiTinh.SelectedValue == "1" ? 1 : 0);
                //oNhanVien.Update();
                //sKey = "";
                bsua = false;
            }
            Init();
            BindData();
        }