예제 #1
0
        // Inherited
        public override void Clear()
        {
            VramAllocation = 2048;
            int moldCount = Molds.Count;

            for (int i = 1; i < moldCount; i++)
            {
                Molds.RemoveAt(1);
            }
            int tileCount = Molds[0].Tiles.Count;

            for (int i = 1; i < tileCount; i++)
            {
                Molds[0].Tiles.RemoveAt(1);
            }
            Molds[0].Gridplane = false;
            UniqueTiles        = new List <Mold.Tile>();
            if (Molds[0].Tiles.Count > 0)
            {
                Molds[0].Tiles[0] = Molds[0].Tiles[0].New(false);
                UniqueTiles.Add(Molds[0].Tiles[0]);
            }
            int sequenceCount = Sequences.Count;

            for (int i = 1; i < sequenceCount; i++)
            {
                Sequences.RemoveAt(1);
            }
            Sequences[0].Frames = new List <Sequence.Frame>();
        }
예제 #2
0
        /// <summary>
        /// 加入單一資料列到資料庫。
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public virtual ExecuteResultEntity Add(Molds entity, bool isLastRecord = true)
        {
            try
            {
                var repo = RepositoryHelper.GetMoldsRepository(database);
                database = repo.UnitOfWork;
                if (repo == null)
                {
                    return(ExecuteResultEntity.CreateErrorResultEntity(string.Format("Can't found data repository of {0}.", typeof(Molds).Name)));
                }

                entity = repo.Add(entity);

                if (isLastRecord)
                {
                    repo.UnitOfWork.Commit();
                    database = repo.UnitOfWork;
                    repo.UnitOfWork.Context.Set <Molds>().Attach(entity);
                    entity = repo.Reload(entity);
                }

                return(ExecuteResultEntity.CreateResultEntity());
            }
            catch (Exception ex)
            {
                return(ExecuteResultEntity.CreateErrorResultEntity(ex));
            }
        }
예제 #3
0
        /// <summary>
        /// 儲存或更新資料庫
        /// </summary>
        /// <param name="model"></param>
        public virtual ExecuteResultEntity <Molds> CreateOrUpdate(Molds entity)
        {
            try
            {
                using (var repo = RepositoryHelper.GetMoldsRepository())
                {
                    if (repo == null)
                    {
                        return(ExecuteResultEntity <Molds> .CreateErrorResultEntity(string.Format("Can't found data repository of {0}.", typeof(Molds).Name)));
                    }

                    database = repo.UnitOfWork;

                    if (repo.Get(IdentifyPrimaryKey(entity)) != null)
                    {
                        var update_result = Update(entity);

                        if (update_result.HasError)
                        {
                            update_result.Result = entity;
                            return(update_result);
                        }

                        return(ExecuteResultEntity <Molds> .CreateResultEntity(update_result.Result));
                    }
                    else
                    {
                        var add_result = Add(entity);
                        if (add_result.HasError)
                        {
                            return(new ExecuteResultEntity <Molds>()
                            {
                                Errors = add_result.Errors,
                                Result = entity
                            });
                        }

                        return(ExecuteResultEntity <Molds> .CreateResultEntity(entity));
                    }
                }
            }
            catch (Exception ex)
            {
                return(ExecuteResultEntity <Molds> .CreateErrorResultEntity(ex));
            }
        }
예제 #4
0
        // Read/write ROM
        private void ReadFromBuffer()
        {
            AnimationOffset = Bits.GetInt24(rom, 0x252000 + (Index * 3)) - 0xC00000;

            // Create source buffer for following properties
            int animationLength = Bits.GetShort(rom, AnimationOffset);

            Buffer = Bits.GetBytes(rom, AnimationOffset, animationLength);

            // Get pointers of data types
            int    offset = 2;
            ushort sequencePacketPointer = Bits.GetShort(Buffer, offset); offset += 2;
            ushort moldPacketPointer     = Bits.GetShort(Buffer, offset); offset += 2;
            byte   sequenceCount         = Buffer[offset++];
            byte   moldCount             = Buffer[offset++];

            VramAllocation = (ushort)(Buffer[offset] << 8); offset += 2;
            Unknown        = Bits.GetShort(Buffer, offset);

            // Build sequence collection
            offset         = sequencePacketPointer;
            this.Sequences = new List <Sequence>();
            for (int i = 0; i < sequenceCount; i++)
            {
                var tSequence = new Sequence();
                tSequence.ReadFromBuffer(Buffer, offset);
                Sequences.Add(tSequence);
                offset += 2;
            }

            // Build mold collection
            offset           = moldPacketPointer;
            this.Molds       = new List <Mold>();
            this.UniqueTiles = new List <Mold.Tile>();
            for (int i = 0; i < moldCount; i++)
            {
                var tMold = new Mold();
                tMold.ReadFromBuffer(Buffer, offset, UniqueTiles, Index, AnimationOffset);
                Molds.Add(tMold);
                offset += 2;
            }
        }
