Exemplo n.º 1
0
        protected void cmd_save_credentials_Click(object sender, EventArgs e)
        {
            string str_ip     = txt_ip.Text;
            string str_user   = txt_user.Text;
            string str_pass   = txt_pass.Text;
            Guid   id_fcenter = Guid.Parse(lbl_idcenter.Text);
            int    str_count;


            using (db_transcriptEntities data_user = new db_transcriptEntities())
            {
                var items_user = (from c in data_user.inf_credenciales
                                  select c).Count();

                str_count = items_user;
            }

            if (str_count == 0)
            {
                using (var insert_fiscal = new db_transcriptEntities())
                {
                    var items_fiscal = new inf_credenciales
                    {
                        ip             = str_ip,
                        usuario        = str_user,
                        clave          = str_pass,
                        id_usuario     = id_fuser,
                        id_centro      = id_fcenter,
                        fecha_registro = DateTime.Now
                    };
                    insert_fiscal.inf_credenciales.Add(items_fiscal);
                    insert_fiscal.SaveChanges();
                }

                clean_txt();
                using (db_transcriptEntities data_user = new db_transcriptEntities())
                {
                    var inf_user = (from u in data_user.inf_credenciales
                                    where u.ip == str_ip
                                    select new
                    {
                        u.id_credenciales,
                        u.ip,
                        u.usuario,
                        u.fecha_registro
                    }).ToList();

                    gv_credentialsf.DataSource = inf_user;
                    gv_credentialsf.DataBind();
                    gv_credentialsf.Visible = true;
                }

                rb_add_credentials.Visible = false;

                lblModalTitle.Text = "tranScript";
                lblModalBody.Text  = "Datos de conexión guardados con éxito";
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "myModal", "$('#myModal').modal();", true);
                upModal.Update();
            }
            else if (rb_edit_credentials.Checked)
            {
                foreach (GridViewRow row in gv_credentials.Rows)
                {
                    if (row.RowType == DataControlRowType.DataRow)
                    {
                        CheckBox chkRow = (row.Cells[0].FindControl("chk_select") as CheckBox);
                        if (chkRow.Checked)
                        {
                            int str_code = Convert.ToInt32(row.Cells[1].Text);

                            using (var data_address = new db_transcriptEntities())
                            {
                                var items_address = (from c in data_address.inf_credenciales
                                                     where c.id_credenciales == str_code
                                                     select c).FirstOrDefault();

                                items_address.ip      = str_ip;
                                items_address.usuario = str_user;
                                items_address.clave   = str_pass;
                                data_address.SaveChanges();
                            }

                            clean_txt();
                            lblModalTitle.Text = "tranScript";
                            lblModalBody.Text  = "Horario de Conversión de videos, actualizado con éxito";
                            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "myModal", "$('#myModal').modal();", true);
                            upModal.Update();

                            using (db_transcriptEntities data_user = new db_transcriptEntities())
                            {
                                var inf_user = (from u in data_user.inf_credenciales
                                                where u.ip == str_ip
                                                select new
                                {
                                    u.id_credenciales,
                                    u.ip,
                                    u.usuario,
                                    u.fecha_registro
                                }).ToList();

                                gv_credentials.DataSource = inf_user;
                                gv_credentials.DataBind();
                                gv_credentials.Visible = true;
                            }
                        }
                    }
                }
            }
        }
        protected void cmd_save_credentials_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txt_ip.Text))
            {
                txt_ip.BackColor = Color.Yellow;
            }
            else
            {
                txt_ip.BackColor = Color.Transparent;
                if (string.IsNullOrEmpty(txt_user.Text))
                {
                    txt_user.BackColor = Color.Yellow;
                }
                else
                {
                    txt_user.BackColor = Color.Transparent;
                    if (string.IsNullOrEmpty(txt_pass.Text))
                    {
                        txt_pass.BackColor = Color.Yellow;
                    }
                    else
                    {
                        txt_pass.BackColor = Color.Transparent;

                        string str_ip   = txt_ip.Text;
                        string str_user = txt_user.Text;
                        string str_pass = txt_pass.Text;

                        int str_count;


                        using (db_transcriptEntities edm_conexion = new db_transcriptEntities())
                        {
                            var i_conexion = (from c in edm_conexion.inf_credenciales
                                              select c).Count();

                            str_count = i_conexion;
                        }

                        if (str_count == 0)
                        {
                            using (var edm_conexion = new db_transcriptEntities())
                            {
                                var ii_conexion = new inf_credenciales
                                {
                                    ip             = str_ip,
                                    usuario        = str_user,
                                    clave          = str_pass,
                                    fecha_registro = DateTime.Now
                                };
                                edm_conexion.inf_credenciales.Add(ii_conexion);
                                edm_conexion.SaveChanges();
                            }
                            using (db_transcriptEntities edm_fecha_transf = new db_transcriptEntities())
                            {
                                var ii_fecha_transf = (from u in edm_fecha_transf.inf_credenciales
                                                       select u).ToList();

                                if (ii_fecha_transf.Count == 0)
                                {
                                }
                                else
                                {
                                    using (var insert_user = new db_transcriptEntities())
                                    {
                                        var items_user = new inf_credenciales_dep
                                        {
                                            id_usuario      = guid_fidusuario,
                                            id_credenciales = ii_fecha_transf[0].id_credenciales,
                                            id_tipo_accion  = id_accion(),
                                            fecha_registro  = DateTime.Now,
                                        };
                                        insert_user.inf_credenciales_dep.Add(items_user);
                                        insert_user.SaveChanges();
                                    }
                                }
                            }
                            clean_txt();
                            using (db_transcriptEntities edm_conexion = new db_transcriptEntities())
                            {
                                var ii_conexion = (from u in edm_conexion.inf_credenciales
                                                   where u.ip == str_ip
                                                   select new
                                {
                                    u.id_credenciales,
                                    u.ip,
                                    u.usuario,
                                    u.fecha_registro
                                }).ToList();

                                gv_credentialsf.DataSource = ii_conexion;
                                gv_credentialsf.DataBind();
                                gv_credentialsf.Visible = true;
                            }

                            rb_add_credentials.Visible = false;

                            lblModalTitle.Text = "transcript";
                            lblModalBody.Text  = "Datos de conexión, guardados con éxito";
                            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "myModal", "$('#myModal').modal();", true);
                            upModal.Update();
                        }
                        else if (rb_edit_credentials.Checked)
                        {
                            foreach (GridViewRow row in gv_credentials.Rows)
                            {
                                if (row.RowType == DataControlRowType.DataRow)
                                {
                                    CheckBox chkRow = (row.Cells[0].FindControl("chk_select") as CheckBox);
                                    if (chkRow.Checked)
                                    {
                                        int str_code = Convert.ToInt32(row.Cells[1].Text);

                                        using (var edm_conexion = new db_transcriptEntities())
                                        {
                                            var i_conexion = (from c in edm_conexion.inf_credenciales
                                                              where c.id_credenciales == str_code
                                                              select c).FirstOrDefault();

                                            i_conexion.ip      = str_ip;
                                            i_conexion.usuario = str_user;
                                            i_conexion.clave   = str_pass;
                                            edm_conexion.SaveChanges();
                                        }
                                        using (db_transcriptEntities edm_fecha_transf = new db_transcriptEntities())
                                        {
                                            var ii_fecha_transf = (from u in edm_fecha_transf.inf_credenciales
                                                                   select u).ToList();

                                            if (ii_fecha_transf.Count == 0)
                                            {
                                            }
                                            else
                                            {
                                                using (var insert_user = new db_transcriptEntities())
                                                {
                                                    var items_user = new inf_credenciales_dep
                                                    {
                                                        id_usuario      = guid_fidusuario,
                                                        id_credenciales = ii_fecha_transf[0].id_credenciales,
                                                        id_tipo_accion  = id_accion(),
                                                        fecha_registro  = DateTime.Now,
                                                    };
                                                    insert_user.inf_credenciales_dep.Add(items_user);
                                                    insert_user.SaveChanges();
                                                }
                                            }
                                        }
                                        clean_txt();
                                        lblModalTitle.Text = "transcript";
                                        lblModalBody.Text  = "Datos de conexión, actualizados con éxito";
                                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "myModal", "$('#myModal').modal();", true);
                                        upModal.Update();

                                        using (db_transcriptEntities edm_conexion = new db_transcriptEntities())
                                        {
                                            var i_conexion = (from u in edm_conexion.inf_credenciales
                                                              select new
                                            {
                                                u.id_credenciales,
                                                u.ip,
                                                u.usuario,
                                                u.fecha_registro
                                            }).ToList();

                                            gv_credentials.DataSource = i_conexion;
                                            gv_credentials.DataBind();
                                            gv_credentials.Visible = true;
                                        }
                                    }
                                }
                            }
                        }
                        //else if (rb_del_credentials.Checked)
                        //{
                        //    foreach (GridViewRow row in gv_credentials.Rows)
                        //    {
                        //        if (row.RowType == DataControlRowType.DataRow)
                        //        {
                        //            CheckBox chkRow = (row.Cells[0].FindControl("chk_select") as CheckBox);
                        //            if (chkRow.Checked)
                        //            {
                        //                int str_code = Convert.ToInt32(row.Cells[1].Text);


                        //                using (var data_user = new db_transcriptEntities())
                        //                {
                        //                    var items_user = (from c in data_user.inf_credenciales
                        //                                      where c.id_credenciales == str_code
                        //                                      select c).FirstOrDefault();

                        //                    data_user.inf_credenciales.Remove(items_user);
                        //                    data_user.SaveChanges();
                        //                }

                        //                clean_txt();
                        //                lblModalTitle.Text = "transcript";
                        //                lblModalBody.Text = "Datos de conexión, actualizado con éxito";
                        //                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "myModal", "$('#myModal').modal();", true);
                        //                upModal.Update();

                        //                using (db_transcriptEntities edm_conexion = new db_transcriptEntities())
                        //                {
                        //                    var i_conexion = (from u in edm_conexion.inf_credenciales
                        //                                      select new
                        //                                      {
                        //                                          u.id_credenciales,
                        //                                          u.ip,
                        //                                          u.usuario,
                        //                                          u.fecha_registro

                        //                                      }).ToList();

                        //                    gv_credentials.DataSource = i_conexion;
                        //                    gv_credentials.DataBind();
                        //                    gv_credentials.Visible = true;
                        //                }
                        //            }
                        //        }
                        //    }

                        //}
                    }
                }
            }
        }