/// <summary>
 /// Mo form KhachVIP de edit
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void grdKhachVIP_DoubleClick(object sender, EventArgs e)
 {
     grdKhachVIP.SelectionMode = Janus.Windows.GridEX.SelectionMode.SingleSelection;
     if (grdKhachVIP.SelectedItems.Count > 0)
     {
         GridEXRow   row         = ((GridEXSelectedItem)grdKhachVIP.SelectedItems[0]).GetRow();
         KhachVIP    objKhachVIP = (KhachVIP)((GridEXSelectedItem)grdKhachVIP.SelectedItems[0]).GetRow().DataRow;
         frmKhachVIP frm         = new frmKhachVIP(objKhachVIP, false);
         if (frm.ShowDialog(this) == DialogResult.OK)
         {
             objKhachVIP = frm.GetKhachVIP();
             frm.Dispose();
             //Insert DataBase
             if (!objKhachVIP.Update())
             {
                 new MessageBox.MessageBoxBA().Show("Lỗi thêm mới khách VIP");
                 return;
             }
             else
             {
                 //Load lai grid
                 LoadListKhachVIP();
             }
         }
         else
         {
             return;
         }
     }
 }
        private void LoadListKhachVIP()
        {
            List <KhachVIP> lstKhachVIP = new List <KhachVIP>();

            lstKhachVIP = new KhachVIP().GetListOfKhachVIPs();

            grdKhachVIP.DataMember = "ListOfKhachVIP";
            grdKhachVIP.SetDataBinding(lstKhachVIP, "ListOfKhachVIP");
        }
        private void SetKhachVIP(KhachVIP KhachVIP)
        {
            editMaKhachVIP.Text = KhachVIP.MaKhachVIP;
            editName.Text       = KhachVIP.Name;
            editAddress.Text    = KhachVIP.Address;
            editPhones.Text     = KhachVIP.Phones;
            editFax.Text        = KhachVIP.Fax;
            editEmail.Text      = KhachVIP.Email;

            editNotes.Text      = KhachVIP.Notes;
            chkIsActive.Checked = KhachVIP.IsActive;
        }
        /// <summary>
        /// Khoi tao mot doi tương KhachVIP, o che do thêm mơi hay sửa đổi thông tin
        /// </summary>
        /// <param name="KhachVIP"></param>
        /// <param name="boolAdd"></param>
        public frmKhachVIP(KhachVIP KhachVIP, bool boolAdd)
        {
            InitializeComponent();
            mIsAdd = boolAdd;
            if (boolAdd)
            {
                this.Text = "Thêm mới đối tác";
            }
            else
            {
                this.Text = "Sửa đổi thông tin đối tác";
            }

            mKhachVIP = KhachVIP;
        }
        private void SuaKhachVIP()
        {
            grdKhachVIP.SelectionMode = Janus.Windows.GridEX.SelectionMode.SingleSelection;
            if (grdKhachVIP.SelectedItems.Count > 0)
            {
                GridEXRow   row         = ((GridEXSelectedItem)grdKhachVIP.SelectedItems[0]).GetRow();
                KhachVIP    objKhachVIP = (KhachVIP)((GridEXSelectedItem)grdKhachVIP.SelectedItems[0]).GetRow().DataRow;
                frmKhachVIP frm         = new frmKhachVIP(objKhachVIP, false);
                if (frm.ShowDialog(this) == DialogResult.OK)
                {
                    objKhachVIP = frm.GetKhachVIP();
                    if (StringTools.TrimSpace(objKhachVIP.Name).Length <= 0)
                    {
                        return;
                    }

                    if (StringTools.TrimSpace(objKhachVIP.Address).Length <= 0)
                    {
                        return;
                    }

                    if (StringTools.TrimSpace(objKhachVIP.Phones).Length < 8)
                    {
                        return;
                    }
                    //Insert DataBase
                    if (!objKhachVIP.Update())
                    {
                        new MessageBox.MessageBoxBA().Show("Lỗi thêm mới khách VIP");
                        return;
                    }
                    else
                    {
                        //Load lai grid
                        LoadListKhachVIP();
                    }
                }
                else
                {
                    return;
                }
            }
        }
        private void ThemKhachVIP()
        {
            // Khoi tao doi tuong KhachVIP voi ma
            string strMaKhachVIP = KhachVIP.GetNextMaKhachVIP();

            if (strMaKhachVIP.Length > 0)
            {
                KhachVIP    objKhachVIP = new KhachVIP(strMaKhachVIP, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, true);
                frmKhachVIP frm         = new frmKhachVIP(objKhachVIP, true);// them moi
                if (frm.ShowDialog(this) == DialogResult.OK)
                {
                    objKhachVIP = frm.GetKhachVIP();

                    //Insert DataBase
                    if (!objKhachVIP.Insert())
                    {
                        new MessageBox.MessageBoxBA().Show("Lỗi thêm mới khách VIP");
                        return;
                    }
                    else
                    {
                        //Load lai grid
                        LoadListKhachVIP();
                    }
                }
                else
                {
                    return;
                }
            }
            else
            {
                new MessageBox.MessageBoxBA().Show("Hết mã cho khách VIP, liên hệ với quản trị");
                return;
            }
        }
        private void XoaKhachVIP()
        {
            grdKhachVIP.SelectionMode = Janus.Windows.GridEX.SelectionMode.SingleSelection;
            if (grdKhachVIP.SelectedItems.Count > 0)
            {
                GridEXRow row               = ((GridEXSelectedItem)grdKhachVIP.SelectedItems[0]).GetRow();
                KhachVIP  objKhachVIP       = (KhachVIP)((GridEXSelectedItem)grdKhachVIP.SelectedItems[0]).GetRow().DataRow;
                MessageBox.MessageBoxBA msg = new Taxi.MessageBox.MessageBoxBA();

                if (msg.Show(this, "Bạn có xóa khách VIP " + objKhachVIP.Name + " không ?", "Xóa khách VIP", Taxi.MessageBox.MessageBoxButtonsBA.OKCancel, Taxi.MessageBox.MessageBoxIconBA.Question).ToString() == DialogResult.OK.ToString())
                {
                    if (!objKhachVIP.Delete(objKhachVIP.MaKhachVIP))
                    {
                        new MessageBox.MessageBoxBA().Show("Lỗi thêm mới khách VIP");
                        return;
                    }
                    else
                    {
                        //Load lai grid
                        LoadListKhachVIP();
                    }
                }
            }
        }