public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);

            // ExStart:ExtendedAttributes
            Project prj = new Project(dataDir + "ExtendedAttributes.mpp");
            ExtendedAttributeDefinitionCollection eads = prj.ExtendedAttributes;

            // Create extended attribute definition
            ExtendedAttributeDefinition ead = new ExtendedAttributeDefinition();
            ead.FieldId = ((int)ExtendedAttributeTask.Start7).ToString();
            ead.FieldName = "Start7";
            eads.Add(ead);

            // Get zero index task
            Task tsk = prj.RootTask.Children.GetById(1);
            ExtendedAttributeCollection eas = tsk.ExtendedAttributes;

            // Add extended attribute
            string dateTimeFormat = "yyyy-MM-ddTHH:mm:ss";
            ExtendedAttribute ea = new ExtendedAttribute();
            ea.FieldId = ead.FieldId;
            ea.Value = XmlConvert.ToString(DateTime.Now, dateTimeFormat);
            eas.Add(ea);
            // ExEnd:ExtendedAttributes
        }
        public static void Run()
        {
            try
            {
                // ExStart:ConfigureGantChart
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName); 
                Project project = new Project(dataDir + "Project5.mpp"); // Create a new project task
                Task task = project.RootTask.Children.Add("New Activity");

                // Add custom text attribute to created task.
                ExtendedAttribute attr = new ExtendedAttribute();
                attr.FieldId = ((int)ExtendedAttributeTask.Text1).ToString();
                attr.Value = "Activity attribute";
                task.ExtendedAttributes.Add(attr);

                // Customize table by adding text attribute field
                TableField attrField = new TableField();
                attrField.Field = Field.TaskText1;
                attrField.Width = 20;
                attrField.Title = "Custom attribute";
                attrField.AlignTitle = StringAlignment.Center;
                attrField.AlignData = StringAlignment.Center;

                Table table = project.Tables.ToList()[0];
                table.TableFields.Insert(3, attrField);
                         
                project.Save(dataDir + "ConfigureGantChart_out.mpp", SaveFileFormat.MPP);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx.");
            }
            // ExEnd:ConfigureGantChart
        }
Exemplo n.º 3
0
 public static string Format(ExtendedAttribute attribute)
 {
     var f = new WebIDLFormatter();
     f.Visit(attribute);
     return f._sb.ToString();
 }
Exemplo n.º 4
0
 private void Visit(ExtendedAttribute attribute)
 {
     attribute.Decompose(
         noArgs => {
             _sb.Append(noArgs.AttributeName);
         },
         argList => {
             _sb.Append(argList.AttributeName);
             Visit(argList.Arguments);
         },
         namedArgList => {
             _sb.Append(namedArgList.AttributeName + "=" + namedArgList.ArgListName);
             Visit(namedArgList.Arguments);
         },
         ident => {
             _sb.Append(ident.AttributeName + "=" + ident.Ident);
         },
         value => {
             _sb.Append(value.AttributeName + "=");
             Visit(value.Value);
         }
     );
 }
        public static void Run()
        {
            // This example requires Aspose.Task for .NET, a trial version can be download from  http://www.aspose.com/corporate/purchase/temporary-license.aspx
            try
            {
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);

                // ExStart:WriteUpdatedExtendedAttributeDefinitions
                Project project = new Project(dataDir + "WriteUpdatedExtendedAttributeDefinitions.mpp");

                #region task attributes
                // Add new text3 extended attribute and one text value
                ExtendedAttributeDefinition taskTextAttr = new ExtendedAttributeDefinition();
                taskTextAttr.Alias = "New text3 attribute";
                taskTextAttr.FieldName = "Text3";
                taskTextAttr.ElementType = ElementType.Task;
                taskTextAttr.CfType = CustomFieldType.Text;
                taskTextAttr.FieldId = Convert.ToInt32(ExtendedAttributeTask.Text3).ToString();
                taskTextAttr.LookupUid = Guid.NewGuid().ToString();
                project.ExtendedAttributes.Add(taskTextAttr);

                Value textVal = new Value();
                textVal.Id = 1;
                textVal.Description = "Text value descr";
                textVal.Val = "Text value1";
                taskTextAttr.ValueList.Add(textVal);

                // Add new cost1 extended attribute and two cost values
                ExtendedAttributeDefinition taskCostAttr = new ExtendedAttributeDefinition();
                taskCostAttr.Alias = "New cost1 attribute";
                taskCostAttr.FieldName = "Cost1";
                taskCostAttr.ElementType = ElementType.Task;
                taskCostAttr.CfType = CustomFieldType.Cost;
                taskCostAttr.FieldId = Convert.ToInt32(ExtendedAttributeTask.Cost1).ToString();
                taskCostAttr.LookupUid = Guid.NewGuid().ToString();
                project.ExtendedAttributes.Add(taskCostAttr);

                Value costVal1 = new Value();
                costVal1.Id = 2;
                costVal1.Description = "Cost value 1 descr";
                costVal1.Val = "99900";

                Value costVal2 = new Value();
                costVal2.Id = 3;
                costVal2.Description = "Cost value 2 descr";
                costVal2.Val = "11100";

                taskCostAttr.ValueList.Add(costVal1);
                taskCostAttr.ValueList.Add(costVal2);

                // Add new task and assign attribute value
                Task task = project.RootTask.Children.Add("New task");

                ExtendedAttribute taskAttr = new ExtendedAttribute();
                taskAttr.AttributeDefinition = taskCostAttr;
                taskAttr.Value = "99900";
                taskAttr.FieldId = taskCostAttr.FieldId;
                task.ExtendedAttributes.Add(taskAttr);

                ExtendedAttributeDefinition taskStartAttr = new ExtendedAttributeDefinition();
                taskStartAttr.Alias = "New start 7 attribute";
                taskStartAttr.CfType = CustomFieldType.Start;
                taskStartAttr.ElementType = ElementType.Task;
                taskStartAttr.FieldName = "Start7";
                taskStartAttr.FieldId = Convert.ToInt32(ExtendedAttributeTask.Start7).ToString();
                taskStartAttr.LookupUid = Guid.NewGuid().ToString();
                Value startVal = new Value();
                startVal.Val = DateTime.Now.ToString();
                startVal.Description = "Start 7 value description";

                taskStartAttr.ValueList.Add(startVal);

                project.ExtendedAttributes.Add(taskStartAttr);

                ExtendedAttributeDefinition taskFinishAttr = new ExtendedAttributeDefinition();
                taskFinishAttr.Alias = "New finish 4 attribute";
                taskFinishAttr.CfType = CustomFieldType.Finish;
                taskFinishAttr.ElementType = ElementType.Task;
                taskFinishAttr.FieldName = "Finish4";
                taskFinishAttr.FieldId = Convert.ToInt32(ExtendedAttributeTask.Finish4).ToString();
                taskFinishAttr.LookupUid = Guid.NewGuid().ToString();
                Value finishVal = new Value();
                finishVal.Val = DateTime.Now.ToString();
                finishVal.Description = "Finish 4 value description";

                taskFinishAttr.ValueList.Add(finishVal);

                project.ExtendedAttributes.Add(taskFinishAttr);

                ExtendedAttributeDefinition numberAttr = new ExtendedAttributeDefinition();
                numberAttr.Alias = "New number attribute";
                numberAttr.FieldName = "Number20";
                numberAttr.CfType = CustomFieldType.Number;
                numberAttr.ElementType = ElementType.Task;
                numberAttr.FieldId = Convert.ToInt32(ExtendedAttributeTask.Number20).ToString();
                numberAttr.LookupUid = Guid.NewGuid().ToString();
                Value val1 = new Value();
                val1.Val = "1";
                val1.Description = "Number 1 value";
                Value val2 = new Value();
                val2.Val = "2";
                val2.Description = "Number 2 value";
                Value val3 = new Value();
                val3.Val = "3";
                val3.Description = "Number 3 value";

                numberAttr.ValueList.Add(val1);
                numberAttr.ValueList.Add(val2);
                numberAttr.ValueList.Add(val3);

                project.ExtendedAttributes.Add(numberAttr);

                #endregion

                ExtendedAttributeDefinition rscStartAttr = new ExtendedAttributeDefinition();
                rscStartAttr.Alias = "New start5 attribute";
                rscStartAttr.FieldName = "Start5";
                rscStartAttr.ElementType = ElementType.Resource;
                rscStartAttr.CfType = CustomFieldType.Start;
                rscStartAttr.CalculationType = CalculationType.Rollup;
                rscStartAttr.RollupType = RollupType.Sum;

                rscStartAttr.FieldId = Convert.ToInt32(ExtendedAttributeTask.Start5).ToString(); ;
                rscStartAttr.LookupUid = Guid.NewGuid().ToString();
                Value startVal2 = new Value();
                startVal2.Id = 4;
                startVal2.Val = DateTime.Now.ToString();
                startVal2.Description = "this is start5 value descr";

                rscStartAttr.ValueList.Add(startVal2);

                project.ExtendedAttributes.Add(rscStartAttr);

                ExtendedAttributeDefinition myTaskDurattr = new ExtendedAttributeDefinition();
                myTaskDurattr.Alias = "New Duration";
                myTaskDurattr.CfType = CustomFieldType.Duration;
                myTaskDurattr.FieldId = ExtendedAttributeTask.Duration1.ToString("D");
                myTaskDurattr.CalculationType = CalculationType.Rollup;
                myTaskDurattr.RollupType = RollupType.Sum;
                myTaskDurattr.ElementType = ElementType.Task;
                project.ExtendedAttributes.Add(myTaskDurattr);

                // Add new task and assign attribute value
                Task timeTask = project.RootTask.Children.Add("New task");

                ExtendedAttribute timeexExtendedAttribute = myTaskDurattr.CreateExtendedAttribute();

                timeexExtendedAttribute.DurationFormat = TimeUnitType.Hour;
                timeexExtendedAttribute.Value = "PT3H0M0S";
                timeTask.ExtendedAttributes.Add(timeexExtendedAttribute);

                MPPSaveOptions mppSaveOptions = new MPPSaveOptions();
                mppSaveOptions.WriteViewData = true;

                // Save the project as MPP project file
                project.Save(dataDir + "WriteUpdatedExtendedAttributeDefinitions_out.mpp", mppSaveOptions);
                // ExEnd:WriteUpdatedExtendedAttributeDefinitions
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
            }

        }
