public static int Insert(mxc_motorista_tipo_contato mxc)
    {
        int retorno = 0;

        try
        {
            //Correto
            IDbConnection objConexao; //Abrir a conexão
            IDbCommand    objCommand; // Criar e executar os comandos
            string        sql = "insert into  mxc_motorista_tipo_contato";
            sql += "(mot_id, tpc_id, mxc_descricao)";
            sql += "values ";
            sql += "(?mot_id, ?tpc_id, ?mxc_descricao)";

            objConexao = Mapped.Connection();
            objCommand = Mapped.Command(sql, objConexao);

            // Chave estrangeira
            objCommand.Parameters.Add(Mapped.Parameter("?mxc_descricao", mxc.Mxc_descricao));
            objCommand.Parameters.Add(Mapped.Parameter("?mot_id", mxc.Mot_id.Mot_id));
            objCommand.Parameters.Add(Mapped.Parameter("?tpc_id", mxc.Tpc_id.Tpc_id));

            objCommand.ExecuteNonQuery();
            objConexao.Close();
            objConexao.Dispose();
            objCommand.Dispose();
        }
        catch (Exception)
        {
            //erro
            retorno = -2;
        }
        return(retorno);
    }
Example #2
0
    public void CarregarVisualizar()
    {
        hdf.Value = Session["value"].ToString();
        usu_usuario   usu = new usu_usuario();
        mot_motorista mot = new mot_motorista();
        pes_pessoa    pes = new pes_pessoa();
        mxc_motorista_tipo_contato mxc = new mxc_motorista_tipo_contato();
        tpc_tipo_contato           tpc = new tpc_tipo_contato();

        DataSet ds = mot_motoristaDB.SelectDados(Convert.ToInt32(hdf.Value));

        if (ds.Tables[0].Rows.Count == 1)
        {
            hdfID.Value                 = ds.Tables[0].Rows[0]["pes_id"].ToString();
            txtNome.Text                = ds.Tables[0].Rows[0]["pes_nome"].ToString();
            txtEmail.Text               = ds.Tables[0].Rows[0]["usu_email"].ToString();
            txtCNPJ.Text                = ds.Tables[0].Rows[0]["mot_cnpj"].ToString();
            ddlSexo.SelectedItem.Text   = ds.Tables[0].Rows[0]["pes_sexo"].ToString();
            ddlCidade.SelectedItem.Text = ds.Tables[0].Rows[0]["pes_cidade"].ToString();
            ddlEstado.SelectedItem.Text = ds.Tables[0].Rows[0]["pes_estado"].ToString();
            ddl.SelectedItem.Text       = ds.Tables[0].Rows[0]["tpc_descricao"].ToString();
            txtTelefone.Text            = ds.Tables[0].Rows[0]["mxc_descricao"].ToString();
            txtData.Text                = ds.Tables[0].Rows[0]["pes_nascimento"].ToString();
        }
    }
    public static void Update(mxc_motorista_tipo_contato mxc)
    {
        //Correto
        IDbConnection objConexao; //Abrir a conexão
        IDbCommand    objCommand; // Criar e executar os comandos
        string        sql = "update mxc_motorista_tipo_contato set mxc_descricao = ?mxc_descricao where mxc_id = ?mxc_id";

        objConexao = Mapped.Connection();
        objCommand = Mapped.Command(sql, objConexao);

        objCommand.Parameters.Add(Mapped.Parameter("?mxc_id", mxc.Mxc_id));
        objCommand.Parameters.Add(Mapped.Parameter("?mxc_descricao", mxc.Mxc_descricao));
        //objCommand.Parameters.Add(Mapped.Parameter("?usu_tipo", usu.Usu_tipo));
        objCommand.ExecuteNonQuery();
        objConexao.Close();
        objConexao.Dispose();
        objCommand.Dispose();
    }
