Esempio n. 1
0
        public bool AddData(clsPhieuNhap phieuNhap)
        {
            _conn.CMD.CommandText = String.Format("INSERT [dbo].[tbPhieuNhap] (NgayLap,idCuaHang,idNhanVien,GhiChu,SoPhieuNhap"
                                                  + ",idLoaiPhieuNhap,idDonDatHang,idChuyenHang,idNhaCungCap,idHoaDon) "
                                                  + "VALUES (cast('{0}' as datetime),N'{1}',N'{2}',N'{3}',N'{4}',N'{5}',{6},{7},{8},{9})"
                                                  , phieuNhap.NgayLap.ToString("yyyy-MM-dd hh:mm:ss.FFF")
                                                  , phieuNhap.IdCuaHang
                                                  , phieuNhap.IdNhanVien
                                                  , phieuNhap.GhiChu
                                                  , phieuNhap.SoPhieuNhap
                                                  , phieuNhap.IdLoaiPhieuNhap
                                                  , (phieuNhap.IdDonDatHang != 0) ? "'" + phieuNhap.IdDonDatHang.ToString() + "'" : "null"
                                                  , (phieuNhap.IdChuyenHang != 0) ? "'" + phieuNhap.IdChuyenHang.ToString() + "'" : "null"
                                                  , (phieuNhap.IdNhaCungCap != 0) ? "'" + phieuNhap.IdNhaCungCap.ToString() + "'" : "null"
                                                  , (phieuNhap.IdHoaDon != 0) ? "'" + phieuNhap.IdHoaDon.ToString() + "'" : "null");

            return(_conn.ExecuteCMD());
        }