Exemplo n.º 6
0
        public FileRecord(byte[] rawBytes, int offset)
        {
            Offset = offset;

            var sig = BitConverter.ToInt32(rawBytes, 0);

            switch (sig)
            {
            case FileSig:
                break;

            case BaadSig:
                _logger.Debug($"Bad signature at offset 0x{offset:X}");
                IsBad = true;
                return;

            default:
                //not initialized
                _logger.Debug($"Uninitialized entry (no signature) at offset 0x{offset:X}");
                IsUninitialized = true;
                return;
            }

            _logger.Debug($"Processing FILE record at offset 0x{offset:X}");

            Attributes = new List <Attribute>();

            FixupOffset     = BitConverter.ToInt16(rawBytes, 0x4);
            FixupEntryCount = BitConverter.ToInt16(rawBytes, 0x6);

            //to build fixup info, take FixupEntryCount x 2 bytes as each are 2 bytes long
            var fixupTotalLength = FixupEntryCount * 2;

            var fixupBuffer = new byte[fixupTotalLength];

            Buffer.BlockCopy(rawBytes, FixupOffset, fixupBuffer, 0, fixupTotalLength);

            //pull this early so we can check if its free in our fix up value messages
            EntryFlags = (EntryFlag)BitConverter.ToInt16(rawBytes, 0x16);

            FixupData = new FixupData(fixupBuffer);

            FixupOk = true;

            //fixup verification
            var counter = 512;

            foreach (var bytese in FixupData.FixupActual)
            {
                //adjust the offset to where we need to check
                var fixupOffset = counter - 2;

                var expected = BitConverter.ToInt16(rawBytes, fixupOffset);
                if (expected != FixupData.FixupExpected && EntryFlags != 0x0)
                {
                    FixupOk = false;
                    _logger.Warn(
                        $"Offset: 0x{Offset:X} Entry/seq: 0x{EntryNumber:X}/0x{SequenceNumber:X} Fixup values do not match at 0x{fixupOffset:X}. Expected: 0x{FixupData.FixupExpected:X2}, actual: 0x{expected:X2}");
                }

                //replace fixup expected with actual bytes. bytese has actual replacement values in it.
                Buffer.BlockCopy(bytese, 0, rawBytes, fixupOffset, 2);

                counter += 512;
            }

            LogSequenceNumber = BitConverter.ToInt64(rawBytes, 0x8);

            SequenceNumber = BitConverter.ToUInt16(rawBytes, 0x10);

            ReferenceCount = BitConverter.ToInt16(rawBytes, 0x12);

            FirstAttributeOffset = BitConverter.ToInt16(rawBytes, 0x14);

            ActualRecordSize = BitConverter.ToInt32(rawBytes, 0x18);

            AllocatedRecordSize = BitConverter.ToInt32(rawBytes, 0x1c);

            var entryBytes = new byte[8];

            Buffer.BlockCopy(rawBytes, 0x20, entryBytes, 0, 8);

            MftRecordToBaseRecord = new MftEntryInfo(entryBytes);

            FirstAvailablAttribueId = BitConverter.ToInt16(rawBytes, 0x28);

            EntryNumber = BitConverter.ToUInt32(rawBytes, 0x2c);

            _logger.Debug($"FILE record entry/seq #: 0x{EntryNumber:X}/{SequenceNumber:X}");

            //start attribute processing at FirstAttributeOffset

            var index = (int)FirstAttributeOffset;

            while (index < ActualRecordSize)
            {
                var attrType = (AttributeType)BitConverter.ToInt32(rawBytes, index);

                var attrSize = BitConverter.ToInt32(rawBytes, index + 4);

                if (attrSize == 0 || attrType == AttributeType.EndOfAttributes)
                {
                    index += 8; //skip -1 type and 0 size

                    if (index != ActualRecordSize)
                    {
                        _logger.Warn($"Slack space found in entry/seq: 0x{EntryNumber:X}/0x{SequenceNumber:X}");
                    }

                    //TODO process slack here?
                    break;
                }

                _logger.Debug(
                    $"Found Attribute Type {attrType.ToString()} at absolute offset: 0x{index + offset:X}");

                _logger.Trace(
                    $"ActualRecordSize: 0x{ActualRecordSize:X}, size: 0x{attrSize:X}, index: 0x{index:X}");

                var rawAttr = new byte[attrSize];
                Buffer.BlockCopy(rawBytes, index, rawAttr, 0, attrSize);

                switch (attrType)
                {
                case AttributeType.StandardInformation:
                    var si = new StandardInfo(rawAttr);
                    Attributes.Add(si);
                    break;

                case AttributeType.FileName:
                    var fi = new FileName(rawAttr);
                    Attributes.Add(fi);
                    break;

                case AttributeType.Data:
                    var d = new Data(rawAttr);
                    Attributes.Add(d);
                    break;

                case AttributeType.IndexAllocation:
                    var ia = new IndexAllocation(rawAttr);
                    Attributes.Add(ia);
                    break;

                case AttributeType.IndexRoot:
                    var ir = new IndexRoot(rawAttr);
                    Attributes.Add(ir);
                    break;

                case AttributeType.Bitmap:
                    var bm = new Bitmap(rawAttr);
                    Attributes.Add(bm);
                    break;

                case AttributeType.VolumeVersionObjectId:
                    var oi = new ObjectId_(rawAttr);
                    Attributes.Add(oi);
                    break;

                case AttributeType.SecurityDescriptor:
                    var sd = new SecurityDescriptor(rawAttr);
                    Attributes.Add(sd);
                    break;

                case AttributeType.VolumeName:
                    var vn = new VolumeName(rawAttr);
                    Attributes.Add(vn);
                    break;

                case AttributeType.VolumeInformation:
                    var vi = new VolumeInformation(rawAttr);
                    Attributes.Add(vi);
                    break;

                case AttributeType.LoggedUtilityStream:
                    var lus = new LoggedUtilityStream(rawAttr);
                    Attributes.Add(lus);
                    break;

                case AttributeType.ReparsePoint:
                    try
                    {
                        var rp = new ReparsePoint(rawAttr);
                        Attributes.Add(rp);
                    }
                    catch (Exception)
                    {
                        var l = LogManager.GetLogger("ReparsePoint");

                        l.Error(
                            $"There was an error parsing a ReparsePoint in FILE record at offset 0x{Offset:X}. Please extract via --dd and --do and send to [email protected]");
                    }

                    break;

                case AttributeType.AttributeList:
                    var al = new AttributeList(rawAttr);
                    Attributes.Add(al);
                    break;

                case AttributeType.Ea:
                    var ea = new ExtendedAttribute(rawAttr);
                    Attributes.Add(ea);
                    break;

                case AttributeType.EaInformation:
                    var eai = new ExtendedAttributeInformation(rawAttr);
                    Attributes.Add(eai);
                    break;

                default:
                    throw new Exception($"Add me: {attrType} (0x{attrType:X})");
                }

                index += attrSize;
            }

            //rest is slack. handle here?
            _logger.Trace($"Slack starts at 0x{index:X} Absolute offset: 0x{index + offset:X}");
        }
