コード例 #1
0
        private void Button3_Click(object sender, EventArgs e)
        {
            NpgsqlConnection  con  = null;
            NpgsqlTransaction tran = null;

            try {
                if (this.oneZone.Count == 0)
                {
                    throw new Exception("zone non generer");
                }
                else if (this.sezaZone.Count == 0)
                {
                    throw new Exception("seza non generer");
                }
                else
                {
                    con = new DbConnect().connect();

                    int    lng        = (int)this.numericUpDown2.Value;
                    int    larg       = (int)this.numericUpDown3.Value;
                    int    espacement = (int)this.numericUpDown4.Value;
                    string nextval    = new Util <int>().getNextval("seq_zone", con);

                    Zone zonInsert = new Zone(nextval, this.textBox4.Text, this.esp.IdEspace, decimal.Parse(this.textBox5.Text), lng, larg, espacement, oneZone.ToArray());
                    tran = con.BeginTransaction();
                    zonInsert.insertTran(tran);
                    for (int i = 0; i < this.sezaZone.Count; i++)
                    {
                        this.sezaZone.ElementAt(i).IdZone = nextval;
                        this.sezaZone.ElementAt(i).insertTran(tran);
                    }
                    tran.Commit();
                    Button2_Click(sender, e);
                    this.comboBox4.Items.Clear();
                    getZones(con);
                    this.textBox4.Text = "";
                    this.textBox5.Text = "";
                }
            }
            catch (Exception ex) {
                if (tran != null)
                {
                    tran.Rollback();
                }
                this.textBox6.Text = ex.Message;
            }
            finally {
                if (con != null)
                {
                    con.Close();
                }
            }
        }