public void CarregarInformacoesProduto(string sCdProd) { if ((sCdProd == null) || (sCdProd.Equals(String.Empty))) { return; } RegistroAtual["CD_PROD"] = sCdProd; DataTable qryProduto = oTabelas.hlpDbFuncoes.qrySeekRet( "PRODUTO", "DS_DETALHE, DS_PROD, CD_SITTRIB, CD_TPUNID, " + "CD_CF, CD_ALIICMS, CD_ALTER", "(CD_PROD = '" + sCdProd + "')"); if (qryProduto.Rows.Count == 1) { DataRow RegProduto = qryProduto.Rows[0]; RegistroAtual["DS_PROD"] = RegProduto["DS_DETALHE"]; if ((RegistroAtual["DS_PROD"] == null) || (RegistroAtual["DS_PROD"].ToString().Trim().Equals(String.Empty))) { RegistroAtual["DS_PROD"] = RegProduto["DS_PROD"]; } RegistroAtual["CD_SITTRIB"] = RegProduto["CD_SITTRIB"]; RegistroAtual["CD_TPUNID"] = RegProduto["CD_TPUNID"]; RegistroAtual["CD_CF"] = RegProduto["CD_CF"]; RegistroAtual["CD_ALIICMS"] = RegProduto["CD_ALIICMS"]; RegistroAtual["CD_ALTER"] = RegProduto["CD_ALTER"]; } PreencheCdLista(); DataTable qryPrecos = oTabelas.hlpDbFuncoes.qrySeekRet( "PRECOS", "VL_PRECOVE", "(CD_PROD = '" + sCdProd + "') AND " + "(CD_LISTA = '" + RegistroAtual["CD_LISTA"].ToString() + "')"); if (qryPrecos.Rows.Count == 1) { RegistroAtual["VL_UNIPROD"] = qryPrecos.Rows[0]["VL_PRECOVE"]; } else { RegistroAtual["VL_UNIPROD"] = 0; } RegistroAtual["VL_ALIIPI"] = HlpFuncoesFaturamento.GetAliquotaIPI( RegistroAtual["CD_OPER"].ToString(), GetRegistroPai()["CD_CLIENTE"].ToString(), RegistroAtual["CD_CF"].ToString(), oTabelas); CalcularTotalItem(); }
protected void btnGravar_Click(object sender, EventArgs e) { try { UsuarioWeb objUsuario = (UsuarioWeb)Session["ObjetoUsuario"]; string sST_DESC = objUsuario.oTabelas.hlpDbFuncoes.qrySeekValue("EMPRESA", "ST_DESC", "CD_EMPRESA = '" + objUsuario.oTabelas.sEmpresa + "'"); string sTipoDocumentoPadrao = cbxDS_TPDOCWEB.SelectedValue.ToString(); string Doc = objUsuario.oTabelas.hlpDbFuncoes.qrySeekValue("TPDOC", "TP_DOC", "CD_TIPODOC='" + sTipoDocumentoPadrao + "'"); string sGenerator = "PEDIDO" + objUsuario.oTabelas.sEmpresa + Doc; if (!objUsuario.oTabelas.hlpDbFuncoes.VerificaExistenciaGenerator(sGenerator)) { int iIni = 0; switch (Doc) { case "PE": iIni = 0; break; case "NE": iIni = 1000000; break; case "NS": iIni = 1000000; break; case "CF": iIni = 2000000; break; case "PC": iIni = 9000000; break; case "OR": iIni = 8000000; break; default: throw new Exception("O generator " + sGenerator + " não existe"); } objUsuario.oTabelas.hlpDbFuncoes.CreateGenerator(sGenerator, iIni); } string sCD_PEDIDO = objUsuario.oTabelas.hlpDbFuncoes.RetornaProximoValorGenerator(sGenerator).PadLeft(7, '0'); string strConn = ConfigurationManager.ConnectionStrings["ConnectionStringFB"].ConnectionString.ToString(); FbConnection Conn = new FbConnection(strConn); FbCommand cmdSelectPed = new FbCommand(); cmdSelectPed.CommandText = "SP_INCLUI_PEDIDO_WEB"; cmdSelectPed.CommandType = CommandType.StoredProcedure; cmdSelectPed.Connection = Conn; Conn.Open(); cmdSelectPed.Parameters.Add("@SCD_EMPRESA", FbDbType.VarChar, 3).Value = objUsuario.oTabelas.sEmpresa.ToString(); cmdSelectPed.Parameters.Add("@SCD_VEND1", FbDbType.VarChar, 7).Value = objUsuario.CodigoVendedor.ToString(); cmdSelectPed.Parameters.Add("@SCD_PEDIDO", FbDbType.VarChar, 7).Value = sCD_PEDIDO; string strRetPedido = cmdSelectPed.ExecuteScalar().ToString(); Conn.Close(); if (strRetPedido != null) { StringBuilder strUpDatePed = new StringBuilder(); string sVL_TOTALPED = GridViewNovo.FooterRow.Cells[8].Text.Replace(".", ""); strUpDatePed.Append(" UPDATE PEDIDO SET CD_PEDIDO = '" + strRetPedido.Trim()); strUpDatePed.Append("', VL_TOTALPED = '" + sVL_TOTALPED.Replace(",", ".")); strUpDatePed.Append("', CD_CLIENTE = '" + txtCodCli.Text.Trim()); strUpDatePed.Append("', NM_GUERRA = '" + ((CliforDAO)(Session["ObjetoClienteDetalhado"])).RegistroAtual["NM_GUERRA"].ToString()); strUpDatePed.Append("', ST_DESC = '" + sST_DESC); strUpDatePed.Append("', NM_CLIFOR = '" + ((CliforDAO)(Session["ObjetoClienteDetalhado"])).RegistroAtual["NM_CLIFOR"].ToString()); strUpDatePed.Append("', DS_ENDNOR = '" + ((CliforDAO)(Session["ObjetoClienteDetalhado"])).RegistroAtual["DS_ENDNOR"].ToString()); strUpDatePed.Append("', NR_ENDNOR = '" + ((CliforDAO)(Session["ObjetoClienteDetalhado"])).RegistroAtual["NR_ENDNOR"].ToString()); strUpDatePed.Append("', NM_BAIRRONOR = '" + ((CliforDAO)(Session["ObjetoClienteDetalhado"])).RegistroAtual["NM_BAIRRONOR"].ToString()); strUpDatePed.Append("', NM_CIDNOR = '" + ((CliforDAO)(Session["ObjetoClienteDetalhado"])).RegistroAtual["NM_CIDNOR"].ToString()); strUpDatePed.Append("', CD_UFNOR = '" + ((CliforDAO)(Session["ObjetoClienteDetalhado"])).RegistroAtual["CD_UFNOR"].ToString()); strUpDatePed.Append("', ST_PESSOAJ = '" + ((CliforDAO)(Session["ObjetoClienteDetalhado"])).RegistroAtual["ST_PESSOAJ"].ToString()); if (((CliforDAO)(Session["ObjetoClienteDetalhado"])).RegistroAtual["ST_PESSOAJ"].ToString() == "S") { strUpDatePed.Append("', CD_CGCCPF = '" + ((CliforDAO)(Session["ObjetoClienteDetalhado"])).RegistroAtual["CD_CGC"].ToString()); strUpDatePed.Append("', CD_INSEST_RG = '" + ((CliforDAO)(Session["ObjetoClienteDetalhado"])).RegistroAtual["cd_insest"].ToString()); } else { strUpDatePed.Append("', CD_CGCCPF = '" + ((CliforDAO)(Session["ObjetoClienteDetalhado"])).RegistroAtual["CD_CPF"].ToString()); strUpDatePed.Append("', CD_INSEST_RG = '" + ((CliforDAO)(Session["ObjetoClienteDetalhado"])).RegistroAtual["CD_RG"].ToString()); } strUpDatePed.Append("', CD_CEPNOR = '" + ((CliforDAO)(Session["ObjetoClienteDetalhado"])).RegistroAtual["CD_CEPNOR"].ToString()); strUpDatePed.Append("', CD_FONENOR = '" + ((CliforDAO)(Session["ObjetoClienteDetalhado"])).RegistroAtual["CD_FONENOR"].ToString()); strUpDatePed.Append("', CD_FAXNOR = '" + ((CliforDAO)(Session["ObjetoClienteDetalhado"])).RegistroAtual["CD_FAXNOR"].ToString()); strUpDatePed.Append("', DT_PEDIDO = '" + txtDataPedido.Text.Replace("/", ".")); //strUpDatePed.Append("', DT_PEDIDO = '" + DateTime.Now.ToString().Replace("/", ".")); strUpDatePed.Append("', CD_TIPODOC = '" + sTipoDocumentoPadrao); strUpDatePed.Append("', CD_PRAZO = '" + cbxCD_PRAZO.SelectedItem.Value.Trim()); strUpDatePed.Append("', CD_TRANS = '" + objUsuario.oTabelas.TRANSP.ToString().Trim()); strUpDatePed.Append("', DS_OBS_WEB = '" + txtObs.Text.ToUpper().Trim()); strUpDatePed.Append("', DT_ABER = '" + txtDataPedido.Text.Replace("/", ".")); strUpDatePed.Append("', CD_USUINC ='" + objUsuario.oTabelas.CdUsuarioAtual); strUpDatePed.Append("', CD_VEND1 = '" + objUsuario.oTabelas.CdVendedorAtual + "'"); strUpDatePed.Append(" WHERE (CD_PEDIDO = '" + strRetPedido.Trim() + "') AND (CD_EMPRESA = '" + objUsuario.oTabelas.sEmpresa.Trim() + "')"); FbCommand cmdUpDatePedido = new FbCommand(strConn); cmdUpDatePedido.CommandText = strUpDatePed.ToString(); cmdUpDatePedido.CommandType = CommandType.Text; cmdUpDatePedido.Connection = Conn; Conn.Open(); int Ret = cmdUpDatePedido.ExecuteNonQuery(); Conn.Close(); if (Ret > 0) { Ret = 0; int iCountSeq = 1; foreach (GridViewRow row in GridViewNovo.Rows) { FbCommand cmdSelectMoviPend = new FbCommand(); cmdSelectMoviPend.CommandText = "SP_INCLUI_MOVITEM_WEB"; cmdSelectMoviPend.CommandType = CommandType.StoredProcedure; cmdSelectMoviPend.Connection = Conn; Conn.Open(); cmdSelectMoviPend.Parameters.Add("@SCD_EMPRESA", FbDbType.VarChar, 3).Value = objUsuario.oTabelas.sEmpresa.ToString(); cmdSelectMoviPend.Parameters.Add("@SCD_PEDIDO", FbDbType.VarChar, 7).Value = strRetPedido.Trim(); string strRetMoviPend = cmdSelectMoviPend.ExecuteScalar().ToString(); Conn.Close(); if (strRetMoviPend != null) { strUpDatePed.Length = 0; string sCD_LISTA = row.Cells[1].Text.Split('-')[1].ToString().Trim(); string sCD_PROD = row.Cells[1].Text.Split('-')[0].ToString().Trim(); TextBox txtQtde = (TextBox)row.Cells[8].FindControl("txtQtde"); string qtde = txtQtde.Text.Trim(); string CF = objUsuario.oTabelas.hlpDbFuncoes.qrySeekValue("PRODUTO", "CD_CF", "CD_PROD = '" + sCD_PROD + "'"); string UNID = objUsuario.oTabelas.hlpDbFuncoes.qrySeekValue("PRODUTO", "CD_TPUNID", "CD_PROD = '" + sCD_PROD + "'"); string CODICMS = objUsuario.oTabelas.hlpDbFuncoes.qrySeekValue("PRODUTO", "CD_ALIICMS", "CD_PROD = '" + sCD_PROD + "'"); string SITTRIB = objUsuario.oTabelas.hlpDbFuncoes.qrySeekValue("PRODUTO", "CD_SITTRIB", "CD_PROD = '" + sCD_PROD + "'"); string scdOper = objUsuario.oTabelas.hlpDbFuncoes.qrySeekValue("tpdoc", "substring(tpdoc.cd_operval from 1 for 3) cd_operval", "cd_tipodoc = '" + sTipoDocumentoPadrao + "'"); // OS. 28381 - Mário string scd_sittribOPEREVE = objUsuario.oTabelas.hlpDbFuncoes.qrySeekValue("OPEREVE", "cd_sittrib", "CD_OPER = '" + scdOper + "'"); // SITTRIB já está com o valor definido na tabela produto... if (!String.IsNullOrEmpty(scd_sittribOPEREVE)) { SITTRIB = scd_sittribOPEREVE; } //FIM OS. 28381 string sSittribipi = objUsuario.oTabelas.hlpDbFuncoes.qrySeekValue("OPEREVE", "cd_sittribipi", "CD_OPER = '" + scdOper + "'"); string sSittribpis = objUsuario.oTabelas.hlpDbFuncoes.qrySeekValue("OPEREVE", "cd_sittribpis", "CD_OPER = '" + scdOper + "'"); string sSittribcofins = objUsuario.oTabelas.hlpDbFuncoes.qrySeekValue("OPEREVE", "cd_sittribcof", "CD_OPER = '" + scdOper + "'"); string sTipoPrazo = objUsuario.oTabelas.hlpDbFuncoes.qrySeekValue("PRAZOS", "DS_FORMULA", "CD_PRAZO = '" + cbxCD_PRAZO.SelectedItem.Value.Trim() + "'"); #region Busca Valor % de comissão decimal dVL_PERCOMI1 = 0; dVL_PERCOMI1 = Convert.ToDecimal(objUsuario.oTabelas.hlpDbFuncoes.qrySeekValue("LISTAPRE", "COALESCE(LISTAPRE.VL_PERCOMI,0)", "CD_LISTA = '" + sCD_LISTA + "'")); #endregion #region Calcula Desconto Item string RecebeCoefDesc = objUsuario.oTabelas.hlpDbFuncoes.qrySeekValue("PRAZOS", "VL_COEF", "(CD_PRAZO = '" + cbxCD_PRAZO.SelectedItem.Value.Trim() + "')"); decimal dCOEFDESC = Convert.ToDecimal((RecebeCoefDesc.Equals(String.Empty) ? "1.0" : RecebeCoefDesc)); decimal dVL_UNIPROD = 0; decimal dVL_DESCONTO_VALOR = 0; decimal VlTotLiq = 0; dVL_UNIPROD = (Convert.ToDecimal(row.Cells[4].Text)); #endregion VlTotLiq = Decimal.Round((Convert.ToDecimal(qtde) * dVL_UNIPROD), 2); string sDS_PROD = objUsuario.oTabelas.hlpDbFuncoes.qrySeekValue("PRODUTO", "DS_PROD", "CD_EMPRESA = '" + objUsuario.oTabelas.sEmpresa.Trim() + "' AND CD_PROD ='" + sCD_PROD + "'"); string sCD_ALTER = objUsuario.oTabelas.hlpDbFuncoes.qrySeekValue("PRODUTO", "CD_ALTER", "CD_EMPRESA = '" + objUsuario.oTabelas.sEmpresa.Trim() + "' AND CD_PROD ='" + sCD_PROD + "'"); strUpDatePed.Append("UPDATE MOVITEM SET NR_LANC = '" + strRetMoviPend.Trim() + "', CD_PEDIDO = '" + strRetPedido.Trim() + "', DS_PROD = '" + sDS_PROD + "', "); strUpDatePed.Append("cd_clifor = '" + txtCodCli.Text.Trim() + "', "); strUpDatePed.Append("CD_VEND1 = '" + objUsuario.oTabelas.CdVendedorAtual + "', "); strUpDatePed.Append("CD_LISTA = '" + sCD_LISTA + "', CD_PROD = '" + sCD_PROD + "', CD_ALTER = '" + sCD_ALTER + "', "); strUpDatePed.Append("QT_SALDOEN = '" + qtde.Replace(".", "").Replace(",", ".") + "', "); strUpDatePed.Append("QT_PROD = '" + qtde.Replace(".", "").Replace(",", ".") + "', VL_UNIPROD_SEM_DESC = '" + dVL_UNIPROD.ToString().Replace(".", "").Replace(",", ".")); strUpDatePed.Append("', VL_TOTLIQ = '" + VlTotLiq.ToString().Replace(".", "").Replace(",", ".") + "'"); // adicionado o campo VL_UNIPROD_SEM_DESC strUpDatePed.Append(", VL_TOTBRUTO = '" + VlTotLiq.ToString().Replace(".", "").Replace(",", ".") + "'"); strUpDatePed.Append(", CD_SEQPED = '" + iCountSeq.ToString().PadLeft(2, '0') + "'"); strUpDatePed.Append(", VL_DESCONTO_VALOR = '" + dVL_DESCONTO_VALOR.ToString().Replace(".", "").Replace(",", ".") + "'"); strUpDatePed.Append(", VL_UNIPROD = '" + dVL_UNIPROD.ToString().Replace(".", "").Replace(",", ".") + "'"); strUpDatePed.Append(", CD_USUINC = '" + objUsuario.oTabelas.CdUsuarioAtual.ToString() + "', dt_doc ='" + txtDataPedido.Text.Replace("/", ".") + "', DT_LANC = '" + txtDataPedido.Text.Replace("/", ".") + "', CD_USUALT = '" + objUsuario.oTabelas.CdUsuarioAtual.ToString() + "', "); strUpDatePed.Append("CD_CF = '" + (CF.Equals(String.Empty) ? "0000000" : CF.Trim()) + "', CD_TPUNID = '" + UNID.Trim() + "', CD_ALIICMS = '" + CODICMS.Trim() + "', CD_SITTRIB = '" + SITTRIB.Trim() + "', VL_COEF = " + dCOEFDESC.ToString().Replace(",", ".") + ", "); //COEF.ToString().Replace(",", ".") + ", "); strUpDatePed.Append("VL_PERCOMI1 = '" + dVL_PERCOMI1.ToString().Replace(".", "").Replace(",", ".") + "', DT_PRAZOEN = '" + txtDataPedido.Text.Replace("/", ".") + "', "); strUpDatePed.Append("VL_ALIIPI = " + HlpFuncoesFaturamento.GetAliquotaIPI(objUsuario.oTabelas.GetOperacaoDefault("CD_OPER"), txtCodCli.Text.Trim(), CF, objUsuario.oTabelas) + ", "); strUpDatePed.Append("CD_OPER = '" + scdOper);//+ "', VL_PERENTR = " + 100 + " "); strUpDatePed.Append("' , cd_sittribipi = '" + sSittribipi + "', cd_sittribpis = '" + sSittribpis + "', cd_sittribcof = '" + sSittribcofins + "' "); strUpDatePed.Append(" WHERE (NR_LANC = '" + strRetMoviPend.Trim() + "') AND (CD_EMPRESA = '" + objUsuario.oTabelas.sEmpresa.Trim() + "')"); FbCommand cmdUpDateMoviPend = new FbCommand(); cmdUpDateMoviPend.CommandText = strUpDatePed.ToString(); cmdUpDateMoviPend.CommandType = CommandType.Text; cmdUpDateMoviPend.Connection = Conn; Conn.Open(); Ret = cmdUpDateMoviPend.ExecuteNonQuery(); Conn.Close(); } } if (Ret > 0) { //EnviarEmailPedido(strRetPedido); LimparSession(); Response.Redirect("~/Informativo.aspx?PARAMETERCODIGO=" + strRetPedido); } else { MessageHLP.ShowPopUpMsg("Cadastro não foi concluído!", this.Page); } } } } catch (Exception ex) { throw ex; } }