Esempio n. 2
0
        public bool AddData(clsPhieuNhap phieuNhap)
        {
            DialogResult result = MessageBox.Show("Xác nhận tạo phiếu nhập " + GetNewMaPhieuNhapTuNhaCungCapByNow() + " ?", "Xác nhận",
                                                  MessageBoxButtons.YesNo, MessageBoxIcon.Question);

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

            if (_mdlPhieuNhap.AddData(phieuNhap))
            {
                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);
        }
        protected void m_grid_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                string commandName = e.CommandName;
                GridViewRow row = m_grid.FooterRow;

                if (commandName == "Insert")
                {
                    clsPhieuNhap oPhieuNhap = new clsPhieuNhap();
                    string PhieuNhap = sKey;
                    string ThietBiId = cboThietBi.SelectedValue.ToString();
                    string Ma_Serial = ((TextBox)row.FindControl("txtIMa_Serial")).Text;
                    string Ma_MAC = ((TextBox)row.FindControl("txtIMA_MAC")).Text;
                    string Ma_SLC = ((TextBox)row.FindControl("txtIMA_SLC")).Text;
                    string Ma_DLK = ((TextBox)row.FindControl("txtIMa_DLK")).Text;
                    string DienGiai = "";
                    int TinhTrang = 1;

                    oPhieuNhap.PhieuNhap_Id = PhieuNhap;
                    oPhieuNhap.ThietBi_Id = ThietBiId;
                    oPhieuNhap.Ma_Serial = Ma_Serial;
                    oPhieuNhap.Ma_MAC = Ma_MAC;
                    oPhieuNhap.Ma_SLC = Ma_SLC;
                    oPhieuNhap.Ma_DLK = Ma_DLK;
                    oPhieuNhap.Dien_Giai = DienGiai;
                    oPhieuNhap.TinhTrangHang = TinhTrang;

                    string _result = oPhieuNhap.InsertThongTinThietBi();
                    bindData(-1);
                }
            }
            catch (Exception ex)
            {
                ltlAnnouncement.Text = "Khong them moi duoc du lieu. Vui long lien he voi quan tri<br>" + ex.Message;
            }
        }
        private void bindData(int index)
        {
            try
            {
                //LAY DANH SACH CAC QUOC GIA RA
                dsGroup = new DataTable();

                //Hiển thị tổng hợp
                clsPhieuNhap oPhieuNhap = new clsPhieuNhap();
                DataTable tblPhieuNhap = new DataTable();
                oPhieuNhap.PhieuNhap_Id = sKey;
                dsGroup = oPhieuNhap.Select_ThongTinThietBi();
                //
                tblPhieuNhap = oPhieuNhap.Select();
                if (tblPhieuNhap.Rows.Count > 0)
                {
                    txtSoPhieu.Text = tblPhieuNhap.Rows[0]["So_Phieu"].ToString();
                    dtpNgayNhap.SelectedDate = Convert.ToDateTime(tblPhieuNhap.Rows[0]["Ngay_Nhap"]);
                    txtNguoiNhan.Text = tblPhieuNhap.Rows[0]["Nguoi_Mua"].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.PhieuNhap_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_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            try
            {
                int id = e.RowIndex;
                m_grid.EditIndex = id;
                GridViewRow row = m_grid.Rows[id];

                clsPhieuNhap oPhieuNhap = new clsPhieuNhap();
                oPhieuNhap.ThongTinThietBi_Id = m_grid.DataKeys[e.RowIndex].Value.ToString();
                DataTable tbltem = new DataTable();
                tbltem = oPhieuNhap.Select_ThongTinThietBi_OneRow();

                string PhieuNhap = sKey;
                string ThietBiId = cboThietBi.SelectedValue.ToString();
                string Ma_Serial = ((TextBox)row.FindControl("txtIMa_Serial")).Text;
                string Ma_MAC = ((TextBox)row.FindControl("txtIMA_MAC")).Text;
                string Ma_SLC = ((TextBox)row.FindControl("txtIMA_SLC")).Text;
                string Ma_DLK = ((TextBox)row.FindControl("txtIMa_DLK")).Text;
                string DienGiai = "";
                int TinhTrang = 1;

                if (m_grid.DataKeys[id].Value.ToString() != "")
                {

                    oPhieuNhap.PhieuNhap_Id = PhieuNhap;
                    oPhieuNhap.ThietBi_Id = ThietBiId;
                    oPhieuNhap.Ma_Serial = Ma_Serial;
                    oPhieuNhap.Ma_MAC = Ma_MAC;
                    oPhieuNhap.Ma_SLC = Ma_SLC;
                    oPhieuNhap.Ma_DLK = Ma_DLK;
                    oPhieuNhap.Dien_Giai = DienGiai;
                    oPhieuNhap.TinhTrangHang = TinhTrang;
                    string _result = oPhieuNhap.InsertThongTinThietBi();
                    if (_result == "1")
                    {
                        ltlAnnouncement.Text = "Sửa kế hoạch nhập xuất chi tiết '" + sKey + "' thành công!";
                    }

                }
            }
            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 m_grid_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            try
            {
                int id = e.RowIndex;
                m_grid.EditIndex = id;

                Guid delId = new Guid(m_grid.DataKeys[e.RowIndex].Value.ToString());
                if (m_grid.DataKeys[e.RowIndex].Value.ToString() != "")
                {
                    clsPhieuNhap oPhieuNhap = new clsPhieuNhap();
                    oPhieuNhap.ThongTinThietBi_Id = m_grid.DataKeys[e.RowIndex].Value.ToString();
                    int status_Delete = oPhieuNhap.Delete_ThongTinThietBi();
                    if (status_Delete == 1)
                    {
                        ltlAnnouncement.Text = "Xóa thành công kế hoạch nhập xuất chi tiết!";
                    }
                    if (status_Delete <= 0)
                    {
                        ltlAnnouncement.Text = "Không xóa được kế hoạch nhập xuất chi tiết.";
                    }
                }
            }
            catch (Exception ex)
            {
                ltlAnnouncement.Text = "Lỗi trong quá trình xóa kế hoạch nhập xuất chi tiết: " + ex.ToString();
            }
            bindData(-1);
        }
        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)
            {
            }
        }
        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.ToString() == "PheDuyet")
            {
                int index = Convert.ToInt32(e.CommandArgument);
                GridViewRow gvRow = GridView1.Rows[index];

                if (GridView1.DataKeys[index].Value.ToString() != "")
                {
                    clsPhieuNhap objPhieuNhap = new clsPhieuNhap();
                    objPhieuNhap.So_Phieu= GridView1.DataKeys[index].Value.ToString();
                    sKey = GridView1.DataKeys[index].Value.ToString();
                    //hien thi popup
                    HttpCookie C = new HttpCookie("So_Phieu");
                    C["Data"] = gvRow.Cells[0].Text;
                    Response.Cookies.Add(C);

                    HttpCookie C1 = new HttpCookie("LoaiPhieu");
                    C1["Data"] = cboLoaiPhieu.SelectedIndex.ToString();
                    Response.Cookies.Add(C1);

                    HttpCookie C2 = new HttpCookie("Phieu_Id");
                    C2["Data"] = sKey;
                    Response.Cookies.Add(C2);

                    string window = "../QLKho/ChiTietPhieuNhapXuat.aspx";
                    string newwin = "window.open('" + window + "');";
                    ClientScript.RegisterStartupScript(this.GetType(), "pop", newwin, true);
                }

            }
            else if (e.CommandName.ToString() == "KhongPheDuyet")
            {
                //try
                //{
                //    int id = Convert.ToInt32(e.CommandArgument);
                //    GridView1.EditIndex = id;

                //    Guid delId = new Guid(GridView1.DataKeys[id].Value.ToString());

                //    if (GridView1.DataKeys[id].Value.ToString() != "")
                //    {
                //        clsKeHoachNhapXuat objKeHoachNhapXuat = new clsKeHoachNhapXuat();
                //        objKeHoachNhapXuat.KeHoachNhapXuat_Id = GridView1.DataKeys[id].Value.ToString();
                //        DataTable mytable = new DataTable();
                //        mytable = objKeHoachNhapXuat.Select_onerow();

                //        objKeHoachNhapXuat.NhanVien_Lap_Id = mytable.Rows[0]["NhanVien_Lap_Id"].ToString();
                //        int status_Delete = objKeHoachNhapXuat.Delete();

                //    }
                //}
                //catch (Exception ex)
                //{
                //    ltlAnnouncement.Text = "Lỗi trong quá trình xóa nhóm người dùng: " + ex.ToString();
                //}
            }
            BindData();
        }
