コード例 #1
0
        protected void btn_actualizar_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txt_motivo.Text))
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Mensaje", "alert('Error: El campo Motivo es requerido!')", true);
            }
            else
            {
                DateTime fInicialSql = DateTime.ParseExact(lfechainicio.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                DateTime fFinalSql   = DateTime.ParseExact(txt_fechafin.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);

                if (fFinalSql <= fInicialSql)
                {
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Mensaje", "alert('Error: La fecha de expiración debe ser mayor a la fecha de inicio!')", true);
                }
                else
                {
                    var fechaInicialSql = fInicialSql.Date.ToString("yyyy-MM-dd HH:mm:ss");
                    var fechaFinalSql   = fFinalSql.Date.ToString("yyyy-MM-dd HH:mm:ss");


                    EvaluadorContrato evaContrato = (from ec in consultas.Db.EvaluadorContratos
                                                     where ec.Id_EvaluadorContrato == CodContrato
                                                     select ec).FirstOrDefault();

                    if (evaContrato != null)
                    {
                        evaContrato.FechaInicio     = DateTime.Parse(fechaInicialSql);
                        evaContrato.FechaExpiracion = DateTime.Parse(fechaFinalSql);
                        evaContrato.Motivo          = txt_motivo.Text;
                    }


                    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);

                    SqlCommand cmd2 = new SqlCommand(UsuarioActual(), con);
                    con.Open();
                    cmd2.ExecuteNonQuery();

                    try
                    {
                        consultas.Db.SubmitChanges();
                    }
                    catch (Exception) { throw; }


                    con.Close();
                    con.Dispose();
                    cmd2.Dispose();

                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Mensaje", "alert('Contrato modificado exitosamente!'); window.opener.location.reload(); window.close();", true);
                }
            }
        }
コード例 #2
0
        protected void btn_Crear_Click(object sender, EventArgs e)
        {
            if (txt_numero.Text == "" || txt_meses.Text == "")
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Mensaje", "alert('Error: Algunos campos están vacíos!')", true);
            }
            else
            {
                DateTime fInicialSql = DateTime.ParseExact(txt_fechainicio.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                DateTime fFinalSql   = fInicialSql.AddMonths(Convert.ToInt32(txt_meses.Text));

                var fechaInicialSql = fInicialSql.Date.ToString("yyyy-MM-dd HH:mm:ss");
                var fechaFinalSql   = fFinalSql.Date.ToString("yyyy-MM-dd HH:mm:ss");


                EvaluadorContrato evaContrato = new EvaluadorContrato();
                evaContrato.CodContacto     = CodContacto;
                evaContrato.numContrato     = int.Parse(txt_numero.Text);
                evaContrato.FechaInicio     = DateTime.Parse(fechaInicialSql);
                evaContrato.FechaExpiracion = DateTime.Parse(fechaFinalSql);


                SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);

                SqlCommand cmd2 = new SqlCommand(UsuarioActual(), con);
                con.Open();
                cmd2.ExecuteNonQuery();


                try
                {
                    consultas.Db.EvaluadorContratos.InsertOnSubmit(evaContrato);
                    consultas.Db.SubmitChanges();
                }
                catch (Exception) { throw; }



                con.Close();
                con.Dispose();
                cmd2.Dispose();


                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Mensaje", "alert('Contrato creado exitosamente!'); window.opener.location.reload(); window.close();", true);
            }
        }