Exemplo n.º 7
0
 public static ExtendedAttribute ToEntity(this ExtendedAttributeModel model, ExtendedAttribute destination)
 {
     return(Mapper.Map(model, destination));
 }
Exemplo n.º 8
0
        private ExtendedAttribute GetExtendedAttributeFormRow(int index, ExtendedAttribute attribute)
        {
            bool isUpdated;

            return(GetExtendedAttributeFormRow(index, attribute, out isUpdated));
        }
Exemplo n.º 9
0
        /// <summary>
        ///     生成查询语句
        /// </summary>
        /// <returns></returns>
        internal string GenerateSelectSql(Type type, string where = "")
        {
            if (!string.IsNullOrEmpty(where))
            {
                if (!where.TrimStart().StartsWith("WHERE", StringComparison.CurrentCultureIgnoreCase))
                {
                    where = " WHERE " + where;
                }
            }
            var selectSql = new StringBuilder("SELECT ");
            List <FieldProperty> fpmap       = FieldProperty.GetFieldPropertys(type);
            List <FieldProperty> tables      = FieldProperty.GetTables(type);
            FieldProperty        masterTable = fpmap.FirstOrDefault(p => string.IsNullOrEmpty(p.MasterTableField));

            foreach (FieldProperty item in fpmap)
            {
                if (string.IsNullOrEmpty(item.FieldAlias))
                {
                    selectSql.AppendFormat("{0}.{1},", item.TableAlias, item.FieldName);
                }
                else
                {
                    selectSql.AppendFormat("{0}.{1} {2},", item.TableAlias, item.FieldName, item.FieldAlias);
                }
            }

            //增加扩展字段
            //Type type = typeof(T);
            PropertyInfo[] propertyInfos = type.GetProperties();
            foreach (PropertyInfo info in propertyInfos)
            {
                ExtendedAttribute extended = ExtendedAttribute.GetAttribute(info);
                if (extended != null)
                {
                    var extSql = extended.ExtendedSql;
                    foreach (FieldProperty item in tables)
                    {
                        extSql = extSql.Replace(" " + item.TableName + ".", " " + item.TableAlias + ".")
                                 .Replace("(" + item.TableName + ".", "(" + item.TableAlias + ".")
                                 .Replace("=" + item.TableName + ".", "=" + item.TableAlias + ".");
                    }
                    selectSql.Append("(" + extSql + ") " + info.Name + ",");
                }
            }

            selectSql = selectSql.Remove(selectSql.Length - 1, 1);
            selectSql.AppendLine();
            selectSql.AppendLine(" FROM ");
            selectSql.Append(" " + "".PadLeft(tables.Count - 1, '('));
            selectSql.AppendFormat(" {0} {1} ", masterTable.TableName, masterTable.TableAlias);

            foreach (FieldProperty item in tables)
            {
                if (!string.IsNullOrEmpty(where))
                {
                    where = where.Replace(" " + item.TableName + ".", " " + item.TableAlias + ".")
                            .Replace("(" + item.TableName + ".", "(" + item.TableAlias + ".")
                            .Replace("=" + item.TableName + ".", "=" + item.TableAlias + ".");
                }
                if (item.TableAlias == masterTable.TableAlias)
                {
                    continue;
                }
                selectSql.AppendFormat(" LEFT JOIN {0} {1} ", item.TableName, item.TableAlias);
                selectSql.AppendFormat(" ON {0}.{1}={2}.{3}) ", masterTable.TableAlias, item.MasterTableField,
                                       item.TableAlias, item.RelateField);
                selectSql.AppendLine();
            }
            string strSql = selectSql + where;

            return(strSql);
        }
