public List <Data.Area> AreaList()
        {
            var list = new List <Data.Area>();

            Data.Area area1 = new Data.Area {
                AREA = "ENG", STANDBY = 0, TEAM = "team1"
            };
            Data.Area area2 = new Data.Area {
                AREA = "ENG", STANDBY = 0, TEAM = "team2"
            };
            Data.Area area3 = new Data.Area {
                AREA = "area3", STANDBY = 3, TEAM = "team3"
            };
            list.Add(area1);
            list.Add(area2);
            list.Add(area3);
            return(list);
        }
Ejemplo n.º 2
0
        //public MapMagic.GeneratorsAsset mapMagicGens;
                #endif

        public void Generate(Data.Area area, Func <float, bool> stop = null)
        {
            if (area.pinned)
            {
                return;
            }
            change = false;
            if (stop != null && stop(0))
            {
                return;
            }

            //special case for preserving a demo scene on generator change
//			if (area.coord.x==0 && area.coord.z==0) return;
            Data.Area savedArea = null;
            if (leaveDemoUntouched && area.coord.x == 0 && area.coord.z == 0)
            {
                savedArea = (Data.Area)area.Clone();
            }

            if (generatorType == GeneratorType.Planar)
            {
                area.ClearLand();
                area.ClearObjects();
                area.ClearGrass();

                Matrix matrix = new Matrix(area.rect);
                planarGen.Generate(matrix, stop);

                area.AddLayer(matrix, planarGen.blockType, heightFactor: 1, noise: null);
            }

            if (generatorType == GeneratorType.Noise)
            {
                area.ClearLand();
                area.ClearObjects();
                area.ClearGrass();

                Noise noise = new Noise(123, permutationCount: 512);                //random to floor floats

                Matrix noiseMatrix = new Matrix(area.rect);

                if (stop != null && stop(0))
                {
                    return;
                }
                if (noiseGen.enabled)
                {
                    noiseGen.Generate(noiseMatrix, seed, stop);
                }

                if (stop != null && stop(0))
                {
                    return;
                }
                if (curveGen.enabled)
                {
                    curveGen.Generate(noiseMatrix, stop);
                }

                if (stop != null && stop(0))
                {
                    return;
                }
                area.AddLayer(noiseMatrix, noiseGen.blockType, heightFactor: heightFactor, noise: noise);              //TODO: set block types instead of magical numbers

                if (slopeGen.enabled)
                {
                    if (stop != null && stop(0))
                    {
                        return;
                    }
                    Matrix slopeMatrix = slopeGen.Generate(noiseMatrix, stop);
                    area.PaintLayer(slopeMatrix, slopeGen.blockType, noise: noise, paintThickness: slopeGen.thickness);
                }

                if (cavityGen.enabled)
                {
                    if (stop != null && stop(0))
                    {
                        return;
                    }
                    Matrix cavityMatrix = cavityGen.Generate(noiseMatrix, stop);
                    area.PaintLayer(cavityMatrix, cavityGen.blockType, noise: noise, paintThickness: cavityGen.thickness);
                }

                Matrix blurMatrix;
                if (blurGen.enabled)
                {
                    if (stop != null && stop(0))
                    {
                        return;
                    }
                    blurMatrix = blurGen.Generate(noiseMatrix, stop);
                    blurMatrix.Max(noiseMatrix);
                    area.ClampAppendLayer(blurMatrix, blurGen.blockType, noise: noise, heightFactor: heightFactor);
                }
                else
                {
                    blurMatrix = noiseMatrix;
                }

                if (stainsGen.enabled)
                {
                    Matrix matrix = area.GetSoilMatrix(stainsGen.soilOpacity);
                    //Matrix stains = new Matrix(area.rect);

                    stainsGen.Generate(matrix, seed, stop);
                    area.PaintLayer(matrix, stainsGen.blockType, noise: noise, paintThickness: stainsGen.thickness);
                }

                if (noiseGenB.enabled)
                {
                    Matrix matrix = new Matrix(area.rect);
                    noiseGenB.Generate(matrix, seed, stop);
                    area.SetLayer(matrix, null, noiseGenB.blockType, heightFactor: heightFactor, noise: noise);
                }

                if (scatterGen.enabled)
                {
                    if (stop != null && stop(0))
                    {
                        return;
                    }

                    SpatialHash spatialHash = new SpatialHash(new Vector2(area.rect.offset.x, area.rect.offset.z), area.rect.size.x, 16);

                    Matrix soil = area.GetSoilMatrix(scatterGen.soilOpacity);

                    scatterGen.Generate(spatialHash, seed, soil);

                    foreach (SpatialObject obj in spatialHash.AllObjs())
                    {
                        int x = (int)(obj.pos.x + 0.5f);
                        int z = (int)(obj.pos.y + 0.5f);
                        int y = (int)((obj.height + blurMatrix[x, z]) * heightFactor);
                        area.AddObject(new CoordDir(x, y, z), (short)scatterGen.blockType);
                    }
                }

                for (int g = 0; g < grassGens.gens.Length; g++)
                {
                    GrassGenerator grassGen = grassGens.gens[g];
                    //if (grassGen.enabled)
                    {
                        if (stop != null && stop(0))
                        {
                            return;
                        }

                        Matrix grassMatrix = area.GetSoilMatrix(grassGen.soilOpacity);

                        grassGen.Generate(grassMatrix, seed);

                        area.SetGrassLayer(grassMatrix, (byte)grassGen.grassType, 1, noise);
                    }
                }
            }

            else if (generatorType == GeneratorType.Heightmap)
            {
                area.ClearLand();
                area.ClearObjects();
                area.ClearGrass();

                Noise noise = new Noise(123, permutationCount: 512);                //random to floor floats

                Matrix matrix = new Matrix(area.rect);

                if (stop != null && stop(0))
                {
                    return;
                }
                if (standaloneHeightGen.enabled)
                {
                    standaloneHeightGen.Generate(matrix, seed, stop);
                }
                area.AddLayer(matrix, noiseGen.blockType, heightFactor: heightFactor, noise: noise);               //TODO: set block types instead of magical numbers
            }

            else if (generatorType == GeneratorType.MapMagic)
            {
                                #if MAPMAGIC
                if (stop != null && stop(0))
                {
                    return;
                }
                if (area.results == null)
                {
                    area.results = new MapMagic.Chunk.Results();
                }
                //MapMagic.Chunk.Size size = new MapMagic.Chunk.Size(area.rect.size.x,area.rect.size.x,heightFactor);

                if (stop != null && stop(0))
                {
                    return;
                }
                if (mapMagicGens != null)
                {
                    //mapMagicGens.Calculate(area.rect.offset.x, area.rect.offset.z, area.rect.size.x, area.results,  new MapMagic.Chunk.Size(area.rect.size.x,area.rect.size.x,heightFactor), seed, stop);
                    mapMagicGens.Generate(area.results, area.rect.offset.x, area.rect.offset.z, area.rect.size.x, area.rect.size.x, heightFactor, seed, stop);
                }
                else
                {
                    area.ClearLand(); area.ClearObjects(); area.ClearGrass();
                }
                                #else
                area.ClearLand(); area.ClearObjects(); area.ClearGrass();
                                #endif
            }

            if (stop != null && stop(0))
            {
                return;
            }
            if (removeThinLayers)
            {
                area.RemoveThinLayers(minLayerThickness);
            }

            if (stop != null && stop(0))
            {
                return;
            }
            if (polish)
            {
                area.Polish();
            }

            //special case for preserving a demo scene on generator change
            if (leaveDemoUntouched && area.coord.x == 0 && area.coord.z == 0)
            {
                Matrix mask = new Matrix(new CoordRect(0, 0, area.lines.Length, area.lines.Length));
                for (int x = 0; x < mask.rect.size.x; x++)
                {
                    for (int z = 0; z < mask.rect.size.z; z++)
                    {
                        int distFromEdge = Mathf.Min(x, mask.rect.size.x - x, z, mask.rect.size.z - z);
                        mask[x, z] = Mathf.Clamp01(distFromEdge / 50f);
                    }
                }

                Matrix maskInverted = (Matrix)mask.Clone(); maskInverted.InvertOne();

                area.MixAreas(new Data.Area[] { (Data.Area)area.Clone(), savedArea }, new Matrix[] { maskInverted, mask });
                area.objects = savedArea.objects;
            }

            //area.generated = true;
            //area.serializable = true;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Xóa
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void barButtonItemDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            DialogResult result = XtraMessageBox.Show("Bạn có chắc muốn xóa không?", "THÔNG BÁO", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (result == DialogResult.Yes)
            {
                foreach (var rowHandle in gridView1.GetSelectedRows())
                {
                    var areaId = gridView1.GetRowCellValue(rowHandle, "AreaID");
                    if (areaId != null)
                    {
                        Data.Area area = _areaService.GetAreaById(areaId.ToString());
                        if (area != null)
                        {
                            try
                            {
                                _areaService.Delete(areaId.ToString());
                            }
                            catch (Exception ex)
                            {
                                XtraMessageBox.Show(string.Format("Lỗi! \n {0}", ex.Message), "THÔNG BÁO",
                                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }
                }
                LoadAreas();
            }
            else
            {
                EnableButtonUpdateAndDelete(false);
            }


            //if (!string.IsNullOrEmpty(AreaId))
            //{
            //    Data.Area area = _areaService.GetAreaById(AreaId);
            //    if (area != null)
            //    {
            //        DialogResult result =
            //            XtraMessageBox.Show(
            //                "Bạn có chắc muốn xóa thông tin Đơn Vị Tính : " + area.AreaName + " không?", "THÔNG BÁO",
            //                MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            //        if (result == DialogResult.Yes)
            //        {
            //            try
            //            {
            //                _areaService.Delete(AreaId);
            //                LoadAreas();
            //            }
            //            catch (Exception ex)
            //            {
            //                XtraMessageBox.Show(string.Format("Lỗi! \n {0}", ex.Message), "THÔNG BÁO",
            //                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            //            }
            //        }
            //        else
            //        {
            //            EnableButtonUpdateAndDelete(false);
            //        }
            //    }
            //}
            //else
            //{


            //}
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Thêm mới
 /// </summary>
 /// <param name="area"></param>
 /// <returns></returns>
 public void Add(Data.Area area)
 {
     _context.Areas.Add(area);
     SaveChanges();
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Lưu thông tin từ file exel đã chọn
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSaveDataFormExel_Click(object sender, EventArgs e)
        {
            string userName    = Program.CurrentUser.UserName;
            string strUpdate   = null;
            string strInsert   = null;
            int    countUpdate = 0;
            int    countInsert = 0;
            int    countExits  = 0;

            if (!string.IsNullOrEmpty(textEditPathFileExel.Text))
            {
                const string sheetName       = "Sheet1";
                string       pathToExcelFile = textEditPathFileExel.Text.Trim();
                var          excelFile       = new ExcelQueryFactory(pathToExcelFile);
                excelFile.AddMapping <Data.Area>(x => x.AreaName, "AreaName");
                excelFile.AddMapping <Data.Area>(x => x.Description, "Description");

                excelFile.TrimSpaces = TrimSpacesType.Both;
                excelFile.ReadOnly   = true;

                IQueryable <Data.Area> areas = (from a in excelFile.Worksheet <Data.Area>(sheetName) select a);

                try
                {
                    foreach (Data.Area area in areas)
                    {
                        // Nếu tên tồn tại
                        if (!_areaService.CheckAreaNameExits(area.AreaName))
                        {
                            // Bỏ qua nếu đã tồn tại
                            if (radioButtonIgnoreIfDepartmentExits.Checked)
                            {
                                countExits++;
                            }
                            // Cập nhật lại thông tin Khu vực nếu đã tồn tại
                            if (radioButtonUpdateIfDepartmentExits.Checked)
                            {
                                Data.Area areaUpdate = _areaService.GetAreaByName(area.AreaName);
                                areaUpdate.UpdateBy    = userName;
                                areaUpdate.ModifyDate  = DateTime.Now;
                                areaUpdate.AreaID      = area.AreaName;
                                areaUpdate.Description = area.Description;
                                try
                                {
                                    _areaService.Update(areaUpdate);
                                    countUpdate++;
                                    strUpdate += string.Format("{0}, ", area.AreaName);
                                }
                                catch (Exception ex)
                                {
                                    XtraMessageBox.Show(string.Format("Lỗi cập nhật \n{0}", ex.Message));
                                }
                            }
                        }
                        // Nếu tên khu vực chưa tồn tại thì thực hiện thêm mới khu vực
                        else
                        {
                            area.AreaID      = NextId();
                            area.CreatedDate = DateTime.Now;
                            area.CreatedBy   = userName;
                            try
                            {
                                _areaService.Add(area);
                                countInsert++;
                                strInsert += string.Format("{0}, ", area.AreaName);
                            }
                            catch (Exception ex)
                            {
                                XtraMessageBox.Show(string.Format("Lỗi thêm mới \n{0}", ex.Message));
                            }
                        }
                    }
                    if (XtraMessageBox.Show(
                            string.Format("Thực hiện thành công.\n" +
                                          "=> Bỏ qua: {3} - vì đã tồn tại \n" +
                                          "=> Thêm mới: {0} - {2} \n" +
                                          "=> Cập nhật: {1} - {4}" +
                                          "\nBạn có muốn thêm mới nữa không?", countInsert, countUpdate, strInsert, countExits, strUpdate),
                            "THÔNG BÁO", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        gridControl1.DataSource   = null;
                        textEditPathFileExel.Text = string.Empty;
                    }
                    else
                    {
                        DialogResult = DialogResult.No;
                    }
                }

                catch (DbEntityValidationException ex)
                {
                    var sb = new StringBuilder();
                    foreach (var eve in ex.EntityValidationErrors)
                    {
                        sb.AppendLine(String.Format("Entity of type '{0}' in state '{1}' has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State));
                        foreach (var ve in eve.ValidationErrors)
                        {
                            sb.AppendLine(String.Format("- Property: '{0}', Error: '{1}'", ve.PropertyName, ve.ErrorMessage));
                        }
                    }
                    throw new Exception(sb.ToString(), ex);
                }
            }
            else
            {
                XtraMessageBox.Show("Vui lòng chọn tập tin để nhập", "Thông Báo Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                textEditPathFileExel.Focus();
            }
        }