public string SearchPropertyValue(PropertyValues ppvs, MFIdentifier def, PropertyValue defaultPpt = null)
        {
            var ppt = defaultPpt;

            if (ppt == null)
            {
                ppt = ppvs.SearchForProperty(def);
            }


            return((ppt.TypedValue.DataType == MFDataType.MFDatatypeLookup) ?
                   ppt.TypedValue.GetLookupID().ToString() : ppt.TypedValue.DisplayValue);
        }
Beispiel #2
0
        public static PropertyValue GetPropertyValue(PropertyValues pvs, int propertydef, Vault vault)
        {
            var pv = new PropertyValue();

            try
            {
                return(pvs.SearchForProperty(propertydef));
            }
            catch (Exception ex)
            {
                //   Writelog(string.Format("GetPropertyValue {0} error: {1}",propertydef, ex.Message));
            }
            return(pv);
        }
        public PropertyValue GetPropertyValue(PropertyValues ppvs, MFIdentifier PropertyDef, MFIdentifier SetDef = null)
        {
            var ppValue = new PropertyValue();

            ppValue.PropertyDef = PropertyDef;

            if (SetDef == null)
            {
                SetDef = PropertyDef;
            }
            var ppt = ppvs.SearchForProperty(SetDef);

            ppValue.Value.SetValue(ppt.TypedValue.DataType, SearchPropertyValue(ppvs, SetDef, ppt));

            return(ppValue);
        }
        public PropertyValue GetPropertyValue(Vault vault, PropertyValues POPpvs, MFIdentifier PODef, MFIdentifier InvDef)
        {
            var ppValue = new PropertyValue();

            ppValue.PropertyDef = InvDef.ID;

            string strVal = GetPropertyValue(POPpvs.SearchForProperty(PODef));

            if (InvDef == ItemNumber_PD)
            {
                string[] displayValues = strVal.Split('=');
                strVal = displayValues[0];
            }
            ppValue.Value.SetValue(vault.PropertyDefOperations.GetPropertyDef(InvDef.ID).DataType, strVal);

            return(ppValue);
        }
Beispiel #5
0
        public PropertyValues ChangeNameOrTitle(PropertyValues props, string newName)
        {
            PropertyValue prop = new PropertyValue {
                PropertyDef = 0
            };

            prop.Value.SetValue(MFDataType.MFDatatypeText, newName);
            if (props.IndexOf(0) == -1)
            {
                props.Add(-1, prop);
            }
            else
            {
                props.SearchForProperty(0).Value.SetValue(MFDataType.MFDatatypeText, newName);
            }
            return(props);
        }
Beispiel #6
0
        public static string GetSecureNoticeNew(EventHandlerEnvironment env) //程序划图片表格
        {
            var rpd = new ReportPrintData();

            Writelog(env.Vault.Name + env.Input + "GetSecureNotice : 查询条件");
            try
            {
                var input = JsonConvert.DeserializeObject <ReportInput>(env.Input);

                #region search issuenotice

                var conditions = new SearchConditions();
                {
                    var condition = new SearchCondition
                    {
                        ConditionType = MFConditionType.MFConditionTypeEqual,
                        Expression    =
                        {
                            DataStatusValueType = MFStatusType.MFStatusTypeObjectTypeID
                        }
                    };
                    condition.TypedValue.SetValueToLookup(new Lookup {
                        Item = OtSecureAdjustNotice.ID
                    });
                    //    Writelog("OtSecureAdjustNotice=" + OtSecureAdjustNotice.ID);
                    conditions.Add(-1, condition);
                }
                {
                    var sc = new SearchCondition
                    {
                        ConditionType = MFConditionType.MFConditionTypeNotEqual,
                        Expression    = { DataStatusValueType = MFStatusType.MFStatusTypeDeleted }
                    };
                    sc.TypedValue.SetValue(MFDataType.MFDatatypeBoolean, true);
                    conditions.Add(-1, sc);
                }
                {
                    var condition = new SearchCondition
                    {
                        ConditionType = MFConditionType.MFConditionTypeGreaterThanOrEqual,
                        Expression    = { DataPropertyValuePropertyDef = PropCheckDate.ID }
                    };
                    //   Writelog("PropCheckDate=" + PropCheckDate.ID);
                    condition.TypedValue.SetValue(MFDataType.MFDatatypeDate, input.StartDate);
                    conditions.Add(-1, condition);
                }
                {
                    var condition = new SearchCondition
                    {
                        ConditionType = MFConditionType.MFConditionTypeLessThanOrEqual,
                        Expression    = { DataPropertyValuePropertyDef = PropCheckDate.ID }
                    };
                    condition.TypedValue.SetValue(MFDataType.MFDatatypeDate, input.EndDate);
                    conditions.Add(-1, condition);
                }
                if (input.Principal != 0)
                {
                    var condition = new SearchCondition();
                    //  Writelog("PropPrincipal=" + PropPrincipal.ID);
                    condition.ConditionType = MFConditionType.MFConditionTypeEqual;
                    condition.Expression.DataPropertyValuePropertyDef = PropPrincipal.ID;
                    condition.TypedValue.SetValueToLookup(new Lookup {
                        Item = input.Principal
                    });
                    conditions.Add(-1, condition);
                }
                if (input.Receiver != 0)
                {
                    var condition = new SearchCondition();
                    //    Writelog("PropSecureReceiver=" + PropSecureReceiver.ID);
                    condition.ConditionType = MFConditionType.MFConditionTypeEqual;
                    condition.Expression.DataPropertyValuePropertyDef = PropSecureReceiver.ID;
                    condition.TypedValue.SetValueToLookup(new Lookup {
                        Item = input.Receiver
                    });
                    conditions.Add(-1, condition);
                }
                ObjectVersions allwork = env.Vault.ObjectSearchOperations.SearchForObjectsByConditionsEx(conditions,
                                                                                                         MFSearchFlags.MFSearchFlagNone, false, 0, 0).GetAsObjectVersions();

                #endregion search issuenotice

                //  Writelog("allwork=" + allwork.Count);

                string templatefile = GetTemplateFile(env);

                try
                {
                    object oMissing = Missing.Value;
                    object objWhat  = WdGoToItem.wdGoToPage;
                    object objWhich = WdGoToDirection.wdGoToLast;
                    var    app      = new Application();
                    object unknow   = Type.Missing;
                    //  var msocoding = MsoEncoding.msoEncodingSimplifiedChineseGB18030;
                    Document doc = app.Documents.Open(templatefile,
                                                      ref unknow, false, ref unknow, ref unknow, ref unknow,
                                                      //        ref unknow, ref unknow, ref unknow, ref unknow, msocoding,
                                                      ref unknow, ref unknow, ref unknow, ref unknow, ref unknow,
                                                      ref unknow, ref unknow, ref unknow, ref unknow, ref unknow);

                    int    issueindex = 0;//问题唯一序号,跨页接续
                    int    tableindex = 1;
                    string temppath   = Path.GetTempPath();
                    doc.Content.Copy();

                    Writelog(String.Format("vault:{0},conditions{1},results:{2}", env.Vault.Name, env.Input,
                                           allwork.Count));
                    int  rowpos  = 1;//问题填写位置,每页刷新
                    bool newpage = false;
                    foreach (ObjectVersion objectVersion in allwork)
                    {
                        // Writelog("debug info aaaa");
                        if (newpage)
                        {
                            newpage = false;
                            //   Writelog("debug info bbbb");
                            object    nothing = Missing.Value;
                            Paragraph para    = doc.Content.Paragraphs.Add(ref nothing);
                            object    pBreak  = (int)WdBreakType.wdSectionBreakNextPage;
                            para.Range.InsertBreak(ref pBreak);
                            //   Writelog("debug info bbbb1111");

                            app.Selection.GoTo(ref objWhat, ref objWhich, ref unknow, ref unknow);
                            //    Writelog("debug info dddd");

                            app.Selection.Paste();
                            //   Writelog("debug info ffff");
                            tableindex++;
                            rowpos = 1;
                        }

                        PropertyValues onepvs = env.Vault.ObjectPropertyOperations.GetProperties(objectVersion.ObjVer);
                        issueindex++;

                        string issuename = env.Vault.Name;
                        //  Writelog("debug info 6666");
                        doc.Tables[tableindex].Cell(4, 2).Range.Text = issuename;


                        //   Writelog("debug info 7777");
                        int rowindex = 6 + rowpos;

                        string secureissuename = onepvs.SearchForProperty(PropIssueCategory).GetValueAsLocalizedText();
                        doc.Tables[tableindex].Cell(rowindex, 1).Range.Text =
                            issueindex.ToString(CultureInfo.InvariantCulture);

                        doc.Tables[tableindex].Cell(rowindex, 2).Range.Text = secureissuename;
                        doc.Tables[tableindex].Cell(rowindex, 3).Range.Text =
                            onepvs.SearchForProperty(PropSecureIssues.ID).GetValueAsLocalizedText();
                        doc.Tables[tableindex].Cell(rowindex, 4).Range.Text =
                            onepvs.SearchForProperty(PropAdjustMeasure.ID).GetValueAsLocalizedText();

                        doc.Tables[tableindex].Cell(rowindex, 5).Range.Text =
                            onepvs.SearchForProperty(PropPrincipal.ID)
                            .GetValueAsLocalizedText();


                        doc.Tables[tableindex].Cell(rowindex, 6).Range.Text =
                            onepvs.SearchForProperty(PropSecureReceiver.ID)
                            .GetValueAsLocalizedText();
                        doc.Tables[tableindex].Cell(rowindex, 7).Range.Text =
                            onepvs.SearchForProperty(PropAdjustMan.ID)
                            .GetValueAsLocalizedText();


                        doc.Tables[tableindex].Cell(rowindex, 8).Range.Text =
                            onepvs.SearchForProperty(PropFuChaRen.ID)
                            .GetValueAsLocalizedText();
                        doc.Tables[tableindex].Cell(rowindex, 9).Range.Text =
                            onepvs.SearchForProperty(PropCountercheckDescription.ID)
                            .GetValueAsLocalizedText();
                        //       Writelog(string.Format("表 {0}, 行 {1},序号 {2}, 行号 {3}",tableindex,rowindex,issueindex,rowpos));
                        if (rowpos++ >= 10)
                        {
                            newpage = true;
                        }
                    }

                    int index = 0;
                    foreach (ObjectVersion objectVersion in allwork)
                    {
                        PropertyValues onepvs = env.Vault.ObjectPropertyOperations.GetProperties(objectVersion.ObjVer);

                        object    nothing = Missing.Value;
                        Paragraph para    = doc.Content.Paragraphs.Add(ref nothing);
                        object    pBreak  = (int)WdBreakType.wdSectionBreakNextPage;
                        para.Range.InsertBreak(ref pBreak);

                        app.Selection.GoTo(ref objWhat, ref objWhich, ref unknow, ref unknow);

                        app.Selection.PageSetup.Orientation = WdOrientation.wdOrientPortrait;
                        Range range = app.Selection.Range;
                        Table table = app.Selection.Tables.Add(range, 7, 1, ref oMissing, ref oMissing);

                        table.Borders.OutsideLineStyle = WdLineStyle.wdLineStyleDouble;
                        table.Borders.InsideLineStyle  = WdLineStyle.wdLineStyleSingle;
                        table.Cell(1, 1).Split(1, 2);
                        for (int i = 2; i <= 3; i++)
                        {
                            table.Cell(i, 1).Split(1, 4);
                        }

                        //Writelog("debug info 888111");
                        //app.Selection.TypeText("序号:" + page);
                        //Writelog("debug info 999000 v1");
                        table.Cell(1, 1).Range.Text = "序号:";
                        table.Cell(1, 2).Range.Text = (++index).ToString(CultureInfo.InvariantCulture);
                        //table.Cell(1, 3).Range.Text = "存在问题:";
                        //table.Cell(1, 4).Range.Text =
                        //    onepvs.SearchForProperty(PropSecureIssues.ID).GetValueAsLocalizedText();
                        //Writelog("debug info 1111 v1-" + tableindex);
                        //table.Cell(rowindex, 1).Range.Text = "检查负责人:";
                        table.Cell(2, 1).Range.Text = "检查日期:";
                        //table.Cell(2, 2).Range.Text =
                        //    onepvs.SearchForProperty(PropPrincipal.ID)
                        //        .GetValueAsLocalizedText();
                        table.Cell(2, 2).Range.Text =
                            onepvs.SearchForProperty(PropCheckDate.ID)
                            .GetValueAsLocalizedText();
                        //Writelog("debug info 222 v1-" + tableindex);
                        //table.Cell(rowindex, 1).Range.Text = "接收人  :";
                        //table.Cell(rowindex++, 3).Range.Text = "整改人:";
                        //table.Cell(3, 2).Range.Text =
                        //    onepvs.SearchForProperty(PropSecureReceiver.ID)
                        //        .GetValueAsLocalizedText();
                        //table.Cell(3, 4).Range.Text =
                        //    onepvs.SearchForProperty(PropAdjustMan.ID)
                        //        .GetValueAsLocalizedText();
                        //   Writelog("debug info 333 v1-" + tableindex);
                        table.Cell(2, 3).Range.Text = "整改期限  :";
                        table.Cell(3, 3).Range.Text = "整改次数:";
                        table.Cell(2, 4).Range.Text =
                            onepvs.SearchForProperty(PropZhengGaiQiXin.ID)
                            .GetValueAsLocalizedText();
                        table.Cell(3, 4).Range.Text =
                            onepvs.SearchForProperty(PropRectificationCount.ID)
                            .GetValueAsLocalizedText();
                        //Writelog("debug info 444 v1-" + tableindex);
                        //table.Cell(rowindex, 1).Range.Text = "复查人  :";
                        table.Cell(3, 1).Range.Text = "复查日期:";
                        //table.Cell(5, 2).Range.Text =
                        //    onepvs.SearchForProperty(PropFuChaRen.ID)
                        //        .GetValueAsLocalizedText();
                        table.Cell(3, 2).Range.Text =
                            onepvs.SearchForProperty(PropReviewDate.ID)
                            .GetValueAsLocalizedText();
                        //    Writelog("debug info 555 v1-" + tableindex);
                        // int rowindex = 2;
                        table.Cell(4, 1).Range.Text = "整改前照片:";
                        table.Cell(6, 1).Range.Text = "复查照片:";
                        ObjectFiles files  = env.Vault.ObjectFileOperations.GetFiles(objectVersion.ObjVer);
                        int         picrow = 5;
                        //  Writelog("before 000000000000");
                        foreach (ObjectFile objectFile in files)
                        {
                            string apicture = temppath + objectFile.GetNameForFileSystem();
                            env.Vault.ObjectFileOperations.DownloadFile(objectFile.ID,
                                                                        objectFile.Version, apicture);
                            object      linkToFile       = false;
                            object      saveWithDocument = true;
                            object      anchor           = table.Cell(picrow, 1).Range;
                            InlineShape insh             = doc.InlineShapes.AddPicture(apicture, ref linkToFile,
                                                                                       ref saveWithDocument,
                                                                                       ref anchor);
                            insh.Height = 259;
                            insh.Width  = 416;
                            picrow     += 2;
                            if (picrow > 7)
                            {
                                break;
                            }
                        }
                    }
                    doc.Close();
                    app.Quit();
                }
                catch (Exception ex)
                {
                    Writelog(ex.Message);
                }

                var pvs = new PropertyValues();
                var pv  = new PropertyValue {
                    PropertyDef = 0
                };
                pv.Value.SetValue(MFDataType.MFDatatypeText, "securenoticereport");
                pvs.Add(-1, pv);
                pv.PropertyDef = 100;
                pv.Value.SetValueToLookup(new Lookup {
                    Item = ClassSecureReport
                });
                pvs.Add(-1, pv);
                var file = new SourceObjectFile {
                    Title = "report", SourceFilePath = templatefile, Extension = "docx"
                };

                try
                {
                    ObjectVersionAndProperties t = env.Vault.ObjectOperations.CreateNewSFDObject(0, pvs, file, true);
                    ObjectFiles f = env.Vault.ObjectFileOperations.GetFiles(t.ObjVer);

                    rpd.Objid       = t.ObjVer.ID;
                    rpd.Objtype     = t.ObjVer.Type;
                    rpd.Objversion  = t.ObjVer.Version;
                    rpd.Fileid      = f[1].FileVer.ID;
                    rpd.Fileversion = f[1].FileVer.Version;
                }
                catch (Exception ex)
                {
                    Writelog("getsecurenotice - create object :" + ex.Message);
                }
            }
            catch (Exception ex)
            {
                Writelog(env.Input + "GetSecureNotice error:" + ex.Message);
            }
            var ret = JsonConvert.SerializeObject(rpd, Formatting.None);
            Writelog("GetSecureNotice ok return:" + ret);
            return(ret);
        }
