예제 #1
0
        public void Insert(CS_TBCostFormation tcs)
        {
            try
            {
                string sql = @"INSERT INTO CS_TBCostFormation (Id, Id_Offer, OfferNo, SumIpiIcms, PIS,
                                            COFINS, ICMS, Freight, IPI, Comission, DF_Percent, DV_Percent,
                                            Margin, MarginVariable, ISS, IR, CSLL, Markup, TotalMarkup,
                                            TotalSimulation, TBCreated, TBModified, TBCreatedID, Item) VALUES (" +
                             $"{tcs.Id}, {tcs.Id_Offer}, '{tcs.OfferNo}', '{tcs.SumIpiIcms}', " +
                             $"{tcs.PIS.ToString().Replace(",", ".")}, {tcs.COFINS.ToString().Replace(",", ".")}, " +
                             $"{tcs.ICMS.ToString().Replace(",", ".")}, {tcs.Freight.ToString().Replace(",", ".")}, " +
                             $"{tcs.IPI.ToString().Replace(",", ".")}, {tcs.Comission.ToString().Replace(",", ".")}, " +
                             $"{tcs.DF_Percent.ToString().Replace(",", ".")}, {tcs.DV_Percent.ToString().Replace(",", ".")}, " +
                             $"{tcs.Margin.ToString().Replace(",", ".")}, {tcs.MarginVariable.ToString().Replace(",", ".")}, " +
                             $"{tcs.ISS.ToString().Replace(",", ".")}, {tcs.IR.ToString().Replace(",", ".")}, " +
                             $"{tcs.CSLL.ToString().Replace(",", ".")}, {tcs.Markup.ToString().Replace(",", ".")}, " +
                             $"{tcs.TotalMarkup.ToString().Replace(",", ".")}, {tcs.TotalSimulation.ToString().Replace(",", ".")}, " +
                             $"'{tcs.TBCreated}', '{tcs.TBModified}', {tcs.TBCreatedID}, '{tcs.Item}'" +
                             ")";

                conn.Open();
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.ExecuteNonQuery();
                conn.Close();
            }
            catch (Exception ex)
            {
                conn.Close();
                throw ex;
            }
        }
