public bool Copiar(string empresaid, tb_plla_afectacionesvac BE)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         using (SqlCommand cmd = new SqlCommand("gspTbPllaRubrosingreso_CopiarRubros", cnx))
         {
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@tipoplanillaorigen", SqlDbType.Char, 1).Value = BE.tipoplanillaorigen;
                 cmd.Parameters.Add("@tipoplanilladestino", SqlDbType.Char, 1).Value = BE.tipoplanilladestino;
             }
             try
             {
                 cnx.Open();
                 if (cmd.ExecuteNonQuery() > 0)
                 {
                     return true;
                 }
                 else
                 {
                     return false;
                 }
             }
             catch (Exception ex)
             {
                 Sql_Error = ex.Message;
                 throw new Exception(ex.Message);
             }
         }
     }
 }
 public bool Delete(string empresaid, tb_plla_afectacionesvac BE)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         using (SqlCommand cmd = new SqlCommand("gspTbPllaafectacionesVac_DELETE", cnx))
         {
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@perianio", SqlDbType.Char, 4).Value = BE.perianio;
                 cmd.Parameters.Add("@perimes", SqlDbType.Char, 2).Value = BE.perimes;
                 cmd.Parameters.Add("@tipoplla", SqlDbType.Char, 1).Value = BE.tipoplla;
                 cmd.Parameters.Add("@rubroid", SqlDbType.Char, 3).Value = BE.rubroid;
             }
             try
             {
                 cnx.Open();
                 if (cmd.ExecuteNonQuery() > 0)
                 {
                     return true;
                 }
                 else
                 {
                     return false;
                 }
             }
             catch (Exception ex)
             {
                 Sql_Error = ex.Message;
                 throw new Exception(ex.Message);
             }
         }
     }
 }
 public bool Copiar(string empresaid, tb_plla_afectacionesvac BE)
 {
     //return tablaDA.Update(empresaid, BE);
     bool zreturn = tablaDA.Copiar(empresaid, BE);
     Sql_Error = tablaDA.Sql_Error;
     return zreturn;
 }
 public bool Insert(string empresaid, tb_plla_afectacionesvac BE)
 {
     //return tablaDA.Insert(empresaid, BE);
     bool zreturn = tablaDA.Insert(empresaid, BE);
     Sql_Error = tablaDA.Sql_Error;
     return zreturn;
 }
 public DataSet GetOne(string empresaid, tb_plla_afectacionesvac BE)
 {
     //return tablaDA.GetOne(empresaid, tipoplla);
     DataSet xreturn = null;
     xreturn = tablaDA.GetOne(empresaid, BE);
     Sql_Error = tablaDA.Sql_Error;
     return xreturn;
 }
 public DataSet GetAll_CONSULTA1(string empresaid, tb_plla_afectacionesvac BE)
 {
     //return tablaDA.GetAll_CONSULTA(empresaid, BE);
     DataSet xreturn = null;
     xreturn = tablaDA.GetAll_CONSULTA1(empresaid, BE);
     Sql_Error = tablaDA.Sql_Error;
     return xreturn;
 }
 public bool Insert_Update(string empresaid, tb_plla_afectacionesvac BE, DataTable TablaDatos)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         bool xreturn = true;
         int lcont = 0;
         using (SqlCommand cmd = new SqlCommand("gspTbPllaafectacionesVac_Eliminar", cnx))
         {
             cmd.CommandType = CommandType.StoredProcedure;
             cmd.Parameters.Add("@perianio", SqlDbType.Char, 4).Value = BE.perianio;
             cmd.Parameters.Add("@perimes", SqlDbType.Char, 2).Value = BE.perimes;
             cmd.Parameters.Add("@tipoplla", SqlDbType.Char, 1).Value = BE.tipoplla;
             try
             {
                 cnx.Open();
                 if (cmd.ExecuteNonQuery() > 0)
                 {
                     xreturn = true;
                 }
                 else
                 {
                     xreturn = false;
                 }
                 cnx.Close();
             }
             catch (Exception ex)
             {
                 Sql_Error = ex.Message;
                 //throw new Exception(ex.Message);
                 xreturn = false;
                 cnx.Close();
             }
         }
         for (lcont = 0; lcont <= TablaDatos.Rows.Count - 1; lcont++)
         {
             using (SqlCommand cmd = new SqlCommand("gspTbPllaafectacionesVac_InsertUpdate", cnx))
             {
                 cmd.CommandTimeout = 0;
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@tipoplla", SqlDbType.Char, 1).Value = TablaDatos.Rows[lcont]["tipoplla"];
                 cmd.Parameters.Add("@perianio", SqlDbType.Char, 4).Value = TablaDatos.Rows[lcont]["perianio"];
                 cmd.Parameters.Add("@perimes", SqlDbType.Char, 2).Value = TablaDatos.Rows[lcont]["perimes"];
                 cmd.Parameters.Add("@rubroid", SqlDbType.Char, 3).Value = TablaDatos.Rows[lcont]["rubroid"];
                 cmd.Parameters.Add("@afecto", SqlDbType.Decimal).Value = TablaDatos.Rows[lcont]["afecto"];
                 //cmd.Parameters.Add("@status", SqlDbType.Decimal).Value = TablaDatos.Rows[lcont]["status"];
                 try
                 {
                     cnx.Open();
                     if (cmd.ExecuteNonQuery() > 0)
                     {
                         xreturn = true;
                     }
                     else
                     {
                         xreturn = false;
                     }
                     cnx.Close();
                 }
                 catch (Exception ex)
                 {
                     Sql_Error = ex.Message;
                     //throw new Exception(ex.Message);
                     xreturn = false;
                     cnx.Close();
                 }
             }
         }
         return xreturn;
     }
 }
        public DataSet GetOne(string empresaid, tb_plla_afectacionesvac BE)
        {
            using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
            {
                using (SqlCommand cmd = new SqlCommand("gspTbPllaafectacionesVac_SELECT", cnx))
                {
                    DataSet ds = new DataSet();
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add("@perianio", SqlDbType.Char, 4).Value = BE.perianio;
                        cmd.Parameters.Add("@perimes", SqlDbType.Char, 2).Value = BE.perimes;
                        cmd.Parameters.Add("@tipoplla", SqlDbType.Char, 1).Value = BE.tipoplla;
                    }

                    try
                    {
                        cnx.Open();
                        using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                        {
                            da.Fill(ds);
                        }
                        return ds;
                    }
                    catch (Exception ex)
                    {
                        Sql_Error = ex.Message;
                        throw new Exception(ex.Message);
                    }
                }
            }
        }
 public DataSet GetAll_CONSULTA1(string empresaid, tb_plla_afectacionesvac BE)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         using (SqlCommand cmd = new SqlCommand("gspTbPllaafectacionesVac_CONSULTA1", cnx))
         {
             DataSet ds = new DataSet();
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@rubroid", SqlDbType.Char, 3).Value = BE.rubroid;
                 cmd.Parameters.Add("@tipoplla", SqlDbType.Char, 1).Value = BE.tipoplla;
                 cmd.Parameters.Add("@descriplike1", SqlDbType.VarChar, 60).Value = BE.descriplike1;
                 cmd.Parameters.Add("@descriplike2", SqlDbType.VarChar, 60).Value = BE.descriplike2;
                 cmd.Parameters.Add("@descriplike3", SqlDbType.VarChar, 60).Value = BE.descriplike3;
                 cmd.Parameters.Add("@norden", SqlDbType.Int).Value = BE.norden;
                 cmd.Parameters.Add("@incluir_blanco", SqlDbType.Int).Value = BE.incluir_blanco;
                 cmd.Parameters.Add("@nestado", SqlDbType.Int).Value = BE.nestado;
                 cmd.Parameters.Add("@descartarrubros", SqlDbType.VarChar, 50).Value = BE.descartarrubros;
             }
             try
             {
                 cnx.Open();
                 using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                 {
                     da.Fill(ds);
                 }
                 return ds;
             }
             catch (Exception ex)
             {
                 Sql_Error = ex.Message;
                 throw new Exception(ex.Message);
             }
         }
     }
 }
 public bool Insert_Update(string empresaid, tb_plla_afectacionesvac BE, DataTable TablaDatos)
 {
     //return tablaDA.Insert(empresaid, BE);
     bool zreturn = tablaDA.Insert_Update(empresaid, BE, TablaDatos);
     Sql_Error = tablaDA.Sql_Error;
     return zreturn;
 }
        private void Accion(int naccion)
        {
            switch (naccion)
            {
                case 1:
                    u_n_opsel = 1;
                    U_RefrescaControles();
                    if ((Examinar.CurrentRow != null))
                    {
                        Examinar.CurrentRow.Selected = false;
                    }
                    break;
                case 2:
                    if (!VariablesPublicas.u_Cerrado(VariablesPublicas.EmpresaID, VariablesPublicas.perianio, cboMesIni.SelectedValue.ToString(), "03", cmbtipoplanilla.SelectedValue.ToString(), ""))
                    {
                        u_n_opsel = 2;
                        U_RefrescaControles();
                        if ((Examinar.CurrentRow != null))
                        {
                            Examinar.CurrentRow.Selected = true;
                        }
                    }
                    break;
                case 3:
                    if (!VariablesPublicas.u_Cerrado(VariablesPublicas.EmpresaID, VariablesPublicas.perianio, cboMesIni.SelectedValue.ToString(), "03", cmbtipoplanilla.SelectedValue.ToString(), "Eliminar"))
                    {
                        xnomcampo = "";
                        if ((Examinar.CurrentRow != null))
                        {
                            if (xnomcampo.Length == 0)
                            {
                                var message = "Desea eliminar Registro  " + Examinar.Rows[Examinar.CurrentRow.Index].Cells["rubroid"].Value.ToString() + " - " + Examinar.Rows[Examinar.CurrentRow.Index].Cells["rubroname"].Value.ToString() + "...?";
                                var caption = "Mensaje del Sistema";
                                var buttons = MessageBoxButtons.YesNo;
                                DialogResult result;
                                result = MessageBox.Show(this, message, caption, buttons, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                                var BL = new tb_plla_afectacionesvacBL();
                                var BE = new tb_plla_afectacionesvac();

                                BE.perianio = spnperiodo.Value.ToString();
                                BE.perimes = cboMesIni.SelectedValue.ToString();
                                BE.tipoplla = cmbtipoplanilla.SelectedValue.ToString();
                                BE.rubroid = Examinar.Rows[Examinar.CurrentRow.Index].Cells["rubroid"].Value.ToString();
                                if (BL.Delete(VariablesPublicas.EmpresaID, BE))
                                {
                                    U_CancelarEdicion(0);
                                }
                                else
                                {
                                    Frm_Class.ShowError(BL.Sql_Error, this);
                                }
                            }
                            else
                            {
                                MessageBox.Show(xnomcampo, "IMPOSIBLE ELIMINAR REGISTRO");
                            }
                        }
                    }
                    break;
            }
        }
        private void save()
        {
            if (u_Validate())
            {
                if (Examinar.IsCurrentCellInEditMode)
                {
                    Examinar.CommitEdit(DataGridViewDataErrorContexts.Commit);
                }
                Tabla.AcceptChanges();
                for (lc_cont = 0; lc_cont <= Tabla.Rows.Count - 1; lc_cont++)
                {
                    Tabla.Rows[lc_cont]["perianio"] = spnperiodo.Value.ToString();
                    Tabla.Rows[lc_cont]["perimes"] = cboMesIni.SelectedValue;
                    Tabla.Rows[lc_cont]["tipoplla"] = cmbtipoplanilla.SelectedValue;
                }
                Tabla.AcceptChanges();

                var BL = new tb_plla_afectacionesvacBL();
                var BE = new tb_plla_afectacionesvac();

                BE.perianio = spnperiodo.Value.ToString();
                BE.perimes = cboMesIni.SelectedValue.ToString();
                BE.tipoplla = cmbtipoplanilla.SelectedValue.ToString();
                if (BL.Insert_Update(VariablesPublicas.EmpresaID, BE, Tabla))
                {
                    U_CancelarEdicion(0);
                }
                else
                {
                    Frm_Class.ShowError(BL.Sql_Error, this);
                }
            }
        }
        private void CargaDatos()
        {
            var xcodmes = "99";
            var xtipoplanilla = ".";
            var sorted = default(SortOrder);
            var xnomcolumna = string.Empty;
            if ((cboMesIni.SelectedValue != null))
            {
                xcodmes = cboMesIni.SelectedValue.ToString();
            }
            if ((cmbtipoplanilla.SelectedValue != null))
            {
                xtipoplanilla = cmbtipoplanilla.SelectedValue.ToString();
            }
            if ((Examinar.SortedColumn != null))
            {
                xnomcolumna = Examinar.Columns[Examinar.SortedColumn.Index].Name;
                sorted = Examinar.SortOrder;
            }
            var BL = new tb_plla_afectacionesvacBL();
            var BE = new tb_plla_afectacionesvac();

            BE.perianio = spnperiodo.Value.ToString();
            BE.perimes = xcodmes;
            BE.tipoplla = xtipoplanilla;
            Tabla = BL.GetAll_CONSULTA(VariablesPublicas.EmpresaID, BE).Tables[0];
            Examinar.AutoGenerateColumns = false;
            Examinar.DataSource = Tabla;
        }