Exemple #1
0
        public static void UpdateExtend(Payment oldEntity, Payment newEntity)
        {
            DataClassesDataContext dc = new DataClassesDataContext();
            string value = newEntity.Value.ToString();

            value = value.Replace(',', '.');
            decimal k = 1;

            if (oldEntity.Value != 0)
            {
                k = newEntity.Value / oldEntity.Value;
            }
            string Kvalue = k.ToString();

            Kvalue = Kvalue.Replace(',', '.');
            string firstQuery = @"UPDATE PaymentsPerInsSubTypes SET PaidValue = " + Kvalue + " * paidvalue, brokeragevalue = " + Kvalue + " * brokeragevalue WHERE PaymentID = " + newEntity.ID;

            dc.ExecuteCommand(firstQuery);
            string query = @"Update Payments SET Value = " + value + " , Date = '" + newEntity.Date.Year + - +newEntity.Date.Month + - +newEntity.Date.Day + "' , PaymentTypeID = " + newEntity.PaymentTypeID;

            if (newEntity.BankslipNumber != string.Empty)
            {
                if (newEntity.BankslipNumber != null)
                {
                    query += @", BankslipNumber = '" + newEntity.BankslipNumber + "'";
                }
                if (newEntity.BankslipBankID != null)
                {
                    query += @", BankslipBankID = " + newEntity.BankslipBankID;
                }
                else
                {
                    query += @", BankslipBankID = null";
                }
            }
            else
            {
                query += @", BankslipNumber = '" + newEntity.BankslipNumber + "'";
                if (newEntity.BankslipBankID != null)
                {
                    query += @", BankslipBankID = " + newEntity.BankslipBankID;
                }
                else
                {
                    query += @", BankslipBankID = null";
                }
            }
            if (newEntity.BankCreditCardID != null)
            {
                query += @", BankCreditCardID = " + newEntity.BankCreditCardID;
            }
            else
            {
                query += @", BankCreditCardID = null";
            }
            query += @" WHERE ID = " + newEntity.ID;
            Rate    r = Rate.Get(newEntity.RateID);
            decimal oldRatePaidValue = r.PaidValue;
            decimal newRatePaidValue = oldRatePaidValue + (newEntity.Value - oldEntity.Value);
            string  valuePaid        = newRatePaidValue.ToString();

            valuePaid = valuePaid.Replace(',', '.');
            string queryRate = "Update Rates Set PaidValue = " + valuePaid + " Where ID = " + r.ID;

            dc.ExecuteCommand(query);
            dc.ExecuteCommand(queryRate);
            Facture.UpdatePaidStatusForFactureExtend(r.PolicyItemID);
        }