예제 #2
0
        public CS_TBCostFormation GetAllWithParams(int idOffer, string offerNo, string item)
        {
            try
            {
                string sql = $"SELECT * FROM CS_TBCostFormation WHERE Id_Offer = {idOffer} AND OfferNo = '{offerNo}' AND Item = '{item}'";
                conn.Open();
                SqlCommand    cmd    = new SqlCommand(sql, conn);
                SqlDataReader reader = cmd.ExecuteReader();
                reader.Read();
                if (reader.HasRows)
                {
                    CS_TBCostFormation tcs = new CS_TBCostFormation();
                    tcs.Id              = Convert.ToInt32(reader["Id"]);
                    tcs.Id_Offer        = Convert.ToInt32(reader["Id_Offer"]);
                    tcs.OfferNo         = reader["OfferNo"].ToString();
                    tcs.Item            = reader["Item"].ToString();
                    tcs.SumIpiIcms      = reader["SumIpiIcms"].ToString();
                    tcs.PIS             = string.IsNullOrEmpty(reader["PIS"].ToString()) ? 0 : Convert.ToDouble(reader["PIS"]);
                    tcs.COFINS          = string.IsNullOrEmpty(reader["COFINS"].ToString()) ? 0 : Convert.ToDouble(reader["COFINS"]);
                    tcs.ICMS            = string.IsNullOrEmpty(reader["ICMS"].ToString()) ? 0 : Convert.ToDouble(reader["ICMS"]);
                    tcs.Freight         = string.IsNullOrEmpty(reader["Freight"].ToString()) ? 0 : Convert.ToDouble(reader["Freight"]);
                    tcs.Comission       = string.IsNullOrEmpty(reader["Comission"].ToString()) ? 0 : Convert.ToDouble(reader["Comission"]);
                    tcs.IPI             = string.IsNullOrEmpty(reader["IPI"].ToString()) ? 0 : Convert.ToDouble(reader["IPI"]);
                    tcs.DF_Percent      = string.IsNullOrEmpty(reader["DF_Percent"].ToString()) ? 0 : Convert.ToDouble(reader["DF_Percent"]);
                    tcs.DV_Percent      = string.IsNullOrEmpty(reader["DV_Percent"].ToString()) ? 0 : Convert.ToDouble(reader["DV_Percent"]);
                    tcs.Margin          = string.IsNullOrEmpty(reader["Margin"].ToString()) ? 0 : Convert.ToDouble(reader["Margin"]);
                    tcs.MarginVariable  = string.IsNullOrEmpty(reader["MarginVariable"].ToString()) ? 0 : Convert.ToDouble(reader["MarginVariable"]);
                    tcs.ISS             = string.IsNullOrEmpty(reader["ISS"].ToString()) ? 0 : Convert.ToDouble(reader["ISS"]);
                    tcs.IR              = string.IsNullOrEmpty(reader["IR"].ToString()) ? 0 : Convert.ToDouble(reader["IR"]);
                    tcs.CSLL            = string.IsNullOrEmpty(reader["CSLL"].ToString()) ? 0 : Convert.ToDouble(reader["CSLL"]);
                    tcs.Markup          = string.IsNullOrEmpty(reader["Markup"].ToString()) ? 0 : Convert.ToDouble(reader["Markup"]);
                    tcs.TotalMarkup     = string.IsNullOrEmpty(reader["TotalMarkup"].ToString()) ? 0 : Convert.ToDouble(reader["TotalMarkup"]);
                    tcs.TotalSimulation = string.IsNullOrEmpty(reader["TotalSimulation"].ToString()) ? 0 : Convert.ToDouble(reader["TotalSimulation"]);
                    conn.Close();

                    return(tcs);
                }
                else
                {
                    conn.Close();
                    return(null);
                }
            }
            catch (Exception ex)
            {
                conn.Close();
                throw ex;
            }
        }
