Example #1
0
        public static void carregaElemento(ElementoTipo tipo)
        {
            var    workingDir = Environment.CurrentDirectory;
            var    caminho    = Directory.GetParent(workingDir).Parent.Parent.FullName;
            string arquivo    = string.Empty;

            switch (tipo)
            {
            case ElementoTipo.PAREDE:
                arquivo = Path.Combine(caminho, @"Data/paredes.txt");
                break;

            case ElementoTipo.GHOSTZONE:
                arquivo = Path.Combine(caminho, @"Data/espacos.txt");
                break;

            case ElementoTipo.PILULA:
                arquivo = Path.Combine(caminho, @"Data/pilulas.txt");
                break;
            }

            //verifica se existe o arquivo
            if (File.Exists(arquivo))
            {
                //quebra o texto em linhas
                string[] linhas = File.ReadAllLines(arquivo);

                int i;
                int j;

                //percorre as linhas
                foreach (var linha in linhas)
                {
                    if (linha.Trim() != "")
                    {
                        //dividi a linhas em posições da matriz
                        string[] valores = linha.Split(",");
                        i = Convert.ToInt16(valores[0]);
                        j = Convert.ToInt16(valores[1]);

                        if (tipo != ElementoTipo.PILULA)
                        {
                            //remover o dot que foi substituido
                            dots--;
                        }
                        mapa[i, j] = (char)tipo;
                    }
                }
            }
        }
Example #2
0
        private void BotonNuevo_Click(object sender, System.EventArgs e)
        {
            this.Hide();
            object Resultado = null;

            if (this.ElementoTipo == null && m_Table == "personas")
            {
                // Esta es una excepción para reconocer cuando se está creando un proveedor
                if (m_Filter != null && m_Filter.IndexOf("tipo&2") >= 0)
                {
                    this.ElementoTipo = typeof(Lbl.Personas.Proveedor);
                }
                else
                {
                    this.ElementoTipo = typeof(Lbl.Personas.Persona);
                }
            }

            try
            {
                if (this.ElementoTipo != null)
                {
                    Resultado = Lfx.Workspace.Master.RunTime.Execute("CREATE", new string[] { ElementoTipo.ToString() });
                }

                if (Resultado == null)
                {
                    Resultado = Lfx.Workspace.Master.RunTime.Execute("CREATE", new string[] { m_Table });
                }
            }
            catch
            {
                Lfx.Workspace.Master.RunTime.Toast("No se puede crear el elemento.", "Error");
            }

            if (Resultado == null)
            {
                // No se puede crear
                this.Show();
            }
            else if (Resultado.GetType().ToString() == "Lfc.FormularioEdicion")
            {
                // Como no puedo establecer la propiedad porque no conozco el tipo Lfc.FormularioEdicion,
                // lo hago usando reflexión
                System.Type Tipo = Resultado.GetType();
                System.Reflection.PropertyInfo PropInfo = Tipo.GetProperty("ControlDestino");
                if (PropInfo != null)
                {
                    PropInfo.SetValue(Resultado, this.ControlDestino, null);
                }
                this.DialogResult = DialogResult.Cancel;
                this.Tag          = Resultado;
                this.Close();
            }
            else if (Resultado is Form)
            {
                this.DialogResult = DialogResult.Cancel;
                this.Close();
            }
            else if (Resultado is Lfx.Types.OperationResult)
            {
                Lfx.Workspace.Master.RunTime.Toast(((Lfx.Types.OperationResult)(Resultado)).Message, "Mensaje");
            }
            else
            {
                // Devolvió algo raro.
            }
        }