コード例 #1
0
        public void New()
        {
            curBill = new HoaDonDangKy();

            string newestBill = db.HoaDonDangKies.OrderByDescending(x => x.MaHDDK).Select(x => x.MaHDDK).FirstOrDefault();

            if (newestBill != null)
            {
                try
                {
                    newestBill = newestBill.Substring(2);
                    int NumberBill = int.Parse(newestBill) + 1;
                    newestBill = "HD" + (NumberBill < 10 ? "0" + NumberBill.ToString() : NumberBill.ToString());
                }
                catch (ArgumentOutOfRangeException e)
                {
                    MessageBox.Show("Có lỗi xảy ra");
                }
            }
            else
            {
                newestBill = "HD01";
            }
            curBill.MaHDDK       = newestBill;
            curBill.ChiPhiDangKy = 50000;
            ShowData();
            //txtBillID.Enabled = true;
        }
コード例 #2
0
 private void gridControl1_Click(object sender, EventArgs e)
 {
     int[] ids = gridView1.GetSelectedRows();
     foreach (int id in ids)
     {
         curBill = gridView1.GetRow(id) as HoaDonDangKy;
         ShowData();
         txtBillID.Enabled = false;
     }
 }
コード例 #3
0
        public void Save()
        {
            if (curBill == null)
            {
                curBill = new HoaDonDangKy();
            }
            curBill.IDSIM        = txtIDSim.Text;
            curBill.ChiPhiDangKy = Convert.ToDecimal(txtPrice.Text);
            curBill.MaHDDK       = txtBillID.Text;
            if (curBill.MaHDDK == null)
            {
                MessageBox.Show("Vui lòng nhập mã hợp đồng");
                return;
            }
            try
            {
                if (db.HoaDonDangKies.FirstOrDefault(x => x.MaHDDK == curBill.MaHDDK) != null)
                {
                    db.HoaDonDangKies.Attach(curBill);
                    db.Entry(curBill).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
                else
                {
                    if (db.HoaDonDangKies.FirstOrDefault(x => x.IDSIM == curBill.IDSIM) != null)
                    {
                        MessageBox.Show("Sim đã có người đăng ký, vui lòng chọn sim khác");
                    }

                    db.HoaDonDangKies.Add(curBill);
                    db.SaveChanges();
                }
                MessageBox.Show("Cập nhật thành công!");
                RefreshData();
            }
            catch (DbEntityValidationException e)
            {
                MessageBox.Show("Có lỗi xảy ra, không thể lưu");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Có lỗi xảy ra, không thể lưu");
            }
        }