コード例 #1
0
ファイル: MainForm.cs プロジェクト: vasya-serega/HomeTaxer
        private void EditOborot(object sender, EventArgs e)
        {
            var editRow   = mainDataGW.SelectedRows[0];
            var updOborot = new Oborot()
            {
                AccountNameId = _service.AccountNameId,
                OborotId      = (int)editRow.Cells[0].Value,
                Date          = (DateTime)editRow.Cells[1].Value,
                CategoryId    = (int)editRow.Cells[2].Value,
                Category      = (string)editRow.Cells[3].Value,
                SubCategoryId = (int?)editRow.Cells[4].Value,
                SubCategory   = (string)editRow.Cells[5].Value,
                Count         = (double)editRow.Cells[6].Value,
                Summa         = (decimal)editRow.Cells[7].Value,
                CurrencyId    = (int)editRow.Cells[8].Value,
                Currency      = (string)editRow.Cells[9].Value,
                Note          = (string)editRow.Cells[10].Value
            };

            var form   = new OborotForm(_service, updOborot);
            var result = form.ShowDialog();

            if (result == DialogResult.OK)
            {
                UpdateOborotInTable(form.UpdatedOborot);
                UpdateOborotToDbAsync(form.UpdatedOborot);
            }
        }
コード例 #2
0
        public int InsertOborot(int userId, OborotDirection direction, Oborot newOborot)
        {
            var command = Db.GetStoredProcCommand("dbo.InsertOborot");

            command.CommandType = CommandType.StoredProcedure;

            var dateParam = new SqlParameter("oborotDate", SqlDbType.DateTime);

            dateParam.Value = newOborot.Date;
            var accountNameIdParam = new SqlParameter("accountNameId", SqlDbType.Int);

            accountNameIdParam.Value = newOborot.AccountNameId;
            var categoryIdParam = new SqlParameter("categoryId", SqlDbType.Int);

            categoryIdParam.Value = newOborot.CategoryId;
            var subCategoryIdParam = new SqlParameter("subCategoryId", SqlDbType.Int);

            subCategoryIdParam.Value = newOborot.SubCategoryId;
            var countParam = new SqlParameter("count", SqlDbType.Float);

            countParam.Value = newOborot.Count;
            var amountParam = new SqlParameter("amount", SqlDbType.Decimal);

            amountParam.Value = newOborot.Summa;
            var currencyIdParam = new SqlParameter("currencyId", SqlDbType.Int);

            currencyIdParam.Value = newOborot.CurrencyId;
            var noteParam = new SqlParameter("note", SqlDbType.NVarChar);

            noteParam.Value = newOborot.Note;
            var userIdParam = new SqlParameter("userId", SqlDbType.Int);

            userIdParam.Value = userId;
            var directionParam = new SqlParameter("direction", SqlDbType.Int);

            directionParam.Value = direction;
            command.Parameters.AddRange(new[]
            {
                dateParam,
                accountNameIdParam,
                categoryIdParam,
                subCategoryIdParam,
                countParam,
                amountParam,
                currencyIdParam,
                noteParam,
                directionParam,
                userIdParam
            });

            var identity = Db.ExecuteScalar(command);

            return(Convert.ToInt32(identity));
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: vasya-serega/HomeTaxer
        private async void UpdateOborotToDbAsync(Oborot updOborot)
        {
            ShowCustProgr(true);

            var result = await _service.UpdateOborot(updOborot);

            if (!result.IsSuccess)
            {
                ShowProgressError(result.Message, result.Exception);
            }

            ShowCustProgr(false);
        }
コード例 #4
0
        public IEnumerable <Oborot> GetOborots(
            DateTime beginDate, DateTime endDate, int accountNameId, int userId, int direction)
        {
            var command = Db.GetStoredProcCommand("dbo.GetOborots");

            command.CommandType = CommandType.StoredProcedure;
            var beginDateParam = new SqlParameter("beginDate", SqlDbType.DateTime);

            beginDateParam.Value = beginDate;
            var endDateParam = new SqlParameter("endDate", SqlDbType.DateTime);

            endDateParam.Value = endDate;
            var accountNameIdParam = new SqlParameter("accountNameId", SqlDbType.Int);

            accountNameIdParam.Value = accountNameId;
            var userIdParam = new SqlParameter("userId", SqlDbType.Int);

            userIdParam.Value = userId;
            var directionParam = new SqlParameter("direction", SqlDbType.Int);

            directionParam.Value = direction;
            command.Parameters.AddRange(new[]
            {
                beginDateParam, endDateParam, accountNameIdParam, userIdParam, directionParam
            });

            var reader  = Db.ExecuteReader(command);
            var oborots = new List <Oborot>();

            while (reader.Read())
            {
                var oborot = new Oborot()
                {
                    OborotId      = reader.GetInt32(0),
                    Date          = reader.GetDateTime(1),
                    CategoryId    = reader.GetInt32(2),
                    Category      = reader.GetString(3),
                    SubCategoryId = reader.GetValue(4).GetType() != typeof(DBNull) ? reader.GetInt32(4) : (int?)null,
                    SubCategory   = reader.GetValue(5).GetType() != typeof(DBNull) ? reader.GetString(5) : null,
                    Count         = reader.GetDouble(6),
                    Summa         = reader.GetDecimal(7),
                    CurrencyId    = reader.GetInt32(8),
                    Currency      = reader.GetString(9),
                    Note          = reader.GetValue(10).GetType() != typeof(DBNull) ? reader.GetString(10) : null
                };
                oborots.Add(oborot);
            }

            return(oborots);
        }
コード例 #5
0
        public OborotForm(HtService htService, Oborot existingOborot = null)
        {
            InitializeComponent();
            _service = htService;

            _defaultCurrencyId = Config.Instance.CurrencyId;
            currencyLbl.Text   = _defaultCurrencyId == 1 ? "грн." : "<ім'я валюти>";

            if (existingOborot != null)
            {
                UpdatedOborot      = existingOborot;
                addMoreBtn.Enabled = false;
            }
        }
コード例 #6
0
        public void UpdateOborot(Oborot updOborot)
        {
            var command = Db.GetStoredProcCommand("dbo.UpdateOborot");

            command.CommandType = CommandType.StoredProcedure;

            var oborotIdParam = new SqlParameter("oborotId", SqlDbType.Int);

            oborotIdParam.Value = updOborot.OborotId;
            var dateParam = new SqlParameter("oborotDate", SqlDbType.DateTime);

            dateParam.Value = updOborot.Date;
            var accountNameIdParam = new SqlParameter("accountNameId", SqlDbType.Int);

            accountNameIdParam.Value = updOborot.AccountNameId;
            var categoryIdParam = new SqlParameter("categoryId", SqlDbType.Int);

            categoryIdParam.Value = updOborot.CategoryId;
            var subCategoryIdParam = new SqlParameter("subCategoryId", SqlDbType.Int);

            subCategoryIdParam.Value = updOborot.SubCategoryId;
            var countParam = new SqlParameter("count", SqlDbType.Float);

            countParam.Value = updOborot.Count;
            var amountParam = new SqlParameter("amount", SqlDbType.Decimal);

            amountParam.Value = updOborot.Summa;
            var currencyIdParam = new SqlParameter("currencyId", SqlDbType.Int);

            currencyIdParam.Value = updOborot.CurrencyId;
            var noteParam = new SqlParameter("note", SqlDbType.NVarChar);

            noteParam.Value = updOborot.Note;

            command.Parameters.AddRange(new[]
            {
                oborotIdParam,
                dateParam,
                accountNameIdParam,
                categoryIdParam,
                subCategoryIdParam,
                countParam,
                amountParam,
                currencyIdParam,
                noteParam
            });

            Db.ExecuteNonQuery(command);
        }
コード例 #7
0
ファイル: HtService.cs プロジェクト: vasya-serega/HomeTaxer
 public Task <InsertOperationResult> InsertOborot(Oborot newOborot)
 {
     return(Task.Run(() =>
     {
         try
         {
             var insertedId = _client.InsertOborot(_userId, OborotDirection.Costs, newOborot);
             return new InsertOperationResult(insertedId, true);
         }
         catch (Exception ex)
         {
             return new InsertOperationResult(false, "Неможливо зберегти дані. ", ex);
         }
     }));
 }
コード例 #8
0
ファイル: HtService.cs プロジェクト: vasya-serega/HomeTaxer
 public Task <OperationResult> UpdateOborot(Oborot updOborot)
 {
     return(Task.Run(() =>
     {
         try
         {
             _client.UpdateOborot(updOborot);
             return new OperationResult(true);
         }
         catch (Exception ex)
         {
             return new OperationResult(false, "Неможливо зберегти дані. ", ex);
         }
     }));
 }
コード例 #9
0
ファイル: MainForm.cs プロジェクト: vasya-serega/HomeTaxer
        private void AddOborotToTable(Oborot record)
        {
            var category    = record.Category ?? _service.GetCategoryNameById(record.CategoryId);
            var subcategory = record.SubCategory ?? _service.GetSubcategoryNameById(record.CategoryId, record.SubCategoryId);
            var currency    = record.Currency ?? _service.Currencies[record.CurrencyId];

            mainDataGW.Rows.Add(record.OborotId,
                                record.Date,
                                record.CategoryId,
                                category,
                                record.SubCategoryId,
                                subcategory,
                                record.Count,
                                record.Summa,
                                record.CurrencyId,
                                currency,
                                record.Note);
        }
コード例 #10
0
        private void AddCopmletedOborot()
        {
            var newOborot = new Oborot();

            newOborot.AccountNameId = _service.AccountNameId;
            newOborot.Date          = DateTime.Now;
            newOborot.CategoryId    = ((Category)categoryComboBox.SelectedItem).Id;
            var subCategoryItem = (KeyValuePair <int, string>)subcategoryComboBox.SelectedItem;

            if (!string.IsNullOrEmpty(subCategoryItem.Value))
            {
                newOborot.SubCategoryId = subCategoryItem.Key;
            }
            newOborot.Count      = Convert.ToDouble(countTextBox.Text.Replace(".", ","));
            newOborot.Summa      = Convert.ToDecimal(amountTextBox.Text.Replace(".", ","));
            newOborot.CurrencyId = _defaultCurrencyId;
            newOborot.Note       = descTextBox.Text;

            _insertedOborots.Add(newOborot);
        }
コード例 #11
0
ファイル: MainForm.cs プロジェクト: vasya-serega/HomeTaxer
        private void UpdateOborotInTable(Oborot record)
        {
            var category    = record.Category ?? _service.GetCategoryNameById(record.CategoryId);
            var subcategory = record.SubCategory ?? _service.GetSubcategoryNameById(record.CategoryId, record.SubCategoryId);
            var currency    = record.Currency ?? _service.Currencies[record.CurrencyId];

            var row = mainDataGW.SelectedRows[0];

            row.Cells["Id"].Value = record.OborotId;

            row.Cells["dateCol"].Value        = record.Date;
            row.Cells["CategoryId"].Value     = record.CategoryId;
            row.Cells["categoryCol"].Value    = category;
            row.Cells["SubcategoryId"].Value  = record.SubCategoryId;
            row.Cells["subCategoryCol"].Value = subcategory;
            row.Cells["CountCol"].Value       = record.Count;
            row.Cells["amountCol"].Value      = record.Summa;
            row.Cells["CurrencyId"].Value     = record.CurrencyId;
            row.Cells["CurrencyCol"].Value    = currency;
            row.Cells["descCol"].Value        = record.Note;
        }
コード例 #12
0
 public void UpdateOborot(Oborot updOborot)
 {
     _dataAccess.UpdateOborot(updOborot);
 }
コード例 #13
0
 public int InsertOborot(int userId, OborotDirection direction, Oborot newOborot)
 {
     return(_dataAccess.InsertOborot(userId, direction, newOborot));
 }