DECLARE res NUMBER; doctype supermag.smdocuments.doctype%TYPE := 'OR'; docid supermag.smdocuments.ID%TYPE := 'ЗП012345'; BEGIN IF supermag.core.getproc IS NULL THEN res := supermag.core.startsmapp (); END IF; supermag.smdoclock (doctype, docid); BEGIN supermag.smenableactualizegoods; -- блокировка supermag.documents.changedocstate (doctype, docid, 1, 0); supermag.smactualizegoods; supermag.smdocunlock (doctype, docid); EXCEPTION WHEN OTHERS THEN supermag.smdocunlock (doctype, docid); RAISE; END; END;
DECLARE pId VARCHAR2(50); pLoc NUMBER(5); pIdCl NUMBER(10); pIdCl1 NUMBER(10); res number; curdocstate number; existdoc number; Cursor docs is select d.id, d.location, nvl(dd.ourselfclient, 0), d.clientindex from smdocuments d, smdatedocs dd where d.doctype = 'OR' and d.docstate in = '1' and d.id Like '%AZ' and d.id = dd.id and d.doctype = dd.doctype Cursor loc is select storeloc from smpostlocmap where storeloc = pLoc; BEGIN supermag.SMDOCLOCK('OR', pId); OPEN docs; LOOP FETCH docs INTO pId, pLoc, pIdCl, pIdCl1; EXIT WHEN docs%NOTFOUND; if supermag.core.getproc is null then res := supermag.Core.StartSMApp(); end if; begin select count(id) into existdoc from smdocuments dm where dm.doctype = 'OR' and id = pId and DOCSTATE not in ('-1','2','0','3'); if existdoc > 0 then supermag.SMENABLEACTUALIZEGOODS; select docstate into curdocstate from smdocuments where doctype = 'OR' and id = pId; if curdocstate = 1 then supermag.documents.changedocstate('OR',pId,1,2); end if; supermag.SMACTUALIZEGOODS; supermag.SMDOCUNLOCK('OR', pId); exception when others then supermag.SMDOCUNLOCK('OR', pId); end; OPEN loc; IF loc%FOUND THEN insert into smpostqueue (enqtime, enqseq, target, objtype, objid, paramint, paramstr, transflags, virtpack, commentary) select sysdate, SMPOSTQUEUESEQ.Nextval, lm.dbaseid, d.doctype, id, null, null, 0, null, null from smdocuments d, smpostlocmap lm where d.doctype = 'OR' and d.id = pId and lm.storeloc = d.location; commit; END IF; CLOSE loc; END LOOP; CLOSE docs; END;
// блокировка документа на базе магазина private bool BlockDocument(string strOraConn, string strDocType, string strDocId, out string strErrors) { using (var conOra = new OracleConnection(strOraConn)) { try { conOra.Open(); } catch (Exception ex) { strErrors = ex.Message; return false; } const string txtSql = "declare " + "res number; " + "curdocstate number; " + "existdoc number; " + "clientindex number; " + "DOCTYPE supermag.smdocuments.doctype%TYPE := :vDocTypeID; " + "DOCID supermag.smdocuments.id%TYPE := :vDocID; " + "begin " + "if supermag.core.getproc is null then " + "res := supermag.Core.StartSMApp(); " + "end if; " + "begin " + "select count(id) into existdoc from smdocuments where doctype = DOCTYPE and id = DOCID and DOCSTATE <> 0; " + "if existdoc > 0 then " + "supermag.SMDOCLOCK(DOCTYPE, DOCID); " + "supermag.SMENABLEACTUALIZEGOODS; " + "select docstate into curdocstate from smdocuments where doctype = DOCTYPE and id = DOCID; " + "if curdocstate = 2 then " + "supermag.documents.changedocstate(DOCTYPE, DOCID, 2, 1); " + "supermag.documents.changedocstate(DOCTYPE, DOCID, 1, 0); " + "else " + "supermag.documents.changedocstate(DOCTYPE, DOCID, 1, 0); " + "end if; " + "supermag.SMACTUALIZEGOODS; " + "supermag.SMDOCUNLOCK(DOCTYPE, DOCID); " + "end if; " + "exception when others then " + "supermag.SMDOCUNLOCK(DOCTYPE, DOCID); " + "raise; " + "end; " + "end;"; using (var cmd = new OracleCommand(txtSql, conOra)) { cmd.Parameters.Add(new OracleParameter("vDocTypeID", OracleType.VarChar)); cmd.Parameters["vDocTypeID"].Value = strDocType; cmd.Parameters.Add(new OracleParameter("vDocID", OracleType.VarChar)); cmd.Parameters["vDocID"].Value = strDocId; try { cmd.ExecuteNonQuery(); strErrors = null; return true; } catch (Exception ex) { strErrors = ex.Message; return false; } } } }