Пример #1
0
 private void btnSua_Click(object sender, EventArgs e)
 {
     if (txtSoSanBayTGMax.Text.Trim() != "" && txtTGBayMin.Text.Trim() != "" && txtTGDungMax.Text.Trim() != "" && txtTGDungMin.Text.Trim() != "" && txtTGMinDatVe.Text.Trim() != "" && txtTGMinHuyVe.Text.Trim() != "")
     {
         try
         {
             dtoThamSo = new DTO_ThamSo(float.Parse(txtTGBayMin.Text), int.Parse(txtSoSanBayTGMax.Text), float.Parse(txtTGDungMin.Text), float.Parse(txtTGDungMax.Text), float.Parse(txtTGMinDatVe.Text), float.Parse(txtTGMinHuyVe.Text));
             if (busThamSo.Update(dtoThamSo))
             {
                 MessageBox.Show("Sửa thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
             else
             {
                 MessageBox.Show("Sửa không thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
         catch (Exception a)
         {
             MessageBox.Show("Sửa không thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         finally
         {
             TaoLai();
             flagCellClick = false;
         }
     }
     else
     {
         MessageBox.Show("Vui lòng nhập đầy đủ thông tin!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Пример #2
0
 public static DTO_ThamSo GetThamSo()
 {
     //DataTable dataTable = DAO.DAO_ThamSo.GetAllThamSo();
     //if (dataTable != null)
     //{
     //    ThamSos.Add(new DTO_ThamSo(dataTable.Columns[COLUMN_TENQUYDINH], float.Parse(dataTable.Columns[COLUMN_GIATRI])));
     //}
     //IsLoaded = true;
     if (!IsLoaded)
     {
         DataTable dataTable = DAO.DAO_ThamSo.GetThamSo();
         if (dataTable != null)
         {
             if (ThamSo == null)
             {
                 ThamSo = new DTO_ThamSo();
             }
             try
             {
                 if (dataTable.Rows.Count > 0)
                 {
                     DataRow row = dataTable.Rows[0];
                     ThamSo.TenQuyDinh = row.ItemArray[0].ToString();
                     ThamSo.GiaTri     = float.Parse(row.ItemArray[1].ToString());
                     IsLoaded          = true;
                 }
             }
             catch (Exception)
             {
                 return(null);
             }
         }
     }
     return(ThamSo);
 }
 private void btnThem_Click(object sender, EventArgs e)
 {
     if (!isThem)//them
     {
         tbxMaThamSo.Text       = bus_thamSo.GetNextMaThamSo();
         tbxTenThamSo.ReadOnly  = false;
         tbxTriGia.ReadOnly     = false;
         tbxTenThamSo.BackColor = SystemColors.ButtonHighlight;
         tbxTriGia.BackColor    = SystemColors.ButtonHighlight;
         btnThem.Text           = "Hoàn tất";
         btnSua.Enabled         = false;
         btnXoa.Enabled         = false;
     }
     else//Luu
     {
         if (tbxTenThamSo.Text.Length > 30)
         {
             MessageBox.Show("Tham số không được quá 30 ký tự!");
             return;
         }
         if (tbxTenThamSo.Text.Length == 0)
         {
             MessageBox.Show("Tên tham số không được để trống!");
             return;
         }
         if (tbxTriGia.Text.Length == 0)
         {
             MessageBox.Show("Trị giá không được để trống!");
             return;
         }
         try
         {
             DTO_ThamSo thamSo = new DTO_ThamSo(tbxMaThamSo.Text, tbxTenThamSo.Text, Int32.Parse(tbxTriGia.Text));
             if (!bus_thamSo.Add(thamSo))
             {
                 MessageBox.Show("Thêm thất bại! Vui lòng kiểm tra lại!");
                 return;
             }
             else
             {
                 MessageBox.Show("Thêm thành công!");
                 ReloadBangThamSo();
             }
         }
         catch
         {
             MessageBox.Show("Thêm thất bại! Vui lòng kiểm tra lại!");
             return;
         }
         tbxTenThamSo.ReadOnly  = true;
         tbxTriGia.ReadOnly     = true;
         tbxTenThamSo.BackColor = SystemColors.Control;
         tbxTriGia.BackColor    = SystemColors.Control;
         btnThem.Text           = "Thêm";
         btnSua.Enabled         = true;
         btnXoa.Enabled         = true;
     }
     isThem = !isThem;
 }
        private void btnEditQuyDinh_Click(object sender, EventArgs e)
        {
            if (mStateMode == STATE_MODE.EDIT)
            {
                txtGiaTri.ReadOnly  = false;
                cbApDung.Enabled    = true;
                mStateMode          = STATE_MODE.SAVE;
                btnEditQuyDinh.Text = "Lưu";
                mStateMode          = STATE_MODE.SAVE;
            }
            else
            {
                Console.WriteLine("SAVE");
                DialogResult dr = MessageBox.Show("Bạn có muốn thay đổi quy định này hay không?", "Xác nhận", MessageBoxButtons.OKCancel);
                if (dr == System.Windows.Forms.DialogResult.OK)
                {
                    if (String.IsNullOrWhiteSpace(txtGiaTri.Text))
                    {
                        MessageBox.Show("Giá trị không được để trống", "Thông báo", MessageBoxButtons.OK);
                        return;
                    }
                    float giaTri = 0.0f;

                    try
                    {
                        giaTri = float.Parse(txtGiaTri.Text);
                        if (giaTri > 10.0f)
                        {
                            return;
                        }
                        if (BUS.BUS_ThamSo.UpdateThamSo(new DTO.DTO_ThamSo(txtTenQuyDinh.Text, giaTri)))
                        {
                            txtGiaTri.ReadOnly = true;
                            cbApDung.Enabled   = false;
                            QuanLyTiecCuoiUI.Properties.Settings.Default.ApplyQuyDinh = cbApDung.Checked;
                            QuanLyTiecCuoiUI.Properties.Settings.Default.Save();
                            mStateMode          = STATE_MODE.EDIT;
                            btnEditQuyDinh.Text = "Sửa";

                            DTO_ThamSo thamSo = BUS.BUS_ThamSo.GetThamSo();
                            txtGiaTri.Text   = thamSo.GiaTri.ToString();
                            cbApDung.Checked = cbApDung.Checked;
                        }
                    }
                    catch
                    {
                    }
                }
                else
                {
                    btnEditQuyDinh.Text = "Sửa";
                    mStateMode          = STATE_MODE.EDIT;
                    txtGiaTri.ReadOnly  = true;
                    cbApDung.Enabled    = false;
                }
            }
        }
        private void btnSua_Click(object sender, EventArgs e)
        {
            if (tbxMaThamSo.Text == "")
            {
                MessageBox.Show("Vui lòng chọn tham số cần sửa!");
                return;
            }
            if (!isSua)//Sua
            {
                tbxTriGia.ReadOnly  = false;
                tbxTriGia.BackColor = SystemColors.ButtonHighlight;
                btnSua.Text         = "Hoàn tất";
                btnThem.Enabled     = false;
                btnXoa.Enabled      = false;
            }
            else
            {
                if (tbxTenThamSo.Text.Length > 30)
                {
                    MessageBox.Show("Tham số không được quá 30 ký tự!");
                    return;
                }
                if (tbxTriGia.Text.Length == 0)
                {
                    MessageBox.Show("Trị giá không được để trống!");
                    return;
                }
                try
                {
                    DTO_ThamSo thamSo = new DTO_ThamSo(tbxMaThamSo.Text, tbxTenThamSo.Text, Int32.Parse(tbxTriGia.Text));
                    if (!bus_thamSo.Update(thamSo))
                    {
                        MessageBox.Show("Sửa thất bại! Vui lòng kiểm tra lại!");
                        return;
                    }
                    else
                    {
                        MessageBox.Show("Sửa thành công!");
                        ReloadBangThamSo();
                    }
                }
                catch
                {
                    MessageBox.Show("Sửa thất bại! Vui lòng kiểm tra lại!");
                    return;
                }
                tbxTriGia.ReadOnly  = true;
                tbxTriGia.BackColor = SystemColors.Control;
                btnSua.Text         = "Sửa";
                btnThem.Enabled     = true;
                btnXoa.Enabled      = true;
            }



            isSua = !isSua;
        }
Пример #6
0
        public static bool UpdateThamSo(DTO_ThamSo thamSo)
        {
            String sql = String.Format("update ThamSo set {0} = {1} where {2} = N'{3}'", COLUMN_GIATRI, thamSo.GiaTri, COLUMN_TENQUYDINH, thamSo.TenQuyDinh);

            if (DatabaseHelper.ExcuteSql(sql) == 1)
            {
                return(true);
            }
            return(false);
        }
Пример #7
0
        public static bool InsertThamSo(DTO_ThamSo thamSo)
        {
            String sql = String.Format("Insert into ThamSo(" + COLUMN_TENQUYDINH + "," + COLUMN_GIATRI + ") values (N'{0}',{1})",
                                       thamSo.TenQuyDinh, thamSo.GiaTri);

            if (DatabaseHelper.ExcuteSql(sql) == 1)
            {
                return(true);
            }
            return(false);
        }
        void frmThayDoiQuyDinh_Load(object sender, EventArgs e)
        {
            txtTenQuyDinh.ReadOnly = true;
            txtGiaTri.ReadOnly     = true;
            cbApDung.Enabled       = false;


            DTO_ThamSo thamSo = BUS.BUS_ThamSo.GetThamSo();

            txtTenQuyDinh.Text = thamSo.TenQuyDinh;
            txtGiaTri.Text     = thamSo.GiaTri.ToString();

            cbApDung.Checked = QuanLyTiecCuoiUI.Properties.Settings.Default.ApplyQuyDinh;
        }
        public bool Add(DTO_ThamSo pThamSo)
        {
            try
            {
                SqlDataAdapter da = new SqlDataAdapter("select * from THAMSO", _cn);
                DataRow        r  = dt.NewRow();
                r["MaThamSo"]     = pThamSo.MaThamSo;
                r["TenThamSo"]    = pThamSo.TenThamSo;
                r["TriGiaThamSo"] = pThamSo.TriGiaThamSo;
                dt.Rows.Add(r);

                SqlCommandBuilder cm = new SqlCommandBuilder(da);
                da.Update(dt);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Пример #10
0
 public bool Update(DTO_ThamSo dto)
 {
     try
     {
         _con.Open();
         string     sqlQuery = string.Format("UPDATE THAMSO SET THOIGIANBAYTOITHIEU='{0}', SOSANBAYTGTOIDA='{1}', THOIGIANDUNGTOITHIEU='{2}', THOIGIANDUNGTOIDA='{3}', TGCHAMNHATDATVE='{4}', TGCHAMNHATHUYDATVE='{5}' ", dto.ThoiGianBayToiThieu, dto.SoSanBayTGToiDa, dto.ThoiGianDungToiThieu, dto.ThoiGianDungToiDa, dto.ThoiGianChamNhatDatVe, dto.ThoiGianChamNhatHuyVe);
         SqlCommand cmd      = new SqlCommand(sqlQuery, _con);
         if (cmd.ExecuteNonQuery() > 0)
         {
             return(true);
         }
     }
     catch (Exception a)
     {
     }
     finally
     {
         _con.Close();
     }
     return(false);
 }
 public bool Update(DTO_ThamSo pThamSo)
 {
     try
     {
         SqlDataAdapter da = new SqlDataAdapter("select * from THAMSO", _cn);
         DataRow        r  = dt.Rows.Find(pThamSo.MaThamSo);
         if (r != null)
         {
             r["MaThamSo"]     = pThamSo.MaThamSo;
             r["TenThamSo"]    = pThamSo.TenThamSo;
             r["TriGiaThamSo"] = pThamSo.TriGiaThamSo;
         }
         SqlCommandBuilder cm = new SqlCommandBuilder(da);
         da.Update(dt);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Пример #12
0
 public static bool UpdateThamSo(DTO_ThamSo thamSo)
 {
     IsLoaded = false;
     return(DAO.DAO_ThamSo.UpdateThamSo(thamSo));
 }
Пример #13
0
 public static bool InsertThamSo(DTO_ThamSo thamSo)
 {
     IsLoaded = false;
     return(DAO.DAO_ThamSo.InsertThamSo(thamSo));
 }
Пример #14
0
 public bool Update(DTO_ThamSo dto)
 {
     return(dal.Update(dto));
 }
 public bool Update(DTO_ThamSo pThamSo)
 {
     return(dal_thamSo.Update(pThamSo));
 }
Пример #16
0
 public bool Add(DTO_ThamSo dto)
 {
     return(dal.Add(dto));
 }
 public bool Add(DTO_ThamSo pThamSo)
 {
     return(dal_thamSo.Add(pThamSo));
 }