Esempio n. 9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // ---- KIEM TRA LOGIN -----
            if (Session["UserId"] == null)
            {
                Response.Redirect("~/login.aspx");
            }
            // ---- END KT LOGIN -------

            if (!this.IsPostBack)
            {

                getAuthorization();
                //
                cboKeHoachNhapXuat.DataSource = GetSourceKeHoach();
                cboKeHoachNhapXuat.DataTextField = "Code";
                cboKeHoachNhapXuat.DataValueField = "KeHoachNhapXuat_Id";
                cboKeHoachNhapXuat.DataBind();
                //
                sPhieuNhap_Id = Guid.NewGuid().ToString();
            }
            _dtFunction = new DataTable();
            _dtFunction = (new QLCV.code.common.clsKhoMain()).Get_List_Menu(Session["UserId"].ToString());
            BindData();
            //Lấy số phiếu
            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();
            string sTemp = "";
            if (cboKeHoachNhapXuat.SelectedValue.ToString().Length > 0)
            {
                sTemp = cboKeHoachNhapXuat.SelectedValue;
            }
            else
            {
                sTemp = Guid.NewGuid().ToString();
            }
            cmd.CommandText = "select b.DonVi_Id,b.Kho_Id from Kho b where b.Kho_Id=(select a.Kho_Id from KeHoachNhapXuat a where a.KeHoachNhapXuat_Id='"+ sTemp +"')";
            cmd.Connection = sqlConnection;
            da = new SqlDataAdapter(cmd);
            da.Fill(ds);
            sqlConnection.Open();
            cmd.ExecuteNonQuery();

            clsPhieuNhap oPhieuNhap = new clsPhieuNhap();
            if (ds.Tables[0].Rows.Count > 0)
            {
                oPhieuNhap.DonVi_Id = ds.Tables[0].Rows[0]["DonVi_Id"].ToString();
                oPhieuNhap.Kho_Id = ds.Tables[0].Rows[0]["Kho_Id"].ToString();
            }
            else
            {
                oPhieuNhap.DonVi_Id = "a0f3f798-b9bc-4537-b97c-997b638f5450";
            }
            oPhieuNhap.LoaiPhieu = 1;
            oPhieuNhap.Ngay_Nhap = DateTime.Today;
            //txtSoPhieu.Text=oPhieuNhap.LaySoPhieu();
        }
        protected void m_grid_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                string commandName = e.CommandName;
                GridViewRow row = m_grid.FooterRow;
                if (commandName == "Insert")
                {
                    string NhanVien_Logon_id = "3d2df69a-4d7c-4d78-a4a3-075a169a109d";
                    string ThietBi_id = ((DropDownList)row.FindControl("txtITenThietBi")).Text;
                    string ThanhPham_id = ((DropDownList)row.FindControl("txtITenThanhPham")).Text;
                    double SoLuong = Convert.ToDouble(((TextBox)row.FindControl("txtISoLuong")).Text);
                    double DonGia = Convert.ToDouble(((TextBox)row.FindControl("txtIDonGia")).Text);
                    double VAT = Convert.ToDouble(((TextBox)row.FindControl("txtIVAT")).Text);
                    double PhiCacLoai = Convert.ToDouble(((TextBox)row.FindControl("txtIPhiCacLoai")).Text);
                    double GiamGia = Convert.ToDouble(((TextBox)row.FindControl("txtIGiamGia")).Text);

                    clsPhieuNhap objPhieuNhap = new clsPhieuNhap();
                    objPhieuNhap.NhanVienLogon_Id = NhanVien_Logon_id;
                    objPhieuNhap.PhieuNhap_Id = sPhieuNhap_Id;
                    objPhieuNhap.ThanhPham_Id = ThanhPham_id;
                    objPhieuNhap.ThietBi_Id = ThietBi_id;
                    objPhieuNhap.SoLuong = SoLuong;
                    objPhieuNhap.DonGia = DonGia;
                    objPhieuNhap.VAT = VAT;
                    objPhieuNhap.GiamGia = GiamGia;
                    objPhieuNhap.PhiCacLoai = PhiCacLoai;

                    string _result = objPhieuNhap.InsertChiTiet();
                    bindData(-1);
                }
            }
            catch (Exception ex)
            {
                ltlAnnouncement.Text = "Khong them moi duoc du lieu. Vui long lien he voi quan tri<br>" + ex.Message;
            }
        }