Exemplo n.º 10
0
        /// <summary>
        ///     生成新增的Sql语句
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        internal string GenerateInsertSql(object obj)
        {
            Type type = obj.GetType();

            PropertyInfo[]     propertyInfos = type.GetProperties();
            var                insertSql     = new StringBuilder();
            TableInfoAttribute tableInfo     = TableInfoAttribute.GetAttribute(type);
            string             tableName;

            if (tableInfo == null)
            {
                tableName = type.Name;
            }
            else
            {
                tableName = tableInfo.TableName;
            }

            insertSql.AppendFormat("INSERT INTO {0} (", tableName);

            var values      = new StringBuilder(" VALUES (");
            int columnCount = 0;

            foreach (PropertyInfo info in propertyInfos)
            {
                ExtendedAttribute extended = ExtendedAttribute.GetAttribute(info);
                if (extended != null)
                {
                    continue;
                }
                ExcludeFieldAttribute exclude = ExcludeFieldAttribute.GetAttribute(info);
                if (exclude != null)
                {
                    continue;
                }
                IdentityAttribute identity = IdentityAttribute.GetAttribute(info);
                if (identity != null)
                {
                    continue;
                }
                RefFieldAttribute refField = RefFieldAttribute.GetAttribute(info);
                if (refField != null)
                {
                    continue;
                }
                if (columnCount != 0)
                {
                    insertSql.Append(",");
                    values.Append(",");
                }
                object value = info.GetValue(obj, null);
                if (value == null || value == DBNull.Value)
                {
                    value = "NULL";
                }
                else
                {
                    value = string.Format("'{0}'", value);
                }
                insertSql.AppendFormat("{0}", info.Name);
                values.Append(value);
                columnCount++;
            }
            insertSql.AppendFormat(") {0} ) ", values);

            string insertSqlstr = insertSql.ToString() + ";";

            //_insertSqlCaches.Add(type, insertSqlstr);//加入缓存
            return(insertSqlstr);
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Projects();

            string newFile = dataDir+ "WriteUpdatedExtendedAttributeDefinitions.mpp";
            string resultFile = dataDir+ "Output.mpp";

            Project project = new Project(dataDir + "WriteUpdatedExtendedAttributeDefinitions.mpp");

            #region task attributes
            // Add new text3 extended attribute and one text value
            ExtendedAttributeDefinition taskTextAttr = new ExtendedAttributeDefinition();
            taskTextAttr.Alias = "New text3 attribute";
            taskTextAttr.FieldName = "Text3";
            taskTextAttr.ElementType = ElementType.Task;
            taskTextAttr.CfType = CustomFieldType.Text;

            project.ExtendedAttributes.Add(taskTextAttr);

            Value textVal = new Value();
            textVal.Id = 1;
            textVal.Description = "Text value descr";
            textVal.Val = "Text value1";

            taskTextAttr.ValueList.Add(textVal);

            // Add new cost1 extended attribute and two cost values
            ExtendedAttributeDefinition taskCostAttr = new ExtendedAttributeDefinition();
            taskCostAttr.Alias = "New cost1 attribute";
            taskCostAttr.FieldName = "Cost1";
            taskCostAttr.ElementType = ElementType.Task;
            taskCostAttr.CfType = CustomFieldType.Cost;

            project.ExtendedAttributes.Add(taskCostAttr);

            Value costVal1 = new Value();
            costVal1.Id = 2;
            costVal1.Description = "Cost value 1 descr";
            costVal1.Val = "99900";

            Value costVal2 = new Value();
            costVal2.Id = 3;
            costVal2.Description = "Cost value 2 descr";
            costVal2.Val = "11100";

            taskCostAttr.ValueList.Add(costVal1);
            taskCostAttr.ValueList.Add(costVal2);

            // Add new task and assign attribute value
            Task task = project.RootTask.Children.Add("New task");

            ExtendedAttribute taskAttr = new ExtendedAttribute();
            taskAttr.AttributeDefinition = taskCostAttr;
            taskAttr.Value = "99900";
            taskAttr.FieldId = taskCostAttr.FieldId;
            task.ExtendedAttributes.Add(taskAttr);

            ExtendedAttributeDefinition taskStartAttr = new ExtendedAttributeDefinition();
            taskStartAttr.Alias = "New start 7 attribute";
            taskStartAttr.CfType = CustomFieldType.Start;
            taskStartAttr.ElementType = ElementType.Task;
            taskStartAttr.FieldName = "Start7";

            Value startVal = new Value();
            startVal.Val = DateTime.Now.ToString();
            startVal.Description = "Start 7 value description";

            taskStartAttr.ValueList.Add(startVal);

            project.ExtendedAttributes.Add(taskStartAttr);

            ExtendedAttributeDefinition taskFinishAttr = new ExtendedAttributeDefinition();
            taskFinishAttr.Alias = "New finish 4 attribute";
            taskFinishAttr.CfType = CustomFieldType.Finish;
            taskFinishAttr.ElementType = ElementType.Task;
            taskFinishAttr.FieldName = "Finish4";

            Value finishVal = new Value();
            finishVal.Val = DateTime.Now.ToString();
            finishVal.Description = "Finish 4 value description";

            taskFinishAttr.ValueList.Add(finishVal);

            project.ExtendedAttributes.Add(taskFinishAttr);

            ExtendedAttributeDefinition numberAttr = new ExtendedAttributeDefinition();
            numberAttr.Alias = "New number attribute";
            numberAttr.FieldName = "Number20";
            numberAttr.CfType = CustomFieldType.Number;
            numberAttr.ElementType = ElementType.Task;

            Value val1 = new Value();
            val1.Val = "1";
            val1.Description = "Number 1 value";
            Value val2 = new Value();
            val2.Val = "2";
            val2.Description = "Number 2 value";
            Value val3 = new Value();
            val3.Val = "3";
            val3.Description = "Number 3 value";

            numberAttr.ValueList.Add(val1);
            numberAttr.ValueList.Add(val2);
            numberAttr.ValueList.Add(val3);

            project.ExtendedAttributes.Add(numberAttr);

            #endregion

            ExtendedAttributeDefinition rscStartAttr = new ExtendedAttributeDefinition();
            rscStartAttr.Alias = "New start5 attribute";
            rscStartAttr.FieldName = "Start5";
            rscStartAttr.ElementType = ElementType.Resource;
            rscStartAttr.CfType = CustomFieldType.Start;

            Value startVal2 = new Value();
            startVal2.Id = 4;
            startVal2.Val = DateTime.Now.ToString();
            startVal2.Description = "this is start5 value descr";

            rscStartAttr.ValueList.Add(startVal2);

            project.ExtendedAttributes.Add(rscStartAttr);


            //Save the project as MPP project file
            project.Save(resultFile, Aspose.Tasks.Saving.SaveFileFormat.MPP);
        }
        public static void Run()
        {
            try
            {
                // ExStart:WriteMetadataToMPP
                string  dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
                Project project = new Project(dataDir + "Project1.mpp");

                // Add working times to project calendar
                WorkingTime wt = new WorkingTime();
                wt.FromTime = new DateTime(2010, 1, 1, 19, 0, 0);
                wt.ToTime   = new DateTime(2010, 1, 1, 20, 0, 0);
                WeekDay day = project.Get(Prj.Calendar).WeekDays.ToList()[1];
                day.WorkingTimes.Add(wt);

                // Change calendar name
                project.Get(Prj.Calendar).Name = "CHANGED NAME!";

                // Add tasks and set task meta data
                Task task = project.RootTask.Children.Add("Task 1");
                task.Set(Tsk.DurationFormat, TimeUnitType.Day);
                task.Set(Tsk.Duration, project.GetDuration(3));
                task.Set(Tsk.Contact, "Rsc 1");
                task.Set(Tsk.IsMarked, true);
                task.Set(Tsk.IgnoreWarnings, true);
                Task task2 = project.RootTask.Children.Add("Task 2");
                task2.Set(Tsk.DurationFormat, TimeUnitType.Day);
                task2.Set(Tsk.Contact, "Rsc 2");

                // Link tasks
                project.TaskLinks.Add(task, task2, TaskLinkType.FinishToStart, project.GetDuration(-1, TimeUnitType.Day));

                // Set project start date
                project.Set(Prj.StartDate, new DateTime(2013, 8, 13, 9, 0, 0));

                // Add resource and set resource meta data
                Resource rsc1 = project.Resources.Add("Rsc 1");
                rsc1.Set(Rsc.Type, ResourceType.Work);
                rsc1.Set(Rsc.Initials, "WR");
                rsc1.Set(Rsc.AccrueAt, CostAccrualType.Prorated);
                rsc1.Set(Rsc.MaxUnits, 1);
                rsc1.Set(Rsc.Code, "Code 1");
                rsc1.Set(Rsc.Group, "Workers");
                rsc1.Set(Rsc.EMailAddress, "*****@*****.**");
                rsc1.Set(Rsc.WindowsUserAccount, "user_acc1");
                rsc1.Set(Rsc.IsGeneric, new NullableBool(true));
                rsc1.Set(Rsc.AccrueAt, CostAccrualType.End);
                rsc1.Set(Rsc.StandardRate, 10);
                rsc1.Set(Rsc.StandardRateFormat, RateFormatType.Day);
                rsc1.Set(Rsc.OvertimeRate, 15);
                rsc1.Set(Rsc.OvertimeRateFormat, RateFormatType.Hour);

                rsc1.Set(Rsc.IsTeamAssignmentPool, true);
                rsc1.Set(Rsc.CostCenter, "Cost Center 1");

                // Create resource assignment and set resource assignment meta data
                ResourceAssignment assn = project.ResourceAssignments.Add(task, rsc1);
                assn.Set(Asn.Uid, 1);
                assn.Set(Asn.Work, task.Get(Tsk.Duration));
                assn.Set(Asn.RemainingWork, assn.Get(Asn.Work));
                assn.Set(Asn.RegularWork, assn.Get(Asn.Work));
                task.Set(Tsk.Work, assn.Get(Asn.Work));

                rsc1.Set(Rsc.Work, task.Get(Tsk.Work));
                assn.Set(Asn.Start, task.Get(Tsk.Start));
                assn.Set(Asn.Finish, task.Get(Tsk.Finish));

                // Add extended attribute for project and task
                ExtendedAttributeDefinition attr = new ExtendedAttributeDefinition();
                attr.FieldId = ((int)ExtendedAttributeTask.Flag1).ToString();
                attr.Alias   = "Labeled";
                project.ExtendedAttributes.Add(attr);
                ExtendedAttribute taskAttr = new ExtendedAttribute();
                taskAttr.Value   = "1";
                taskAttr.FieldId = attr.FieldId;
                task2.ExtendedAttributes.Add(taskAttr);

                // Save project as MPP
                project.Save(dataDir + "WriteMetaData_out.mpp", SaveFileFormat.MPP);
                // ExEnd:WriteMetadataToMPP
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
            }
        }
