Ejemplo n.º 1
0
        private void LoadData()
        {
            int previouslySelectedPositionId = 0;

            if (this.selectedPosition != null)
            {
                previouslySelectedPositionId = this.selectedPosition.Id;
            }

            this.isLoadingData = true;

            this.LoadHeader();
            this.LoadLicensorsTab();
            this.LoadScheduleTab();

            tabControlAgreement.Enabled = (this.agreement.Id > 0) ? true : false;
            this.gridPositionsRepo.BindDataSet(gridExPositions, this.agreement.Id);

            if (gridExPositions.RowCount < 1)
            {
                this.selectedPosition = new AgreementPosition();
                this.LoadPositionDetails();
            }

            this.SetAgreementChangesPending(false);
            this.SetPositionChangesPending(false);
            this.isPositionAddPending = false;
            this.isLoadingData        = false;

            if (previouslySelectedPositionId > 0)
            {
                this.SelectPositionById(previouslySelectedPositionId);
            }
        }
Ejemplo n.º 2
0
        public static void InsertUpdate(AgreementPosition position)
        {
            using (SqlConnection dbConnection = new DBConnection().Connection)
            {
                string sqlQuery = "";

                if (position.Id > 0)
                {
                    sqlQuery = string.Format("UPDATE [PozycjaUmowy] " +
                                             "SET KTM = @ktm, Deskryptor = @deskryptor, ModelId = @modelId, WalutaId = @walutaId, PoczatekOkresuRozliczeniowego = @poczatekOkresuRozliczeniowego, " +
                                             "UmowaNaCzasOkreslony = @umowaNaCzasOkreslony, KoniecOkresuRozliczeniowego = @koniecOkresuRozliczeniowego, OkresRozliczeniowy = @okresRozliczeniowy, " +
                                             "NaliczanieOdPierwszejSprzedazy = @naliczanieOdPierwszejSprzedazy, LiczbaEgzemplarzyBezOplat = @liczbaEgzemplarzyBezOplat, " +
                                             "DataZakonczeniaKontraktu = @dataZakonczeniaKontraktu, StalaCena = @stalaCena, ProcentOdCeny = @procentOdCeny, Uwagi = @uwagi, " +
                                             "DataStart = @dataStart, EdycjaUzytkownik = @uzytkownik " +
                                             "WHERE Id = @id");
                }
                else
                {
                    sqlQuery = string.Format("INSERT INTO [PozycjaUmowy] (UmowaId, KTM, Deskryptor, ModelId, WalutaId, PoczatekOkresuRozliczeniowego, " +
                                             "UmowaNaCzasOkreslony, KoniecOkresuRozliczeniowego, OkresRozliczeniowy, NaliczanieOdPierwszejSprzedazy, LiczbaEgzemplarzyBezOplat, " +
                                             "DataZakonczeniaKontraktu, StalaCena, ProcentOdCeny, Uwagi, DataStart, WprowadzenieUzytkownik) " +
                                             "OUTPUT INSERTED.ID " +
                                             "VALUES (@umowaId, @ktm, @deskryptor, @modelId, @walutaId, @poczatekOkresuRozliczeniowego, " +
                                             "@umowaNaCzasOkreslony, @koniecOkresuRozliczeniowego, @okresRozliczeniowy, @naliczanieOdPierwszejSprzedazy, @liczbaEgzemplarzyBezOplat, " +
                                             "@dataZakonczeniaKontraktu, @stalaCena, @procentOdCeny, @uwagi, @dataStart, @uzytkownik)");
                }

                using (SqlCommand command = new SqlCommand(sqlQuery, dbConnection))
                {
                    command.Parameters.Add("@id", SqlDbType.Int, 6).Value                                 = position.Id;
                    command.Parameters.Add("@umowaId", SqlDbType.Int, 6).Value                            = position.AgreementId;
                    command.Parameters.Add("@ktm", SqlDbType.VarChar, 50).Value                           = position.KTM;
                    command.Parameters.Add("@deskryptor", SqlDbType.VarChar, 50).Value                    = position.Descriptor;
                    command.Parameters.Add("@modelId", SqlDbType.Int, 6).Value                            = position.ModelId;
                    command.Parameters.Add("@walutaId", SqlDbType.Int, 6).Value                           = position.CurrencyId;
                    command.Parameters.Add("@okresRozliczeniowy", SqlDbType.TinyInt, 6).Value             = position.BillingPeriod;
                    command.Parameters.Add("@poczatekOkresuRozliczeniowego", SqlDbType.DateTime, 8).Value = position.BillingPeriodStart;
                    command.Parameters.Add("@koniecOkresuRozliczeniowego", SqlDbType.DateTime, 8).Value   = position.BillingPeriodEnd ?? SqlDateTime.Null;
                    command.Parameters.Add("@naliczanieOdPierwszejSprzedazy", SqlDbType.Bit, 6).Value     = position.IsChargedFromFirstSale;
                    command.Parameters.Add("@umowaNaCzasOkreslony", SqlDbType.Bit, 6).Value               = position.IsIndifinitePeriod;
                    command.Parameters.Add("@liczbaEgzemplarzyBezOplat", SqlDbType.Int, 6).Value          = position.FreeCopies;
                    command.Parameters.Add("@dataZakonczeniaKontraktu", SqlDbType.DateTime, 8).Value      = position.ExpirationDate ?? SqlDateTime.Null;
                    command.Parameters.Add("@stalaCena", SqlDbType.Decimal, 10).Value                     = position.ModelFixedPrice;
                    command.Parameters.Add("@procentOdCeny", SqlDbType.Decimal, 10).Value                 = position.ModelPercent;
                    command.Parameters.Add("@uwagi", SqlDbType.VarChar, 1000).Value                       = position.Comments;
                    command.Parameters.Add("@dataStart", SqlDbType.DateTime, 8).Value                     = position.FirstSettlementDate ?? SqlDateTime.Null;
                    command.Parameters.Add("@uzytkownik", SqlDbType.Int, 6).Value                         = AppUser.Instance.UserId;

                    if (position.Id > 0)
                    {
                        command.ExecuteNonQuery();
                    }
                    else
                    {
                        position.Id = (int)command.ExecuteScalar();
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void LoadData()
        {
            int previouslySelectedPositionId = 0;

            if (this.selectedPosition != null)
            {
                previouslySelectedPositionId = this.selectedPosition.Id;
            }

            this.isLoadingData = true;

            this.LoadHeader();
            this.LoadLicensorsTab();
            this.LoadScheduleTab();

            tabControlAgreement.Enabled = (this.agreement.Id > 0) ? true : false;
            this.gridPositionsRepo.BindDataSet(gridExPositions, this.agreement.Id);

            if (gridExPositions.RowCount < 1)
            {
                this.selectedPosition = new AgreementPosition();
                this.LoadPositionDetails();
            }

            this.SetAgreementChangesPending(false);
            this.SetPositionChangesPending(false);
            this.isPositionAddPending = false;
            this.isLoadingData        = false;

            if (previouslySelectedPositionId > 0)
            {
                this.SelectPositionById(previouslySelectedPositionId);
            }

            gridExArticles.RootTable.AllowAddNew        = InheritableBoolean.False;
            gridExRelatedProducts.RootTable.AllowAddNew = InheritableBoolean.False;
            gridExThresholds.RootTable.AllowAddNew      = InheritableBoolean.False;
            gridExLicensors.RootTable.AllowAddNew       = InheritableBoolean.False;
            gridExSchedule.RootTable.AllowAddNew        = InheritableBoolean.False;

            if (this.agreement.Id > 0)
            {
                btnAgreementWFMAG.Enabled = false;
            }
        }
Ejemplo n.º 4
0
        public static AgreementPosition GetByID(int Id)
        {
            AgreementPosition position = new AgreementPosition();

            using (SqlConnection dbConnection = new DBConnection().Connection)
            {
                string sqlQuery = string.Format("SELECT * FROM [vPozycjeUmowy] WHERE [Id] = '{0}' ", Id);

                using (SqlCommand command = new SqlCommand(sqlQuery, dbConnection))
                {
                    SqlDataReader reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        position.Id                     = Id;
                        position.AgreementId            = reader.GetInt32(reader.GetOrdinal("UmowaId"));
                        position.Title                  = reader.GetString(reader.GetOrdinal("Tytul")).Equals(string.Empty) ? "(...)" : reader.GetString(reader.GetOrdinal("Tytul"));
                        position.ModelId                = reader.GetInt32(reader.GetOrdinal("ModelId"));
                        position.KTM                    = reader.GetString(reader.GetOrdinal("KTM"));
                        position.Descriptor             = reader.GetString(reader.GetOrdinal("Deskryptor"));
                        position.CurrencyId             = reader.GetInt32(reader.GetOrdinal("WalutaId"));
                        position.BillingPeriodStart     = reader.GetDateTime(reader.GetOrdinal("PoczatekOkresuRozliczeniowego"));
                        position.BillingPeriodEnd       = reader.IsDBNull(reader.GetOrdinal("KoniecOkresuRozliczeniowego")) ? (DateTime?)null : reader.GetDateTime(reader.GetOrdinal("KoniecOkresuRozliczeniowego"));
                        position.IsIndifinitePeriod     = reader.GetBoolean(reader.GetOrdinal("UmowaNaCzasOkreslony"));
                        position.IsChargedFromFirstSale = reader.GetBoolean(reader.GetOrdinal("NaliczanieOdPierwszejSprzedazy"));
                        position.BillingPeriod          = reader.GetByte(reader.GetOrdinal("OkresRozliczeniowy"));
                        position.FreeCopies             = reader.GetInt32(reader.GetOrdinal("LiczbaEgzemplarzyBezOplat"));
                        position.ExpirationDate         = reader.IsDBNull(reader.GetOrdinal("DataZakonczeniaKontraktu")) ? (DateTime?)null : reader.GetDateTime(reader.GetOrdinal("DataZakonczeniaKontraktu"));
                        position.WFMagDeliveryDate      = reader.IsDBNull(reader.GetOrdinal("Data_dostawy")) ? (DateTime?)null : reader.GetDateTime(reader.GetOrdinal("Data_dostawy"));
                        position.WFMagFirstSaleDate     = reader.IsDBNull(reader.GetOrdinal("DataPierwszejSprzedazy")) ? (DateTime?)null : reader.GetDateTime(reader.GetOrdinal("DataPierwszejSprzedazy"));
                        position.WFMagNetto             = reader.GetDecimal(reader.GetOrdinal("DetalNetto"));
                        position.WFMagBrutto            = reader.GetDecimal(reader.GetOrdinal("DetalBrutto"));
                        position.WFMagPZ                = reader.GetDecimal(reader.GetOrdinal("IloscPz"));
                        position.ModelPercent           = reader.GetDecimal(reader.GetOrdinal("ProcentOdCeny"));
                        position.ModelFixedPrice        = reader.GetDecimal(reader.GetOrdinal("StalaCena"));
                        position.Comments               = reader.GetString(reader.GetOrdinal("Uwagi"));
                        position.FirstSettlementDate    = reader.IsDBNull(reader.GetOrdinal("DataStart")) ? (DateTime?)null : reader.GetDateTime(reader.GetOrdinal("DataStart"));
                    }
                }
            }

            return(position);
        }
Ejemplo n.º 5
0
        private void BindKTM()
        {
            if (this.IsPositionSelected())
            {
                string ktm                 = gridExProductsAndArticles.CurrentRow.Cells["KTM"].Value.ToString();
                string descriptor          = gridExProductsAndArticles.CurrentRow.Cells["Deskryptor"].Value.ToString();
                string positionKtm         = gridExAgreementsListGrouped.CurrentRow.Cells["KTM"].Value.ToString();
                string positionDescriptor  = gridExAgreementsListGrouped.CurrentRow.Cells["Deskryptor"].Value.ToString();
                int    agreementId         = (int)gridExAgreementsListGrouped.CurrentRow.Cells["IdUmowy"].Value;
                int    agreementPositionId = (int)gridExAgreementsListGrouped.CurrentRow.Cells["PozycjaId"].Value;

                if (MessageBox.Show(string.Format("W pozycji:\r\n\r\nKTM:\t\t{0}\r\nDeskryptor:\t{1}\r\n\r\nna umowie {2} zostanie zmieniony parametr:\r\n\r\nKTM:\t\t{3}",
                                                  positionKtm, positionDescriptor, agreementId.ToString(), ktm), "Przypisanie", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                {
                    try
                    {
                        AgreementPosition agreementPosition = AgreementPositionsRepo.GetByID(agreementPositionId);
                        agreementPosition.KTM = ktm;

                        AgreementPositionsRepo.InsertUpdate(agreementPosition);

                        MessageBox.Show("KTM został poprawnie zmieniony.", "Przypisanie", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch
                    {
                        MessageBox.Show("Nie udało się wykonać powiązania.\r\nOdśwież listę i spróbuj ponownie.", "Przypisanie", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    this.LoadData();
                }
            }
            else
            {
                MessageBox.Show("Ta opcja wymaga zaznaczenia jednej pozycji umowy.", "Przypisanie", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Ejemplo n.º 6
0
        // GRIDS
        #region
        private void gridExPositions_SelectionChanged(object sender, EventArgs e)
        {
            // IF SELECTED ROW
            if (!this.isLoadingData && gridExPositions.CurrentRow != null && gridExPositions.CurrentRow.RowIndex > -1)
            {
                if (this.selectedPosition.Id != (int)gridExPositions.CurrentRow.Cells["id"].Value && !this.isCancellingSelection)
                {
                    if (this.isPositionSavePending && !this.isPositionAddPending)
                    {
                        if (MessageBox.Show("Masz niezapisane zmiany na pozycji, które utracisz przechodząc do innej.\r\nKliknij OK, aby przejść dalej lub Anuluj, aby wrócić i zapisać zmiany.", "Uwaga", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                        {
                            int positionId = (int)gridExPositions.CurrentRow.Cells["id"].Value;
                            this.selectedPosition = AgreementPositionsRepo.GetByID(positionId);
                            this.LoadPositionDetails();
                        }
                        else
                        {
                            this.isCancellingSelection = true;
                            this.SelectPositionById(this.selectedPosition.Id);
                            this.isCancellingSelection = false;
                        }
                    }
                    else
                    {
                        if (this.isPositionAddPending)
                        {
                            if (MessageBox.Show("Nowa pozycja nie została zapisana, utracisz ją jeśli przejdziesz dalej.\r\nKliknij OK, aby przejść dalej lub Anuluj, aby wrócić i zapisać zmiany.", "Uwaga", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                            {
                                this.gridPositionsRepo.DeleteLastRow();

                                int positionId = (int)gridExPositions.CurrentRow.Cells["id"].Value;
                                this.selectedPosition = AgreementPositionsRepo.GetByID(positionId);
                                this.LoadPositionDetails();
                                this.isPositionAddPending = false;
                            }
                            else
                            {
                                this.isCancellingSelection = true;
                                gridExPositions.MoveLast();
                                this.isCancellingSelection = false;
                            }
                        }
                        else
                        {
                            int positionId = (int)gridExPositions.CurrentRow.Cells["id"].Value;
                            this.selectedPosition = AgreementPositionsRepo.GetByID(positionId);
                            this.LoadPositionDetails();
                        }
                    }
                }
            }
            else
            {
                if (gridExPositions.CurrentRow != null && gridExPositions.CurrentRow.RowIndex > -1)
                {
                    int positionId = (int)gridExPositions.CurrentRow.Cells["id"].Value;
                    this.selectedPosition = AgreementPositionsRepo.GetByID(positionId);
                    this.LoadPositionDetails();
                }
            }
        }