예제 #1
0
        private void CargarGridCostos()
        {
            var CostosFiltro = new[] { "" };

            if (TipoPantalla == "Costos")
            {
                CostosFiltro = new[] { "PR", "HH", "AC" }
            }
            ;
            else
            {
                CostosFiltro = new[] { "TM", "FII", "FIE", "FRC" }
            };

            CostosDataSource                           = new BindingList <Costos>(CostosBL.GetCostos().Where(x => CostosFiltro.Contains(x.Categoria)).ToList());
            dataGridView1.DataSource                   = CostosDataSource;
            dataGridView1.Columns["Id"].Visible        = false;
            dataGridView1.Columns["Estado"].Visible    = false;
            dataGridView1.Columns["Categoria"].Visible = false;
            dataGridView1.Columns["Valor2"].Visible    = false;
            if (TipoPantalla == "Factores")
            {
                dataGridView1.Columns["Unidad"].Visible = false;
            }

            dataGridView1.Columns[5].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            dataGridView1.Columns[5].DefaultCellStyle.Format    = "#,0.00###";

            dataGridView1.AutoSizeColumnsMode     = DataGridViewAutoSizeColumnsMode.AllCells;
            dataGridView1.Columns[4].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            dataGridView1.Columns[5].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            //dataGridView1.AjustColumnsWidthForGridWidth();
            //dataGridView1.Columns[3].Width = 200;
        }
예제 #2
0
        private void btnAgregar_Click(object sender, EventArgs e)
        {
            if (ValidarCampos())
            {
                List <Costos> lcosto = new List <Costos>();
                Costos        Cost   = new Costos();
                string        Categ  = "";

                switch (cmbTipo.Text.Trim())
                {
                case "RR.HH.":
                    Categ = "HH";
                    break;

                case "Procesos":
                    Categ = "PR";
                    break;

                case "Aceros":
                    Categ = "AC";
                    break;

                case "Tasa":
                    Categ = "TM";
                    break;

                case "Factor Industrial Interno":
                    Categ = "FII";
                    break;

                case "Factor Industrial Externo":
                    Categ = "FIE";
                    break;

                case "Factor Comercial":
                    Categ = "FRC";
                    break;
                }

                Cost.Categoria = Categ;
                Cost.Tipo      = txtDescripcion.Text.Trim();
                Cost.Unidad    = cmbUnidad.Text.Trim();
                Cost.Estado    = materialCheckBox1.Checked ? 1 : 0;
                Cost.Valor     = Convert.ToDecimal(txtValor.Text);
                Cost.Valor2    = Convert.ToDecimal(txtValor2.Text);

                switch (labelNoMouse1.Text.Trim())
                {
                case "Agregar":
                    lcosto.Add(Cost);
                    CostosBL.InserCostos(lcosto);

                    CargarGridCostos();
                    // LimpiarCampos();
                    dataGridView1.Rows[(dataGridView1.RowCount - 1)].Selected = true;
                    dataGridView1.FirstDisplayedScrollingRowIndex             = dataGridView1.RowCount - 1;
                    dataGridView1.CurrentCell = dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[3];

                    CargarCampos(dataGridView1.RowCount - 1);
                    FormatearCategoria();
                    break;

                case "Actualizar":
                    Cost.Id = Convert.ToInt32(dataGridView1[1, dataGridView1.CurrentRow.Index].Value);
                    lcosto.Add(Cost);
                    CostosBL.UpdateCostos(lcosto);
                    ItemCostoBL.UpdateItemCostosID(Cost.Id);

                    int nRow = dataGridView1.CurrentRow.Index;
                    CargarGridCostos();
                    FormatearCategoria();

                    dataGridView1.Rows[nRow].Selected = true;
                    dataGridView1.CurrentCell         = dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[3];
                    break;
                }
            }
        }