Exemplo n.º 13
0
        internal static List <FieldProperty> GetFieldPropertys(Type t)
        {
            var fplist = new List <FieldProperty>();
            TableInfoAttribute tableInfo = TableInfoAttribute.GetAttribute(t);

            PropertyInfo[] ps = t.GetProperties();

            #region 取出映射关系

            foreach (PropertyInfo item in ps)
            {
                var fp = new FieldProperty();
                var excludeFieldAttribute = (ExcludeFieldAttribute)Attribute.GetCustomAttribute(item, typeof(ExcludeFieldAttribute));
                if (excludeFieldAttribute != null)
                {
                    continue;
                }

                ExtendedAttribute extendedAttribute = ExtendedAttribute.GetAttribute(item);
                if (extendedAttribute != null)
                {
                    continue;
                }

                RefFieldAttribute fieldattr = RefFieldAttribute.GetAttribute(item);
                if (fieldattr != null)
                {
                    fp.TableName        = fieldattr.RefTableName;
                    fp.FieldName        = fieldattr.RefFieldName ?? item.Name;
                    fp.FieldAlias       = item.Name;
                    fp.PropertyName     = item.Name;
                    fp.MasterTableField = fieldattr.MasterTableField;
                    fp.RelateField      = fieldattr.RefTableKey;
                    fplist.Add(fp);
                }
                else
                {
                    fp.TableName    = tableInfo == null ? t.Name : tableInfo.TableName;
                    fp.FieldName    = item.Name;
                    fp.PropertyName = item.Name;
                    fplist.Add(fp);
                }
            }

            #endregion

            List <FieldProperty> tables = Distinct(fplist);
            for (int i = 0; i < tables.Count; i++)
            {
                string alias = "t" + i;
                foreach (FieldProperty item in fplist)
                {
                    if (item.TableName == tables[i].TableName && item.MasterTableField == tables[i].MasterTableField)
                    {
                        item.TableAlias = alias;
                        //if (string.IsNullOrEmpty(item.FieldAlias))
                        //    item.FieldAlias = alias + "_" + item.FieldName;
                    }
                }
            }
            return(fplist);
        }
        public static void Run()
        {
            //ExStart: WriteUpdatedExtendedAttributeDefinitions
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Projects();

            string newFile    = dataDir + "WriteUpdatedExtendedAttributeDefinitions.mpp";
            string resultFile = dataDir + "Output.mpp";

            Project project = new Project(dataDir + "WriteUpdatedExtendedAttributeDefinitions.mpp");

            #region task attributes
            // Add new text3 extended attribute and one text value
            ExtendedAttributeDefinition taskTextAttr = new ExtendedAttributeDefinition();
            taskTextAttr.Alias       = "New text3 attribute";
            taskTextAttr.FieldName   = "Text3";
            taskTextAttr.ElementType = ElementType.Task;
            taskTextAttr.CfType      = CustomFieldType.Text;

            project.ExtendedAttributes.Add(taskTextAttr);

            Value textVal = new Value();
            textVal.Id          = 1;
            textVal.Description = "Text value descr";
            textVal.Val         = "Text value1";

            taskTextAttr.ValueList.Add(textVal);

            // Add new cost1 extended attribute and two cost values
            ExtendedAttributeDefinition taskCostAttr = new ExtendedAttributeDefinition();
            taskCostAttr.Alias       = "New cost1 attribute";
            taskCostAttr.FieldName   = "Cost1";
            taskCostAttr.ElementType = ElementType.Task;
            taskCostAttr.CfType      = CustomFieldType.Cost;

            project.ExtendedAttributes.Add(taskCostAttr);

            Value costVal1 = new Value();
            costVal1.Id          = 2;
            costVal1.Description = "Cost value 1 descr";
            costVal1.Val         = "99900";

            Value costVal2 = new Value();
            costVal2.Id          = 3;
            costVal2.Description = "Cost value 2 descr";
            costVal2.Val         = "11100";

            taskCostAttr.ValueList.Add(costVal1);
            taskCostAttr.ValueList.Add(costVal2);

            // Add new task and assign attribute value
            Task task = project.RootTask.Children.Add("New task");

            ExtendedAttribute taskAttr = new ExtendedAttribute();
            taskAttr.AttributeDefinition = taskCostAttr;
            taskAttr.Value   = "99900";
            taskAttr.FieldId = taskCostAttr.FieldId;
            task.ExtendedAttributes.Add(taskAttr);

            ExtendedAttributeDefinition taskStartAttr = new ExtendedAttributeDefinition();
            taskStartAttr.Alias       = "New start 7 attribute";
            taskStartAttr.CfType      = CustomFieldType.Start;
            taskStartAttr.ElementType = ElementType.Task;
            taskStartAttr.FieldName   = "Start7";

            Value startVal = new Value();
            startVal.Val         = DateTime.Now.ToString();
            startVal.Description = "Start 7 value description";

            taskStartAttr.ValueList.Add(startVal);

            project.ExtendedAttributes.Add(taskStartAttr);

            ExtendedAttributeDefinition taskFinishAttr = new ExtendedAttributeDefinition();
            taskFinishAttr.Alias       = "New finish 4 attribute";
            taskFinishAttr.CfType      = CustomFieldType.Finish;
            taskFinishAttr.ElementType = ElementType.Task;
            taskFinishAttr.FieldName   = "Finish4";

            Value finishVal = new Value();
            finishVal.Val         = DateTime.Now.ToString();
            finishVal.Description = "Finish 4 value description";

            taskFinishAttr.ValueList.Add(finishVal);

            project.ExtendedAttributes.Add(taskFinishAttr);

            ExtendedAttributeDefinition numberAttr = new ExtendedAttributeDefinition();
            numberAttr.Alias       = "New number attribute";
            numberAttr.FieldName   = "Number20";
            numberAttr.CfType      = CustomFieldType.Number;
            numberAttr.ElementType = ElementType.Task;

            Value val1 = new Value();
            val1.Val         = "1";
            val1.Description = "Number 1 value";
            Value val2 = new Value();
            val2.Val         = "2";
            val2.Description = "Number 2 value";
            Value val3 = new Value();
            val3.Val         = "3";
            val3.Description = "Number 3 value";

            numberAttr.ValueList.Add(val1);
            numberAttr.ValueList.Add(val2);
            numberAttr.ValueList.Add(val3);

            project.ExtendedAttributes.Add(numberAttr);

            #endregion

            ExtendedAttributeDefinition rscStartAttr = new ExtendedAttributeDefinition();
            rscStartAttr.Alias       = "New start5 attribute";
            rscStartAttr.FieldName   = "Start5";
            rscStartAttr.ElementType = ElementType.Resource;
            rscStartAttr.CfType      = CustomFieldType.Start;

            Value startVal2 = new Value();
            startVal2.Id          = 4;
            startVal2.Val         = DateTime.Now.ToString();
            startVal2.Description = "this is start5 value descr";

            rscStartAttr.ValueList.Add(startVal2);

            project.ExtendedAttributes.Add(rscStartAttr);


            //Save the project as MPP project file
            project.Save(resultFile, Aspose.Tasks.Saving.SaveFileFormat.MPP);
            //ExEnd: WriteUpdatedExtendedAttributeDefinitions
        }
