public static bool kiemTraXoa1(string sma, string scotcon, string strBangCon, string scotcha)
        {
            string      strSQL    = "SELECT TABLE_NAME tablename FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = N'" + scotcon + "_sd'";
            SqlFunction _sqlClass = new SqlFunction(HttpContext.Current.Session.GetConnectionString2());
            DataTable   _dt       = new DataTable();

            _dt    = _sqlClass.GetData(strSQL);
            strSQL = " ";
            if (_dt.Rows.Count > 0)
            {
                try
                {
                    for (int i = 0; i < _dt.Rows.Count; i++)
                    {
                        if (i == 0)
                        {
                            strSQL = "select " + scotcon + "_sd from " + _dt.Rows[i][0] + " where " + scotcon + "_sd in  (select " + scotcon + " from  " + strBangCon + " where " + scotcha + " = N'" + sma + "')";
                        }
                        else
                        {
                            strSQL = strSQL + " UNION ALL select " + scotcon + "_sd from " + _dt.Rows[i][0] + " where " + scotcon + "_sd in  (select " + scotcon + " from  " + strBangCon + " where " + scotcha + " = N'" + sma + "')";
                        }
                    }
                    return(_sqlClass.CheckHasRecord(strSQL));
                }
                catch { return(true); }
            }
            else
            {
                return(false);
            }
        }
        public static DataTable danhMucNguon(string sttDuAn)
        {
            SqlFunction sqlFunc = new SqlFunction(HttpContext.Current.Session.GetConnectionString2());
            string      sql     = "";

            if (sqlFunc.CheckHasRecord(" SELECT sttCanhBaopr_sd FROM tblCanhBao WHERE sttCanhBaopr_sd=8 and maDonVipr_sd='" + HttpContext.Current.Session.GetDonVi().maDonVi + "'"))
            {
                sql = sql = @"SELECT '' maNguonVonpr,'' tenNguonVon union all 
                        SELECT maNguonVonpr,(CASE 
                        WHEN LEN(maNguonVonpr)=1 THEN tenNguonVon
                        WHEN LEN(maNguonVonpr)=2 THEN '--- '+tenNguonVon
                        WHEN (LEN(maNguonVonpr)=4 OR LEN(maNguonVonpr)=3) THEN '--- --- '+tenNguonVon
                        WHEN (LEN(maNguonVonpr)=6 OR LEN(maNguonVonpr)=5) THEN '--- --- --- '+tenNguonVon
                        ELSE '--- --- --- --- '+tenNguonVon END
                        ) AS tenNguonVon FROM dbo.tblDMNguonVon WHERE isnull(ngungSD,0) = 0
						and maCapQuanLypr_sd=(select maCapQLpr_sd from tblDuAn where sttDuAnpr='"                         + sttDuAn + "')  ORDER BY maNguonVonpr ";
            }
            else
            {
                sql = @"SELECT maNguonVonpr,(CASE 
                                    WHEN LEN(maNguonVonpr)=1 THEN tenNguonVon
                                    WHEN LEN(maNguonVonpr)=2 THEN '--- '+tenNguonVon
                                    WHEN (LEN(maNguonVonpr)=4 OR LEN(maNguonVonpr)=3) THEN '--- --- '+tenNguonVon
                                    WHEN (LEN(maNguonVonpr)=6 OR LEN(maNguonVonpr)=5) THEN '--- --- --- '+tenNguonVon
                                    ELSE '--- --- --- --- '+tenNguonVon END
                                    ) AS tenNguonVon FROM dbo.tblDMNguonVon WHERE isnull(ngungSD,0) = 0";
            }
            return(sqlFunc.GetData(sql));
        }