예제 #5
0
 public async override void SaveModel()
 {
     try
     {
         MoldsController controller = new MoldsController();
         MaterialManagementController MMcontroller = new MaterialManagementController();
         Collection <Molds>           dataset      = new Collection <Molds>();
         var logineduser = MMcontroller.GetCurrentLoginUser().Result;
         if (Items.Any())
         {
             foreach (var model in Items)
             {
                 Molds data = new Molds();
                 model.DoEvents();
                 CopyToModel(data, model);
                 dataset.Add(data);
                 if (model.Materials.Status.IsNewInstance)
                 {
                     model.DoEvents();
                     MMcontroller.Add(new Materials()
                     {
                         CreateTime      = DateTime.Now,
                         CreateUser      = logineduser,
                         CreateUserId    = logineduser.UserId,
                         Id              = Guid.NewGuid(),
                         ManufacturersId = model.ManufacturersId,
                         Name            = model.Materials.Name,
                         UnitPrice       = 0F
                     });
                 }
             }
         }
         await controller.CreateOrUpdateAsync(dataset);
     }
     catch (Exception ex)
     {
         setErrortoModel(this, ex);
     }
 }
예제 #6
0
        // Inherited
        public override void Clear()
        {
            // Clear sequences
            foreach (var s in Sequences)
            {
                s.Frames = new List <Sequence.Frame>();
            }

            // Clear molds
            int moldCount = Molds.Count;

            for (int i = 1; i < moldCount; i++)
            {
                Molds.RemoveAt(1);
            }

            // Clear tileset, palette, graphics data
            Tileset_bytes    = new byte[Tileset_bytes.Length];
            PaletteSetLength = 32;
            GraphicSetLength = 32;
            TilesetLength    = 64;
            GraphicSet       = new byte[GraphicSet.Length];
            PaletteSet       = new PaletteSet(new byte[256], 0, 0, 8, 16, 32);

            // Clear formatting properties
            Codec  = 0;
            Width  = 1;
            Height = 1;

            // Clear tile data
            foreach (var tile in Tileset_tiles.Tiles)
            {
                for (int i = 0; i < 4; i++)
                {
                    tile.Subtiles[i] = new Subtile(0, new byte[0x20], 0, new int[16], false, false, false, Codec == 1);
                }
            }
        }
예제 #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public virtual ExecuteResultEntity <Molds> Update(Molds fromModel, bool isLastRecord = true)
        {
            try
            {
                using (var repo = RepositoryHelper.GetMoldsRepository())
                {
                    if (repo == null)
                    {
                        return(ExecuteResultEntity <Molds> .CreateErrorResultEntity(string.Format("Can't found data repository of {0}.", typeof(Molds).Name)));
                    }

                    database = repo.UnitOfWork;

                    Molds findresult = repo.Get(IdentifyPrimaryKey(fromModel));

                    if (findresult != null)
                    {
                        CheckAndUpdateValue(fromModel, findresult);

                        if (isLastRecord)
                        {
                            repo.UnitOfWork.Commit();
                            database   = repo.UnitOfWork;
                            findresult = repo.Get(IdentifyPrimaryKey(findresult));
                        }

                        return(ExecuteResultEntity <Molds> .CreateResultEntity(findresult));
                    }
                }
                return(ExecuteResultEntity <Molds> .CreateErrorResultEntity("Data not found."));
            }
            catch (Exception ex)
            {
                return(ExecuteResultEntity <Molds> .CreateErrorResultEntity(ex));
            }
        }
