protected void btnUpdate_Click(object sender, EventArgs e) { ser_servicos serv = new ser_servicos(); tra_transporte tra = new tra_transporte(); con_condutor con = new con_condutor(); sco_servicoscondutor sco = new sco_servicoscondutor(); tra.Tra_id = Convert.ToInt32(ddlTransporte.SelectedValue); serv.Tra_id = tra; //serv.Ser_datacadastro = data; serv.Ser_id = Convert.ToInt32(Label1.Text); serv.Ser_origem = txtOrigem.Text; serv.Ser_destino = txtDestino.Text; serv.Ser_descricao = txtDescricao.Text; serv.Ser_datafim = Convert.ToDateTime(txtDataFim.Text + " " + txtHoraRetorno.Text); serv.Ser_datainicio = Convert.ToDateTime(txtDataInicio.Text + " " + txtHoraPartida.Text); serv.Ser_lugares = Convert.ToInt32(txtLugares.Text); //serv.Mot_id = mot; switch (ser_servicosDB.Update(serv)) { case 0: ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModalSS();", true); //lblMsg.Text = "Cadastrado com sucesso"; break; case -2: //lblMsg.Text = "ERRO"; ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModalSE();", true); break; } DataSet id = new DataSet(); if (ddlCondutor.SelectedIndex != 0) { con.Con_id = Convert.ToInt32(ddlCondutor.SelectedValue); id = sco_servicoscondutorDB.SelectID(Convert.ToInt32(Label4.Text), Convert.ToInt32(Label1.Text)); sco.Sco_id = Convert.ToInt32(id.Tables[0].Rows[0][0]); sco.Con_id = con; sco.Ser_id = serv; sco_servicoscondutorDB.Update(sco); } }
public void CarregarVisualizar(string par) { ser_servicos usu = new ser_servicos(); con_condutor con = new con_condutor(); DataSet data = ser_servicosDB.SelectCon(Convert.ToInt32(par)); Label1.Text = par; int qtd = data.Tables[0].Rows.Count; if (qtd != 0) { DataSet ds = ser_servicosDB.SelectDados(Convert.ToInt32(par)); if (ds.Tables[0].Rows.Count == 1) { Label1.Text = ds.Tables[0].Rows[0]["ser_id"].ToString(); txtOrigem.Text = ds.Tables[0].Rows[0]["ser_origem"].ToString(); txtDestino.Text = ds.Tables[0].Rows[0]["ser_destino"].ToString(); txtDataInicio.Text = ds.Tables[0].Rows[0]["ser_datainicio"].ToString(); txtDataFim.Text = ds.Tables[0].Rows[0]["ser_datafim"].ToString(); txtLugares.Text = ds.Tables[0].Rows[0]["ser_lugares"].ToString(); txtDescricao.Text = ds.Tables[0].Rows[0]["ser_descricao"].ToString(); ddlCondutor.SelectedValue = ds.Tables[0].Rows[0]["con_id"].ToString(); ddlTransporte.SelectedValue = ds.Tables[0].Rows[0]["tra_id"].ToString(); Label1.Text = ds.Tables[0].Rows[0]["ser_id"].ToString(); Label4.Text = ds.Tables[0].Rows[0]["con_id"].ToString(); } } else { DataSet ds = ser_servicosDB.SelectDadosCon(Convert.ToInt32(par)); if (ds.Tables[0].Rows.Count == 1) { Label1.Text = ds.Tables[0].Rows[0]["ser_id"].ToString(); txtOrigem.Text = ds.Tables[0].Rows[0]["ser_origem"].ToString(); txtDestino.Text = ds.Tables[0].Rows[0]["ser_destino"].ToString(); txtDataInicio.Text = ds.Tables[0].Rows[0]["ser_datainicio"].ToString(); txtDataFim.Text = ds.Tables[0].Rows[0]["ser_datafim"].ToString(); txtLugares.Text = ds.Tables[0].Rows[0]["ser_lugares"].ToString(); txtDescricao.Text = ds.Tables[0].Rows[0]["ser_descricao"].ToString(); //ddlCondutor.SelectedValue = ds.Tables[0].Rows[0]["con_id"].ToString(); ddlTransporte.SelectedValue = ds.Tables[0].Rows[0]["tra_id"].ToString(); Label1.Text = ds.Tables[0].Rows[0]["ser_id"].ToString(); } } }
public static int Insert(ser_servicos ser) { int retorno = 0; try { //Correto IDbConnection objConexao; //Abrir a conexão IDbCommand objCommand; // Criar e executar os comandos string sql = "insert into ser_servicos "; sql += "(ser_datacadastro, ser_datainicio, ser_datafim, ser_origem, ser_destino, ser_descricao, ser_lugares, mot_id, tra_id)"; sql += "values "; sql += "(?ser_datacadastro, ?ser_datainicio, ?ser_datafim, ?ser_origem, ?ser_destino, ?ser_descricao, ?ser_lugares, ?mot_id, ?tra_id)"; objConexao = Mapped.Connection(); objCommand = Mapped.Command(sql, objConexao); objCommand.Parameters.Add(Mapped.Parameter("?ser_datacadastro", ser.Ser_datacadastro)); //objCommand.Parameters.Add(Mapped.Parameter("?ser_nome", ser.Ser_nome)); objCommand.Parameters.Add(Mapped.Parameter("?ser_datainicio", ser.Ser_datainicio)); objCommand.Parameters.Add(Mapped.Parameter("?ser_datafim", ser.Ser_datafim)); objCommand.Parameters.Add(Mapped.Parameter("?ser_origem", ser.Ser_origem)); objCommand.Parameters.Add(Mapped.Parameter("?ser_destino", ser.Ser_destino)); objCommand.Parameters.Add(Mapped.Parameter("?ser_descricao", ser.Ser_descricao)); objCommand.Parameters.Add(Mapped.Parameter("?ser_lugares", ser.Ser_lugares)); // Chave estrangeira objCommand.Parameters.Add(Mapped.Parameter("?mot_id", ser.Mot_id.Mot_id)); objCommand.Parameters.Add(Mapped.Parameter("?tra_id", ser.Tra_id.Tra_id)); objCommand.ExecuteNonQuery(); objConexao.Close(); objConexao.Dispose(); objCommand.Dispose(); } catch (Exception) { //erro retorno = -2; } return(retorno); }
public static int Update(ser_servicos ser) { int retorno = 0; try { //Correto IDbConnection objConexao; //Abrir a conexão IDbCommand objCommand; // Criar e executar os comandos string sql = "update ser_servicos set ser_datafim = ?ser_datafim, ser_origem = ?ser_origem, ser_datainicio = ?ser_datainicio, ser_destino = ?ser_destino, ser_descricao = ?ser_descricao, ser_lugares = ?ser_lugares, tra_id = ?tra_id where ser_id = ?ser_id"; objConexao = Mapped.Connection(); objCommand = Mapped.Command(sql, objConexao); objCommand.Parameters.Add(Mapped.Parameter("?ser_id", ser.Ser_id)); objCommand.Parameters.Add(Mapped.Parameter("?ser_datacadastro", ser.Ser_datacadastro)); //objCommand.Parameters.Add(Mapped.Parameter("?ser_nome", ser.Ser_nome)); objCommand.Parameters.Add(Mapped.Parameter("?ser_datafim", ser.Ser_datafim)); objCommand.Parameters.Add(Mapped.Parameter("?ser_origem", ser.Ser_origem)); objCommand.Parameters.Add(Mapped.Parameter("?ser_datainicio", ser.Ser_datainicio)); objCommand.Parameters.Add(Mapped.Parameter("?ser_destino", ser.Ser_destino)); objCommand.Parameters.Add(Mapped.Parameter("?ser_descricao", ser.Ser_descricao)); objCommand.Parameters.Add(Mapped.Parameter("?ser_lugares", ser.Ser_lugares)); objCommand.Parameters.Add(Mapped.Parameter("?tra_id", ser.Tra_id.Tra_id)); objCommand.ExecuteNonQuery(); objConexao.Close(); objConexao.Dispose(); objCommand.Dispose(); } catch (Exception) { //erro retorno = -2; } return(retorno); }
protected void btnCadastrar_Click(object sender, EventArgs e) { if (txtOrigem.Text == "" || txtDestino.Text == "" || txtDataInicio.Text == "" || txtLugares.Text == "") { ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModalObrigatorio();", true); } else if (ddlTransporte.SelectedIndex == 0) { ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModalObrigatorioVeiculo();", true); } else { hdf.Value = Session["value"].ToString(); mot_motorista mot1 = new mot_motorista(); DataSet codigo1 = new DataSet(); codigo1 = mot_motoristaDB.SelectID(Convert.ToInt32(hdf.Value)); mot1.Mot_id = Convert.ToInt32(codigo1.Tables[0].Rows[0][0]); int a1 = Convert.ToInt32(codigo1.Tables[0].Rows[0][0]); DataSet ds1 = mot_motoristaDB.SelectPETC(a1); foreach (DataRow dados1 in ds1.Tables[0].Rows) { if (Convert.ToInt32(dados1["mot_publicacoes"]) >= 5 && Convert.ToString(dados1["tip_descricao"]) == "Free") { ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModalLimite();", true); } else { if (Convert.ToDateTime(txtDataInicio.Text + " " + txtHoraPartida.Text) > Convert.ToDateTime(txtDataFim.Text + " " + txtHoraRetorno.Text)) { ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModalSET();", true); } else if (Convert.ToDateTime(txtDataFim.Text + " " + txtHoraRetorno.Text) < DateTime.Now) { ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModalSETN();", true); } else { DateTime data = DateTime.Now; hdf.Value = Session["value"].ToString(); mot_motorista mot = new mot_motorista(); DataSet codigo = new DataSet(); codigo = mot_motoristaDB.SelectID(Convert.ToInt32(hdf.Value)); mot.Mot_id = Convert.ToInt32(codigo.Tables[0].Rows[0][0]); int a = Convert.ToInt32(codigo.Tables[0].Rows[0][0]); DataSet ds = mot_motoristaDB.SelectCon(a); DataSet dsp = mot_motoristaDB.SelectPublicacoes(mot.Mot_id); foreach (DataRow dados in dsp.Tables[0].Rows) { int publicacoes = Convert.ToInt32(dados["mot_publicacoes"]); publicacoes++; mot.Mot_publicacoes = publicacoes; mot_motoristaDB.UpdatePublicacoes(mot); } int qtd = ds.Tables[0].Rows.Count; ser_servicos serv = new ser_servicos(); con_condutor con = new con_condutor(); tra_transporte tra = new tra_transporte(); if (ddlTransporte.SelectedIndex != 0) { tra.Tra_id = Convert.ToInt32(ddlTransporte.SelectedValue); serv.Tra_id = tra; serv.Ser_datacadastro = data; serv.Ser_origem = txtOrigem.Text; serv.Ser_destino = txtDestino.Text; serv.Ser_descricao = txtDescricao.Text; serv.Ser_datafim = Convert.ToDateTime(txtDataFim.Text + " " + txtHoraRetorno.Text); serv.Ser_datainicio = Convert.ToDateTime(txtDataInicio.Text + " " + txtHoraPartida.Text); serv.Ser_lugares = Convert.ToInt32(txtLugares.Text); serv.Mot_id = mot; switch (ser_servicosDB.Insert(serv)) { case 0: ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModalSS();", true); //lblMsg.Text = "Cadastrado com sucesso"; break; case -2: //lblMsg.Text = "ERRO"; ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModalSE();", true); break; } string descricao = txtDescricao.Text; DataSet id = new DataSet(); id = ser_servicosDB.SelectID(descricao); serv.Ser_id = Convert.ToInt32(id.Tables[0].Rows[0][0]); sco_servicoscondutor sco = new sco_servicoscondutor(); if (ddlCondutor.SelectedIndex != 0) { con.Con_id = Convert.ToInt32(ddlCondutor.SelectedValue); sco.Con_id = con; sco.Ser_id = serv; sco_servicoscondutorDB.Insert(sco); } txtOrigem.Text = ""; txtDestino.Text = ""; txtDataFim.Text = ""; txtDescricao.Text = ""; txtDataInicio.Text = ""; txtLugares.Text = ""; txtHoraPartida.Text = ""; txtHoraRetorno.Text = ""; } else { Label3.Visible = true; } } } } } }