文档的移动,保存和修改

public class ROG_Document
{
    Object                  obj;
    FormDataSource          FDS;
 
    Common                  common;
 
    QueryRun                qr;
 
    Str                     parmStr;
    Int                     hwnd;
 
    ROG_DocumentTable       documentTable;
 
    HRMApplicantTable       applicantTable;
 
    userid                  userid;
 
    ROG_Document            _documentPack;
 
    ROG_DocumentHelper      documentHelper;
}
 
Object dialog()
{
    FormRun dialogForm;
    Args                            args   =   new Args("ROG_SelectUserid");
 
   ;
    args.caller(_documentPack);
    dialogForm = classfactory.formRunClass(args);
    dialogForm.init();
    dialogForm.run();
    dialogForm.wait();
    return dialogForm;
}
 
object FDS(FormDataSource _fds = FDS)
{
    ;
    FDS = _fds;
    return FDS;
}
 
str getOnlyFileName(Str     _str)
{
    str     _name;
    int     i;
    int     position;
    boolean flg;
    ;
    if(_str)
    {
        if (strfind(_str,"\\",1,strlen(_str)))
        {
            do
            {
 
                i = strfind(_str,"\\",position,strlen(_str));
                _str = substr(_str,i,strlen(_str) - i);
 
            } while(i);
 
            return substr(_str,1,strlen(_str) - strfind(_str,".",1,strlen(_str)) - 1);
        }
        else
            return "";
 
    }
    else
        return "";
}
 
object obj(object _obj = obj)
{
    ;
    obj = _obj;
    return obj;
}
 
Common parmCommon(Common    _common = common)
{
    ;
    common = _common;
    return common;
}
 
ROG_Document parmDocument(ROG_Document  _ROG_Document = _documentPack)
{
;
    _documentPack = _ROG_Document;
    return _documentPack;
}
 
int parmhwnd(int    _hwnd = hwnd)
{
;
    hwnd    = _hwnd;
    return hwnd;
 
}
 
Str parmstr(Str _parmStr = parmStr)
{
    ;
    parmStr = _parmStr;
    return parmStr;
}
 
userid parmUserid(userid      _userid)
{
    ;
 
    userid  = _userid;
    return userid;
 
}
 
void run()
{
;
    documentTable = ROG_DocumentTable::find(common.TableId,common.RecId);
    if(common.TableId == tablenum(HRMApplicantTable))
    {
        applicantTable = common;
        this.RunHRMApplicantTable();
    }
 
}
 
void RunHRMApplicantTable()
{
;
    if(parmStr == "save")
    {
        this.saveDocument();
    }
    else if(parmStr == "saveas" )
    {
        this.saveAsDocument();
    }
    else if(parmStr == "open")
    {
        ROG_Document::openDocument(documentTable.FilePath);
    }
    else if(parmStr == "companyOpen")
    {
        ROG_Document::openDocument(documentTable.FilePathROG);
    }
    else if(parmStr == "companySave")
    {
        this.saveCompanyDocument();
    }
}
 
void saveAsDocument()
{
    Filename    onlyFilename;
    Filename    curFileExtension;
    Filename    toFileName;
;
    documentHelper   = new ROG_DocumentHelper();
    documentHelper.parmDocumentHelper(documentHelper);
 
    if(documentHelper.prompt())
    {
        info(documentHelper.parmUserid());
 
        this.parmUserid(documentHelper.parmUserid());
        if(userid)
        {
            info(userid);
 
            [onlyFilename,curFileExtension]  = Docu::splitFilename(documentTable.FilePath);
 
            toFileName = documentTable.completeFilename(onlyFilename,curFileExtension,userid);
 
            winAPI::copyFile(documentTable.FilePath,toFileName);
            winAPI::deleteFile(documentTable.FilePath);
 
            ttsbegin;
            documentTable.selectForUpdate(true);
            documentTable.FilePath  = toFileName;
            //documentTable.createdBy =
            documentTable.update();
            ttscommit;
 
        }
        else
        {
            info("@ROG101");
        }
    }
 
}
 
void saveAsDocumentbackup()
{
 
    FormRun                         form;
    Args                            a   =   new Args("FOG_SelectUserid");
    Filename    onlyFilename;
    Filename    curFileExtension;
    Filename    toFileName;
    ;
    a.caller(_documentPack);
    form    =   ClassFactory.formRunClass(a);
    form.init();
    form.run();
    form.wait();
 
    if(userid)
    {
        info(userid);
 
        [onlyFilename,curFileExtension]  = Docu::splitFilename(documentTable.FilePath);
 
        toFileName = documentTable.completeFilename(onlyFilename,curFileExtension,userid);
 
        winAPI::copyFile(documentTable.FilePath,toFileName);
        winAPI::deleteFile(documentTable.FilePath);
 
        ttsbegin;
        documentTable.selectForUpdate(true);
        documentTable.FilePath = toFileName;
        documentTable.update();
        ttscommit;
    }
 
}
 
void saveAsDocumentDialog()
{
    FormRun          _dialog;
 
 
    FormRun                         form;
    Args                            a   =   new Args("ROG_SelectUserid");
    Filename    onlyFilename;
    Filename    curFileExtension;
    Filename    toFileName;
    ;
    /*
    a.caller(_documentPack);
    form    =   ClassFactory.formRunClass(a);
    form.init();
    //form.run();
    //form.wait();
 
    _dialog = new dialog("ffd",_documentPack,"fds",formstr(ROG_SelectUserid));
    //dlf     = _dialog.addField(typeid(userid));
    //formstr(ROG_SelectUserid);
    */
    this.dialog();
 
    if(userid)
    {
        info(userid);
 
        [onlyFilename,curFileExtension]  = Docu::splitFilename(documentTable.FilePath);
 
        toFileName = documentTable.completeFilename(onlyFilename,curFileExtension,userid);
 
        winAPI::copyFile(documentTable.FilePath,toFileName);
        winAPI::deleteFile(documentTable.FilePath);
 
        ttsbegin;
        documentTable.selectForUpdate(true);
        documentTable.FilePath = toFileName;
        documentTable.update();
        ttscommit;
    }
 
}
 
void saveCompanyDocument()
{
    str             filename;
    FileNameFilter  filter;// = ['Image Files','*.jpg'];
 
    Bindata binData = new BinData();
    Filename    onlyFilename;
    Filename    curFileExtension;
    Filename    toFileName;
    ;
 
    filename = Winapi::getOpenFileName(hwnd,filter,'', "@SYS53008", '','');
 
 
    if ((filename) && (StrScan(filename,".doc",1,strlen(filename)) > 0))
    {
        //if (binData.loadFile(filename))
        {
            [onlyFilename,curFileExtension]  = Docu::splitFilename(filename);
 
            if (onlyFilename)
            {
                toFileName = documentTable.completeFilename(onlyFilename,curFileExtension);
                if(toFileName)
                {
                    if(filename == toFileName)
                    {
                        info("@HFM1587");
                    }
                    else
                    {
                        winapi::copyFile(filename, toFileName,true);
                        ttsbegin;
                        documentTable.selectForUpdate(true);
                        documentTable.FilePathROG = toFileName;
                        documentTable.update();
                        ttscommit;
                    }
 
                }
                else
                {
                    throw error("@ROG94");
                }
            }
        }
    }
}
 
 
void saveDocument()
{
     str             filename;
    FileNameFilter  filter;// = ['Image Files','*.jpg'];
 
    Bindata binData = new BinData();
    Filename    onlyFilename;
    Filename    curFileExtension;
    Filename    toFileName;
    ;
 
    filename = Winapi::getOpenFileName(hwnd,filter,'', "@SYS53008", '','');
 
 
    if ((filename) && (StrScan(filename,".doc",1,strlen(filename)) > 0))
    {
        //if (binData.loadFile(filename))
        {
            [onlyFilename,curFileExtension]  = Docu::splitFilename(filename);
 
            if (onlyFilename)
            {
                toFileName = documentTable.completeFilename(onlyFilename,curFileExtension);
                if(toFileName)
                {
                    if(filename == toFileName)
                    {
                        info("@HFM1587");
                    }
                    else
                    {
                        winapi::copyFile(filename, toFileName,true);
                        ttsbegin;
                        documentTable.selectForUpdate(true);
                        documentTable.FilePath = toFileName;
                        documentTable.update();
                        ttscommit;
 
                        ttsbegin;
                        applicantTable.selectForUpdate(true);
                        //info(useridStr.valueStr());
                        applicantTable.ROG_createBy = applicantTable.createdBy;
                        applicantTable.update();
                        ttscommit;
 
                    }
 
                }
                else
                {
                    throw error("@ROG94");
                }
            }
        }
    }
 
 
}
 
 
boolean setUserid(userid      _userid)
{
    ;
    if(_userid)
    {
        userid  = _userid;
        return true;
    }
    else
    {
        return false;
    }
}
 
 
static Str checkFolderChar(Str pFolderName)
{
    Str mReturn = "";
    Int mLoop;
    ;
 
    for (mLoop=1; mLoop<=StrLen(pFolderName); mLoop++)
    {
        if ((substr(pFolderName, mLoop, 1) != "\\")
        && (substr(pFolderName, mLoop, 1) != "/")
        && (substr(pFolderName, mLoop, 1) != ":")
        && (substr(pFolderName, mLoop, 1) != "*")
        && (substr(pFolderName, mLoop, 1) != "?")
        && (substr(pFolderName, mLoop, 1) != '"')
        && (substr(pFolderName, mLoop, 1) != "<")
        && (substr(pFolderName, mLoop, 1) != ">")
        && (substr(pFolderName, mLoop, 1) != "|"))
        {
            mReturn = mReturn + substr(pFolderName, mLoop, 1);
        }
    }
 
    return mReturn;
}
 
 
public static ROG_Document construct()
{
    return new ROG_Document();
}
 
 
static void openDocument(str filename)
{
    COM     wordApplication;
    COM     wordDocuments;
    COM     wordDocument;
    COM     wordRange;
    ;
    wordApplication = new COM("word.application");
    wordDocuments   = wordApplication.Documents();
 
    //wordDocument    = wordDocuments.add("F:\\Resume\\andyl\\Testdocdoc.doc");//add(filename);
    wordDocument    = wordDocuments.add(filename);
    wordApplication.visible(TRUE);
}
 
 
 
server static void main(Args args)
{
    ROG_Document   _document = ROG_Document::construct();
    ;
    //breakpoint;
    _document.obj(args.caller());
    _document.parmCommon(args.record());
    _document.FDS(_document.obj().dataSource());
    _document.parmstr(args.parm());
 
    _document.parmhwnd(_document.obj().hwnd());
 
    _document.parmDocument(_document);
    _document.run();
 
}

  

 

posted @   adingkui  阅读(325)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示