Пример #1
0
        // public static string remote = "Server=.;Trusted_Connection=yes;";

        public static void CreateTonHienTai(clsDB db, string @ma_dvcs, string @ma_kho, string @ma_vi_tri, string @masp)
        {
            string @ma_vi_triCondition = @ma_vi_tri;
            string query = "";


            if (@ma_vi_triCondition.Equals("00"))
            {
                @ma_vi_triCondition = "";
            }

            string sql = "\n IF OBJECT_ID('tempdb.dbo.#TonHienTai') IS NOT NULL DROP TABLE #TonHienTai  " +
                         "\n CREATE TABLE #TonHienTai ( ma_dvcs nvarchar(500),ma_kho nvarchar(500),ma_vi_tri nvarchar(500),ma_vt nvarchar(500), ton float ) " +
                         "\n if isnull((select dongboERP from nhaphanphoi where mafast ='" + ma_dvcs + "'),0) = 1 " +
                         "\n     insert #TonHienTai (ma_dvcs,ma_kho,ma_vi_tri,ma_vt,ton)   " +
                         "\n     select distinct ma_dvcs,ma_kho, case ma_vi_tri when '' then '00' else ma_vi_tri end ma_vi_tri ,ma_vt,ton from  OPENROWSET('SQLNCLI', '" + remote + "','SET FMTONLY OFF; " +
                         "\n     exec [FAST].[HTP_FBOR2_A].dbo.Fast$DMSGESO$CurrentStock ''" + ma_dvcs + "'',''" + ma_kho + "'',''" + ma_vi_triCondition + "'',''" + masp + "'' ') where 1=1 ";

            int sodo = db.updateQueryReturnInt(sql);



            query =
                "\n if isnull((select dongboERP from nhaphanphoi where mafast ='" + ma_dvcs + "'),0) = 0 " +
                "\n     insert #TonHienTai (ma_dvcs,ma_kho,ma_vi_tri,ma_vt,ton)   " +
                "\n     select distinct ma_dvcs,ma_kho, ma_vi_tri ,ma_vt,ton from  Kho_Test_HTP x " +
                "\n     where 1= 1 and not exists (select 1 from #TonHienTai y where  y.ma_dvcs = x.ma_dvcs and y.ma_kho = x.ma_kho and y.ma_vi_tri = x.ma_vi_tri  and y.ma_vt = x.ma_vt )   ";
            if (@ma_dvcs.Trim().Length > 0)
            {
                query += " and ma_dvcs = '" + @ma_dvcs + "'";
            }
            if (@ma_kho.Trim().Length > 0)
            {
                query += " and ma_kho  ='" + @ma_kho + "' ";
            }
            if (@ma_vi_tri.Trim().Length > 0)
            {
                query += " and ma_vi_tri =  '" + @ma_vi_tri + "' ";
            }
            if (@masp.Trim().Length > 0)
            {
                query += " and masp =  '" + @masp + "'";
            }

            int sodo2 = db.updateQueryReturnInt(query);
        }
Пример #2
0
        public static void CreateTonDau(clsDB db, string @ma_dvcs, string @ma_kho, string @ma_vi_tri, string @masp)
        {
            string @ma_vi_triCondition = @ma_vi_tri;
            string query = "";


            if (@ma_vi_triCondition.Equals("00"))
            {
                @ma_vi_triCondition = "";
            }

            string sql = "\n IF OBJECT_ID('tempdb.dbo.#TonDau') IS NOT NULL DROP TABLE #TonDau  " +
                         "\n CREATE TABLE #TonDau ( ma_dvcs nvarchar(500),ma_kho nvarchar(500),ma_vi_tri nvarchar(500),ma_vt nvarchar(500), ton float ) " +
                         "\n if isnull((select dongboERP from nhaphanphoi where mafast ='" + ma_dvcs + "'),0) = 1 " +
                         "\n     insert #TonHienTai (ma_dvcs,ma_kho,ma_vi_tri,ma_vt,ton)   " +
                         "\n     select distinct ma_dvcs,ma_kho, case ma_vi_tri when '' then '00' else ma_vi_tri end ma_vi_tri ,ma_vt,ton from  OPENROWSET('SQLNCLI', '" + remote + "','SET FMTONLY OFF; " +
                         "\n     exec [FAST].[HTP_FBOR2_A].dbo.Fast$DMSGESO$Stock ''" + ma_dvcs + "'',''" + ma_kho + "'',''" + ma_vi_triCondition + "'',''" + masp + "'' ') where 1=1 ";

            int sodo = db.updateQueryReturnInt(sql);
        }