コード例 #1
0
ファイル: ProductServices.cs プロジェクト: TalasZh/opencbs
 public int InsertLoanCycle(LoanCycle loanCycle)
 {
     if (_productManager.IsLoanCycleNameAlreadyExist(loanCycle.Name))
             throw new OpenCbsPackageSaveException(OpenCbsPackageSaveExceptionEnum.LoanCycleNameAlreadyExists);
     using (SqlConnection conn = _productManager.GetConnection())
     using (SqlTransaction t = conn.BeginTransaction())
     {
         try
         {
             loanCycle.Id = _productManager.InsertLoanCycle(loanCycle, t);
             t.Commit();
             return loanCycle.Id;
         }
         catch (Exception ex)
         {
             t.Rollback();
             throw ex;
         }
     }
 }
コード例 #2
0
        public List<LoanCycle> SelectLoanCycles()
        {
            List<LoanCycle> loanCycles = new List<LoanCycle>();
            string q = @"SELECT [id], [name]  FROM [dbo].[Cycles]";
            using (SqlConnection conn = GetConnection())
            using (OpenCbsCommand c = new OpenCbsCommand(q, conn))
            using (OpenCbsReader r = c.ExecuteReader())
            {
                while (r.Read())
                {
                    LoanCycle loanCycle = new LoanCycle();
                    loanCycle.Id = r.GetInt("id");
                    loanCycle.Name = r.GetString("name");
                    loanCycles.Add(loanCycle);
                }
            }

            return loanCycles;
        }
コード例 #3
0
ファイル: FrmAddLoanProduct.cs プロジェクト: TalasZh/opencbs
        private void buttonNewAmountCycles_Click(object sender, EventArgs e)
        {
            try
            {
                InputBox inputBox = new InputBox();
                string inputBoxText = MultiLanguageStrings.GetString(Ressource.PackagesForm, "InputNameCaption.Text");
                inputBox.Text = inputBoxText;
                inputBox.ShowDialog();

                if (inputBox.Result != null)
                {
                    listViewLoanCycles.Items.Clear();
                    buttonRemoveAmountCycles.Enabled = false;
                    buttonAmountCyclesSave.Enabled = false;
                    buttonAddAmountCycle.Enabled = true;
                    panelAmountCycles.Enabled = true;
                    panelAmountCycles.Visible = true;
                    groupBoxAmountCycle.Text = MultiLanguageStrings.GetString(Ressource.FrmAddLoanProduct, "messageAmountCycle.Text");
                    buttonSave.Enabled = true;
                    LoanCycle loanCycle = new LoanCycle();
                    loanCycle.Name = inputBox.Result;
                    loanCycle.Id = ServicesProvider.GetInstance().GetProductServices().InsertLoanCycle(loanCycle);
                    InitializeComboBoxLoanCycles();
                    SelectLoanCycleItemInComboBox(loanCycle.Id);
                    groupBoxAmountCycle.Text = MultiLanguageStrings.GetString(Ressource.FrmAddLoanProduct, "messageAmountCycle.Text");
                }
            }
            catch (Exception ex)
            {
                new frmShowError(CustomExceptionHandler.ShowExceptionText(ex)).ShowDialog();
            }
        }
コード例 #4
0
        /// <summary>
        /// Add a loan cycle into the databse
        /// </summary>
        /// <param name="loanCycle">An instance of the class LoanCycle</param>
        /// <param name="transac">SQL transaction</param>
        /// <returns></returns>
        public int InsertLoanCycle(LoanCycle loanCycle, SqlTransaction t)
        {
            const string q = "INSERT INTO Cycles (name) VALUES (@name) SELECT SCOPE_IDENTITY()";

            using (OpenCbsCommand c = new OpenCbsCommand(q, t.Connection, t))
            {
                c.AddParam("@name", loanCycle.Name);
                return Convert.ToInt32(c.ExecuteScalar());
            }
        }