Beispiel #7
0
        public DocumentOperation(StateEnvironment stateEnvironment)
        {
            vault  = stateEnvironment.Vault;
            objver = stateEnvironment.ObjVer;

            try
            {
                var config = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location);
                SignaturePicturePath = string.Empty;
                var spp = config.AppSettings.Settings["SignaturePicturePath"];
                if (spp != null)
                {
                    SignaturePicturePath = spp.Value;
                }

                var files = vault.ObjectFileOperations.GetFiles(objver);
                filepath = Path.GetTempFileName();

                foreach (ObjectFile objectFile in files)
                {
                    vault.ObjectFileOperations.DownloadFile(objectFile.ID, objectFile.Version, filepath);
                    break;
                }
                var sc = new SearchCondition();
                sc.ConditionType = MFConditionType.MFConditionTypeEqual;
                sc.Expression.DataStatusValueType = MFStatusType.MFStatusTypeObjectTypeID;
                sc.TypedValue.SetValueToLookup(new Lookup
                {
                    Item =
                        vault.GetMetadataStructureItemIDByAlias(
                            MFMetadataStructureItem.MFMetadataStructureItemObjectType, MfilesAliasConfig.ObjProject)
                });
                var sr = vault.ObjectSearchOperations.SearchForObjectsByCondition(sc, false).ObjectVersions;
                if (sr.Count < 1)
                {
                    Writelog(string.Format("DocumentOperation- can't find project object in the vault <{0}>--", vault.Name));
                }
                foreach (ObjectVersion objectVersion in sr)
                {
                    pvs = vault.ObjectPropertyOperations.GetProperties(objectVersion.ObjVer);

                    Project = new ProjectInMfiles
                    {
                        PropProjName =
                            pvs.SearchForPropertyByAlias(vault, MfilesAliasConfig.PropProjName, true).GetValueAsLocalizedText(),
                        PropProjNum     = pvs.SearchForPropertyByAlias(vault, MfilesAliasConfig.PropProjNum, true).GetValueAsLocalizedText(),
                        PropDescription =
                            pvs.SearchForPropertyByAlias(vault, MfilesAliasConfig.PropDescription, true).GetValueAsLocalizedText(),
                        PropProprietorUnit =
                            pvs.SearchForPropertyByAlias(vault, MfilesAliasConfig.PropProprietorUnit, true).GetValueAsLocalizedText(),
                        PropSupervisorUnit =
                            pvs.SearchForPropertyByAlias(vault, MfilesAliasConfig.PropSupervisorUnit, true).GetValueAsLocalizedText(),
                        PropDesignUnit =
                            pvs.SearchForPropertyByAlias(vault, MfilesAliasConfig.PropDesignUnit, true).GetValueAsLocalizedText(),
                        PropStartDate =
                            pvs.SearchForPropertyByAlias(vault, MfilesAliasConfig.PropStartDate, true).GetValueAsLocalizedText(),
                        Deadline =
                            pvs.SearchForProperty((int)MFBuiltInPropertyDef.MFBuiltInPropertyDefDeadline)
                            .GetValueAsLocalizedText(),
                    };
                    break;
                }
                pvs = vault.ObjectPropertyOperations.GetProperties(objver);
                app = new Application();
                object unknow = Type.Missing;
                doc = app.Documents.Open(filepath,
                                         ref unknow, false, ref unknow, ref unknow, ref unknow,
                                         ref unknow, ref unknow, ref unknow, ref unknow, ref unknow,
                                         ref unknow, ref unknow, ref unknow, ref unknow, ref unknow);
                table = doc.Tables[doc.Tables.Count];
            }
            catch (Exception ex)
            {
                Writelog(string.Format("DocumentOperation-- vault={0},type={1},id={2},version={3},CurrentUserID={4},StateID={5},DisplayID={6},{7}",
                                       vault.Name, objver.Type, objver.ID, objver.Version, stateEnvironment.CurrentUserID, stateEnvironment.StateID, stateEnvironment.DisplayID, ex.Message));
            }
        }