Exemplo n.º 15
0
        private bool IsAttributeUpdated()
        {
            if (!HasModify)
            {
                return(false);
            }

            ProductCategory category = Session[ORIGINALSELECTECATEGORY] as ProductCategory;

            if (!int.Parse(dplParent.SelectedValue).Equals(category.ParentId))
            {
                return(true);
            }
            if (!txtCategory.Text.Equals(category.Name))
            {
                return(true);
            }
            if (!txtDescription.Text.Equals(category.Description))
            {
                return(true);
            }

            IList <ExtendedAttribute> originalAttributes = Session[ORIGINALATTRIBUTES] as List <ExtendedAttribute>;

            if (originalAttributes.Count != gvwExtendedAttribute.Rows.Count)
            {
                return(true);
            }

            for (int i = 0; i < gvwExtendedAttribute.Rows.Count; i++)
            {
                GridViewRow       row       = gvwExtendedAttribute.Rows[i];
                ExtendedAttribute attribute = originalAttributes[i];

                if (!attribute.Order.Equals(int.Parse(row.Cells[0].Text)))
                {
                    return(true);
                }

                if (!attribute.Name.Equals(row.Cells[1].Text))
                {
                    return(true);
                }

                if (!attribute.DisplayName.Equals(row.Cells[2].Text))
                {
                    return(true);
                }

                CheckBox checkBox = row.Cells[3].FindControl("chkEnableEmpty") as CheckBox;
                if (!attribute.IsRequired.Equals(checkBox.Checked))
                {
                    return(true);
                }

                DropDownList dplDataType = row.Cells[4].FindControl("dplDataType") as DropDownList;
                if (!attribute.DataType.Equals(dplDataType.SelectedValue))
                {
                    return(true);
                }

                DropDownList dplDataUnit = row.Cells[5].FindControl("dplDataUnit") as DropDownList;
                if (!attribute.DataUnit.Id.Equals(int.Parse(dplDataUnit.SelectedValue)))
                {
                    return(true);
                }

                DropDownList dplCategory = row.Cells[6].FindControl("dplCategory") as DropDownList;
                if (!attribute.AttributeCategory.Equals((MyRabbit.Data.Entity.ExtendedAttributeCategory)Enum
                                                        .Parse(typeof(MyRabbit.Data.Entity.ExtendedAttributeCategory), dplCategory.SelectedValue, false)))
                {
                    return(true);
                }
            }

            return(false);
        }
        public static void Run()
        {
            try
            {
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);

                // ExStart:AddTaskExtendedAttributes
                // Create new project
                Project project1 = new Project(dataDir + "Blank2010.mpp");

                // Create the Extended Attribute Definition of Text Type
                ExtendedAttributeDefinition taskExtendedAttributeText9Definition;
                taskExtendedAttributeText9Definition = new ExtendedAttributeDefinition();
                taskExtendedAttributeText9Definition.Alias = "Task City Name";      
                taskExtendedAttributeText9Definition.FieldName = "Text9";
                taskExtendedAttributeText9Definition.ElementType = ElementType.Task;
                taskExtendedAttributeText9Definition.CfType = CustomFieldType.Text;
                taskExtendedAttributeText9Definition.FieldId = Convert.ToInt32(ExtendedAttributeTask.Text9).ToString(System.Globalization.CultureInfo.InvariantCulture);

                // Create an Extended Attribute Definition of Flag Type
                ExtendedAttributeDefinition taskExtendedAttributeFlag1Definition;
                taskExtendedAttributeFlag1Definition = new ExtendedAttributeDefinition();
                taskExtendedAttributeFlag1Definition.Alias = "Is Billable";
                taskExtendedAttributeFlag1Definition.FieldName = "Flag1";
                taskExtendedAttributeFlag1Definition.ElementType = ElementType.Task;
                taskExtendedAttributeFlag1Definition.CfType = CustomFieldType.Flag;
                taskExtendedAttributeFlag1Definition.FieldId = Convert.ToInt32(ExtendedAttributeTask.Flag1).ToString(System.Globalization.CultureInfo.InvariantCulture);

                // Add the Extended Attribute Definitions to the Project's Extended Attribute Collection
                project1.ExtendedAttributes.Add(taskExtendedAttributeText9Definition);
                project1.ExtendedAttributes.Add(taskExtendedAttributeFlag1Definition);

                // Add a task to project and set its properties
                Task task = project1.RootTask.Children.Add("Task 1");
                task.Set(Tsk.Start, new DateTime(2016, 7, 27, 8, 0, 0));
                task.Set(Tsk.Duration, project1.GetDuration(8, TimeUnitType.Hour));

                // Create Extended Attribute and set it's values
                ExtendedAttribute taskExtendedAttributeText9 = new ExtendedAttribute();
                taskExtendedAttributeText9.FieldId = taskExtendedAttributeText9Definition.FieldId;
                taskExtendedAttributeText9.Value = "London";               
                
                // Create Extended Attribute of Flag type and set it's values
                ExtendedAttribute taskExtendedAttributeFlag1 = new ExtendedAttribute();
                taskExtendedAttributeFlag1.FieldId = taskExtendedAttributeFlag1Definition.FieldId;
                taskExtendedAttributeFlag1.Value = "1";

                // Add the Extended Attributes to Task
                task.ExtendedAttributes.Add(taskExtendedAttributeText9);
                task.ExtendedAttributes.Add(taskExtendedAttributeFlag1);

                // Save the Project               
                project1.Save(dataDir + "AddTaskExtendedAttributes_out.mpp", SaveFileFormat.MPP);
                // ExEnd:AddTaskExtendedAttributes
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
            }
        }