예제 #8
0
        // Read/write buffer
        private void ReadFromBuffer()
        {
            AnimationOffset = Bits.GetInt24(rom, 0x252C00 + (Index * 3)) - 0xC00000;

            // Create source buffer for following properties
            ushort animationLength = Bits.GetShort(rom, AnimationOffset);

            Buffer = Bits.GetBytes(rom, AnimationOffset, Bits.GetShort(rom, AnimationOffset));

            // Get pointers of data types
            int    offset                = 2;
            ushort graphicSetPointer     = Bits.GetShort(Buffer, offset); offset += 2;
            ushort paletteSetPointer     = Bits.GetShort(Buffer, offset); offset += 2;
            ushort sequencePacketPointer = Bits.GetShort(Buffer, offset); offset += 2;
            ushort moldPacketPointer     = Bits.GetShort(Buffer, offset); offset += 2;

            // Skip 2 unknown bytes
            offset += 2;

            // Get formatting properties
            Width  = Buffer[offset++];
            Height = Buffer[offset++];
            Codec  = Bits.GetShort(Buffer, offset); offset += 2;

            // Get graphics, palette, tileset data
            int tileSetPointer = Bits.GetShort(Buffer, offset);

            GraphicSetLength = paletteSetPointer - graphicSetPointer;
            GraphicSet       = new byte[0x2000];
            System.Buffer.BlockCopy(Buffer, graphicSetPointer, GraphicSet, 0, GraphicSetLength);
            PaletteSetLength = (ushort)(tileSetPointer - paletteSetPointer);
            PaletteSet       = new PaletteSet(Buffer, 0, paletteSetPointer, 8, 16, 32);
            TilesetLength    = sequencePacketPointer - tileSetPointer - 2;
            Tileset_bytes    = new byte[64 * 4 * 2 * 4];
            System.Buffer.BlockCopy(Buffer, tileSetPointer, Tileset_bytes, 0, TilesetLength);

            // Build sequence collection
            this.Sequences = new List <Sequence>();
            offset         = sequencePacketPointer;
            for (int i = 0; Bits.GetShort(Buffer, offset) != 0x0000; i++)
            {
                Sequence tSequence = new Sequence();
                tSequence.ReadFromBuffer(Buffer, offset);
                Sequences.Add(tSequence);
                offset += 2;
            }

            // Build mold collection
            this.Molds = new List <Mold>();
            offset     = moldPacketPointer;
            ushort end = 0;

            for (int i = 0; Bits.GetShort(Buffer, offset) != 0x0000; i++)
            {
                if (Bits.GetShort(Buffer, offset + 2) == 0x0000)
                {
                    end = animationLength;
                }
                else
                {
                    end = Bits.GetShort(Buffer, offset + 2);
                }
                Mold tMold = new Mold();
                tMold.ReadFromBuffer(Buffer, offset, end);
                Molds.Add(tMold);
                offset += 2;
            }
        }