Beispiel #8
0
        //Export Button
        private void button1_Click(object sender, EventArgs e, Vault currVault, MFilesClientApplication mFilesApp)
        {
            //MessageBox.Show(currVault.Name);

            SaveFileDialog saveFile = new SaveFileDialog();

            saveFile.Filter = "XML Files (*.xml)|*.xml";


            if (saveFile.ShowDialog() == DialogResult.OK)
            {
                //pull invoices using search conditions
                var searchConditions = new SearchConditions();

                //is it not deleted
                var isNotDeleted = new SearchCondition();
                isNotDeleted.Expression.DataStatusValueType         = MFStatusType.MFStatusTypeDeleted;
                isNotDeleted.Expression.DataStatusValueDataFunction = MFDataFunction.MFDataFunctionNoOp;
                isNotDeleted.ConditionType = MFConditionType.MFConditionTypeNotEqual;
                isNotDeleted.TypedValue.SetValue(MFDataType.MFDatatypeBoolean, true);
                searchConditions.Add(-1, isNotDeleted);

                //is it part of the Invoice workflow
                var isInvoice = new SearchCondition();
                isInvoice.Expression.DataPropertyValuePropertyDef = (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefWorkflow;
                isInvoice.ConditionType = MFConditionType.MFConditionTypeEqual;
                isInvoice.TypedValue.SetValue(MFDataType.MFDatatypeLookup, Properties.Settings.Default.invoiceWorkflow);
                searchConditions.Add(-1, isInvoice);

                //is it in the accounting state
                var isAccounting = new SearchCondition();
                isAccounting.Expression.DataPropertyValuePropertyDef = (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefState;
                isAccounting.ConditionType = MFConditionType.MFConditionTypeEqual;
                isAccounting.TypedValue.SetValue(MFDataType.MFDatatypeLookup, Properties.Settings.Default.stateAccounting);
                searchConditions.Add(-1, isAccounting);

                //Perform search
                var invoices = currVault.ObjectSearchOperations.SearchForObjectsByConditions(searchConditions, MFSearchFlags.MFSearchFlagNone, false);


                //start output file
                XElement output   = new XElement("YsiTran");
                XElement payables = new XElement("Payables");

                //get post month
                var postMonthForm = new PostMonth();
                postMonthForm.ShowDialog();

                //loop through invoices collecting at import workflow state, build XML file from the inside out.
                int count = 0;
                foreach (ObjectVersion invoice in invoices)
                {
                    XElement payable     = new XElement("Payable");
                    double   totalAmount = 0;
                    count++;

                    var propValues        = new PropertyValues();
                    var currPropertyValue = new PropertyValue();
                    var objLedger         = new ObjectVersion();
                    propValues = currVault.ObjectPropertyOperations.GetProperties(invoice.ObjVer);

                    XElement details = new XElement("Details");

                    //Get Ledger Entry reference
                    currPropertyValue = propValues.SearchForProperty(Properties.Settings.Default.propLedgerEntry);

                    if (currPropertyValue.TypedValue.DataType == MFDataType.MFDatatypeMultiSelectLookup)
                    {
                        var lookups = new Lookups();

                        lookups = currPropertyValue.TypedValue.GetValueAsLookups();

                        int i = 0;
                        foreach (Lookup lookup in lookups)
                        {
                            XElement detail = new XElement("Detail");

                            var propDef = new PropertyDef();
                            propDef = currVault.PropertyDefOperations.GetPropertyDef(currPropertyValue.PropertyDef);
                            var valListObjType = new ObjType();
                            valListObjType = currVault.ValueListOperations.GetValueList(propDef.ValueList);

                            if (valListObjType.RealObjectType)
                            {
                                i++;
                                //Get Ledgery Entry Object
                                var objDetail = new ObjVer();
                                objDetail.SetIDs(valListObjType.ID, lookup.Item, lookup.Version);
                                var detailValues = new PropertyValues();
                                var detailValue  = new PropertyValue();
                                detailValues = currVault.ObjectPropertyOperations.GetProperties(objDetail);
                                //MessageBox.Show(i.ToString());
                                //Get Account
                                detailValue = detailValues.SearchForProperty(Properties.Settings.Default.propAccount);
                                if (detailValue.TypedValue.DataType == MFDataType.MFDatatypeMultiSelectLookup)
                                {
                                    Lookup lookupAccount = new Lookup();
                                    lookupAccount = detailValue.TypedValue.GetValueAsLookup();

                                    propDef        = currVault.PropertyDefOperations.GetPropertyDef(detailValue.PropertyDef);
                                    valListObjType = currVault.ValueListOperations.GetValueList(propDef.ValueList);

                                    if (valListObjType.RealObjectType)
                                    {
                                        //Get Account Number
                                        var objAccount = new ObjVer();
                                        objAccount.SetIDs(valListObjType.ID, lookupAccount.Item, lookupAccount.Version);
                                        var accountValues = new PropertyValues();
                                        var accountValue  = new PropertyValue();
                                        accountValues = currVault.ObjectPropertyOperations.GetProperties(objAccount);
                                        accountValue  = accountValues.SearchForProperty(Properties.Settings.Default.propGLCode);
                                        XElement account = new XElement("AccountId");
                                        account.SetValue(accountValue.GetValueAsLocalizedText());
                                        detail.Add(account);
                                    }
                                }

                                //get Description-Notes
                                detailValue = detailValues.SearchForProperty(Properties.Settings.Default.propDescription);
                                XElement notes = new XElement("Notes");
                                notes.SetValue(detailValue.GetValueAsLocalizedText());
                                detail.Add(notes);

                                //get Amount
                                detailValue = detailValues.SearchForProperty(Properties.Settings.Default.propGLAmount);
                                XElement amount = new XElement("Amount");
                                amount.SetValue(detailValue.GetValueAsLocalizedText());
                                detail.Add(amount);
                                totalAmount += Convert.ToDouble(detailValue.GetValueAsLocalizedText());
                            }

                            XElement propertyID = new XElement("PropertyId");
                            detail.Add(propertyID);
                            details.Add(detail);
                        }
                    }

                    //Get Property ID
                    currPropertyValue = propValues.SearchForProperty(Properties.Settings.Default.propProperty);
                    if (currPropertyValue.TypedValue.DataType == MFDataType.MFDatatypeMultiSelectLookup)
                    {
                        //Getlookup of property to find object
                        var lookup = new Lookup();
                        lookup = currPropertyValue.TypedValue.GetValueAsLookup();
                        var propDef = new PropertyDef();
                        propDef = currVault.PropertyDefOperations.GetPropertyDef(currPropertyValue.PropertyDef);
                        var valListObjType = new ObjType();
                        valListObjType = currVault.ValueListOperations.GetValueList(propDef.ValueList);

                        if (valListObjType.RealObjectType)
                        {
                            //Get property ID
                            var objProperty = new ObjVer();
                            objProperty.SetIDs(valListObjType.ID, lookup.Item, lookup.Version);
                            var propertyValues = new PropertyValues();
                            var propertyValue  = new PropertyValue();
                            propertyValues = currVault.ObjectPropertyOperations.GetProperties(objProperty);
                            propertyValue  = propertyValues.SearchForProperty(Properties.Settings.Default.propPropertyID);



                            IEnumerable <XElement> ieDetails = from el in details.Elements() select el;


                            //loop through items

                            foreach (XElement detail in ieDetails)
                            {
                                //Check that a check has been cut in Yardi.
                                if (detail.Elements("PropertyId").Any())
                                {
                                    detail.Element("PropertyId").SetValue(propertyValue.GetValueAsLocalizedText());
                                }
                            }
                        }
                    }

                    //Get Vendor ID
                    currPropertyValue = propValues.SearchForProperty(Properties.Settings.Default.propVendor);
                    if (currPropertyValue.TypedValue.DataType == MFDataType.MFDatatypeMultiSelectLookup)
                    {
                        //Getlookup of vendor to find object
                        var lookup = new Lookup();
                        lookup = currPropertyValue.TypedValue.GetValueAsLookup();
                        var propDef = new PropertyDef();
                        propDef = currVault.PropertyDefOperations.GetPropertyDef(currPropertyValue.PropertyDef);
                        var valListObjType = new ObjType();
                        valListObjType = currVault.ValueListOperations.GetValueList(propDef.ValueList);

                        if (valListObjType.RealObjectType)
                        {
                            //Get Vendor ID
                            var objProperty = new ObjVer();
                            objProperty.SetIDs(valListObjType.ID, lookup.Item, lookup.Version);
                            var vendorValues = new PropertyValues();
                            var vendorValue  = new PropertyValue();
                            vendorValues = currVault.ObjectPropertyOperations.GetProperties(objProperty);
                            vendorValue  = vendorValues.SearchForProperty(Properties.Settings.Default.propYardiCode);
                            XElement propertyID = new XElement("PersonId");
                            propertyID.SetValue(vendorValue.GetValueAsLocalizedText());
                            payable.Add(propertyID);
                        }
                    }

                    // Add details to payable
                    payable.Add(details);

                    //Add Post Month
                    XElement postMonth = new XElement("PostMonth");
                    postMonth.SetValue(postMonthForm.StrPostMonth);
                    payable.Add(postMonth);

                    //Get link to object
                    XElement link    = new XElement("Notes");
                    string   strLink = "m-files://show/" + Properties.Settings.Default.vaultGUID + "/" + invoice.ObjVer.Type.ToString() + "-" + invoice.ObjVer.ID.ToString();
                    link.SetValue(strLink);
                    payable.Add(link);

                    //get Invoice Number
                    currPropertyValue = propValues.SearchForProperty(Properties.Settings.Default.propInvoiceNumber);
                    XElement invoiceNumber = new XElement("InvoiceNumber");
                    invoiceNumber.SetValue(currPropertyValue.GetValueAsLocalizedText());
                    payable.Add(invoiceNumber);

                    //get Invoice date
                    currPropertyValue = propValues.SearchForProperty(Properties.Settings.Default.propInvoiceDate);
                    XElement invoiceDate = new XElement("InvoiceDate");
                    invoiceDate.SetValue(currPropertyValue.GetValueAsLocalizedText());
                    payable.Add(invoiceDate);

                    //get Due Date
                    currPropertyValue = propValues.SearchForProperty(Properties.Settings.Default.propDueDate);
                    XElement dueDate = new XElement("DueDate");
                    dueDate.SetValue(currPropertyValue.GetValueAsLocalizedText());
                    payable.Add(dueDate);

                    //Set Expense Type
                    XElement expenseType = new XElement("ExpenseType");
                    expenseType.SetValue("Contract");
                    payable.Add(expenseType);


                    //Set Total
                    XElement total = new XElement("TotalAmount");
                    total.SetValue(totalAmount.ToString());


                    payables.Add(payable);

                    //change workflow state
                    propValues.SearchForProperty((int)MFBuiltInPropertyDef.MFBuiltInPropertyDefState).TypedValue.SetValue(MFDataType.MFDatatypeLookup, Properties.Settings.Default.stateProcessing);
                    currVault.ObjectPropertyOperations.SetAllProperties(invoice.ObjVer, true, propValues);
                }



                output.Add(payables);
                output.Save(saveFile.FileName);
                MessageBox.Show(count.ToString() + " Files Exported!");
            }
        }
Beispiel #9
0
        private void button2_Click(object sender, EventArgs e, Vault currVault, MFilesClientApplication mFilesApp)
        {
            OpenFileDialog openFile = new OpenFileDialog();

            openFile.Filter = "XML Files (*.xml) | *.xml";

            if (openFile.ShowDialog() == DialogResult.OK)
            {
                //open XML file
                XElement inputFile = XElement.Load(openFile.FileName);
                IEnumerable <XElement> inputxml = from el in inputFile.Element("Payables").Elements() select el;


                //loop through items
                int count = 0;
                foreach (XElement payable in inputxml)
                {
                    //Check that a check has been cut in Yardi.
                    if (payable.Element("Details").Element("Detail").Elements("CheckNumber").Any())
                    {
                        string checkNumber = payable.Element("Details").Element("Detail").Element("CheckNumber").Value;
                        //MessageBox.Show(checkNumber);

                        //Find Invoice in mFiles
                        //pull invoices using search conditions
                        var searchConditions = new SearchConditions();

                        //is it not deleted
                        var isNotDeleted = new SearchCondition();
                        isNotDeleted.Expression.DataStatusValueType         = MFStatusType.MFStatusTypeDeleted;
                        isNotDeleted.Expression.DataStatusValueDataFunction = MFDataFunction.MFDataFunctionNoOp;
                        isNotDeleted.ConditionType = MFConditionType.MFConditionTypeNotEqual;
                        isNotDeleted.TypedValue.SetValue(MFDataType.MFDatatypeBoolean, true);
                        searchConditions.Add(-1, isNotDeleted);

                        //is it part of the Invoice workflow
                        var isInvoice = new SearchCondition();
                        isInvoice.Expression.DataPropertyValuePropertyDef = (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefWorkflow;
                        isInvoice.ConditionType = MFConditionType.MFConditionTypeEqual;
                        isInvoice.TypedValue.SetValue(MFDataType.MFDatatypeLookup, Properties.Settings.Default.invoiceWorkflow);
                        searchConditions.Add(-1, isInvoice);

                        //is it in the payment processing state
                        var isAccounting = new SearchCondition();
                        isAccounting.Expression.DataPropertyValuePropertyDef = (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefState;
                        isAccounting.ConditionType = MFConditionType.MFConditionTypeEqual;
                        isAccounting.TypedValue.SetValue(MFDataType.MFDatatypeLookup, Properties.Settings.Default.stateProcessing);
                        searchConditions.Add(-1, isAccounting);

                        //is it the correct payable
                        var isPayable = new SearchCondition();
                        isPayable.Expression.DataPropertyValuePropertyDef = Properties.Settings.Default.propInvoiceNumber;
                        isPayable.ConditionType = MFConditionType.MFConditionTypeEqual;
                        isPayable.TypedValue.SetValue(MFDataType.MFDatatypeText, payable.Element("InvoiceNumber").Value);
                        searchConditions.Add(-1, isPayable);

                        //Perform search
                        var invoices = currVault.ObjectSearchOperations.SearchForObjectsByConditions(searchConditions, MFSearchFlags.MFSearchFlagNone, false);

                        foreach (ObjectVersion invoice in invoices)
                        {
                            var propValues        = new PropertyValues();
                            var currPropertyValue = new PropertyValue();
                            propValues = currVault.ObjectPropertyOperations.GetProperties(invoice.ObjVer);

                            //currPropertyValue = propValues.SearchForProperty(Properties.Settings.Default.propCheckNumber);
                            count++;
                            propValues.SearchForProperty(Properties.Settings.Default.propCheckNumber).TypedValue.SetValue(MFDataType.MFDatatypeText, checkNumber);
                            //change workflow state
                            propValues.SearchForProperty((int)MFBuiltInPropertyDef.MFBuiltInPropertyDefState).TypedValue.SetValue(MFDataType.MFDatatypeLookup, Properties.Settings.Default.stateComplete);
                            currVault.ObjectPropertyOperations.SetAllProperties(invoice.ObjVer, true, propValues);
                        }
                    }
                }
                MessageBox.Show(count.ToString() + " Invoices update in mFiles!");
            }
        }