예제 #3
0
        private void BtnSaveAll_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //if (serviceCQ.ExistCostFormation(int.Parse(txtCustQuotaId.Text), cbItemGrid.Text))
                //{
                //    MessageBox.Show("Já existe formação de custo para a simulãção selecionada!", "Aviso", MessageBoxButton.OK, MessageBoxImage.Warning);
                //    ClearFields();
                //    return;
                //}

                if (!serviceCompOp.ExistData(Convert.ToInt32(txtCustQuotaId.Text), cbItemGrid.Text))
                {
                    MessageBox.Show("Não existe simulação para o item da oferta selecionada!", "Aviso", MessageBoxButton.OK, MessageBoxImage.Warning);
                    ClearFields();
                    return;
                }


                // calculo da formação de custo
                int    id   = Convert.ToInt32(txtCustQuotaId.Text);
                string item = cbItemGrid.Text;
                CalculateFieldsView(Convert.ToDouble(unitValue));
                double?costValue = Convert.ToDouble(txtTotalMarkup.Text);
                if (serviceCQ.UpdateCostFormationCustQuatas(id, costValue))
                {
                    try
                    {
                        if (tcsService.GetAllWithParams(Convert.ToInt32(txtCustQuotaId.Text), txtSelectItem.Text, cbItemGrid.Text) != null)
                        {
                            MessageBoxResult resultMessage = MessageBox.Show("Já existem dados salvos para essa formação de custo! Deseja sobrescrever os dados?", "Pergunta",
                                                                             MessageBoxButton.YesNo, MessageBoxImage.Question);
                            if (resultMessage == MessageBoxResult.Yes)
                            {
                                tcsService.DeleteData(Convert.ToInt32(txtCustQuotaId.Text), txtSelectItem.Text, cbItemGrid.Text);

                                CS_TBCostFormation tcs = new CS_TBCostFormation();
                                tcs.Id       = tcsService.GetMaxId();
                                tcs.Id_Offer = Convert.ToInt32(txtCustQuotaId.Text);
                                tcs.OfferNo  = txtSelectItem.Text;
                                tcs.Item     = cbItemGrid.Text;
                                if (ckSumIcmsIpi.IsChecked == true)
                                {
                                    tcs.SumIpiIcms = "1";
                                }
                                else
                                {
                                    tcs.SumIpiIcms = "0";
                                }
                                tcs.PIS             = string.IsNullOrEmpty(txtPis.Text) ? 0 : Convert.ToDouble(txtPis.Text);
                                tcs.COFINS          = string.IsNullOrEmpty(txtCofins.Text) ? 0 : Convert.ToDouble(txtCofins.Text);
                                tcs.ICMS            = string.IsNullOrEmpty(txtIcms.Text) ? 0 : Convert.ToDouble(txtIcms.Text);
                                tcs.Freight         = string.IsNullOrEmpty(txtFreightValue.Text) ? 0 : Convert.ToDouble(txtFreightValue.Text);
                                tcs.Comission       = string.IsNullOrEmpty(txtComissions.Text) ? 0 : Convert.ToDouble(txtComissions.Text);
                                tcs.IPI             = string.IsNullOrEmpty(txtIpi.Text) ? 0 : Convert.ToDouble(txtIpi.Text);
                                tcs.DF_Percent      = string.IsNullOrEmpty(txtFixedExpenses.Text) ? 0 : Convert.ToDouble(txtFixedExpenses.Text);
                                tcs.DV_Percent      = string.IsNullOrEmpty(txtVariableExpenses.Text) ? 0 : Convert.ToDouble(txtVariableExpenses.Text);
                                tcs.Margin          = string.IsNullOrEmpty(txtMargin.Text) ? 0 : Convert.ToDouble(txtMargin.Text);
                                tcs.MarginVariable  = string.IsNullOrEmpty(txtVariableMargin.Text) ? 0 : Convert.ToDouble(txtVariableMargin.Text);
                                tcs.ISS             = string.IsNullOrEmpty(txtISS.Text) ? 0 : Convert.ToDouble(txtISS.Text);
                                tcs.IR              = string.IsNullOrEmpty(txtIR.Text) ? 0 : Convert.ToDouble(txtIR.Text);
                                tcs.CSLL            = string.IsNullOrEmpty(txtCSLL.Text) ? 0 : Convert.ToDouble(txtCSLL.Text);
                                tcs.Markup          = string.IsNullOrEmpty(txtMarkup.Text) ? 0 : Convert.ToDouble(txtMarkup.Text);
                                tcs.TotalMarkup     = string.IsNullOrEmpty(txtTotalMarkup.Text) ? 0 : Convert.ToDouble(txtTotalMarkup.Text);
                                tcs.TotalSimulation = string.IsNullOrEmpty(txtTotalSimulation.Text) ? 0 : Convert.ToDouble(txtTotalSimulation.Text);
                                tcs.TBCreated       = DateTime.Now;
                                tcs.TBModified      = DateTime.Now;
                                tcs.TBCreatedID     = 1;

                                tcsService.Insert(tcs);
                            }
                            else
                            {
                            }
                        }
                        else
                        {
                            CS_TBCostFormation tcs = new CS_TBCostFormation();
                            tcs.Id       = tcsService.GetMaxId();
                            tcs.Id_Offer = Convert.ToInt32(txtCustQuotaId.Text);
                            tcs.OfferNo  = txtSelectItem.Text;
                            tcs.Item     = cbItemGrid.Text;
                            if (ckSumIcmsIpi.IsChecked == true)
                            {
                                tcs.SumIpiIcms = "1";
                            }
                            else
                            {
                                tcs.SumIpiIcms = "0";
                            }
                            tcs.PIS             = string.IsNullOrEmpty(txtPis.Text) ? 0 : Convert.ToDouble(txtPis.Text);
                            tcs.COFINS          = string.IsNullOrEmpty(txtCofins.Text) ? 0 : Convert.ToDouble(txtCofins.Text);
                            tcs.ICMS            = string.IsNullOrEmpty(txtIcms.Text) ? 0 : Convert.ToDouble(txtIcms.Text);
                            tcs.Freight         = string.IsNullOrEmpty(txtFreightValue.Text) ? 0 : Convert.ToDouble(txtFreightValue.Text);
                            tcs.Comission       = string.IsNullOrEmpty(txtComissions.Text) ? 0 : Convert.ToDouble(txtComissions.Text);
                            tcs.IPI             = string.IsNullOrEmpty(txtIpi.Text) ? 0 : Convert.ToDouble(txtIpi.Text);
                            tcs.DF_Percent      = string.IsNullOrEmpty(txtFixedExpenses.Text) ? 0 : Convert.ToDouble(txtFixedExpenses.Text);
                            tcs.DV_Percent      = string.IsNullOrEmpty(txtVariableExpenses.Text) ? 0 : Convert.ToDouble(txtVariableExpenses.Text);
                            tcs.Margin          = string.IsNullOrEmpty(txtMargin.Text) ? 0 : Convert.ToDouble(txtMargin.Text);
                            tcs.MarginVariable  = string.IsNullOrEmpty(txtVariableMargin.Text) ? 0 : Convert.ToDouble(txtVariableMargin.Text);
                            tcs.ISS             = string.IsNullOrEmpty(txtISS.Text) ? 0 : Convert.ToDouble(txtISS.Text);
                            tcs.IR              = string.IsNullOrEmpty(txtIR.Text) ? 0 : Convert.ToDouble(txtIR.Text);
                            tcs.CSLL            = string.IsNullOrEmpty(txtCSLL.Text) ? 0 : Convert.ToDouble(txtCSLL.Text);
                            tcs.Markup          = string.IsNullOrEmpty(txtMarkup.Text) ? 0 : Convert.ToDouble(txtMarkup.Text);
                            tcs.TotalMarkup     = string.IsNullOrEmpty(txtTotalMarkup.Text) ? 0 : Convert.ToDouble(txtTotalMarkup.Text);
                            tcs.TotalSimulation = string.IsNullOrEmpty(txtTotalSimulation.Text) ? 0 : Convert.ToDouble(txtTotalSimulation.Text);
                            tcs.TBCreated       = DateTime.Now;
                            tcs.TBModified      = DateTime.Now;
                            tcs.TBCreatedID     = 1;

                            tcsService.Insert(tcs);
                        }
                    }
                    catch (Exception exc)
                    {
                        MessageBox.Show("Erro ao salvar dados completos da formação de custo" + "\n" + exc.Message, "Erro", MessageBoxButton.OK, MessageBoxImage.Error);
                    }

                    MessageBox.Show($"Formação de Custo (R$ { Math.Round(Convert.ToDouble(costValue), 2) }) e Simulação de Engenharia de Produtos salva com sucesso!",
                                    "Informação", MessageBoxButton.OK, MessageBoxImage.Information);
                    MessageBoxResult resultDialog = MessageBox.Show("Deseja realizar outra simulação?", "Pergunta",
                                                                    MessageBoxButton.YesNo, MessageBoxImage.Question);
                    if (resultDialog == MessageBoxResult.Yes)
                    {
                        ClearFields();
                    }
                    else
                    {
                        Environment.Exit(0);
                    }
                }
                else
                {
                    MessageBox.Show("Não existe dados!", "Aviso", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " - " + ex.StackTrace,
                                "Erro", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }