Esempio n. 1
0
        public static void Insert(PrepaymentTask task)
        {
            var connection = DatabaseConnection.Connection;

            using (var command = connection.CreateCommand())
            {
                const string sql = "insert into T_Prepayment_Tasks(Prepayment_Tasks_Prepayment_Id,Prepayment_Tasks_Level,Prepayment_Tasks_Amount,Prepayment_Tasks_Date) values(@id,@level,@amount,@date)";
                command.CommandText = sql;
                command.Parameters.AddWithValue("@id", task.PrepaymentId);
                command.Parameters.AddWithValue("@level", task.Level);
                command.Parameters.AddWithValue("@amount", task.Amount);
                command.Parameters.AddWithValue("@date", task.Date);
                Logger.LogQuery($"{sql}\r\n{task}");
                command.ExecuteNonQuery();
                connection.Close();
            }
        }
Esempio n. 2
0
        public static void Update(PrepaymentTask task)
        {
            var connection = DatabaseConnection.Connection;

            using (var command = connection.CreateCommand())
            {
                const string sql = "update T_Prepayment_Tasks set Prepayment_Tasks_Amount = @amount , Prepayment_Tasks_Date = @date where Prepayment_Tasks_Prepayment_Id = @id and Prepayment_Tasks_Level = @level";
                command.CommandText = sql;
                command.Parameters.AddWithValue("@id", task.PrepaymentId);
                command.Parameters.AddWithValue("@level", task.Level);
                command.Parameters.AddWithValue("@date", task.Date);
                command.Parameters.AddWithValue("@amount", task.Amount);
                Logger.LogQuery($"{sql}\r\n{task}");
                command.ExecuteNonQuery();
                connection.Close();
            }
        }
Esempio n. 3
0
        public static PrepaymentTask SelectByPrepaymentIdAndLevel(string prepaymentId, string level)
        {
            var connection = DatabaseConnection.Connection;

            using (var command = connection.CreateCommand())
            {
                const string sql = "select * from T_Prepayment_Tasks where Prepayment_Tasks_Prepayment_Id = @id and Prepayment_Tasks_Level = @level";
                command.CommandText = sql;
                command.Parameters.AddWithValue("@id", prepaymentId);
                command.Parameters.AddWithValue("@level", level);
                Logger.LogQuery($"{sql}\r\nid = {prepaymentId}\r\nlevel = {level}");
                using (var reader = command.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        var task = new PrepaymentTask(prepaymentId, level)
                        {
                            Amount            = reader["Prepayment_Tasks_Amount"].ToString(),
                            IsExistInDatabase = true
                        };
                        //date
                        var date = reader["Prepayment_Tasks_Date"].ToString();
                        try
                        {
                            task.Date = DateConverter.StringToPersianDate(date);
                        }
                        catch (Exception e)
                        {
                            Logger.LogException(e);
                        }
                        connection.Close();
                        return(task);
                    }
                    throw new ItemNotFoundException("prepayment level " + level, "prepayment id", prepaymentId);
                }
            }
        }
        public void DeleteTask(PrepaymentTask task)
        {
            Application.Current.Dispatcher.Invoke(() =>
            {
                for (var i = 0; i < ViewModel.PaymentCollection.Count; i++)
                {
                    //get contract windows
                    var contractWindowList        = ManageContractViewModel.Instance.EditContractWindowList;
                    EditContractWindow editWindow = null;
                    foreach (var window in contractWindowList)
                    {
                        if (!window.ViewModel.ContractId.Equals(ViewModel.ContractId))
                        {
                            //not found yet!!!
                            continue;
                        }

                        //found it and add new popup dialog to windows
                        editWindow = window;
                        break;
                    }
                    var level = string.Empty;
                    PersianDatePicker datePicker = LevelOneDatePicker;
                    if (task.Level.Equals("1"))
                    {
                        level = "اول";
                    }
                    else if (task.Level.Equals("2"))
                    {
                        level      = "دوم";
                        datePicker = LevelTwoDatePicker;
                    }
                    else if (task.Level.Equals("3"))
                    {
                        level      = "سوم";
                        datePicker = LevelThreeDatePicker;
                    }

                    var msg    = "آیا مایل به حذف پیش پرداخت مرحله " + level + " با مقدار " + task.Amount + " در تاریخ " + task.Date + " می باشید؟";
                    var dialog = new DialogUserControl(msg, () =>
                    {
                        try
                        {
                            PrepaymentTasksDataAccess.Delete(task.PrepaymentId, task.Level);
                            task.Amount             = string.Empty;
                            task.Date               = PersianDate.Today;
                            task.IsExistInDatabase  = false;
                            datePicker.SelectedDate = PersianDate.Today;
                            var message             = "مرحله " + level + " با موفقیت حذف شد.";
                            ViewModel.ShowPrePaymentTaskMessage(message, false);
                            ViewModel.PrepaymentItem.UpdatePrepaymentSum();
                        }
                        catch (Exception e)
                        {
                            Logger.LogException(e);
                            var message = "خطا در حین حذف مرحله " + level;
                            ViewModel.ShowPrePaymentTaskMessage(message, true);
                        }
                    }, editWindow?.ViewModel.RemovePopupAction);
                    editWindow?.ViewModel.AddPopupAction(dialog);
                    break;
                }
            });
        }