Example #4
0
    protected void btnSalvar_Click(object sender, EventArgs e)
    {
        mxc_motorista_tipo_contato mxc = new mxc_motorista_tipo_contato();
        mot_motorista    mot           = new mot_motorista();
        tpc_tipo_contato tpc           = new tpc_tipo_contato();

        DataSet ds = mot_motoristaDB.SelectID(Convert.ToInt32(hdf.Value));


        mot.Mot_id   = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
        mot.Mot_cnpj = txtCNPJ.Text;
        mot_motoristaDB.Update(mot);

        //tpc.Tpc_id = Convert.ToInt32(ddl.SelectedValue);
        //mxc.Tpc_id = tpc;

        //tpc_tipo_contatoDB.Update(tpc);

        mxc.Mxc_descricao = txtTelefone.Text;
        mxc_motorista_tipo_contatoDB.Update(mxc);

        pes_pessoa pes = new pes_pessoa();

        pes.Pes_id         = Convert.ToInt32(hdf.Value);
        pes.Pes_nome       = txtNome.Text;
        pes.Pes_sexo       = ddlSexo.SelectedValue;
        pes.Pes_cidade     = ddlCidade.SelectedValue;
        pes.Pes_estado     = ddlEstado.SelectedValue;
        pes.Pes_nascimento = Convert.ToDateTime(txtData.Text);

        switch (pes_pessoaDB.Update(pes))
        {
        case 0:
            //Response.Write("OK");
            Response.Write("<script>alert('Cadastrado com Sucesso');</script>");
            break;

        case -2:
            //Response.Write("ERRO");
            Response.Write("<script>alert('Ocorreu um Erro');</script>");
            break;
        }
    }
    protected void btnEnviar_Click(object sender, EventArgs e)
    {
        hdf.Value = Session["value"].ToString();

        DataSet ds = mot_motoristaDB.SelectID(Convert.ToInt32(hdf.Value));

        mot_motorista mot = new mot_motorista();

        mot.Mot_id = Convert.ToInt32(ds.Tables[0].Rows[0]["mot_id"]);

        tpc_tipo_contato tpc = new tpc_tipo_contato();

        tpc.Tpc_id = Convert.ToInt32(ddl.SelectedValue);


        mxc_motorista_tipo_contato mxc = new mxc_motorista_tipo_contato();

        if (ddl.SelectedIndex == 1)
        {
            mxc.Mxc_descricao = txtTelefone.Text;
        }
        else if (ddl.SelectedIndex == 2)
        {
            mxc.Mxc_descricao = txtCelular.Text;
        }
        else if (ddl.SelectedIndex == 3)
        {
            mxc.Mxc_descricao = txtWhatsapp.Text;
        }
        else if (ddl.SelectedIndex == 4)
        {
            mxc.Mxc_descricao = txtEmailAlt.Text;
        }

        mxc.Mot_id = mot;
        mxc.Tpc_id = tpc;
        mxc_motorista_tipo_contatoDB.Insert(mxc);

        string dir = Request.PhysicalApplicationPath + "pg\\uploads\\";

        if (!Directory.Exists(dir))
        {
            Directory.CreateDirectory(dir);
        }

        foreach (HttpPostedFile flp in fup.PostedFiles)
        {
            double mp = 2000;

            if (fup.HasFile)
            {
                string arq = Path.GetFileName(flp.FileName);
                string ext = Path.GetExtension(flp.FileName);
                ext = ext.ToLower();
                double ta = flp.ContentLength / 1024;

                if (ext == ".jpg" || ext == ".png" || ext == ".gif")
                {
                    if (ta <= mp)
                    {
                        arq = DateTime.Now.ToString("yyyyMMddHHmmssfff") + ext;
                        if (!File.Exists(dir + arq))
                        {
                            flp.SaveAs(dir + arq);

                            System.Drawing.Image imgOriginal = System.Drawing.Image.FromFile(Server.MapPath("~/pg/uploads/" + arq), true);

                            System.Drawing.Image.GetThumbnailImageAbort miniatura = new System.Drawing.Image.GetThumbnailImageAbort(erro);

                            System.Drawing.Image imgRedimensionada;

                            int width, height;

                            if (imgOriginal.Width > 200)
                            {
                                width = 200; height = (int)(width * imgOriginal.Height) / imgOriginal.Width;
                            }
                            else
                            {
                                width = imgOriginal.Width; height = imgOriginal.Height;
                            }

                            imgRedimensionada = imgOriginal.GetThumbnailImage(width, height, miniatura, IntPtr.Zero);


                            imgRedimensionada.Dispose();

                            imgOriginal.Dispose();

                            //Atualizar tipo de conta
                            if (rbMensal.Checked)
                            {
                                string        kindOfPremium = "Premium M";
                                DataSet       dsp           = new DataSet();
                                tip_tipoconta tip           = new tip_tipoconta();

                                dsp        = tip_tipocontaDB.SelectID(kindOfPremium);
                                tip.Tip_id = Convert.ToInt32(dsp.Tables[0].Rows[0][0]);
                                mot.Tip_id = tip;
                                mot_motoristaDB.UpdatePremium(mot);
                            }
                            else if (rbAnual.Checked)
                            {
                                string        kindOfPremium = "Premium A";
                                DataSet       dsp           = new DataSet();
                                tip_tipoconta tip           = new tip_tipoconta();

                                dsp        = tip_tipocontaDB.SelectID(kindOfPremium);
                                tip.Tip_id = Convert.ToInt32(dsp.Tables[0].Rows[0][0]);
                                mot.Tip_id = tip;
                                mot_motoristaDB.UpdatePremium(mot);
                            }

                            //Response.Write("<script>alert('Cadastrado com sucesso');</script>");
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModalS();", true);
                            tdo_tipodocumento tdo = new tdo_tipodocumento();
                            tdo.Tdo_image = arq;
                            tdo_tipodocumentoDB.Insert(tdo);

                            string  img = arq;
                            DataSet id  = new DataSet();
                            id         = tdo_tipodocumentoDB.SelectImage(img);
                            tdo.Tdo_id = Convert.ToInt32(id.Tables[0].Rows[0][0]);

                            doc_documento doc = new doc_documento();
                            doc.Mot_id = mot;
                            doc.Tdo_id = tdo;
                            doc_documentoDB.Insert(doc);

                            pBefore.Visible = false;
                            pAfter.Visible  = true;
                        }
                        else
                        {
                            //Response.Write("<script>alert('Arquivo ja existe');</script>");
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModalF();", true);
                        }
                    }
                    else
                    {
                        //Response.Write("<script>alert('Tamanho maximo excedido - 500KB');</script>");
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModalMS();", true);
                    }
                }
                else
                {
                    //Response.Write("<script>alert('Extensão invalida');</script>");
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModalEI();", true);
                }
            }
            else
            {
                //Response.Write("<script>alert('Selecione um arquivo');</script>");
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModalSl();", true);
            }
        }
    }