private bool ReadDETFile(ref string ErrMSG) { //Check the file if exist if ((string.IsNullOrEmpty(DETFilePath)) || (!File.Exists(DETFilePath))) { ErrMSG = "File not found (" + DETFilePath + ") !"; return(false); } //**** Datei einlesen **** DETdata = new DET(); using (StreamReader r = new StreamReader(DETFilePath)) { try { string json = r.ReadToEnd(); DETdata = JsonConvert.DeserializeObject <DET>(json); } catch { ErrMSG = "Error during file read! " + "(" + DETFilePath + ")"; return(false); } } // Return value return(true); }
/* * public static List<DetalleDocumento> GetDetalleFromMove(int moveId) * { * List<DetalleDocumento> DetallesToRetrieve = new List<DetalleDocumento>(); * * MySqlConnection connection = null; * * connection = new MySqlConnection(ConnectionConfig.connectionString); * Console.WriteLine(ConnectionConfig.connectionString); * MySqlCommand command = connection.CreateCommand(); * command.CommandText = "SELECT " + * "it_tdetamove.Move_Deta_ITEM_ID, " + * "it_titem.ITEM_Sale_Price, " + * "it_titem.ITEM_Description, " + * "it_tdetamove.Move_Deta_price, " + * "it_tdetamove.Move_Deta_price, " + * "it_tdetamove.Move_Deta_Q, " + * "it_tunit.UNIT_Name, " + * //"# Cosas para sacar el descuento " + * "it_tdetamove.On_Sale, " + * "it_tdetamove.Discount_Code, " + * "it_tdetamove.Move_REG_price, " + * //"# it_tdetamove.Move_Deta_price - it_tdetamove.Move_REG_price " + * "it_tdetamove.Move_Deta_Tax_Value, " + * "it_tdetamove.Move_Deta_Tax2_Value, " + * "(it_tdetamove.Move_Deta_Q * it_titem.ITEM_Sale_Price) AS 'Total', " + * "(it_tdetamove.Move_Deta_Q * it_titem.ITEM_Sale_Price) -it_tdetamove.Move_Deta_Tax_Value-it_tdetamove.Move_Deta_Tax2_Value AS 'Suma' " + * "FROM it_tdetamove " + * "INNER JOIN it_titem ON it_tdetamove.Move_Deta_ITEM_ID = it_titem.ITEM_ID " + * "INNER JOIN it_tunit ON it_tunit.UNIT_ID = it_titem.ITEM_Unit_ID " + * "WHERE it_tdetamove.modi = 0 " + * "AND it_tdetamove.Subitem_of = 0 " + * "AND it_tdetamove.Move_Deta_Move_ID = " + moveId + ";"; * MySqlDataReader Reader; * Console.WriteLine(command.CommandText); * connection.Open(); * Reader = command.ExecuteReader(); * int i = 0; * while (Reader.Read()) * { * string Move_Deta_ID = Reader.GetString("Move_Deta_ITEM_ID"); * string Descripcion = Reader.GetString("ITEM_Description"); * decimal PrecioUnitario = Reader.GetInt32("Move_Deta_price"); * decimal PrecioReferencial = Reader.GetInt32("Move_Deta_price"); * decimal Cantidad = Reader.GetInt32("Move_Deta_Q"); * string UnidadMedida = Reader.GetString("UNIT_Name"); * //AQUI CALCULA * decimal Descuento = Reader.GetInt32("Move_Deta_Q"); * * decimal Impuesto = Reader.GetInt32("Move_Deta_Tax_Value"); * decimal OtroImpuesto = Reader.GetInt32("Move_Deta_Tax2_Value"); * decimal TotalVenta = Reader.GetInt32("Total"); * decimal Suma = Reader.GetInt32("Suma"); * * DetalleDocumento deta = new DetalleDocumento() * { * Id = i++, * CodigoItem = Move_Deta_ID, * Descripcion = Descripcion, * PrecioUnitario = PrecioUnitario, * PrecioReferencial = PrecioReferencial, * TipoPrecio = "01: Precio unitario Incluye IGV", * Cantidad = Cantidad, * * UnidadMedida = UnidadMedida, * Descuento = Descuento, * Impuesto = Impuesto, //IGV * TipoImpuesto = "10: Gravado - Operación Onerosa", * //ImpuestoSelectivo = 1.0m, //ISC * OtroImpuesto = OtroImpuesto, // RC * TotalVenta = TotalVenta, * Suma = Suma, // precio unitario * cantidad * }; * DetallesToRetrieve.Add(deta); * } * * Reader.Close(); * * return DetallesToRetrieve; * }*/ public static DetasPlusTaxes GetDETFromMove(int moveId) { DetasPlusTaxes detasPlusTaxes = new DetasPlusTaxes(); List <DET> DetallesToRetrieve = new List <DET>(); decimal grabadas = 0.0m; decimal nograbadas = 0.0m; decimal exoneradas = 0.0m; decimal gratuitas = 0.0m; MySqlConnection connection = null; connection = new MySqlConnection(ConnectionConfig.connectionString); Console.WriteLine(ConnectionConfig.connectionString); MySqlCommand command = connection.CreateCommand(); command.CommandText = "SELECT " + "it_tdetamove.Move_Deta_ITEM_ID, " + "it_titem.ITEM_Sale_Price, " + "it_titem.ITEM_Description, " + "it_tdetamove.Move_Deta_price, " + "it_tdetamove.Move_Deta_price, " + "it_tdetamove.Move_Deta_Q, " + "it_tunit.UNIT_Name, " + //"# Cosas para sacar el descuento " + "it_tdetamove.On_Sale, " + "it_tdetamove.Discount_Code, " + "it_tdetamove.Move_REG_price, " + "it_tdetamove.Discount_Code, " + "it_tcategory.TAXPERC, " + "it_tcategory.TAXPERC2, " + "it_tcategory.TAXPERC3," + //"# it_tdetamove.Move_Deta_price - it_tdetamove.Move_REG_price " + "it_tdetamove.Move_Deta_Tax_Value, " + "it_tdetamove.Move_Deta_Tax2_Value, " + "(it_tdetamove.Move_Deta_Q * it_titem.ITEM_Sale_Price) AS 'Total', " + "(it_tdetamove.Move_Deta_Q * it_titem.ITEM_Sale_Price) -it_tdetamove.Move_Deta_Tax_Value-it_tdetamove.Move_Deta_Tax2_Value AS 'Suma' " + "FROM it_tdetamove " + "INNER JOIN it_titem ON it_tdetamove.Move_Deta_ITEM_ID = it_titem.ITEM_ID " + "INNER JOIN it_tunit ON it_tunit.UNIT_ID = it_titem.ITEM_Unit_ID " + "INNER JOIN it_tcategory ON it_tcategory.Cate_ID = it_titem.ITEM_Cate_ID " + "WHERE it_tdetamove.modi = 0 " + "AND it_tdetamove.Subitem_of = 0 " + "AND it_tdetamove.Move_Deta_Move_ID = " + moveId + ";"; MySqlDataReader Reader; Console.WriteLine(command.CommandText); connection.Open(); Reader = command.ExecuteReader(); int i = 0; while (Reader.Read()) { string Move_Deta_ID = Reader.GetString("Move_Deta_ITEM_ID"); string Descripcion = Reader.GetString("ITEM_Description"); decimal PrecioUnitario = Reader.GetInt32("Move_Deta_price"); decimal PrecioReferencial = Reader.GetInt32("Move_Deta_price"); decimal Cantidad = Reader.GetInt32("Move_Deta_Q"); string UnidadMedida = Reader.GetString("UNIT_Name"); //AQUI CALCULA decimal Descuento = Reader.GetInt32("Move_Deta_Q"); string DiscountCode = HelpersDatabase.GetString(Reader, "Discount_Code"); decimal Impuesto = Reader.GetInt32("Move_Deta_Tax_Value"); decimal OtroImpuesto = Reader.GetInt32("Move_Deta_Tax2_Value"); decimal TotalVenta = Reader.GetInt32("Total"); decimal Suma = Reader.GetInt32("Suma"); decimal TAX1 = HelpersDatabase.GetDecimal(Reader, "TAXPERC"); decimal TAX2 = HelpersDatabase.GetDecimal(Reader, "TAXPERC2"); decimal TAX3 = HelpersDatabase.GetDecimal(Reader, "TAXPERC3"); if (!string.IsNullOrEmpty(DiscountCode)) { if (CheckDicountCode(DiscountCode)) { gratuitas = TotalVenta; } } else if (TAX1 == 0.0m) { grabadas = TotalVenta; } else { nograbadas = TotalVenta; }/* * else if (TAX3 == 0.0m) * { * exoneradas++; * }*/ DET dET = new DET() { numeroItem = i++.ToString(), codigoProducto = Move_Deta_ID, descripcionProducto = Descripcion, cantidadItems = Cantidad.ToString(), unidad = UnidadMedida, valorUnitario = PrecioUnitario.ToString(), precioVentaUnitario = PrecioUnitario.ToString(), totalImpuestos = new List <TotalImpuesto>() { new TotalImpuesto() { idImpuesto = "1000", montoImpuesto = Impuesto.ToString(), tipoAfectacion = "10" }, //IGV new TotalImpuesto() { idImpuesto = "2000", montoImpuesto = OtroImpuesto.ToString(), tipoAfectacion = "10" }, //RC }, valorVenta = TotalVenta.ToString(), }; DetallesToRetrieve.Add(dET); } Reader.Close(); detasPlusTaxes = new DetasPlusTaxes() { grabadas = grabadas, gratuitas = gratuitas, exoneradas = exoneradas, nograbada = nograbadas, DET = DetallesToRetrieve }; return(detasPlusTaxes); }
private void btnSalvar_Click(object sender, EventArgs e) { decimal totalIpi = 0; decimal totalICms = 0; decimal totalpis = 0; decimal totalCofins = 0; string dataEmissao = mskDtVenda.Text.Trim(); int numeroNota = Convert.ToInt32(txtNunNota.Text.Trim()); string modeloNota = "55"; string serie = txtSerie.Text; string finalidadeNota = comboBox1.SelectedIndex.ToString(); int cadastro = Convert.ToInt32(txtcodFornecedor.Text.Trim()); string cfop = txtCodCfod.Text.Trim(); string nfeReferenciada = txtNFEreferenciada.Text.Trim(); decimal subtotal = Convert.ToDecimal(txtsomaTudo.Text.Trim()); decimal desconto = Convert.ToDecimal(txtSomaDesconto.Text.Trim()); decimal totaldaNotacomdesconto = Convert.ToDecimal(txtCdesconto.Text.Trim()); string obsNota = txtObs.Text.Trim(); string transportador; if (txtCodTransp.Text == string.Empty) { transportador = "0"; } else { transportador = txtCodTransp.Text.Trim(); } string vencimento = txtVenc.Text; string updateNota = "update nota set not_dtemissao = @not_dtemissao, not_numero = @not_numero, not_modelo = @not_modelo, not_serie = not_serie, not_finalidade = @not_finalidade," + "cadastro = @cadastro, cfo_codigo = @cfo_codigo, not_referenciada = @not_referenciada, not_subtotal = @not_subtotal, not_desconto = @not_desconto, not_nfetotal = @not_nfetotal," + "not_obs = @not_obs, cod_forncedor = @cad_fornecedor, not_vencimento = @not_vencimento, not_cancelada = @not_cancelada, not_inutilizada = @not_inutilizada, not_peso = @not_peso," + "not_volume = @not_volume, not_marca = @not_marca, not_icmsbase = @not_icmsbase, not_icmsvalor = @not_icmsvalor, not_icmspercentual = @not_icmspercentual," + "not_icmsstvalor = @not_icmsstvalor where not_codigo = " + txtControle.Text; SqlConnection con = new SqlConnection(); con.ConnectionString = utils.ConexaoDb(); SqlCommand cmd = new SqlCommand(updateNota, con); cmd.CommandType = CommandType.Text; cmd.Parameters.Add("@not_dtemissao", SqlDbType.NVarChar).Value = dataEmissao; cmd.Parameters.Add("@not_numero", SqlDbType.Int).Value = numeroNota; cmd.Parameters.Add("@not_modelo", SqlDbType.NVarChar).Value = modeloNota; cmd.Parameters.Add("@not_serie", SqlDbType.NVarChar).Value = serie; cmd.Parameters.Add("@not_finalidade", SqlDbType.NVarChar).Value = finalidadeNota; cmd.Parameters.Add("@cadastro", SqlDbType.Int).Value = cadastro; cmd.Parameters.Add("@cfo_codigo", SqlDbType.Int).Value = cfop; cmd.Parameters.Add("@not_referenciada", SqlDbType.NVarChar).Value = nfeReferenciada; cmd.Parameters.Add("@not_subtotal", SqlDbType.Decimal).Value = subtotal; cmd.Parameters.Add("@not_desconto", SqlDbType.Decimal).Value = desconto; cmd.Parameters.Add("@not_nfetotal", SqlDbType.Decimal).Value = totaldaNotacomdesconto; cmd.Parameters.Add("@not_obs", SqlDbType.NVarChar).Value = obsNota; cmd.Parameters.Add("@cad_fornecedor", SqlDbType.Int).Value = transportador; cmd.Parameters.Add("@not_vencimento", SqlDbType.NVarChar).Value = vencimento; cmd.Parameters.Add("@not_cancelada", SqlDbType.Int).Value = 0; cmd.Parameters.Add("@not_inutilizada", SqlDbType.Int).Value = 0; cmd.Parameters.Add("@not_peso", SqlDbType.NVarChar).Value = 1; cmd.Parameters.Add("@not_volume", SqlDbType.NVarChar).Value = 1; cmd.Parameters.Add("@not_marca", SqlDbType.NVarChar).Value = "marca"; cmd.Parameters.Add("@not_icmsbase", SqlDbType.Decimal).Value = 0; cmd.Parameters.Add("@not_icmsvalor", SqlDbType.Decimal).Value = 0; cmd.Parameters.Add("@not_icmspercentual", SqlDbType.Decimal).Value = 0; cmd.Parameters.Add("@not_icmsstvalor", SqlDbType.Decimal).Value = 0; con.Open(); try { int i = cmd.ExecuteNonQuery(); if (i > 0) { u.messageboxSucesso(); } var nfeContexto = new NFeContexto(false, NFeEletronica.Versao.NFeVersao.VERSAO_3_1_0, new GerenciadorDeCertificado()); var nota = new Nota(nfeContexto); nota.ide.cUF = "41"; nota.ide.natOp = txtDescCfop.Text; nota.ide.indPag = "0"; nota.ide.mod = "55"; nota.ide.serie = txtSerie.Text; //string ultimoReg = "Select not_codigo From nota where not_codigo = (Select MAX(not_numero) From nota)"; //SqlConnection con1 = new SqlConnection(); //con.ConnectionString = utils.ConexaoDb(); //SqlCommand cmd2 = new SqlCommand(ultimoReg, con1); //con.Open(); //SqlDataReader dR = cmd2.ExecuteReader(); //if (dR.Read()) //{ // txtNunNota.Text = 1 + dR[0].ToString(); //} //con.Close(); DataContext db = new DataContext(); var pessoa = db.Clientes.Find(Convert.ToInt32(txtcodFornecedor.Text.Trim())); var CidadeEstado = db.Cidades.Find(pessoa.CidadeCodigo); nota.ide.nNF = txtNunNota.Text; nota.ide.dEmi = mskDtVenda.Text; nota.ide.tpNF = "1"; //normal contingencia nota.ide.cMunFG = CidadeEstado.Ibge; nota.ide.tpImp = "1"; nota.ide.tpEmis = "1"; nota.ide.cDV = "0"; nota.ide.idDest = "1"; nota.ide.indFinal = "0"; nota.ide.indPres = "0"; nota.ide.tpAmb = "2"; nota.ide.finNFe = finalidadeNota; nota.ide.procEmi = "3";// soft utilizado // DataContext.fil_codigo = Convert.ToInt32(textBox3.Text.Trim()); var filial = db.Filiais.Find(DataContext.fil_codigo); nota.emit.CNPJ = filial.CpfCnpj; nota.emit.xNome = filial.Razao; nota.emit.xLgr = filial.Endereco; nota.emit.nro = filial.Numero; nota.emit.xBairro = filial.Bairro; var cidade = db.Cidades.Find(filial.CidadeCodigo); nota.emit.cMun = cidade.Ibge; nota.emit.xMun = cidade.Descricao; nota.emit.UF = cidade.UF; nota.emit.CEP = filial.Cep; nota.emit.cPais = "1058"; nota.emit.xPais = "Brasil"; nota.emit.fone = filial.Telefone; nota.emit.IE = filial.IE; nota.emit.CRT = "1"; //financeiro var dup = new NFeEletronica.NotaFiscal.DUP(); dup.nDup = "123"; dup.dVenc = "2014-03-21"; dup.vDup = "23.33"; nota.cobr.dup.Add(dup); //transportadora nota.transp.modFrete = "1"; nota.transp.xNome = "O Mesmo"; nota.transp.IE = "637322284114"; nota.transp.xEnder = "Rua ficticia, 123"; nota.transp.xMun = "São Lucas"; nota.transp.UF = "RO"; //produstos foreach (DataGridViewRow row in dataGridView1.Rows) { foreach (DataGridViewColumn column in dataGridView1.Columns) { var notaProduto = new DET(); notaProduto.cProd = row.Cells["Column1"].Value.ToString(); DataView dv = new DataView(DataContext.CarregaProdutos()); Produto produto = new Produto(); var produtoIncluir = db.Produtos.Find(Convert.ToInt32(notaProduto.cProd)); notaProduto.cEAN = produtoIncluir.EAN; notaProduto.xProd = produtoIncluir.Descricao; notaProduto.NCM = produtoIncluir.NCM; notaProduto.CFOP = Convert.ToString(produtoIncluir.CFOP); notaProduto.uCom = produtoIncluir.UnidadeMedida; notaProduto.qCom = row.Cells["Column2"].Value.ToString(); notaProduto.vUnCom = row.Cells["Column3"].Value.ToString(); notaProduto.vProd = row.Cells["Column4"].Value.ToString(); notaProduto.cEANTrib = produtoIncluir.EAN; notaProduto.uTrib = produtoIncluir.UnidadeMedida; notaProduto.qTrib = notaProduto.qCom; notaProduto.vUnTrib = notaProduto.vUnCom; notaProduto.indTot = "1"; switch (produtoIncluir.CstICMS) { case "00": notaProduto.icms = ICMS.ICMS00; break; case "10": notaProduto.icms = ICMS.ICMS10; break; case "20": notaProduto.icms = ICMS.ICMS20; break; case "30": notaProduto.icms = ICMS.ICMS30; break; case "40": notaProduto.icms = ICMS.ICMS40_50; break; case "41": notaProduto.icms = ICMS.ICMS40_50; break; case "50": notaProduto.icms = ICMS.ICMS40_50; break; case "51": notaProduto.icms = ICMS.ICMS51; break; case "60": notaProduto.icms = ICMS.ICMS60; break; case "70": notaProduto.icms = ICMS.ICMS70; break; case "90": notaProduto.icms = ICMS.ICMS90; break; case "101": notaProduto.icms = ICMS.ICMS101; break; case "102": notaProduto.icms = ICMS.ICMS102_400; break; case "103": notaProduto.icms = ICMS.ICMS102_400; break; case "201": notaProduto.icms = ICMS.ICMS201; break; case "202": notaProduto.icms = ICMS.ICMS202; break; case "500": notaProduto.icms = ICMS.ICMS500; break; case "900": notaProduto.icms = ICMS.ICMS900; break; default: notaProduto.icms = ICMS.ICMS00; break; } notaProduto.icms_orig = Convert.ToString(produtoIncluir.OrigemDoProduto); if (nota.emit.CRT == "1") { notaProduto.icms_CSOSN = produtoIncluir.CstICMS; } else { notaProduto.icms_CST = produtoIncluir.CstICMS; } notaProduto.ipi = IPI.IPI00_49_50_99; notaProduto.ipi_CST = "99"; notaProduto.ipi_vIPI = "0"; notaProduto.pis = PIS.PIS01_02; notaProduto.pis_CST = "01"; notaProduto.pis_vBC = "0"; notaProduto.pis_pPIS = "0"; notaProduto.pis_vPIS = "0"; notaProduto.cofins = COFINS.CST01_02; notaProduto.cofins_CST = "01"; notaProduto.cofins_vBC = "0"; notaProduto.cofins_pCOFINS = "0"; notaProduto.cofins_vCOFINS = "0"; nota.AddDet(notaProduto); } } //fim de um produto if (nota.emit.CRT == "1") { nota.total.vBC = "0.00"; } else { nota.total.vBC = Convert.ToString(totaldaNotacomdesconto); } nota.total.vICMS = "0.00"; nota.total.vICMSDeson = "0.00"; nota.total.vBCST = "0.00"; nota.total.vST = "0.00"; nota.total.vProd = "1.00"; nota.total.vFrete = "0.00"; nota.total.vSeg = "0.00"; nota.total.vDesc = "0.00"; nota.total.vII = "0.00"; nota.total.vIPI = "0.00"; nota.total.vPIS = "0.00"; nota.total.vCOFINS = "0.00"; nota.total.vOutro = "0.00"; nota.total.vNF = "1.00"; nota.total.vTotTrib = "0.00"; nota.SalvarNota(@"C:\temp\teste-nota.xml"); } catch (Exception ex) { u.messageboxErro(ex.ToString()); } finally { con.Close(); } Unovo(); }
private void Form1_Load(object sender, EventArgs e) { TextReader reader = File.OpenText("input.txt"); string text = reader.ReadLine(); string[] bits = text.Split(' '); int m, n; m = int.Parse(bits[0]); n = int.Parse(bits[1]); a = new double[m, n]; b = new double[n]; N = n; for (int i = 0; i < m; i++) { text = reader.ReadLine(); bits = text.Split(' '); for (int j = 0; j < n; j++) { double temp = double.Parse(bits[j]); a[i, j] = temp; } } text = reader.ReadLine(); text = reader.ReadLine(); bits = text.Split(' '); for (int i = 0; i < n; i++) { double temp = double.Parse(bits[i]); b[i] = temp; } this.dataGridViewMatrix.ColumnCount = n; for (int j = 0; j < n; j++) { DataGridViewColumn col = dataGridViewMatrix.Columns[j]; col.Width = 30; } DataGridViewRow row; for (int i = 0; i < m; i++) { row = new DataGridViewRow(); row.CreateCells(this.dataGridViewMatrix); for (int j = 0; j < n; j++) { row.Cells[j].Value = a[i, j]; } this.dataGridViewMatrix.Rows.Add(row); } row = new DataGridViewRow(); row.CreateCells(this.dataGridViewMatrix); this.dataGridViewMatrix.Rows.Add(row); row = new DataGridViewRow(); row.CreateCells(this.dataGridViewMatrix); for (int j = 0; j < n; j++) { row.Cells[j].Value = b[j]; } this.dataGridViewMatrix.Rows.Add(row); // Inverse Matrix double[,] aInv = Inv(a); this.dataGridViewInvMatrix.ColumnCount = N; for (int j = 0; j < N; j++) { DataGridViewColumn col = dataGridViewInvMatrix.Columns[j]; col.Width = 50; } for (int i = 0; i < N; i++) { row = new DataGridViewRow(); row.CreateCells(this.dataGridViewInvMatrix); for (int j = 0; j < N; j++) { row.Cells[j].Value = aInv[i, j]; } this.dataGridViewInvMatrix.Rows.Add(row); } // show a * aInv double[,] I = MultMatrix(a, aInv, N, N, N); this.dataGridViewIdentity.ColumnCount = N; for (int j = 0; j < N; j++) { DataGridViewColumn col = dataGridViewIdentity.Columns[j]; col.Width = 50; } for (int i = 0; i < N; i++) { row = new DataGridViewRow(); row.CreateCells(this.dataGridViewIdentity); for (int j = 0; j < N; j++) { row.Cells[j].Value = Math.Round(I[i, j], 1); } this.dataGridViewIdentity.Rows.Add(row); } double DET; DET = determinantOfMatrix(a, N); /*LUdecomp(a); * DET = 1; * for (int i = 0; i < N; i++) * DET *= a[i, i]; * DET = Math.Round(DET, 4);*/ labelDET.Text = DET.ToString(); double cond = MatrixNorm(a, N) * MatrixNorm(aInv, N); labelCond.Text = cond.ToString(); labelNorm.Text = MatrixNorm(a, N).ToString(); }