예제 #9
0
        public ExecuteResultEntity <ICollection <Molds> > ImportsMoldsFromExecl(string filename)
        {
            try
            {
                Collection <Molds>       DestTarget    = new Collection <Molds>();
                Dictionary <int, string> ColumnMapping = new Dictionary <int, string>();
                XSSFWorkbook             workbook;
                using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite))
                {
                    workbook = new XSSFWorkbook(fs);
                    XSSFSheet xsheet   = (XSSFSheet)workbook.GetSheetAt(0);
                    var       firstrow = xsheet.GetRow(0);

                    for (int coli = 0; coli < firstrow.LastCellNum; coli++)
                    {
                        ICell HeaderCell = firstrow.GetCell(coli);
                        if (HeaderCell.CellType == CellType.String)
                        {
                            switch (HeaderCell.StringCellValue.ToLowerInvariant())
                            {
                            case "專案名稱":
                                ColumnMapping.Add(HeaderCell.ColumnIndex, "MoldsInProjects.Projects.Name");
                                break;

                            case "開模日期":
                                ColumnMapping.Add(HeaderCell.ColumnIndex, "OpenDate");
                                break;

                            case "圖例":
                            case "圖例               模具縮小圖":
                                ColumnMapping.Add(HeaderCell.ColumnIndex, "LegendMoldReduction");
                                break;

                            case "使用位置":
                                ColumnMapping.Add(HeaderCell.ColumnIndex, "UsePosition");
                                break;

                            case "東菊編號":
                                ColumnMapping.Add(HeaderCell.ColumnIndex, "Code");
                                break;

                            case "廠商":
                                ColumnMapping.Add(HeaderCell.ColumnIndex, "Manufacturers.Name");
                                break;

                            case "廠商編號":
                                ColumnMapping.Add(HeaderCell.ColumnIndex, "Manufacturers.Code");
                                break;

                            case "材質":
                                ColumnMapping.Add(HeaderCell.ColumnIndex, "Materials.Name");
                                break;

                            case "單位重(kg/M)":
                                ColumnMapping.Add(HeaderCell.ColumnIndex, "UnitWeight");
                                break;

                            case "表面處理":
                                ColumnMapping.Add(HeaderCell.ColumnIndex, "SurfaceTreatment");
                                break;

                            case "烤漆面積(㎡)":
                                ColumnMapping.Add(HeaderCell.ColumnIndex, "PaintArea");
                                break;

                            case "皮膜處理(kg)":
                                ColumnMapping.Add(HeaderCell.ColumnIndex, "MembraneTreatment");
                                break;

                            case "最低產量":
                                ColumnMapping.Add(HeaderCell.ColumnIndex, "MinimumYield");
                                break;

                            case "生產錠徑":
                                ColumnMapping.Add(HeaderCell.ColumnIndex, "ProductionIngot");
                                break;

                            case "模具費用":
                                ColumnMapping.Add(HeaderCell.ColumnIndex, "");
                                break;

                            case "訂單總重量":
                                ColumnMapping.Add(HeaderCell.ColumnIndex, "TotalOrderWeight");
                                break;

                            case "模具使用狀況":
                                ColumnMapping.Add(HeaderCell.ColumnIndex, "MoldUseStatus.Name");
                                break;

                            case "備註":
                                ColumnMapping.Add(HeaderCell.ColumnIndex, "Comment");
                                break;

                            default:
                                continue;
                            }
                        }
                    }

                    int ColumnCount = firstrow.LastCellNum; //取得欄位數
                    int RowCount    = xsheet.LastRowNum;    //取得資料列數

                    for (int rowi = 1; rowi < RowCount; rowi++)
                    {
                        var datarow = xsheet.GetRow(rowi);

                        Molds fromFileData = new Molds();

                        fromFileData.Id           = Guid.NewGuid();
                        fromFileData.CreateTime   = DateTime.Now;
                        fromFileData.CreateUser   = GetCurrentLoginUser().Result;
                        fromFileData.CreateUserId = fromFileData.CreateUser.UserId;

                        Type dataTypeRef = fromFileData.GetType();
                        for (int coli = 0; coli < ColumnCount; coli++)
                        {
                            ICell cell = datarow.GetCell(coli);

                            switch (cell.CellType)
                            {
                            case CellType.Blank:
                                continue;

                            case CellType.Boolean:
                                var prop_bool = dataTypeRef.GetProperty(ColumnMapping[cell.ColumnIndex]);

                                if (prop_bool != null && prop_bool.PropertyType == typeof(bool))
                                {
                                    prop_bool.SetValue(fromFileData, cell.BooleanCellValue);
                                }
                                break;

                            case CellType.Error:
                                break;

                            case CellType.Formula:
                                break;

                            case CellType.Numeric:
                                var prop_Numeric = dataTypeRef.GetProperty(ColumnMapping[cell.ColumnIndex]);

                                if (prop_Numeric != null &&
                                    (prop_Numeric.PropertyType == typeof(double)))
                                {
                                    //prop_bool.SetValue(fromFileData, cell.BooleanCellValue);
                                }
                                break;

                            case CellType.String:
                                break;

                            case CellType.Unknown:
                                break;
                            }
                        }
                    }
                }

                var repo = RepositoryHelper.GetMoldsRepository();
                database = repo.UnitOfWork;
                Collection <Molds> MoldsSource = new Collection <Molds>(repo.All().ToList());
                return(ExecuteResultEntity <ICollection <Molds> > .CreateResultEntity(MoldsSource));
            }
            catch (Exception ex)
            {
                return(ExecuteResultEntity <ICollection <Molds> > .CreateErrorResultEntity(ex));
            }
        }