Exemplo n.º 17
0
        /// <summary>
        ///     生成新增的Sql语句
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        internal string GenerateInsertSql(Type type)
        {
            //判断缓存中存在已经生成的Sql语句,则直接返回
            if (_insertSqlCaches.ContainsKey(type))
            {
                return(_insertSqlCaches[type]);
            }
            PropertyInfo[] propertyInfos = type.GetProperties();
            var            insertSql     = new StringBuilder();

            bool hasIdentityField        = false;
            TableInfoAttribute tableInfo = TableInfoAttribute.GetAttribute(type);
            string             tableName = tableInfo == null ? type.Name : tableInfo.TableName;

            insertSql.AppendFormat("INSERT INTO {0} (", tableName);

            var values      = new StringBuilder(" VALUES (");
            int columnCount = 0;

            foreach (PropertyInfo info in propertyInfos)
            {
                ExtendedAttribute extended = ExtendedAttribute.GetAttribute(info);
                if (extended != null)
                {
                    continue;
                }
                ExcludeFieldAttribute exclude = ExcludeFieldAttribute.GetAttribute(info);
                if (exclude != null)
                {
                    continue;
                }
                IdentityAttribute identity = IdentityAttribute.GetAttribute(info);
                if (identity != null)
                {
                    hasIdentityField = true;
                    continue;
                }
                GuidIdentityAttribute guidIdentity = GuidIdentityAttribute.GetAttribute(info);
                if (guidIdentity != null)
                {
                    hasIdentityField = true;
                }
                RefFieldAttribute refField = RefFieldAttribute.GetAttribute(info);
                if (refField != null)
                {
                    continue;
                }
                if (columnCount != 0)
                {
                    insertSql.Append(",");
                    values.Append(",");
                }
                insertSql.AppendFormat("{0}", info.Name);
                values.AppendLine("@" + info.Name);
                columnCount++;
            }
            insertSql.AppendFormat(") {0} ) ", values);

            if (hasIdentityField)
            {
                insertSql.AppendFormat(_identity);
            }
            string insertSqlstr = insertSql.ToString();

            _insertSqlCaches.Add(type, insertSqlstr); //加入缓存
            return(insertSqlstr);
        }
