示例#1
0
        private void btnDong_Click(object sender, EventArgs e)
        {
            try {
                if (dtSoPhieuNhap != null && dtSoPhieuNhap.Rows.Count > 0)
                {
                    btnGhi_Click(sender, e);
                    GtidCommand sqlCmd = ConnectionUtil.Instance.GetConnection().CreateCommand();
                    sqlCmd.CommandTimeout = 0;
                    sqlCmd.CommandType    = CommandType.Text;
                    sqlCmd.CommandText    = String.Format("SELECT ct.IdChungTu, ct.SoChungTu, t1.ThucTe, t2.SoSach FROM tbl_ChungTu ct "
                                                          + "INNER JOIN (SELECT IdChungTu, SUM(ctcthh.SoLuong) as ThucTe FROM tbl_ChungTu_ChiTiet_HangHoa ctcthh "
                                                          + "INNER JOIN tbl_ChungTu_ChiTiet ctct ON ctct.IdChiTiet = ctcthh.IdChiTietChungTu "
                                                          + "GROUP BY IdChungTu) t1 ON ct.IdChungTu = t1.IdChungTu AND ct.LoaiChungTu={0} AND ct.IdKho={1} AND ct.ThoigianTao < '{2}' AND ct.ThoigianTao > '{3}' "

                                                          + "RIGHT OUTER JOIN (SELECT t1.SoPhieuNhap, t1.SoPO, ct.IdChungTu, SUM(SoLuong) as SoSach FROM tbl_Tmp_NhapHang t1 "
                                                          + "LEFT OUTER JOIN tbl_ChungTu ct ON ct.SoChungTu=t1.SoPhieuNhap AND ct.SoSeri=t1.SoPO AND ct.LoaiChungTu={0} AND ct.IdKho={1} "
                                                          + "AND (SELECT TOP (1) soluong FROM tbl_chungtu_chitiet WHERE tbl_chungtu_chitiet.idchungtu = ct.idchungtu)>=0 "
                                                          + "WHERE InventoryOrg='{4}' AND InventorySub='{5}' AND ThoiGian < '{2}' AND ThoiGian > '{3}' AND SoLuong >= 0 GROUP BY SoPhieuNhap, SoPO, IdChungTu "
                                                          + "UNION ALL "
                                                          + "SELECT t1.SoPhieuNhap, t1.SoPO, ct.IdChungTu, SUM(SoLuong) as SoSach FROM tbl_Tmp_NhapHang t1 "
                                                          + "LEFT OUTER JOIN tbl_ChungTu ct ON ct.SoChungTu=t1.SoPhieuNhap AND ct.SoSeri=t1.SoPO AND ct.LoaiChungTu={0} AND ct.IdKho={1} "
                                                          + "AND (SELECT TOP (1) soluong FROM tbl_chungtu_chitiet WHERE tbl_chungtu_chitiet.idchungtu = ct.idchungtu)<0 "
                                                          + "WHERE InventoryOrg='{4}' AND InventorySub='{5}' AND ThoiGian < '{2}' AND ThoiGian > '{3}' AND SoLuong < 0 GROUP BY SoPhieuNhap, SoPO, IdChungTu "
                                                          + ") t2 ON ct.IdChungTu = t2.IdChungTu",
                                                          (int)TransactionType.NHAP_PO,
                                                          Declare.IdKho,
                                                          DateTime.Now.ToString(new CultureInfo("en-US")),
                                                          //dtNgayDongBo.Value.ToString(new CultureInfo("en-US")),
                                                          lanDongBoTruoc.ToString(new CultureInfo("en-US")),
                                                          inventoryOrg,
                                                          inventorySub);
                    DataTable dt = DBTools.getData(sqlCmd, "Temp").Tables["Temp"];
                    if (dt.Rows.Count == 0)
                    {
                        MessageBox.Show("Bạn chưa nhập đủ số lượng hàng trong các phiếu mua này", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        return;
                    }
                    foreach (DataRow dr in dt.Rows)
                    {
                        if (!int.Equals(dr["ThucTe"], dr["SoSach"]))
                        {
                            MessageBox.Show("Bạn chưa nhập đủ số lượng hàng trong các phiếu mua này", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                            return;
                        }
                    }
                    sqlCmd.CommandText = String.Format("Update tbl_DM_Kho set LanDongBoTruoc='{0}' WHERE IdKho={1}", dtNgayDongBo.Value.ToString(new CultureInfo("en-US")), DBTools.getValue(String.Format("SELECT IdKho FROM tbl_DM_Kho WHERE MaKho='{0}'", cboKho.SelectedValue)));
                    sqlCmd.ExecuteNonQuery();
                    MessageBox.Show("Đã cập nhật thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                isFinished = true;
                this.Close();
            }
            catch (System.Exception ex) {
#if DEBUG
                MessageBox.Show(ex.ToString());
#else
                MessageBox.Show(ex.Message);
#endif
            }
        }
示例#2
0
        private void tsbDelete_Click(object sender, EventArgs e)
        {
            try {
                if (IdChungTu > 0)
                {
                    if (MessageBox.Show("Bạn có chắc chắn không?", "Xác nhận", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        GtidCommand sqlcmd = new GtidCommand();
                        sqlcmd.CommandType = CommandType.StoredProcedure;
                        sqlcmd.CommandText = "sp_tbl_ChungTu_XuatHuyTieuHao_Delete";
                        sqlcmd.Parameters.AddWithValue("@IdChungTu", IdChungTu);
                        DBTools.ExecuteScalar(sqlcmd);
                        dgvList.Rows.Clear();
                        MessageBox.Show("Đã xóa thành công");
                        //int IdKho = int.Parse(DBTools.getValue(String.Format("Select IdKho from tbl_DM_Kho where MaKho='{0}'", dgr.Cells["MaKho"].Value)));
                        //QLBanHang.Class.Common.LogAction("Xóa xuất hủy", "IdChungTu " + IdChungTu, IdKho);
                        GetChungTuData();
                        if (CurrentIndex >= dtChungTu.Rows.Count)
                        {
                            CurrentIndex--;
                        }
                        LoadFormIndex();
                        EnableForm(this, false);
                        EnableMenuFunc();
                    }
                }
            }
            catch (System.Exception ex) {
#if DEBUG
                MessageBox.Show("Lỗi ngoại lệ: " + ex.ToString(), Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
#else
                MessageBox.Show("Lỗi ngoại lệ: " + ex.Message, Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
#endif
            }
        }
示例#3
0
        private void frm_ChungTuNhap_FormClosing(object sender, FormClosingEventArgs e)
        {
            try {
                if (dtSoPhieuNhap != null && dtSoPhieuNhap.Rows.Count > 0 && !isFinished && e.CloseReason == CloseReason.UserClosing)
                {
                    if (MessageBox.Show("Các phiếu mua hàng chưa được cập nhật hết, bạn có thực sự muốn đóng lại không?", "Xác nhận", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    {
                        e.Cancel = true;
                        return;
                    }
                    if (!IsValid())
                    {
                        return;
                    }
                    btnGhi_Click(sender, e);
                }

                GtidCommand sqlCmd = ConnectionUtil.Instance.GetConnection().CreateCommand();
                sqlCmd.CommandText = "sp_LockFunction_Update";
                sqlCmd.CommandType = CommandType.StoredProcedure;
                sqlCmd.Parameters.AddWithValue("@FormName", this.GetType().Name);
                sqlCmd.Parameters.AddWithValue("@IdKho", Declare.IdKho);
                sqlCmd.ExecuteNonQuery();
            }
            catch (System.Exception ex) {
                EventLogProvider.Instance.WriteLog(ex.ToString(), this.Name);
#if DEBUG
                MessageBox.Show(ex.ToString());
#else
                MessageBox.Show(ex.Message);
#endif
            }
        }
示例#4
0
        private void UpdateChiTiet(int IdKiemKe, int IdSanPham, int SoLuong)
        {
            GtidCommand sqlcmd = new GtidCommand();

            sqlcmd.CommandType = CommandType.StoredProcedure;

            sqlcmd.CommandText = "sp_KiemKe_ChiTiet_Insert";
            sqlcmd.Parameters.Clear();
            sqlcmd.Parameters.AddWithValue("@IdChiTiet", 0).Direction = ParameterDirection.Output;
            sqlcmd.Parameters.AddWithValue("@IdKiemKe", IdKiemKe);
            sqlcmd.Parameters.AddWithValue("@IdSanPham", IdSanPham);
            sqlcmd.Parameters.AddWithValue("@SoLuong", SoLuong);
            if (!DBTools.InsertRecord(sqlcmd))
            {
                throw DBTools._LastError;
            }
            int IdChiTietKiemKe = int.Parse(sqlcmd.Parameters["@IdChiTiet"].Value.ToString());

            sqlcmd.CommandText = "sp_KiemKe_ChiTiet_HangHoa_Insert";
            for (int i = 0; i < dgvList.Rows.Count; i++)
            {
                if (IdSanPham == int.Parse(dgvList.Rows[i].Cells["IdSanPham"].Value.ToString()))
                {
                    sqlcmd.Parameters.Clear();
                    sqlcmd.Parameters.AddWithValue("@IdChiTietKiemKe", IdChiTietKiemKe);
                    sqlcmd.Parameters.AddWithValue("@IdChiTietHangHoa", dgvList.Rows[i].Cells["IdChiTietHangHoa"].Value);
                    sqlcmd.Parameters.AddWithValue("@SoLuong", dgvList.Rows[i].Cells["SoLuong"].Value);
                    if (!DBTools.InsertRecord(sqlcmd))
                    {
                        throw DBTools._LastError;
                    }
                }
            }
        }
示例#5
0
        private GtidCommand DeleteCommandPhieuXuat(int IdPhieuXuat)
        {
            GtidCommand sql = new GtidCommand("sp_PhieuXuat_Delete");

            sql.Parameters.AddWithValue("@IdPhieuXuat", IdPhieuXuat).Direction = ParameterDirection.Input;
            sql.CommandType = CommandType.StoredProcedure;
            return(sql);
        }
示例#6
0
        private GtidCommand DanhMuc_IsChecExitForeginKeyCommand(int IdDM)
        {
            GtidCommand sql = new GtidCommand("sp" + this.TenBang.Substring(3) + "_ChkRef");

            sql.Parameters.AddWithValue("@" + TenTruong1, IdDM).Direction = ParameterDirection.Input;
            sql.Parameters.AddWithValue("@IsCheck", 0).Direction          = ParameterDirection.Output;
            sql.CommandType = CommandType.StoredProcedure;
            return(sql);
        }
示例#7
0
        private GtidCommand DanhMuc_DeleteCommand(int IdDanhMuc)
        {
            GtidCommand sqlcmd = new GtidCommand();

            sqlcmd.CommandText = "sp" + this.TenBang.Substring(3) + "_Delete";
            sqlcmd.Parameters.AddWithValue("@" + this.TenTruong1.Trim(), IdDanhMuc).Direction = ParameterDirection.Input;
            sqlcmd.CommandType = CommandType.StoredProcedure;
            return(sqlcmd);
        }
示例#8
0
        private GtidCommand ChecIsDelete_NguoiDung(int IdNguoiDung)
        {
            GtidCommand sql = new GtidCommand("sp_DM_NguoiDung_CheckIsDelete");

            sql.Parameters.AddWithValue("@IdNguoiDung", IdNguoiDung).Direction = ParameterDirection.Input;
            sql.Parameters.AddWithValue("@IsCheck", 0).Direction = ParameterDirection.Output;
            sql.CommandType = CommandType.StoredProcedure;
            return(sql);
        }
示例#9
0
        private void LaySoPhieu()
        {
            GtidCommand sqlcmd = new GtidCommand();

            sqlcmd.CommandText = "sp_KiemKe_SoHoaDonTuDong";
            sqlcmd.CommandType = CommandType.StoredProcedure;
            sqlcmd.Parameters.AddWithValue("@Code", "KK");
            txtSoPhieu.Text = (string)DBTools.ExecuteScalar(sqlcmd);
        }
        private void btnXoa_Click(object sender, EventArgs e)
        {
            try {
                if (MessageBox.Show("Bạn có chắc chắn xóa toàn bộ dữ liệu không?", "Xác nhận", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    GtidCommand sqlcmd = new GtidCommand();
                    sqlcmd.CommandType = CommandType.StoredProcedure;
                    sqlcmd.CommandText = "sp_CapNhatTonDauKy_Delete";
                    ConnectionUtil.Instance.BeginTransaction();
                    foreach (DataGridViewRow dgr in dgvList.Rows)
                    {
                        sqlcmd.Parameters.Clear();
                        sqlcmd.Parameters.AddWithValue("@ThoiGian", dtNgayDuDau.Value.Date);
                        sqlcmd.Parameters.AddWithValue("@IdKho", cboKho.SelectedValue);
                        sqlcmd.Parameters.AddWithValue("@IdSanPham", dgr.Cells["IdSanPham"].Value == null ? DBNull.Value : dgr.Cells["IdSanPham"].Value);
                        sqlcmd.Parameters.AddWithValue("@NguoiTao", Declare.UserId);
                        if (!DBTools.DeleteRecord(sqlcmd))
                        {
                            throw DBTools._LastError;
                        }
                    }
                    dgvList.DataSource = null;
                    dgvList.Rows.Clear();
                    if (deletedTemp != null)
                    {
                        foreach (int i in deletedTemp)
                        {
                            sqlcmd.Parameters.Clear();
                            sqlcmd.Parameters.AddWithValue("@ThoiGian", dtNgayDuDau.Value.Date);
                            sqlcmd.Parameters.AddWithValue("@IdKho", cboKho.SelectedValue);
                            sqlcmd.Parameters.AddWithValue("@IdSanPham", i);
                            sqlcmd.Parameters.AddWithValue("@NguoiTao", Declare.UserId);
                            if (!DBTools.DeleteRecord(sqlcmd))
                            {
                                throw DBTools._LastError;
                            }
                        }
                        deletedTemp = null;
                    }
                    if (arrTemp != null)
                    {
                        arrTemp = null;
                    }
                    ConnectionUtil.Instance.CommitTransaction();
                }
            }
            catch (System.Exception ex) {
                ConnectionUtil.Instance.RollbackTransaction();
#if DEBUG
                MessageBox.Show(ex.ToString());
#else
                MessageBox.Show(ex.Message);
#endif
            }
        }
        private void frmThongTin_Load(object sender, EventArgs e)
        {
            //Connection objConn = new Connection();
            IDataReader DataReader = null;

            //SqlConnection SqlConn = Connection.Instance.GetSqlConnection();
            //using (SqlConnection SqlConn = objConn.GetSqlConnection())
            //{
            try
            {
                GtidCommand SqlComm = new GtidCommand("Select * From tbl_ThongTin", ConnectionUtil.Instance.GetConnection());
                SqlComm.CommandType = CommandType.Text;
                //if (!(SqlConn.State == ConnectionState.Open)) SqlConn.Open();
                DataReader = SqlComm.ExecuteReader();
                if (DataReader.Read())
                {
                    txtTenDoanhNghiep.Text = DataReader["TenDoanhNghiep"].ToString();
                    txtDiaChi.Text         = DataReader["DiaChi"].ToString();
                    txtVPGiaoDich.Text     = DataReader["VPGiaoDich"].ToString();
                    txtDienThoai.Text      = DataReader["DienThoai"].ToString();
                    txtFax.Text            = DataReader["Fax"].ToString();
                    txtEmail.Text          = DataReader["Email"].ToString();
                    txtWebsite.Text        = DataReader["Website"].ToString();
                    txtMaSoThue.Text       = DataReader["MaSoThue"].ToString();
                    txtSoTaiKhoan.Text     = DataReader["SoTaiKhoan"].ToString();
                    txtNganHang.Text       = DataReader["NganHang"].ToString();
                    txtMota.Text           = DataReader["MoTa"].ToString();
                }
                else
                {
                    txtTenDoanhNghiep.Text = "";
                    txtDiaChi.Text         = "";
                    txtVPGiaoDich.Text     = "";
                    txtDienThoai.Text      = "";
                    txtFax.Text            = "";
                    txtEmail.Text          = "";
                    txtWebsite.Text        = "";
                    txtMaSoThue.Text       = "";
                    txtSoTaiKhoan.Text     = "";
                    txtNganHang.Text       = "";
                    txtMota.Text           = "";
                }
            }
            catch
            {
            }
            finally
            {
                DataReader.Close();
                //if (!(SqlConn.State == ConnectionState.Closed)) SqlConn.Close();
            }
            //}
        }
示例#12
0
        private GtidCommand DanhMuc_UpdateCommand(Object[] arrMangThongTin)
        {
            GtidCommand sqlcmd = new GtidCommand();

            sqlcmd.CommandText = "sp" + this.TenBang.Substring(3) + "_Update";
            sqlcmd.Parameters.AddWithValue("@" + this.TenTruong1.Trim(), arrMangThongTin[0]).Direction = ParameterDirection.Input;
            sqlcmd.Parameters.AddWithValue("@" + this.TenTruong2.Trim(), arrMangThongTin[1]).Direction = ParameterDirection.Input;
            sqlcmd.Parameters.AddWithValue("@" + this.TenTruong3.Trim(), arrMangThongTin[2]).Direction = ParameterDirection.Input;
            sqlcmd.Parameters.AddWithValue("@" + this.TenTruong4.Trim(), arrMangThongTin[3]).Direction = ParameterDirection.Input;
            sqlcmd.Parameters.AddWithValue("@" + this.TenTruong5.Trim(), arrMangThongTin[4]).Direction = ParameterDirection.Input;
            sqlcmd.CommandType = CommandType.StoredProcedure;
            return(sqlcmd);
        }
示例#13
0
        public static void Unlock(string functionName, int idKho)
        {
            GtidCommand sqlCmd = ConnectionUtil.Instance.GetConnection().CreateCommand();

            sqlCmd.CommandText = "sp_LockFunction_Update1";
            sqlCmd.CommandType = CommandType.StoredProcedure;
            sqlCmd.Parameters.AddWithValue("@FormName", functionName);
            sqlCmd.Parameters.AddWithValue("@IdKho", idKho);
            sqlCmd.Parameters.AddWithValue("@IdUser", Declare.UserId);
            sqlCmd.Parameters.AddWithValue("@Computer", Common.GetComputerName());
            sqlCmd.Parameters.AddWithValue("@ProcessId", Process.GetCurrentProcess().Id);
            sqlCmd.ExecuteNonQuery();
        }
        private void CapNhatTheBaoHanh()
        {
            try
            {
                oDataSource.IdChungTu   = ChungTu.IdChungTu;
                oDataSource.SoPhieuXuat = txtSoPhieu.Text.ToUpper().Trim();
                oDataSource.TenDoiTuong = txtHoTen.Text.Trim();
                oDataSource.DienThoai   = txtDienThoai.Text.Trim();
                oDataSource.MaRieng     = txtMaKH.Text.Trim();
                oDataSource.DiaChi      = txtDiaChi.Text.Trim();

                foreach (InPhieuBaoHanhChiTietInfor pt in lstBaoHanh)
                {
                    GtidCommand sqlcmd = null;
                    sqlcmd = ConnectionUtil.Instance.GetConnection().CreateCommand();
                    ConnectionUtil.Instance.BeginTransaction();

                    sqlcmd.CommandType = CommandType.StoredProcedure;
                    sqlcmd.CommandText = "sp_BaoHanh_Insert";

                    int    idPhieuXuat = oDataSource != null ? oDataSource.IdChungTu : 0;
                    string ghichu      = "Số phiếu BH: " + txtSoPhieu.Text;
                    ghichu += "\r\n Khách hàng: " + txtHoTen.Text;
                    ghichu += "\r\n Nơi mua hàng: " + pt.NoiMua;

                    sqlcmd.Parameters.Clear();
                    sqlcmd.Parameters.AddWithValue("@IdBaoHanh", 0).Direction             = ParameterDirection.Output;
                    sqlcmd.Parameters.AddWithValue("@SerialNumber", pt.MaVach).Direction  = ParameterDirection.Input;
                    sqlcmd.Parameters.AddWithValue("@IdPhieuXuat", idPhieuXuat).Direction = ParameterDirection.Input;
                    sqlcmd.Parameters.AddWithValue("@NgayBatDau", pt.NgayMua).Direction   = ParameterDirection.Input;
                    sqlcmd.Parameters.AddWithValue("@NgayKetThuc", pt.DenNgay).Direction  = ParameterDirection.Input;
                    sqlcmd.Parameters.AddWithValue("@GhiChu", ghichu).Direction           = ParameterDirection.Input;

                    DBTools.InsertRecord(sqlcmd);

                    ConnectionUtil.Instance.CommitTransaction();
                    Common.LogAction("Cập nhật phiếu bảo hành", "Số phiếu bảo hành = " + txtSoPhieu.Text, Declare.IdKho);
                }
            }
            catch (System.Exception ex)
            {
                ConnectionUtil.Instance.RollbackTransaction();
#if DEBUG
                //MessageBox.Show("Lỗi ngoại lệ: " + ex.ToString(), Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
#else
                //MessageBox.Show("Lỗi ngoại lệ: " + ex.Message, Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
#endif
            }
            //return -1;
        }
示例#15
0
 private void btnXoa_Click(object sender, EventArgs e)
 {
     if (IdKiemKe != 0)
     {
         GtidCommand sqlcmd = new GtidCommand();
         sqlcmd.CommandType = CommandType.StoredProcedure;
         sqlcmd.CommandText = "sp_KiemKe_Delete";
         sqlcmd.Parameters.AddWithValue("@IdKiemKe", IdKiemKe);
         if (!DBTools.DeleteRecord(sqlcmd))
         {
             throw DBTools._LastError;
         }
     }
 }
示例#16
0
        public void UpdateUserStatus(int userId, int status)
        {
            //CreateCommonCommand(Declare.StoreProcedureNamespace.spNguoiDungUpdateStatus);
            //Parameters.AddWithValue("@p_UserID", userId);
            //Parameters.AddWithValue("@p_Status", status);
            //ExecuteNoneQuery();

            string sql = "Update tbl_DM_NguoiDung nd Set nd.Status = " + status +
                         " Where nd.IdNguoiDung = " + userId;
            GtidCommand SqlComm = new GtidCommand(sql, ConnectionUtil.Instance.GetConnection());

            SqlComm.CommandType = CommandType.Text;
            SqlComm.ExecuteNonQuery();
        }
示例#17
0
        protected void SetSqlParameters(string cmdText, CommandType cmdType, params object[] srcName)
        {
            GtidCommand sqlcmd = new GtidCommand();

            sqlcmd.CommandType = cmdType;
            switch (cmdType)
            {
            case CommandType.StoredProcedure:
                if (this.InvokeRequired)
                {
                    this.Invoke(new SetSqlParameterCollectionDelegate(OnSetSqlParameters), new object[] { sqlcmd.Parameters });
                }
                else
                {
                    OnSetSqlParameters(sqlcmd.Parameters);
                }
                break;

            case CommandType.Text:
                if (this.InvokeRequired)
                {
                    cmdText = (string)this.Invoke(new SetSqlParameterStringDelegate(OnSetSqlParameters), new object[] { cmdText });
                }
                else
                {
                    cmdText = OnSetSqlParameters(cmdText);
                }
                break;
            }

            sqlcmd.CommandText = cmdText;
            source             = getData(sqlcmd, (string)srcName[0]);
            if (srcName.Length > 1)
            {
                for (int i = 0; i < srcName.Length; i++)
                {
                    if ((source as DataSet).Tables.Count > i)
                    {
                        (source as DataSet).Tables[i].TableName = (string)srcName[i];
                    }
                    else
                    {
                        throw new Exception(String.Format("Table {0} does not exist.", srcName[i]));
                    }
                }
            }
        }
示例#18
0
        public static void Lock(string functionName, int idKho)
        {
            string    sql = String.Format("SELECT lk.IdUser,nd.TenDangNhap,lk.Computer FROM tbl_Function_Locking lk INNER JOIN tbl_dm_nguoidung nd ON lk.IdUser = nd.IdNguoidung WHERE lk.FormName='{0}' AND lk.IdKho={1}", functionName, idKho);
            DataTable dt  = SqlHelper.ExecuteDataset(ConnectionUtil.Instance.GetConnection(), CommandType.Text, sql).Tables[0];

            if (dt != null && dt.Rows.Count > 0)
            {
                if (!Equals(dt.Rows[0]["Computer"], Common.GetComputerName()))
                {
                    throw new ManagedException(String.Format("Chức năng này đang được chạy bởi một máy khác [{0}]", dt.Rows[0]["Computer"]));
                }

                if (Common.IntValue(dt.Rows[0]["IdUser"]) != Declare.UserId)
                {
                    throw new ManagedException(String.Format("Chức năng này đang được chạy bởi một người dùng khác [{0}]", dt.Rows[0]["TenDangNhap"]));
                }

                if (dt.Rows[0]["ProcessId"] != DBNull.Value && Common.IntValue(dt.Rows[0]["ProcessId"]) != Process.GetCurrentProcess().Id)
                {
                    try
                    {
                        Process.GetProcessById(Common.IntValue(dt.Rows[0]["ProcessId"]));
                        throw new ManagedException("Chức năng này đang được chạy bởi ứng dụng khác");
                    }
                    catch (Exception)
                    {
                        //nothing
                    }
                }

                return;
            }

            GtidCommand sqlCmd = ConnectionUtil.Instance.GetConnection().CreateCommand();

            sqlCmd.CommandText = "sp_LockFunction_Insert1";
            sqlCmd.CommandType = CommandType.StoredProcedure;
            sqlCmd.Parameters.AddWithValue("@FormName", functionName);
            sqlCmd.Parameters.AddWithValue("@IdKho", idKho);
            sqlCmd.Parameters.AddWithValue("@IdUser", Declare.UserId);
            sqlCmd.Parameters.AddWithValue("@Computer", Common.GetComputerName());
            sqlCmd.Parameters.AddWithValue("@ProcessId", Process.GetCurrentProcess().Id);
            sqlCmd.ExecuteNonQuery();

            return;
        }
示例#19
0
        private void btnChapNhan_Click(object sender, EventArgs e)
        {
            progressBar1.Value = 0;
            lblStatus.Text     = "Đang xử lý";

            SqlComm             = ConnectionUtil.Instance.GetConnection().CreateCommand();
            SqlComm.CommandType = CommandType.Text;

            importThread = new Thread(Import);
            importThread.Start();

            //try {
            //}
            //catch (Exception ex) {
            //    MessageBox.Show(ex.ToString());
            //}
        }
示例#20
0
        public static DataSet getData(GtidCommand sql, string TableName)
        {
            GtidDataAdapter adap = new GtidDataAdapter();

            adap.SelectCommand = sql;

            DataSet ds;

            ds = new DataSet();
            try
            {
                adap.Fill(ds, TableName);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(ds);
        }
        private void btnXoa_Click(object sender, EventArgs e)
        {
            try {
                if (dgvList.CurrentRow == null)
                {
                    return;
                }
                if (String.IsNullOrEmpty(_cmdTextDelete))
                {
                    MessageBox.Show("Lệnh xóa hóa đơn này chưa được thiết lập");
                    return;
                }
                if (MessageBox.Show("Bạn có chắc chắn xóa hóa đơn này không?", "Xác nhận", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                {
                    return;
                }

                if (dgvList.CurrentRow.Cells["LoaiChungTu"].Value != null)
                {
                    GtidCommand sqlcmd = new GtidCommand();
                    sqlcmd.CommandType = _cmdType;
                    sqlcmd.CommandText = _cmdTextDelete;
                    ConnectionUtil.Instance.BeginTransaction();
                    sqlcmd.Parameters.AddWithValue("@IdChungTu", int.Parse(dgvList.CurrentRow.Cells["IdChungTu"].Value.ToString()));
                    if (!DBTools.DeleteRecord(sqlcmd))
                    {
                        throw DBTools._LastError;
                    }
                    ConnectionUtil.Instance.CommitTransaction();
                }
            }
            catch (System.Exception ex) {
                ConnectionUtil.Instance.RollbackTransaction();
#if DEBUG
                MessageBox.Show(ex.ToString());
#else
                MessageBox.Show(ex.Message);
#endif
            }
        }
示例#22
0
        private void UpdateChiTiet(int IdChungTu, int IdSanPham, int SoLuong, double DonGia)
        {
            GtidCommand sqlcmd = new GtidCommand();

            sqlcmd.CommandType = CommandType.StoredProcedure;

            sqlcmd.CommandText = "sp_tbl_ChungTu_XuatHuyTieuHao_ChiTiet_Insert";
            sqlcmd.Parameters.Clear();
            sqlcmd.Parameters.AddWithValue("@IdChiTiet", 0).Direction = ParameterDirection.Output;
            sqlcmd.Parameters.AddWithValue("@IdChungTu", IdChungTu);
            sqlcmd.Parameters.AddWithValue("@IdSanPham", IdSanPham);
            sqlcmd.Parameters.AddWithValue("@SoLuong", SoLuong);
            sqlcmd.Parameters.AddWithValue("@DonGia", DonGia);
            sqlcmd.Parameters.AddWithValue("@ThanhTien", SoLuong * DonGia);
            if (!DBTools.InsertRecord(sqlcmd))
            {
                throw DBTools._LastError;
            }
            int IdChungTuChiTiet = int.Parse(sqlcmd.Parameters["@IdChiTiet"].Value.ToString());

            sqlcmd.CommandText = "sp_tbl_ChungTu_ChiTiet_HangHoa_Insert";
            for (int i = 0; i < dgvList.Rows.Count; i++)
            {
                if (IdSanPham == int.Parse(dgvList.Rows[i].Cells["IdSanPham"].Value.ToString()))
                {
                    sqlcmd.Parameters.Clear();
                    sqlcmd.Parameters.AddWithValue("@IdChiTietChungTu", IdChungTuChiTiet);
                    sqlcmd.Parameters.AddWithValue("@IdChiTietHangHoa", dgvList.Rows[i].Cells["IdChiTietHangHoa"].Value);
                    sqlcmd.Parameters.AddWithValue("@SoLuong", dgvList.Rows[i].Cells["SoLuong"].Value);
                    if (!DBTools.InsertRecord(sqlcmd))
                    {
                        throw DBTools._LastError;
                    }
                }
            }
        }
示例#23
0
 private void getSqlParams(ref GtidCommand SqlCmd)
 {
     SqlCmd.Parameters.AddWithValue("@IdPhieu", IdPhieu).Direction = ParameterDirection.InputOutput;
     SqlCmd.Parameters.AddWithValue("@SoPhieu", txtSoPhieu.Text.Trim());
     SqlCmd.Parameters.AddWithValue("@NgayLap", this.dtNgayLap.Value.ToString(new CultureInfo("en-US")));
     SqlCmd.Parameters.AddWithValue("@IdKho", cboKho.SelectedValue);
     SqlCmd.Parameters.AddWithValue("@IdNhanVien", cboNguoiNhan.SelectedValue);
     SqlCmd.Parameters.AddWithValue("@IdDoiTuong", cboDoiTuong.SelectedValue);
     SqlCmd.Parameters.AddWithValue("@HoTen", txtHoTen.Text.ToString());
     SqlCmd.Parameters.AddWithValue("@DiaChi", txtDiaChi.Text.Trim());
     SqlCmd.Parameters.AddWithValue("@SoTaiKhoan", txtSoTaiKhoan.Text);
     SqlCmd.Parameters.AddWithValue("@NganHang", txtNganHang.Text);
     SqlCmd.Parameters.AddWithValue("@NoiDungThuChi", txtNoiDungThuChi.Text);
     SqlCmd.Parameters.AddWithValue("@SoTien", Common.DoubleValue(txtSoTien.Text.Trim()));
     SqlCmd.Parameters.AddWithValue("@IdTienTe", int.Parse(cboLoaiTien.SelectedValue.ToString()));
     SqlCmd.Parameters.AddWithValue("@TyGia", Common.DoubleValue(txtTyGia.Text.Trim()));
     SqlCmd.Parameters.AddWithValue("@SoTienChu", Common.ReadNumner_(txtSoTienChu.Text));
     SqlCmd.Parameters.AddWithValue("@SoChungTuKem", txtSoChungTuKem.Text.Trim());
     SqlCmd.Parameters.AddWithValue("@ChungTuGoc", txtChungTuGoc.Text.Trim());
     SqlCmd.Parameters.AddWithValue("@HinhThucThanhToan", cboHinhThucThanhToan.SelectedItem == null ? System.DBNull.Value : cboHinhThucThanhToan.SelectedItem);
     //SqlCmd.Parameters.AddWithValue("@Type", 0);
     SqlCmd.Parameters.AddWithValue("@IdThuChi", cboLoaiThu.SelectedValue);
     SqlCmd.Parameters.AddWithValue("@DoiTuongType", cboNhomDoiTuong.SelectedIndex);
     if (IdPhieu > 0)
     {
         SqlCmd.Parameters.AddWithValue("@NguoiSua", Declare.UserName);
         SqlCmd.Parameters.AddWithValue("@NgaySua", DateTime.Now);
         SqlCmd.Parameters.AddWithValue("@TenMaySua", Declare.TenMay);
     }
     else
     {
         SqlCmd.Parameters.AddWithValue("@NguoiTao", Declare.UserName);
         SqlCmd.Parameters.AddWithValue("@NgayTao", DateTime.Now);
         SqlCmd.Parameters.AddWithValue("@TenMayTao", Declare.TenMay);
     }
 }
示例#24
0
        private void LoadThongTin()
        {
            //Connection objConn = new Connection();
            IDataReader DataReader = null;

            //SqlConnection SqlConn = Connection.Instance.GetSqlConnection();
            //using (SqlConnection SqlConn = objConn.GetSqlConnection())
            //{
            try
            {
                IDbCommand SqlComm = new GtidCommand("Select * From tbl_ThongTin", ConnectionUtil.Instance.GetConnection());
                SqlComm.CommandType = CommandType.Text;
                //if (!(SqlConn.State == ConnectionState.Open)) SqlConn.Open();
                DataReader = SqlComm.ExecuteReader();
                if (DataReader.Read())
                {
                    //while (DataReader.Read())
                    //{
                    txtTenDoanhNghiep.Text         = DataReader["TenDoanhNghiep"].ToString();
                    txtDiaChi.Text                 = DataReader["DiaChi"].ToString();
                    txtVPGiaoDich.Text             = DataReader["VPGiaoDich"].ToString();
                    txtDienThoai.Text              = DataReader["DienThoai"].ToString();
                    txtFax.Text                    = DataReader["Fax"].ToString();
                    txtEmail.Text                  = DataReader["Email"].ToString();
                    txtWebsite.Text                = DataReader["Website"].ToString();
                    txtMaSoThue.Text               = DataReader["MaSoThue"].ToString();
                    txtSoTaiKhoan.Text             = DataReader["SoTaiKhoan"].ToString();
                    txtNganHang.Text               = DataReader["NganHang"].ToString();
                    txtMota.Text                   = DataReader["MoTa"].ToString();
                    this.cboLoaiTien.SelectedValue = Common.IntValue(DataReader["IdTienTe"].ToString());
                    txtTyleGia.Text                = DataReader["TyLeGia"].ToString();
                    string str = DataReader["ChuanMaVach"].ToString();
                    if (str != "")
                    {
                        for (int i = 0; i < mavach.Length; i++)
                        {
                            if (mavach[i].Equals(str))
                            {
                                cboChuanMaVach.SelectedIndex = i;
                                break;
                            }
                        }
                    }
                    //}
                }
                else
                {
                    txtTenDoanhNghiep.Text      = "";
                    txtDiaChi.Text              = "";
                    txtVPGiaoDich.Text          = "";
                    txtDienThoai.Text           = "";
                    txtFax.Text                 = "";
                    txtEmail.Text               = "";
                    txtWebsite.Text             = "";
                    txtMaSoThue.Text            = "";
                    txtSoTaiKhoan.Text          = "";
                    txtNganHang.Text            = "";
                    txtMota.Text                = "";
                    txtTyleGia.Text             = "0";
                    cboChuanMaVach.SelectedText = "Code 128";
                }
            }
            catch
            {
            }
            finally
            {
                DataReader.Close();
                //if (!(SqlConn.State == ConnectionState.Closed)) SqlConn.Close();
            }
            //}
        }
示例#25
0
        private void btnGhi_Click(object sender, EventArgs e)
        {
            try {
                GtidCommand sqlcmd = new GtidCommand();
                sqlcmd.CommandType = CommandType.StoredProcedure;
                if (IdKiemKe == 0)
                {
                    string sql = String.Format("select SoPhieu from tbl_KiemKe where SoPhieu ='{0}'", txtSoPhieu.Text);
                    if (DBTools.ExecuteScalar(sql) != null)
                    {
                        MessageBox.Show("Số phiếu này đã được sử dụng, hãy dùng số khác");
                        return;
                    }
                    sqlcmd.CommandText = "sp_KiemKe_Insert";
                    sqlcmd.Parameters.AddWithValue("@IdKiemKe", 0).Direction = ParameterDirection.Output;
                    sqlcmd.Parameters.AddWithValue("@IdKho", cboKho.SelectedValue);
                    sqlcmd.Parameters.AddWithValue("@NgayKiemKe", dtNgayKiemKe.Value);
                    sqlcmd.Parameters.AddWithValue("@SoPhieu", txtSoPhieu.Text);
                    sqlcmd.Parameters.AddWithValue("@IdNhanVien", cboNhanVien.SelectedValue);
                    sqlcmd.Parameters.AddWithValue("@TongTienHang", Common.DoubleValue(txtTongTien.Text));
                    sqlcmd.Parameters.AddWithValue("@GhiChu", txtGhiChu.Text);
                    if (!DBTools.InsertRecord(sqlcmd))
                    {
                        throw DBTools._LastError;
                    }
                    IdKiemKe = Convert.ToInt32(sqlcmd.Parameters["@IdKiemKe"].Value);

                    dgvList.Sort(dgvList.Columns["IdSanPham"], ListSortDirection.Ascending);
                    int IdSanPham = 0;
                    int SoLuong   = 0;

                    foreach (DataGridViewRow dgr in dgvList.Rows)
                    {
                        if (IdSanPham == 0)
                        {
                            IdSanPham = int.Parse(dgr.Cells["IdSanPham"].Value.ToString());
                            SoLuong   = int.Parse(dgr.Cells["SoLuong"].Value.ToString());
                        }
                        else if (IdSanPham == int.Parse(dgr.Cells["IdSanPham"].Value.ToString()))
                        {
                            SoLuong += int.Parse(dgr.Cells["SoLuong"].Value.ToString());
                        }
                        else
                        {
                            UpdateChiTiet(IdKiemKe, IdSanPham, SoLuong);
                            IdSanPham = int.Parse(dgr.Cells["IdSanPham"].Value.ToString());
                            SoLuong   = int.Parse(dgr.Cells["SoLuong"].Value.ToString());
                        }
                    }
                    UpdateChiTiet(IdKiemKe, IdSanPham, SoLuong);
                }
                else
                {
                    sqlcmd.CommandText = "sp_KiemKe_Update";
                    sqlcmd.Parameters.AddWithValue("@IdKiemKe", IdKiemKe);
                    sqlcmd.Parameters.AddWithValue("@IdKho", cboKho.SelectedValue);
                    sqlcmd.Parameters.AddWithValue("@NgayKiemKe", dtNgayKiemKe.Value);
                    sqlcmd.Parameters.AddWithValue("@IdNhanVien", cboNhanVien.SelectedValue);
                    sqlcmd.Parameters.AddWithValue("@TongTienHang", Common.DoubleValue(txtTongTien.Text));
                    sqlcmd.Parameters.AddWithValue("@GhiChu", txtGhiChu.Text);
                    if (!DBTools.UpdateRecord(sqlcmd))
                    {
                        throw DBTools._LastError;
                    }

                    sqlcmd.CommandText = "sp_KiemKe_ChiTiet_Delete";
                    sqlcmd.Parameters.Clear();
                    sqlcmd.Parameters.AddWithValue("@IdKiemKe", IdKiemKe);
                    if (!DBTools.DeleteRecord(sqlcmd))
                    {
                        throw DBTools._LastError;
                    }

                    dgvList.Sort(dgvList.Columns["IdSanPham"], ListSortDirection.Ascending);
                    int IdSanPham = 0;
                    int SoLuong   = 0;

                    foreach (DataGridViewRow dgr in dgvList.Rows)
                    {
                        if (IdSanPham == int.Parse(dgr.Cells["IdSanPham"].Value.ToString()))
                        {
                            SoLuong += int.Parse(dgr.Cells["SoLuong"].Value.ToString());
                        }
                        else
                        {
                            if (IdSanPham != 0)
                            {
                                UpdateChiTiet(IdKiemKe, IdSanPham, SoLuong);
                            }
                            IdSanPham = int.Parse(dgr.Cells["IdSanPham"].Value.ToString());
                            SoLuong   = int.Parse(dgr.Cells["SoLuong"].Value.ToString());
                        }
                    }
                    UpdateChiTiet(IdKiemKe, IdSanPham, SoLuong);
                }
            }
            catch (System.Exception ex) {
#if DEBUG
                MessageBox.Show("Lỗi ngoại lệ: " + ex.ToString(), Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
#else
                MessageBox.Show("Lỗi ngoại lệ: " + ex.Message, Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
#endif
            }
        }
示例#26
0
        private void tsbUpdate_Click(object sender, EventArgs e)
        {
            try {
                if (dgvList.Rows.Count == 0)
                {
                    MessageBox.Show("Phải có ít nhất một mặt hàng");
                    return;
                }
                if (!Valid())
                {
                    return;
                }
                GtidCommand sqlcmd = new GtidCommand();
                sqlcmd.CommandType = CommandType.StoredProcedure;
                ConnectionUtil.Instance.BeginTransaction();
                if (IdChungTu == 0)
                {
                    if (txtSoPhieu.Text == "")
                    {
                        txtSoPhieu.Text = Common.TaoSoPhieuTuDong("XH", "tbl_ChungTu", "SoChungTu");
                    }

                    sqlcmd.Parameters.Clear();
                    sqlcmd.CommandText = "sp_tbl_ChungTu_XuatHuyTieuHao_Insert";
                    sqlcmd.Parameters.AddWithValue("@IdChungTu", 0).Direction = ParameterDirection.Output;
                    sqlcmd.Parameters.AddWithValue("@LoaiChungTu", TransactionType.XUAT_HUY_TIEU_HAO);
                    sqlcmd.Parameters.AddWithValue("@SoSeri", txtSoSeri.Text);
                    sqlcmd.Parameters.AddWithValue("@SoChungTu", txtSoPhieu.Text);
                    sqlcmd.Parameters.AddWithValue("@NgayLap", dtNgayHuy.Value);
                    sqlcmd.Parameters.AddWithValue("@IdKho", cboKho.SelectedValue);
                    sqlcmd.Parameters.AddWithValue("@IdNhanVien", cboNhanVien.SelectedValue);
                    sqlcmd.Parameters.AddWithValue("@GhiChu", txtGhiChu.Text.Trim());
                    sqlcmd.Parameters.AddWithValue("@TongTienHang", Common.DoubleValue(txtTongTien.Text));
                    sqlcmd.Parameters.AddWithValue("@NguoiTao", Declare.UserName);
                    DateTime date = DateTime.Now;
                    sqlcmd.Parameters.AddWithValue("@ThoigianTao", date);
                    sqlcmd.Parameters.AddWithValue("@TenMayTao", Declare.TenMay);
                    sqlcmd.Parameters.AddWithValue("@NguoiSua", Declare.UserName);
                    sqlcmd.Parameters.AddWithValue("@ThoigianSua", date);
                    sqlcmd.Parameters.AddWithValue("@TenMaySua", Declare.TenMay);
                    if (!DBTools.InsertRecord(sqlcmd))
                    {
                        throw DBTools._LastError;
                    }

                    IdChungTu = int.Parse(sqlcmd.Parameters["@IdChungTu"].Value.ToString());

                    dgvList.Sort(dgvList.Columns["IdSanPham"], ListSortDirection.Ascending);
                    int    IdSanPham = 0;
                    int    SoLuong   = 0;
                    double DonGia    = 0;

                    foreach (DataGridViewRow dgr in dgvList.Rows)
                    {
                        if (IdSanPham == 0)
                        {
                            IdSanPham = int.Parse(dgr.Cells["IdSanPham"].Value.ToString());
                            SoLuong   = int.Parse(dgr.Cells["SoLuong"].Value.ToString());
                            DonGia    = double.Parse(dgr.Cells["DonGia"].Value.ToString());
                        }
                        else if (IdSanPham == int.Parse(dgr.Cells["IdSanPham"].Value.ToString()))
                        {
                            SoLuong += int.Parse(dgr.Cells["SoLuong"].Value.ToString());
                        }
                        else
                        {
                            UpdateChiTiet(IdChungTu, IdSanPham, SoLuong, DonGia);
                            IdSanPham = int.Parse(dgr.Cells["IdSanPham"].Value.ToString());
                            SoLuong   = int.Parse(dgr.Cells["SoLuong"].Value.ToString());
                            DonGia    = double.Parse(dgr.Cells["DonGia"].Value.ToString());
                        }
                    }
                    UpdateChiTiet(IdChungTu, IdSanPham, SoLuong, DonGia);

                    CurrentIndex = dtChungTu == null ? 0 : dtChungTu.Rows.Count;
                    //sqlcmd.CommandText = "sp_tbl_ChungTu_ChiTiet_HangHoa_Insert";

                    //int IdKho = int.Parse(DBTools.getValue(String.Format("Select IdKho from tbl_DM_Kho where MaKho='{0}'", dgr.Cells["MaKho"].Value)));
                    //QLBanHang.Class.Common.LogAction("Tạo mới xuất hủy", "IdChungTu " + IdChungTu, IdKho);
                }
                else
                {
                    sqlcmd.CommandText = "sp_tbl_ChungTu_XuatHuyTieuHao_Update";
                    sqlcmd.Parameters.AddWithValue("@IdChungTu", IdChungTu);
                    sqlcmd.Parameters.AddWithValue("@LoaiChungTu", TransactionType.XUAT_HUY_TIEU_HAO);
                    sqlcmd.Parameters.AddWithValue("@SoSeri", txtSoSeri.Text);
                    sqlcmd.Parameters.AddWithValue("@SoChungTu", txtSoPhieu.Text);
                    sqlcmd.Parameters.AddWithValue("@NgayLap", dtNgayHuy.Value);
                    sqlcmd.Parameters.AddWithValue("@IdKho", cboKho.SelectedValue);
                    sqlcmd.Parameters.AddWithValue("@IdNhanVien", cboNhanVien.SelectedValue);
                    sqlcmd.Parameters.AddWithValue("@GhiChu", txtGhiChu.Text.Trim());
                    sqlcmd.Parameters.AddWithValue("@TongTienHang", Common.DoubleValue(txtTongTien.Text));
                    DateTime date = DateTime.Now;
                    sqlcmd.Parameters.AddWithValue("@NguoiSua", Declare.UserName);
                    sqlcmd.Parameters.AddWithValue("@ThoigianSua", date);
                    sqlcmd.Parameters.AddWithValue("@TenMaySua", Declare.TenMay);
                    if (!DBTools.UpdateRecord(sqlcmd))
                    {
                        throw DBTools._LastError;
                    }

                    sqlcmd.CommandText = "sp_tbl_ChungTu_XuatHuyTieuHao_ChiTiet_Delete";
                    sqlcmd.Parameters.Clear();
                    sqlcmd.Parameters.AddWithValue("@IdChungTu", IdChungTu);
                    if (!DBTools.DeleteRecord(sqlcmd))
                    {
                        throw DBTools._LastError;
                    }

                    dgvList.Sort(dgvList.Columns["IdSanPham"], ListSortDirection.Ascending);
                    int    IdSanPham = 0;
                    int    SoLuong   = 0;
                    double DonGia    = 0;

                    foreach (DataGridViewRow dgr in dgvList.Rows)
                    {
                        if (IdSanPham == int.Parse(dgr.Cells["IdSanPham"].Value.ToString()))
                        {
                            SoLuong += int.Parse(dgr.Cells["SoLuong"].Value.ToString());
                        }
                        else
                        {
                            if (IdSanPham != 0)
                            {
                                UpdateChiTiet(IdChungTu, IdSanPham, SoLuong, DonGia);
                            }
                            IdSanPham = int.Parse(dgr.Cells["IdSanPham"].Value.ToString());
                            SoLuong   = int.Parse(dgr.Cells["SoLuong"].Value.ToString());
                            DonGia    = double.Parse(dgr.Cells["DonGia"].Value.ToString());
                        }
                    }
                    UpdateChiTiet(IdChungTu, IdSanPham, SoLuong, DonGia);

                    //int IdKho = int.Parse(DBTools.getValue(String.Format("Select IdKho from tbl_DM_Kho where MaKho='{0}'", dgr.Cells["MaKho"].Value)));
                    //QLBanHang.Class.Common.LogAction("Cập nhật xuất hủy", "IdChungTu " + IdChungTu, IdKho);
                }
                ConnectionUtil.Instance.CommitTransaction();
                MessageBox.Show("Đã cập nhật thành công");
                Updating = false;
                GetChungTuData();
                EnableForm(this, false);
                EnableMenuFunc();
                foreach (DataGridViewRow dgr in dgvList.Rows)
                {
                    dgr.Cells["SoLuongDau"].Value = Common.IntValue(dgr.Cells["SoLuong"].Value);
                }
            }
            catch (System.Exception ex) {
                ConnectionUtil.Instance.RollbackTransaction();
#if DEBUG
                MessageBox.Show("Lỗi ngoại lệ: " + ex.ToString(), Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
#else
                MessageBox.Show("Lỗi ngoại lệ: " + ex.Message, Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
#endif
            }
        }
        private void frmHT_ThemNhomNSD_Load(object sender, EventArgs e)
        {
            dgvGroupList.ReadOnly           = true;
            dgvGroupList.AllowUserToAddRows = false;

            dgvGroupList.AutoSizeRowsMode         = DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders;
            dgvGroupList.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Raised;
            dgvGroupList.CellBorderStyle          = DataGridViewCellBorderStyle.Single;
            dgvGroupList.GridColor         = SystemColors.ActiveBorder;
            dgvGroupList.RowHeadersVisible = false;
            dgvGroupList.RowHeadersVisible = false;

            dgvGroupList.Rows.Clear();
            dgvGroupList.Columns.Clear();

            DataGridViewTextBoxColumn colSTT = new DataGridViewTextBoxColumn();

            colSTT.Name       = "STT";
            colSTT.HeaderText = "STT";
            colSTT.SortMode   = DataGridViewColumnSortMode.NotSortable;
            colSTT.Width      = 50;
            colSTT.ReadOnly   = true;
            colSTT.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            colSTT.DataPropertyName           = "STT";
            dgvGroupList.Columns.Add(colSTT);

            DataGridViewTextBoxColumn colId = new DataGridViewTextBoxColumn();

            colId.Name       = "Id";
            colId.HeaderText = "Id";
            colId.SortMode   = DataGridViewColumnSortMode.NotSortable;
            colId.Width      = 40;
            colId.ReadOnly   = true;
            colId.Visible    = false;
            colId.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            colId.DataPropertyName           = "IdNhomNguoiDung";
            dgvGroupList.Columns.Add(colId);

            DataGridViewTextBoxColumn colMaNhom = new DataGridViewTextBoxColumn();

            colMaNhom.Name       = "MaNhom";
            colMaNhom.HeaderText = "Mã nhóm";
            colMaNhom.ValueType  = typeof(string);
            colMaNhom.SortMode   = DataGridViewColumnSortMode.Automatic;
            colMaNhom.Width      = 100;
            colMaNhom.ReadOnly   = true;
            colMaNhom.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
            colMaNhom.DataPropertyName           = "MaNhom";
            dgvGroupList.Columns.Add(colMaNhom);

            DataGridViewTextBoxColumn colTenNhom = new DataGridViewTextBoxColumn();

            colTenNhom.Name       = "TenNhom";
            colTenNhom.HeaderText = "Tên nhóm";
            colTenNhom.ValueType  = typeof(string);
            colTenNhom.SortMode   = DataGridViewColumnSortMode.Automatic;
            colTenNhom.Width      = 208;
            colTenNhom.ReadOnly   = true;
            colTenNhom.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
            colTenNhom.DataPropertyName           = "TenNhom";
            dgvGroupList.Columns.Add(colTenNhom);

            DataGridViewCheckBoxColumn colSuDung = new DataGridViewCheckBoxColumn();

            colSuDung.Name       = "SuDung";
            colSuDung.HeaderText = "Sử dụng";
            colSuDung.Width      = 80;
            colSuDung.ReadOnly   = true;
            colSuDung.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            colSuDung.DataPropertyName           = "SuDung";
            dgvGroupList.Columns.Add(colSuDung);

            dgvGroupList.Columns[1].Visible = false;
            dgvGroupList.Columns[0].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgvGroupList.Columns[1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
            dgvGroupList.Columns[2].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;

            dgvGroupList.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            dgvGroupList.MultiSelect   = false;

            dgvGroupList.RowTemplate.Height = 35;
            dgvGroupList.ColumnHeadersDefaultCellStyle.Font = new Font("Microsoft Sans Serif", 8, FontStyle.Regular);


            this.RefreshGrid();

            string sql = "SELECT tbl_DM_ChucNang.IdChucNang, tbl_DM_ChucNang.TenChucNang " +
                         "FROM tbl_DM_ChucNang;";
            GtidCommand SqlComm    = null;
            IDataReader DataReader = null;

            //Connection objConn = new Connection();
            //SqlConnection SqlConn = Connection.Instance.GetSqlConnection();
            //using (SqlConnection SqlConn = objConn.GetSqlConnection())
            //{
            try
            {
                //if (!(SqlConn.State == ConnectionState.Open)) SqlConn.Open();
                SqlComm             = ConnectionUtil.Instance.GetConnection().CreateCommand();
                SqlComm.CommandType = CommandType.Text;
                SqlComm.CommandText = sql;
                DataReader          = SqlComm.ExecuteReader();

                while (DataReader.Read())
                {
                    chklstRightOfGroup.Items.Add(new ListItem(Common.IntValue(DataReader[0].ToString()), DataReader[1].ToString()), false);
                }
                DataReader.Close();
            }

            catch
            {
            }
            finally
            {
                //if (!(SqlConn.State == ConnectionState.Closed)) SqlConn.Close();
            }
            this.dgvGroupList_SelectionChanged(null, EventArgs.Empty);
            //}

            this.SetButtomStatus(Declare.GroupCode);
        }
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            try {
                string          sql;
                bool            InUse;
                int             index;
                CurrencyManager cm;
                if (String.IsNullOrEmpty(txtGroupId.Text))
                {
                    MessageBox.Show(Declare.msgInputData, Declare.titleNotice, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txtGroupId.Focus();
                    return;
                }
                else
                {
                    sql = "select * from tbl_DM_NhomNguoiDung where MaNhom like N'" + txtGroupId.Text + "'";
                    if (!String.IsNullOrEmpty(txtId.Text))
                    {
                        sql += " and IdNhomNguoiDung <> " + txtId.Text;
                    }
                    if (DBTools.ExecuteScalar(sql) != null)
                    {
                        MessageBox.Show(Resources.MaDaDung, Declare.titleNotice, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        txtGroupId.Focus();
                        return;
                    }
                }
                if (String.IsNullOrEmpty(txtGroupName.Text))
                {
                    MessageBox.Show(Declare.msgInputData, Declare.titleNotice, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txtGroupName.Focus();
                    return;
                }
                else
                {
                    sql = "select * from tbl_DM_NhomNguoiDung where TenNhom like N'" + txtGroupName.Text + "'";
                    if (!String.IsNullOrEmpty(txtId.Text))
                    {
                        sql += " and IdNhomNguoiDung <> " + txtId.Text;
                    }
                    if (DBTools.ExecuteScalar(sql) != null)
                    {
                        MessageBox.Show(Resources.TenDaDung, Declare.titleNotice, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        txtGroupName.Focus();
                        return;
                    }
                }

                if (chkSuDung.Checked)
                {
                    InUse = true;
                }
                else
                {
                    InUse = false;
                }
                if (flgUpdate || dgvGroupList.RowCount == 0)
                {
                    if (!DBTools.ExistData("tbl_DM_NhomNguoiDung", "MaNhom", typeof(string), txtGroupId.Text.Trim()))
                    {
                        //sql = "Insert Into tbl_DM_NhomNguoiDung(MaNhom, TenNhom, SuDung) Values(?,?,?)";
                        sql = "Insert Into tbl_DM_NhomNguoiDung Values(@MaNhom, @TenNhom, @SuDung)";

                        //SqlConnection SqlConn = Connection.Instance.GetSqlConnection();
                        //if (!(SqlConn.State == ConnectionState.Open)) SqlConn.Open();

                        GtidCommand SqlCmd = ConnectionUtil.Instance.GetConnection().CreateCommand();
                        SqlCmd.CommandText = "sp_DM_NhomNguoiDung_Insert";

                        SqlCmd.Parameters.AddWithValue("@IdNhomNguoiDung", 0).Direction         = ParameterDirection.Output;
                        SqlCmd.Parameters.AddWithValue("@MaNhom", txtGroupId.Text).Direction    = ParameterDirection.Input;
                        SqlCmd.Parameters.AddWithValue("@TenNhom", txtGroupName.Text).Direction = ParameterDirection.Input;
                        SqlCmd.Parameters.AddWithValue("@SuDung", InUse).Direction = ParameterDirection.Input;
                        SqlCmd.CommandType = CommandType.StoredProcedure;

                        SqlCmd.ExecuteNonQuery();
                        MessageBox.Show("Cập nhật thành công nhóm người dùng", Declare.titleNotice, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        Common.LogAction("Thêm mới nhóm người dùng", "Tên nhóm " + txtGroupName.Text, -1);

                        object[] arrMang = { SqlCmd.Parameters[0].Value, this.txtGroupId.Text.Trim(), this.txtGroupName.Text, InUse };
                        dtUserGroup.Rows.Add(arrMang);

                        txtId.Text = SqlCmd.Parameters[0].Value.ToString();
                        //this.UpdateAutoColumn("STT", this.dtUserGroup.Rows.Count - 1);
                        index = this.dtUserGroup.Rows.Count - 1;

                        //sql = "Insert Into tbl_DM_NhomNguoiDung(MaNhom, TenNhom, SuDung) Values(N'" + txtGroupId.Text + "', N'" + txtGroupName.Text + "', " +InUse + ")";
                        //if (DBTools.ExecuteQuery(sql, CommandType.Text)!= null)
                        //{
                        //    this.RefreshGrid();

                        //    DataTable dtDanhSach = (DataTable)DBTools.getData("tbl_DM_NhomNguoiDung").Tables["tbl_DM_NhomNguoiDung"];
                        //    CurrencyManager cm = (CurrencyManager)this.BindingContext[dtDanhSach];
                        //    cm.Position = dtDanhSach.Rows.Count - 1;

                        //    dgvGroupList.Rows[dgvGroupList.Rows.Count - 1].Selected = true;
                        //    txtId.Text = dgvGroupList.Rows[dgvGroupList.Rows.Count - 1].Cells[1].Value.ToString();
                        //    txtGroupId.Text = dgvGroupList.Rows[dgvGroupList.Rows.Count - 1].Cells[2].Value.ToString();
                        //    txtGroupName.Text = dgvGroupList.Rows[dgvGroupList.Rows.Count - 1].Cells[3].Value.ToString();
                        //}
                        //else
                        //{
                        //    MessageBox.Show(Declare.msgUpdateErr, Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        //    return;
                        //}
                    }
                    else
                    {
                        MessageBox.Show(Declare.msgExistData, Declare.titleWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                }
                else
                {
                    sql = "Update tbl_DM_NhomNguoiDung Set MaNhom = N'" + txtGroupId.Text + "', TenNhom = N'" + txtGroupName.Text + "', SuDung = " + (InUse ? 1 : 0) + " Where IdNhomNguoiDung = " + Common.IntValue(txtId.Text);
                    if (DBTools.ExecuteQuery(sql, CommandType.Text) != null)
                    {
                        dgvGroupList.CurrentRow.Cells["MaNhom"].Value  = txtGroupId.Text;
                        dgvGroupList.CurrentRow.Cells["TenNhom"].Value = txtGroupName.Text;
                        dgvGroupList.Rows[dgvGroupList.CurrentCell.RowIndex].Selected = true;

                        sql = "Delete From tbl_NhomND_ChucNang Where IdNhomNguoiDung = " + Common.IntValue(txtId.Text);
                        if (DBTools.ExecuteQuery(sql, CommandType.Text) == null)
                        {
                            MessageBox.Show(Declare.msgUpdateErr, Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        index = dgvGroupList.Rows.IndexOf(dgvGroupList.CurrentRow);

                        Common.LogAction("Thêm mới nhóm người dùng", "GroupId " + txtId.Text, -1);
                    }
                    else
                    {
                        MessageBox.Show(Declare.msgUpdateErr, Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                //MessageBox.Show("Cập nhật thông tin thành công!");
                for (int i = 0; i < chklstRightOfGroup.Items.Count; i++)
                {
                    if (chklstRightOfGroup.GetItemCheckState(i) == CheckState.Checked)
                    {
                        ListItem itemChecked = (ListItem)chklstRightOfGroup.Items[i];
                        sql = "Insert Into tbl_NhomND_ChucNang(IdNhomNguoiDung, IdChucNang) Values(" + Common.IntValue(txtId.Text) + ", " + Common.IntValue(itemChecked.ItemData.ToString()) + ")";
                        if (DBTools.ExecuteQuery(sql, CommandType.Text) == null)
                        {
                            MessageBox.Show(Declare.msgUpdateErr, Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }
                }
                MessageBox.Show("Cập nhật thông tin thành công!");
                RefreshGrid();
                cm          = (CurrencyManager)this.BindingContext[this.dtUserGroup];
                cm.Position = index;
            }
            catch (System.Exception ex) {
#if DEBUG
                MessageBox.Show("Lỗi ngoại lệ: " + ex.ToString(), Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
#else
                MessageBox.Show("Lỗi ngoại lệ: " + ex.Message, Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
#endif
            }
            finally {
                //this.dgvGroupList_SelectionChanged(null, EventArgs.Empty);
            }
        }
示例#29
0
        private void btCapNhat_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtMaCauHinh.Text.Trim() == "")
                {
                    MessageBox.Show("Mã loại cấu hình không được để trống!", Declare.titleNotice, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (txtCauHinh.Text.Trim() == "")
                {
                    MessageBox.Show("Tên cấu hình không được để trống!", Declare.titleNotice, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (KiemtraMaCauhinh(_listItem, txtMaCauHinh.Text.Trim()) == true)
                {
                    if (btThem.Enabled == false)
                    {
                        GtidCommand SqlCmd = ConnectionUtil.Instance.GetConnection().CreateCommand();
                        SqlCmd.CommandText = "sp_DM_CauHinh_Insert";
                        SqlCmd.CommandType = CommandType.StoredProcedure;
                        SqlCmd.Parameters.AddWithValue("@MaCauHinh", txtMaCauHinh.Text).Direction          = ParameterDirection.Input;
                        SqlCmd.Parameters.AddWithValue("@IdLoaiItem", cboLoaiItem.SelectedValue).Direction = ParameterDirection.Input;
                        SqlCmd.Parameters.AddWithValue("@TenCauHinh_ThietBi", txtCauHinh.Text).Direction   = ParameterDirection.Input;
                        SqlCmd.Parameters.AddWithValue("@GhiChu", txtGhiChu.Text).Direction   = ParameterDirection.Input;
                        SqlCmd.Parameters.AddWithValue("@SuDung", cbSuDung.Checked).Direction = ParameterDirection.Input;
                        SqlCmd.ExecuteNonQuery();

                        MessageBox.Show("Cập nhật danh mục thành công!", Declare.titleNotice, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        int rowIndex = dgvList.CurrentRow.Index;

                        GtidCommand SqlCmd = ConnectionUtil.Instance.GetConnection().CreateCommand();
                        SqlCmd.CommandText = "sp_DM_CauHinh_Update";
                        SqlCmd.CommandType = CommandType.StoredProcedure;
                        SqlCmd.Parameters.AddWithValue("@MaCauHinh", txtMaCauHinh.Text).Direction = ParameterDirection.Input;
                        SqlCmd.Parameters.AddWithValue("@IdCauHinh_ThietBi", (int)dgvList["IdCauHinh_ThietBi", rowIndex].Value).Direction = ParameterDirection.Input;
                        SqlCmd.Parameters.AddWithValue("@IdLoaiItem", cboLoaiItem.SelectedValue).Direction = ParameterDirection.Input;
                        SqlCmd.Parameters.AddWithValue("@TenCauHinh_ThietBi", txtCauHinh.Text).Direction   = ParameterDirection.Input;
                        SqlCmd.Parameters.AddWithValue("@GhiChu", txtGhiChu.Text).Direction   = ParameterDirection.Input;
                        SqlCmd.Parameters.AddWithValue("@SuDung", cbSuDung.Checked).Direction = ParameterDirection.Input;
                        SqlCmd.ExecuteNonQuery();

                        MessageBox.Show("Cập nhật danh mục thành công!", Declare.titleNotice, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    string strSql = "Select tb.*,li.* from tbl_DM_CauHinh tb inner join tbl_DM_LoaiItem li on tb.IdLoaiItem=li.IdLoaiItem";
                    _listItem = ut.getDataTable(strSql);
                    dgvList.AutoGenerateColumns = false;
                    dgvList.DataSource          = _listItem;
                    btThem.Enabled = true;
                }
                else
                {
                    MessageBox.Show("Mã loại cấu hình này đã được sử dụng", Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Question);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi ngoại lệ: " + ex.Message, Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#30
0
        private void tsbUpdate_Click(object sender, EventArgs e)
        {
            try {
                if (!ValidateBefore())
                {
                    return;
                }

                GtidCommand SqlCmd = ConnectionUtil.Instance.GetConnection().CreateCommand();
                ConnectionUtil.Instance.BeginTransaction();

                int IdKho = int.Parse(cboKho.SelectedValue.ToString());

                if (IdPhieu == 0)
                {
                    SqlCmd.CommandText = "sp_tbl_ThuChi_Insert";
                    SqlCmd.CommandType = CommandType.StoredProcedure;
                    getSqlParams(ref SqlCmd);

                    if (DBTools.InsertRecord(SqlCmd))
                    {
                        IdPhieu = int.Parse(SqlCmd.Parameters["@IdPhieu"].Value.ToString());
                        Common.LogAction("Tạo mới " + this.Text.ToLower(), "Completed. IdPhieu=" + IdPhieu, IdKho);
                        this.txtSoPhieu.ReadOnly = true;
                        ConnectionUtil.Instance.CommitTransaction();
                        MessageBox.Show("Thêm mới phiếu thu thành công.", Declare.titleNotice, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        CurrentIndex = dtPhieuThu.Rows.Count;
                    }
                    else
                    {
                        Common.LogAction("Tạo mới " + this.Text.ToLower(), "Failed.", IdKho);
                        ConnectionUtil.Instance.RollbackTransaction();
                        MessageBox.Show("Lỗi thực hiện thêm mới phiếu thu." + "\n" + (DBTools._LastError != null ? DBTools._LastError.Message : ""), Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                else
                {
                    SqlCmd.CommandText = "sp_tbl_ThuChi_Update";
                    SqlCmd.CommandType = CommandType.StoredProcedure;
                    getSqlParams(ref SqlCmd);

                    if (DBTools.UpdateRecord(SqlCmd))
                    {
                        Common.LogAction("Cập nhật " + this.Text.ToLower(), "Completed. IdPhieu=" + IdPhieu, IdKho);

                        MessageBox.Show("Cập nhật phiếu thu thành công.", Declare.titleNotice, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        ConnectionUtil.Instance.CommitTransaction();
                        if (currentRow != null)
                        {
                            this.DialogResult = DialogResult.OK;
                        }
                    }
                    else
                    {
                        ConnectionUtil.Instance.RollbackTransaction();
                        Common.LogAction("Cập nhật " + this.Text.ToLower(), "Failed. IdPhieu=" + IdPhieu, IdKho);
                        MessageBox.Show("Lỗi thực hiện quá trình cập nhật." + "\n" + (DBTools._LastError != null ? DBTools._LastError.Message : ""), Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }

                EnableForm(this, false);
                Updating = false;
                GetAllItem();
                EnableMenuFunc();
                //if (IdPhieu == 0) CurrentIndex = dtPhieuThu.Rows.Count - 1;
                //IdPhieu = int.Parse(SqlCmd.Parameters["@IdPhieu"].Value.ToString());
                LoadFormData(dtPhieuThu.Rows[CurrentIndex]);
            }
            catch (System.Exception ex) {
#if DEBUG
                MessageBox.Show("Lỗi ngoại lệ: " + ex.ToString(), Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
#else
                MessageBox.Show("Lỗi ngoại lệ: " + ex.Message, Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
#endif
            }
        }