示例#1
0
        public static void DeleteExtend(Payment entityToDelete)
        {
            DataClassesDataContext dc = new DataClassesDataContext();
            string firstQuery         = @"DELETE FROM PaymentsPerInsSubTypes WHERE PaymentID = " + entityToDelete.ID;

            dc.ExecuteCommand(firstQuery);
            string query = @"DELETE FROM Payments WHERE ID = " + entityToDelete.ID;

            dc.ExecuteCommand(query);
            Rate    r = Rate.Get(entityToDelete.RateID);
            decimal oldRatePaidValue = r.PaidValue;
            decimal newRatePaidValue = oldRatePaidValue - entityToDelete.Value;
            string  valuePaid        = newRatePaidValue.ToString();

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

            dc.ExecuteCommand(queryRate);
            Facture.UpdatePaidStatusForFactureExtend(r.PolicyItemID);
        }
示例#2
0
        public static void UpdateExtend(Rate oldEntity, Rate newEntity)
        {
            decimal polValue          = PolicyItem.Get(newEntity.PolicyItemID).PremiumValue;
            DataClassesDataContext dc = new DataClassesDataContext();
            string value = newEntity.Value.ToString();

            value = value.Replace(',', '.');
            string query = "Update Rates SET Value = " + value + " , Date = '" + newEntity.Date.Year + - +newEntity.Date.Month + - +newEntity.Date.Day + "' WHERE ID = " + newEntity.ID;

            dc.ExecuteCommand(query);
            //Cascade update rest rates
            string      selQuery    = @"Select r.* FROM Rates r WHERE r.PolicyItemID = " + newEntity.PolicyItemID + " ORDER BY r.Number";
            List <Rate> lstAllRates = dc.ExecuteQuery <Rate>(selQuery).ToList();

            if (lstAllRates != null)
            {
                if (lstAllRates.Count > 0)
                {
                    List <Rate> lstPreviousRates = lstAllRates.Where(c => c.Number <= oldEntity.Number).ToList();
                    decimal     totValue         = 0;
                    foreach (Rate rate in lstPreviousRates)
                    {
                        totValue += rate.Value;
                    }
                    List <Rate> lstRateForUpdates = lstAllRates.Where(c => c.Number > oldEntity.Number).ToList();
                    if (lstRateForUpdates.Count > 0)
                    {
                        decimal rightValue = (polValue - totValue) / lstRateForUpdates.Count;
                        foreach (Rate rateU in lstRateForUpdates)
                        {
                            string valueU = rightValue.ToString();
                            valueU = valueU.Replace(',', '.');
                            string queryU = "Update Rates SET Value = " + valueU + " WHERE ID = " + rateU.ID;
                            dc.ExecuteCommand(queryU);
                        }
                    }
                }
            }
        }
示例#3
0
        /// <summary>
        /// Brisi zapisi od tabelata
        /// </summary>
        /// <param name="list">List(UsersWebPage) list</param>
        /// Se povikuva vo UserManagementControllers\WebpagesVisibilityController.cs
        public static void DeleteUserWebPages(List <UsersWebPage> list)
        {
            // TODO: Problemi so EntityBase::Delete() - da se razreshi
            // pagjashe pri Table.Attach(T); vo EntityBase
            // Za razlika od tuka kaj UsersFunctions.cs e OK !!

            DataClassesDataContext dc = new DataClassesDataContext();

            foreach (UsersWebPage uPage in list)
            {
                string query = @"DELETE FROM UsersWebPages 
                                 WHERE UserId=" + uPage.UserID + @" 
                                 AND WebPageId=" + uPage.WebPageID;
                dc.ExecuteCommand(query);
            }
        }
示例#4
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);
        }