Esempio n. 3
0
 public bool kiemTraLuuToChuc(string ma)
 {
     try
     {
         SqlFunction sqlFunc = new SqlFunction(HttpContext.Current.Session.GetConnectionString2());
         return(sqlFunc.CheckHasRecord("select maToChucpr from tblDMToChuc where maToChucpr=N'" + ma + "'"));
     }
     catch
     {
     }
     return(false);
 }
        //kiem tra ma khi them vao bang DL

        //Ngày bỗ sung: 19/12/2018
        //Người bỗ sung: Vịnh
        //Nội dung: Các class dùng chung theme boostrap
        #region Các class dùng chung boostrap

        /// <summary>
        /// Kiêm tra trùng mã trong 1 bảng dữ liệu
        /// </summary>
        /// <param name="strMaKiemTra">Mã cần kiểm tra VD: 010</param>
        /// <param name="strBangKiemTra">Bảng cần kiểm tra VD: tblDMKho</param>
        /// <param name="strCotKiemTra">Cột cần kiểm tra VD: maKhopr</param>
        /// <returns>True: trùng mã, False: Không trùng mã</returns>
        public static bool kiemTraTrungMa(string strMaKiemTra, string strBangKiemTra, string strCotKiemTra)
        {
            try
            {
                SqlFunction sqlFun = new SqlFunction(HttpContext.Current.Session.GetConnectionString2());
                string      strSQL = @"Select " + strCotKiemTra + " FROM " + strBangKiemTra + " WHERE " + strCotKiemTra + "=N'" + strMaKiemTra + "'";
                return(sqlFun.CheckHasRecord(strSQL));
            }
            catch
            {
                return(false);
            }
        }
        //kiem tram ma khi xoa
        public static bool kiemTraXoa(string sma, string schuoitru, string scot, string scotcon)
        {
            SqlFunction _sqlClass = new SqlFunction(HttpContext.Current.Session.GetConnectionString2());

            if (scot == "sttNhapKhopr_sd" && _sqlClass.CheckHasRecord("SELECT sttNhapKhopr FROM dbo.tblNhapKho WHERE sttNhapKhopr = '" + sma + "' AND trangThai ='1'") == true)
            {
                return(true);
            }
            if (scot == "sttTraNhapKhopr_sd" && _sqlClass.CheckHasRecord("SELECT sttTraNhapKhopr FROM dbo.tblTraNhapKho WHERE sttTraNhapKhopr = '" + sma + "' AND trangThai ='1'") == true)
            {
                return(true);
            }
            if (scot == "sttHoaDonpr_sd" && _sqlClass.CheckHasRecord("SELECT sttHoaDonpr FROM dbo.tblHoaDon WHERE sttHoaDonpr = '" + sma + "' AND trangThai ='1'") == true)
            {
                return(true);
            }
            if (scot == "sttKiemKhopr_sd" && _sqlClass.CheckHasRecord("SELECT sttKiemKhopr FROM dbo.tblKiemKho WHERE sttKiemKhopr = '" + sma + "' AND trangThai ='1'") == true)
            {
                return(true);
            }
            bool      travee = false;
            string    strSQL = "SELECT TABLE_NAME tablename FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = N'" + scot + "' AND TABLE_NAME NOT IN (" + schuoitru + ")";
            DataTable _dt    = new DataTable();

            _dt    = _sqlClass.GetData(strSQL);
            strSQL = " ";
            if (_dt.Rows.Count > 0)
            {
                try
                {
                    for (int i = 0; i < _dt.Rows.Count; i++)
                    {
                        if (i == 0)
                        {
                            strSQL = "select " + scot + " from " + _dt.Rows[i][0] + " where " + scot + " =N'" + sma + "'";
                        }
                        else
                        {
                            strSQL = strSQL + " UNION ALL select " + scot + " from " + _dt.Rows[i][0] + " where " + scot + " =N'" + sma + "'";
                        }
                    }
                    if (!_sqlClass.CheckHasRecord(strSQL))
                    {
                        if (schuoitru == "''" || schuoitru == "")
                        {
                            travee = false;
                        }
                        else
                        {
                            string   strBangTru  = schuoitru.Replace("'", "");
                            string[] mangBangTru = strBangTru.Split(',');
                            string[] mangCotCon  = scotcon.Split(',');
                            for (int i = 0; i < mangBangTru.Length; i++)
                            {
                                travee = kiemTraXoa1(sma, mangCotCon[i].ToString(), mangBangTru[i].ToString(), scot);
                                if (travee)
                                {
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        travee = true;
                    }
                }
                catch { travee = true; }
            }
            else
            {
                travee = false;
            }

            return(travee);
        }