Exemplo n.º 18
0
 //attributes
 public static ExtendedAttributeModel ToModel(this ExtendedAttribute entity)
 {
     return(Mapper.Map <ExtendedAttribute, ExtendedAttributeModel>(entity));
 }
        public static void Run()
        {
            try
            {
                // ExStart:WriteMetadataToMPP
                string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
                Project project = new Project(dataDir + "Project1.mpp");

                // Add working times to project calendar
                WorkingTime wt = new WorkingTime();
                wt.FromTime = new DateTime(2010, 1, 1, 19, 0, 0);
                wt.ToTime = new DateTime(2010, 1, 1, 20, 0, 0);
                WeekDay day = project.Get(Prj.Calendar).WeekDays.ToList()[1];
                day.WorkingTimes.Add(wt);

                // Change calendar name
                project.Get(Prj.Calendar).Name = "CHANGED NAME!";

                // Add tasks and set task meta data
                Task task = project.RootTask.Children.Add("Task 1");
                task.Set(Tsk.DurationFormat, TimeUnitType.Day);
                task.Set(Tsk.Duration, project.GetDuration(3));
                task.Set(Tsk.Contact, "Rsc 1");
                task.Set(Tsk.IsMarked, true);
                task.Set(Tsk.IgnoreWarnings, true);
                Task task2 = project.RootTask.Children.Add("Task 2");
                task2.Set(Tsk.DurationFormat, TimeUnitType.Day);
                task2.Set(Tsk.Contact, "Rsc 2");

                // Link tasks
                project.TaskLinks.Add(task, task2, TaskLinkType.FinishToStart, project.GetDuration(-1, TimeUnitType.Day));

                // Set project start date
                project.Set(Prj.StartDate, new DateTime(2013, 8, 13, 9, 0, 0));

                // Add resource and set resource meta data
                Resource rsc1 = project.Resources.Add("Rsc 1");
                rsc1.Set(Rsc.Type, ResourceType.Work);
                rsc1.Set(Rsc.Initials, "WR");
                rsc1.Set(Rsc.AccrueAt, CostAccrualType.Prorated);
                rsc1.Set(Rsc.MaxUnits, 1);
                rsc1.Set(Rsc.Code, "Code 1");
                rsc1.Set(Rsc.Group, "Workers");
                rsc1.Set(Rsc.EMailAddress, "*****@*****.**");
                rsc1.Set(Rsc.WindowsUserAccount, "user_acc1");
                rsc1.Set(Rsc.IsGeneric, new NullableBool(true));
                rsc1.Set(Rsc.AccrueAt, CostAccrualType.End);
                rsc1.Set(Rsc.StandardRate, 10);
                rsc1.Set(Rsc.StandardRateFormat, RateFormatType.Day);
                rsc1.Set(Rsc.OvertimeRate, 15);
                rsc1.Set(Rsc.OvertimeRateFormat, RateFormatType.Hour);

                rsc1.Set(Rsc.IsTeamAssignmentPool, true);
                rsc1.Set(Rsc.CostCenter, "Cost Center 1");

                // Create resource assignment and set resource assignment meta data
                ResourceAssignment assn = project.ResourceAssignments.Add(task, rsc1);
                assn.Set(Asn.Uid, 1);
                assn.Set(Asn.Work, task.Get(Tsk.Duration));
                assn.Set(Asn.RemainingWork, assn.Get(Asn.Work));
                assn.Set(Asn.RegularWork, assn.Get(Asn.Work));
                task.Set(Tsk.Work, assn.Get(Asn.Work));

                rsc1.Set(Rsc.Work, task.Get(Tsk.Work));
                assn.Set(Asn.Start, task.Get(Tsk.Start));
                assn.Set(Asn.Finish, task.Get(Tsk.Finish));

                // Add extended attribute for project and task
                ExtendedAttributeDefinition attr = new ExtendedAttributeDefinition();
                attr.FieldId = ((int)ExtendedAttributeTask.Flag1).ToString();
                attr.Alias = "Labeled";
                project.ExtendedAttributes.Add(attr);
                ExtendedAttribute taskAttr = new ExtendedAttribute();
                taskAttr.Value = "1";
                taskAttr.FieldId = attr.FieldId;
                task2.ExtendedAttributes.Add(taskAttr);

                // Save project as MPP
                project.Save(dataDir + "WriteMetaData_out.mpp", SaveFileFormat.MPP);
                // ExEnd:WriteMetadataToMPP
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// 保存类别
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (!CategoryNameValidate())
                {
                    ShowMessage("类别名称不能重复!");
                    return;
                }

                selectedCategory.Name        = txtCategory.Text.Trim();
                selectedCategory.Description = txtDescription.Text.Trim();
                selectedCategory.ParentId    = int.Parse(dplParent.SelectedValue);

                //update attribute
                for (int i = 0; i < gvwExtendedAttribute.Rows.Count; i++)
                {
                    attributes[i].Order = i + 1;
                    attributes[i]       = GetExtendedAttributeFormRow(i, attributes[i]);
                }

                //TO Sort attributes
                IList <int> lstOrderChanged = new List <int>();
                int         order           = 1;
                for (int i = 0; i < attributes.Count; i++)
                {
                    ExtendedAttribute attr = attributes[i];
                    if (lstOrderChanged.Contains(attr.Id))
                    {
                        continue;
                    }
                    attr.Order = order;
                    order++;

                    for (int j = i + 1; j < attributes.Count; j++)
                    {
                        if (attributes[j].Group.Equals(attr.Group))
                        {
                            attributes[j].Order = order;
                            order++;
                            lstOrderChanged.Add(attributes[j].Id);
                        }
                    }
                }

                productCategoryManager.Save(selectedCategory, attributes, removedAttributes);

                //write operation log
                string message = selectedCategory.Id.Equals(0) ? "新增类别:" : "变更类别:";
                message += txtCategory.Text;
                OperationLogType type = selectedCategory.Id.Equals(0) ? OperationLogType.Insert : OperationLogType.Update;
                WriteOperationLog(type, message);

                categories = productCategoryManager.GetByParentId(0);

                TreeNode root = new TreeNode("中材产品类别", "0");
                tvwCategory.Nodes.Clear();
                tvwCategory.Nodes.Add(root);

                AddChildNode(root, categories);
                tvwCategory.ExpandAll();

                attributes = attributes.OrderBy <ExtendedAttribute, int>(p => p.Order).ToList <ExtendedAttribute>();
                InitGridView();

                ShowMessage("保存成功。");

                //For Edit Status
                HasModify           = false;
                hdfEditStatus.Value = string.Empty;
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                RedirectToErrorPage();
            }
        }