private void btnUpdate_Click(object sender, EventArgs e)
 {
     try
     {
         if (String.IsNullOrEmpty(txtName.Text) == true)
         {
             txtName.Focus();
             MessageBox.Show("Vui lòng nhập tên nhóm .", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         else
         {
             CustomerGroups aCustomerGroups = new CustomerGroups();
             aCustomerGroups.ID = IDCustomerGroups_Old;
             aCustomerGroups.IDCompany = Convert.ToInt32(lueCompany.EditValue);
             aCustomerGroups.Name = txtName.Text;
             aCustomerGroups.Status = cboStatus.SelectedIndex + 1;
             aCustomerGroups.Type = cboType.SelectedIndex + 1;
             aCustomerGroups.Disable = bool.Parse(cboDisable.Text);
             aCustomerGroupsBO.Update(aCustomerGroups);
             this.afrmLst_CustomerGroups.ReloadData();
             MessageBox.Show("Cập nhật dữ liệu thành công .", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
             this.Close();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("frmEditCustomerGroup.btnUpdate_Click\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
    protected void btnSave_Click(object sender, System.EventArgs e)
    {
        byte SysMessageTypeId = 0;
        int  SysMessageId     = 0;

        System.Int16   EditId;
        CustomerGroups m_CustomerGroups = new CustomerGroups();

        if (Request.QueryString["id"] == null)
        {
            EditId = 0;
        }
        else
        {
            EditId = System.Int16.Parse(Request.QueryString["id"].ToString());
            m_CustomerGroups.CustomerGroupId = EditId;
            m_CustomerGroups = m_CustomerGroups.Get();
        }
        try
        {
            if (txCustomerGroupName.Text == "")
            {
                JSAlertHelpers.Alert("Mời bạn nhập các thông tin bắt buộc!", this);
                return;
            }


            m_CustomerGroups.CrUserId = ActUserId;

            if (txCustomerGroupName.Text != "")
            {
                m_CustomerGroups.CustomerGroupName = txCustomerGroupName.Text;
            }

            if (txCustomerGroupDesc.Text != "")
            {
                m_CustomerGroups.CustomerGroupDesc = txCustomerGroupDesc.Text;
            }

            m_CustomerGroups.CustomerGroupId = EditId;
            SysMessageTypeId = m_CustomerGroups.InsertOrUpdate(ConstantHelpers.Replicated, ActUserId, ref SysMessageId);

            StringBuilder       csText = new StringBuilder();
            Type                cstype = this.GetType();
            ClientScriptManager cs     = Page.ClientScript;
            csText.Clear();
            csText.Append("<script type=\"text/javascript\">");
            csText.Append("window.parent.jQuery('#divEdit').dialog('close');");
            csText.Append("</script>");
            cs = Page.ClientScript;
            cs.RegisterClientScriptBlock(this.GetType(), "system_message", csText.ToString());
        }
        catch (Exception ex)
        {
            sms.utils.LogFiles.LogError(((new System.Diagnostics.StackTrace()).GetFrames()[0]).GetMethod().Name + "\t" + ex.ToString());
            JSAlertHelpers.Alert(ex.Message, this);
        }
    }
 public void DeleteAllCustomersFromCustomerGroup_ByIDBookingRs(int IDBookingRs)
 {
     CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
     CustomerGroups aCustomerGroups = new CustomerGroups();
     aCustomerGroups = aCustomerGroupsBO.Select_ByIDBookingR(IDBookingRs);
     List<CustomerGroups_Customers> aCustomerGroups_Customers = this.Select_ByIDCustomerGroup(aCustomerGroups.ID);
     foreach (CustomerGroups_Customers item in aCustomerGroups_Customers)
     {
         this.Delete(item);
     }
 }
Exemple #4
0
        private void BtnGroups_Click(object sender, EventArgs e)
        {
            Blur blur = new Blur(this.ParentForm, UIConstants.FormBlurOpacity);

            blur.Show();

            CustomerGroups customerGroups = new CustomerGroups
            {
                TopMost = true
            };

            customerGroups.ShowDialog();

            blur.Close();
        }
    protected void m_grid_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string message = "";

        try
        {
            CustomerGroups m_CustomerGroups = new CustomerGroups();
            m_CustomerGroups.CustomerGroupId = System.Int16.Parse(m_grid.DataKeys[e.RowIndex].Value.ToString());
            m_CustomerGroups.Delete();
        }
        catch (Exception ex)
        {
            sms.utils.Log.writeLog(ex.ToString(), ((new System.Diagnostics.StackTrace()).GetFrames()[0]).GetMethod().Name);
        }
        ShowGrid();
    }
Exemple #6
0
        public void InsertForm()
        {
            using (VaranegarEntities db = new VaranegarEntities())
            {
                CustomerGroups pg = new CustomerGroups();

                pg.CustomerGroupID       = Guid.NewGuid();
                pg.CustomerGroupTitle    = txtTitle.Text;
                pg.En_CustomerGroupTitle = txtEN_Title.Text;
                pg.CustomerGroupName     = txtName.Text;

                pg.IsDelete = false;

                db.CustomerGroups.Add(pg);
                db.SaveChanges();
            }
        }
 private void bindData()
 {
     System.Int16 EditId;
     if (Request.QueryString["id"] == null)
     {
         return;
     }
     else
     {
         EditId = System.Int16.Parse(Request.QueryString["id"].ToString());
         CustomerGroups m_CustomerGroups = new CustomerGroups();
         m_CustomerGroups.CustomerGroupId = EditId;
         m_CustomerGroups         = m_CustomerGroups.Get();
         txCustomerGroupName.Text = m_CustomerGroups.CustomerGroupName.ToString();
         txCustomerGroupDesc.Text = m_CustomerGroups.CustomerGroupDesc.ToString();
         txCrUserId.Text          = m_CustomerGroups.CrUserId.ToString();
     }
 }
Exemple #8
0
        public static async Task <IActionResult> GetCustomerGroups(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            string     resource = "https://" + environmentId + ".cloudax.dynamics.com";
            HttpClient client   = new HttpClient();

            AuthenticationHelper bearerToken = new AuthenticationHelper();

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", bearerToken.GetBearerToken(environmentId).Result.AccessToken.ToString());

            CustomerGroups customerGroups = new CustomerGroups();

            customerGroups.GetCustomerGroups(client, resource);

            string responseMessage = JsonConvert.SerializeObject(customerGroups);

            return(new OkObjectResult(responseMessage));
        }
Exemple #9
0
        public async Task <DeliveryPayment> GetDeliveryPayment(int affiliateId, int customerId)
        {
            if (affiliateId < 1 ||
                customerId < 1)
            {
                return(null);
            }
            else
            {
                string json = await base.GetJsonAsync("/webapplication/servicecenter/getinvoice", new Dictionary <string, object>() { { "affiliateId", affiliateId }, { "customerid", customerId } }).ConfigureAwait(false);

                DeliveryPayment deliveryPayment = JsonConvert.DeserializeObject <DeliveryPayment>(json);

                if (deliveryPayment.CustomerGroupId != 0)
                {
                    deliveryPayment.CustomerGroupName = CustomerGroups.Single(x => x.CustomerGroupId == deliveryPayment.CustomerGroupId).CustomerGroupName;
                }

                return(deliveryPayment);
            }
        }
    //--------------------------------------------------------------------------------

    private void ShowGrid()
    {
        try
        {
            CustomerGroups m_CustomerGroups = new CustomerGroups();
            m_CustomerGroups.CustomerGroupName = txtSearch.Text;
            string DateFrom = txtDateFrom.Text;
            string DateTo   = txtDateTo.Text;
            int    RowCount = 0;
            List <CustomerGroups> l_CustomerGroups = m_CustomerGroups.GetPage("", "", ddlOrderBy.SelectedValue, m_grid.PageSize, CustomPaging.PageIndex - 1, ref RowCount);

            m_grid.DataSource = l_CustomerGroups;
            m_grid.DataBind();
            lblTong.Text           = RowCount.ToString();
            CustomPaging.TotalPage = (RowCount == 0) ? 1 : (RowCount % m_grid.PageSize == 0) ? RowCount / m_grid.PageSize : (RowCount - RowCount % m_grid.PageSize) / m_grid.PageSize + 1;
        }
        catch (Exception ex)
        {
            sms.utils.Log.writeLog(ex.ToString(), ((new System.Diagnostics.StackTrace()).GetFrames()[0]).GetMethod().Name);
        }
    }
Exemple #11
0
        public async Task <Invoice> GetOrCreateInvoice(string userName, int affiliateId, int customerId)
        {
            if (string.IsNullOrEmpty(userName) ||
                affiliateId < 0 ||
                customerId < 1)
            {
                return(null);
            }
            else
            {
                string json = await base.GetJsonAsync("/webapplication/servicecenter/getorcreateinvoice", new Dictionary <string, object>() { { "userName", userName }, { "affiliateId", affiliateId }, { "customerid", customerId } }).ConfigureAwait(false);

                Invoice invoice = JsonConvert.DeserializeObject <Invoice>(json);

                if (invoice.CustomerGroupId != 0)
                {
                    invoice.CustomerGroupName = CustomerGroups.Single(x => x.CustomerGroupId == invoice.CustomerGroupId).CustomerGroupName;
                }

                return(invoice);
            }
        }
Exemple #12
0
        public async Task <Summary> GetSummary(int affiliateId, int customerId)
        {
            if (affiliateId < 1 ||
                customerId < 1)
            {
                return(null);
            }
            else
            {
                string json = await base.GetJsonAsync("/webapplication/servicecenter/getinvoice", new Dictionary <string, object>() { { "affiliateId", affiliateId }, { "customerid", customerId } }).ConfigureAwait(false);

                Summary summary = JsonConvert.DeserializeObject <Summary>(json);

                if (summary != null &&
                    summary.CustomerGroupId != 0)
                {
                    summary.CustomerGroupName = CustomerGroups.Single(x => x.CustomerGroupId == summary.CustomerGroupId).CustomerGroupName;
                }

                return(summary);
            }
        }
 protected void lbDelete_Click(object sender, EventArgs e)
 {
     try
     {
         CustomerGroups m_CustomerGroups = new CustomerGroups();
         foreach (GridViewRow m_Row in m_grid.Rows)
         {
             CheckBox chkAction = (CheckBox)m_Row.FindControl("chkAction");
             if (chkAction != null)
             {
                 if (chkAction.Checked)
                 {
                     m_CustomerGroups.CustomerGroupId = System.Int16.Parse(m_grid.DataKeys[m_Row.RowIndex].Value.ToString());
                     m_CustomerGroups.Delete();
                 }
             }
         }
         ShowGrid();
     }
     catch (Exception ex)
     {
         sms.utils.Log.writeLog(ex.ToString(), ((new System.Diagnostics.StackTrace()).GetFrames()[0]).GetMethod().Name);
     }
 }
 //Linhting - Tự động tạo nhóm
 public int AutoInsertCustomerGroup(string Name, int IDCompany)
 {
     try
     {
         if (this.Select_All().Where(a => a.Name == Name).ToList().Count > 0)
         {
             return this.Select_All().Where(a => a.Name == Name).ToList()[0].ID;
         }
         else
         {
             CustomerGroups CustomerGroups = new CustomerGroups();
             CustomerGroups.IDCompany = IDCompany;
             CustomerGroups.Name = Name;
             CustomerGroups.Status = 1;
             CustomerGroups.Disable = false;
             this.Insert(CustomerGroups);
             return CustomerGroups.ID;
         }
     }
     catch (Exception ex)
     {
         throw new Exception(string.Format("CustomerGroupBO.AutoInsertCustomerGroup :" + ex.Message.ToString()));
     }
 }
        //Hiennv     25/11/2014     Viet lai phuong thuc BookingRoom
        public bool NewBookingRoom(NewBookingEN aNewBookingEN)
        {
            try
            {
                int IDBookingR = 0;
                int IDCompany = 0;
                int IDCustomerGroup = 0;
                int IDCustomer = 0;

                string customerType = string.Empty;
                if (aNewBookingEN.CustomerType == 0)
                {
                    customerType = "Tất cả loại khác";
                }
                else if (aNewBookingEN.CustomerType == 1)
                {
                    customerType = "Khách nhà nước";
                }
                else if (aNewBookingEN.CustomerType == 2)
                {
                    customerType = "Khách đoàn";
                }
                else if (aNewBookingEN.CustomerType == 3)
                {
                    customerType = "Khách lẻ";
                }
                else if (aNewBookingEN.CustomerType == 4)
                {
                    customerType = "Khách vãng lai";
                }
                else if (aNewBookingEN.CustomerType == 5)
                {
                    customerType = "Khách bộ ngoại giao";
                }
                else
                {
                    customerType = string.Empty;
                }

                #region Them moi khach hang khi khach hang chua co
                if (aNewBookingEN.IDCustomer > 0)
                {
                    IDCustomer = aNewBookingEN.IDCustomer;
                }
                else
                {
                    CustomersBO aCustomersBO = new CustomersBO();
                    Customers aCustomers = new Customers();
                    if (aNewBookingEN.NameCustomer.Length > 50)
                    {
                        aCustomers.Name = aNewBookingEN.NameCustomer.Substring(0, 50);
                    }
                    else
                    {
                        aCustomers.Name = aNewBookingEN.NameCustomer;
                    }
                    IDCustomer = aCustomersBO.Insert(aCustomers);
                }
                #endregion

                #region Them moi cong ty khi cong ty chua co
                if (aNewBookingEN.IDCompany > 0)
                {
                    IDCompany = aNewBookingEN.IDCompany;
                }
                else
                {
                    CompaniesBO aCompaniesBO = new CompaniesBO();
                    Companies aCompanies = new Companies();
                    if (aNewBookingEN.NameCompany.Length > 250)
                    {
                        aCompanies.Name = aNewBookingEN.NameCompany.Substring(0, 250);
                    }
                    else
                    {
                        aCompanies.Name = aNewBookingEN.NameCompany;
                    }

                    aCompanies.TaxNumberCode = string.Empty;
                    aCompanies.Address = string.Empty;
                    aCompanies.Type = aNewBookingEN.CustomerType;
                    aCompanies.Status = 1;
                    aCompanies.Disable = false;
                    IDCompany = aCompaniesBO.Insert(aCompanies);
                }
                #endregion

                #region Them moi nhom vao trong cong ty
                if (IDCompany > 0)
                {
                    CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
                    CustomerGroups aCustomerGroups = new CustomerGroups();
                    string nameGroup;
                    if (string.IsNullOrEmpty(aNewBookingEN.Subject))
                    {
                        nameGroup = "[" + customerType + "][" + aNewBookingEN.NameCompany + "][" + DateTime.Now.ToString() + "]";
                    }
                    else
                    {
                        nameGroup = aNewBookingEN.Subject;
                    }
                    aCustomerGroups.IDCompany = IDCompany;
                    if (nameGroup.Length > 250)
                    {
                        aCustomerGroups.Name = nameGroup.Substring(0, 250);
                    }
                    else
                    {
                        aCustomerGroups.Name = nameGroup;
                    }

                    aCustomerGroups.Type = 1;
                    aCustomerGroups.Status = 1;
                    aCustomerGroups.Disable = false;
                    IDCustomerGroup = aCustomerGroupsBO.Insert(aCustomerGroups);
                }
                #endregion

                #region Them moi bookingRs
                if (IDCustomer > 0 && IDCustomerGroup > 0)
                {
                    string subject = "[" + customerType + "][" + aNewBookingEN.NameCompany + "][" + DateTime.Now.ToString() + "]";

                    BookingRs aBookingRs = new BookingRs();

                    aBookingRs.CreatedDate = DateTime.Now;
                    aBookingRs.CustomerType = aNewBookingEN.CustomerType;
                    aBookingRs.BookingType = aNewBookingEN.BookingType;
                    if (subject.Length > 250)
                    {
                        aBookingRs.Subject = subject.Substring(0, 250);
                    }
                    else
                    {
                        aBookingRs.Subject = subject;
                    }
                    aBookingRs.IDCustomerGroup = IDCustomerGroup;
                    aBookingRs.IDCustomer = IDCustomer;
                    aBookingRs.IDSystemUser = aNewBookingEN.IDSystemUser;
                    aBookingRs.PayMenthod = aNewBookingEN.PayMenthod;
                    aBookingRs.StatusPay = aNewBookingEN.StatusPay;
                    aBookingRs.BookingMoney = aNewBookingEN.BookingMoney;
                    aBookingRs.ExchangeRate = aNewBookingEN.ExchangeRate;
                    aBookingRs.Level = 0;// de mac dinh hien tai chua dung den
                    aBookingRs.Note = string.Empty;
                    aBookingRs.Description = string.Empty;
                    aBookingRs.DatePay = aNewBookingEN.CheckOutPlan;
                    aBookingRs.DateEdit = aNewBookingEN.CheckInActual;
                    aBookingRs.Status = aNewBookingEN.Status;
                    aBookingRs.Type = aNewBookingEN.Type;
                    aBookingRs.Disable = aNewBookingEN.Disable;

                    //add new bookingRs
                    BookingRsBO aBookingRsBO = new BookingRsBO();
                    IDBookingR = aBookingRsBO.Insert(aBookingRs);
                }
                #endregion

                #region them moi bookingRoom
                if (IDBookingR > 0)
                {
                    BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                    BookingRooms aBookingRooms;
                    for (int i = 0; i < aNewBookingEN.aListNewRoomMembers.Count; i++)
                    {
                        aBookingRooms = new BookingRooms();
                        aBookingRooms.IDBookingR = IDBookingR;
                        aBookingRooms.CodeRoom = aNewBookingEN.aListNewRoomMembers[i].RoomCode;
                        aBookingRooms.PercentTax = 10;
                        aBookingRooms.CostRef_Rooms = aNewBookingEN.aListNewRoomMembers[i].RoomCostRef;
                        aBookingRooms.Cost = aNewBookingEN.aListNewRoomMembers[i].RoomCostRef;
                        aBookingRooms.CheckInPlan = aNewBookingEN.CheckInActual;
                        aBookingRooms.CheckInActual = aNewBookingEN.CheckInActual;
                        aBookingRooms.CheckOutPlan = aNewBookingEN.CheckOutPlan;
                        aBookingRooms.CheckOutActual = aNewBookingEN.CheckOutActual;
                        aBookingRooms.StartTime = aNewBookingEN.CheckInActual;
                        aBookingRooms.EndTime = aNewBookingEN.CheckOutPlan;
                        aBookingRooms.BookingStatus = 1;
                        aBookingRooms.Type = 3; //Tính CheckIn sớm và CheckOut muộn
                        aBookingRooms.Status = aNewBookingEN.Status;
                        aBookingRooms.PriceType = "G1";
                        //add new bookingRoom
                        aBookingRoomsBO.Insert(aBookingRooms);

                    }
                }
                #endregion

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        //Hiennv     26/11/2014     Viet lai phuong thuc checkInForRoomBooking
        public bool NewCheckInForRoomBooking(CheckInEN aCheckInEN)
        {
            try
            {
                CustomersBO aCustomersBO = new CustomersBO();
                List<Customers> aListCustomersTemp = aCustomersBO.Select_All();

                BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                List<BookingRooms> aListBookingRoomTemp = aBookingRoomsBO.Select_All();

                int IDBookingRooms = 0;
                int IDCompany = 0;
                int IDCustomerGroup = 0;
                int IDCustomer = 0;
                int Result = 0;

                string customerType = string.Empty;

                if (aCheckInEN.CustomerType == 0)
                {
                    customerType = "Tất cả loại khác";
                }
                else if (aCheckInEN.CustomerType == 1)
                {
                    customerType = "Khách nhà nước";
                }
                else if (aCheckInEN.CustomerType == 2)
                {
                    customerType = "Khách đoàn";
                }
                else if (aCheckInEN.CustomerType == 3)
                {
                    customerType = "Khách lẻ";
                }
                else if (aCheckInEN.CustomerType == 4)
                {
                    customerType = "Khách vãng lai";
                }
                else if (aCheckInEN.CustomerType == 5)
                {
                    customerType = "Khách bộ ngoại giao";
                }
                else
                {
                    customerType = string.Empty;
                }

                #region Them moi cong ty khi cong ty chua co
                if (aCheckInEN.IDCompany > 0)
                {
                    IDCompany = aCheckInEN.IDCompany;
                }
                else
                {
                    CompaniesBO aCompaniesBO = new CompaniesBO();
                    Companies aCompanies = new Companies();
                    if (aCheckInEN.NameCompany.Length > 250)
                    {
                        aCompanies.Name = aCheckInEN.NameCompany.Substring(0, 250);
                    }
                    else
                    {
                        aCompanies.Name = aCheckInEN.NameCompany;
                    }

                    aCompanies.TaxNumberCode = string.Empty;
                    aCompanies.Address = string.Empty;
                    aCompanies.Type = aCheckInEN.CustomerType;
                    aCompanies.Status = 1;
                    aCompanies.Disable = false;
                    IDCompany = aCompaniesBO.Insert(aCompanies);
                }
                #endregion

                #region Them moi nhom vao trong cong ty
                CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
                CustomerGroups aCustomerGroups;
                aCustomerGroups = aCustomerGroupsBO.Select_ByIDCompanyAndIDCustomerGroup(IDCompany, aCheckInEN.IDCustomerGroup);

                if (aCustomerGroups == null)
                {

                    aCustomerGroups = new CustomerGroups();

                    string nameGroup = "[" + customerType + "][" + aCheckInEN.NameCompany + "][" + DateTime.Now.ToString() + "]";
                    aCustomerGroups.IDCompany = IDCompany;
                    if (nameGroup.Length > 250)
                    {
                        aCustomerGroups.Name = nameGroup.Substring(0, 250);
                    }
                    else
                    {
                        aCustomerGroups.Name = nameGroup;
                    }

                    aCustomerGroups.Type = 1;
                    aCustomerGroups.Status = 1;
                    aCustomerGroups.Disable = false;
                    IDCustomerGroup = aCustomerGroupsBO.Insert(aCustomerGroups);
                }
                else
                {
                    IDCustomerGroup = aCheckInEN.IDCustomerGroup;
                }
                #endregion

                string subject = "[" + customerType + "][" + aCheckInEN.NameCompany + "][" + DateTime.Now.ToString() + "]";

                BookingRsBO aBookingRsBO = new BookingRsBO();
                BookingRs aBookingRs = aBookingRsBO.Select_ByID(aCheckInEN.IDBookingR);
                if (aBookingRs != null)
                {
                    aBookingRs.CreatedDate = DateTime.Now;
                    aBookingRs.CustomerType = aCheckInEN.CustomerType;
                    aBookingRs.BookingType = aCheckInEN.BookingType;
                    if (subject.Length > 250)
                    {
                        aBookingRs.Subject = subject.Substring(0, 250);
                    }
                    else
                    {
                        aBookingRs.Subject = subject;
                    }

                    aBookingRs.IDCustomerGroup = IDCustomerGroup;
                    aBookingRs.IDCustomer = aCheckInEN.IDCustomer;
                    aBookingRs.IDSystemUser = aCheckInEN.IDSystemUser;
                    aBookingRs.PayMenthod = aCheckInEN.PayMenthod;
                    aBookingRs.StatusPay = aCheckInEN.StatusPay;
                    aBookingRs.BookingMoney = aCheckInEN.BookingMoney;
                    aBookingRs.ExchangeRate = aCheckInEN.ExchangeRate;
                    aBookingRs.Level = 0;// de mac dinh hien tai chua dung den
                    aBookingRs.Note = string.Empty;
                    aBookingRs.Description = string.Empty;
                    aBookingRs.DatePay = aCheckInEN.CheckOutPlan;
                    aBookingRs.DateEdit = aCheckInEN.CheckInActual;
                    aBookingRs.Status = aCheckInEN.Status;
                    aBookingRs.Type = aCheckInEN.Type;
                    aBookingRs.Disable = aCheckInEN.Disable;
                    aBookingRsBO.Update(aBookingRs);
                }

                //==========================================================
                BookingRooms aBookingRooms;
                BookingRoomsMembers aBookingRoomsMembers;

                for (int i = 0; i < aCheckInEN.aListRoomMembers.Count; i++)
                {

                    List<BookingRooms> aListBookingRoom = aListBookingRoomTemp.Where(r => r.ID == aCheckInEN.aListRoomMembers[i].IDBookingRooms).ToList();
                    if (aListBookingRoom.Count > 0)
                    {
                        aBookingRooms = new BookingRooms();
                        aBookingRooms = aListBookingRoom[0];
                        aBookingRooms.IDBookingR = aCheckInEN.IDBookingR;
                        aBookingRooms.CodeRoom = aCheckInEN.aListRoomMembers[i].RoomCode;
                        aBookingRooms.PercentTax = 10;
                        aBookingRooms.CostRef_Rooms = aCheckInEN.aListRoomMembers[i].RoomCostRef;
                        aBookingRooms.Cost = aCheckInEN.aListRoomMembers[i].RoomCostRef;
                        aBookingRooms.CheckInPlan = aCheckInEN.CheckInActual;
                        aBookingRooms.CheckInActual = aCheckInEN.CheckInActual;
                        aBookingRooms.CheckOutPlan = aCheckInEN.CheckOutPlan;
                        aBookingRooms.CheckOutActual = aCheckInEN.CheckOutActual;
                        aBookingRooms.StartTime = aCheckInEN.CheckInActual;
                        aBookingRooms.EndTime = aCheckInEN.CheckOutPlan;
                        aBookingRooms.BookingStatus = 1;
                        aBookingRooms.Type = 3; //Tính CheckIn sớm và CheckOut muộn
                        aBookingRooms.Status = aCheckInEN.Status;
                        aBookingRooms.PriceType = "G1";
                        aBookingRoomsBO.Update(aBookingRooms);

                        IDBookingRooms = aCheckInEN.aListRoomMembers[i].IDBookingRooms;
                    }
                    else
                    {
                        aBookingRooms = new BookingRooms();
                        aBookingRooms.IDBookingR = aCheckInEN.IDBookingR;
                        aBookingRooms.CodeRoom = aCheckInEN.aListRoomMembers[i].RoomCode;
                        aBookingRooms.PercentTax = 10;
                        aBookingRooms.CostRef_Rooms = aCheckInEN.aListRoomMembers[i].RoomCostRef;
                        aBookingRooms.Cost = aCheckInEN.aListRoomMembers[i].RoomCostRef;
                        aBookingRooms.CheckInPlan = aCheckInEN.CheckInActual;
                        aBookingRooms.CheckInActual = aCheckInEN.CheckInActual;
                        aBookingRooms.CheckOutPlan = aCheckInEN.CheckOutPlan;
                        aBookingRooms.CheckOutActual = aCheckInEN.CheckOutActual;
                        aBookingRooms.StartTime = aCheckInEN.CheckInActual;
                        aBookingRooms.EndTime = aCheckInEN.CheckOutPlan;
                        aBookingRooms.BookingStatus = 1;
                        aBookingRooms.Type = 3; //Tính CheckIn sớm và CheckOut muộn
                        aBookingRooms.Status = aCheckInEN.Status;
                        aBookingRooms.PriceType = "G1";
                        //add new bookingRoom
                        IDBookingRooms = aBookingRoomsBO.Insert(aBookingRooms);
                    }

                    //-----------------------------------------------------------
                    aBookingRoomsMembers = new BookingRoomsMembers();
                    aBookingRoomsMembers.IDBookingRoom = IDBookingRooms;

                    BookingRoomsMembersBO aBookingRoomsMembersBO = new BookingRoomsMembersBO();
                    for (int ii = 0; ii < aCheckInEN.aListRoomMembers[i].ListCustomer.Count; ii++)
                    {
                        Customers aCustomers;
                        List<Customers> aListCustomers = aListCustomersTemp.Where(c => c.ID == aCheckInEN.aListRoomMembers[i].ListCustomer[ii].ID).ToList();
                        if (aListCustomers.Count > 0)
                        {
                            IDCustomer = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].ID;
                            aCustomers = aListCustomers[0];
                            aCustomers.Name = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Name;
                            aCustomers.Identifier1 = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Identifier1;
                            aCustomers.Birthday = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Birthday;
                            aCustomers.Gender = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Gender;
                            aCustomers.Tel = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Tel;
                            aCustomers.Nationality = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Nationality;
                            aCustomersBO.Update(aCustomers);
                        }
                        else
                        {
                            aCustomers = new Customers();
                            aCustomers.Name = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Name;
                            aCustomers.Identifier1 = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Identifier1;
                            aCustomers.Birthday = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Birthday;
                            aCustomers.Gender = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Gender;
                            aCustomers.Tel = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Tel;
                            aCustomers.Nationality = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Nationality;

                            //Them moi khach hang
                            IDCustomer = aCustomersBO.Insert(aCustomers);
                        }
                        aBookingRoomsMembers.IDCustomer = IDCustomer;
                        aBookingRoomsMembers.PurposeComeVietnam = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].PurposeComeVietnam;
                        aBookingRoomsMembers.DateEnterCountry = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].DateEnterCountry;
                        aBookingRoomsMembers.EnterGate = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].EnterGate;
                        aBookingRoomsMembers.TemporaryResidenceDate = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].TemporaryResidenceDate;
                        aBookingRoomsMembers.LimitDateEnterCountry = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].LimitDateEnterCountry;
                        aBookingRoomsMembers.Organization = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Organization;
                        aBookingRoomsMembers.LeaveDate = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].LeaveDate;

                        //add new bookingRoomMember
                        aBookingRoomsMembersBO.Insert(aBookingRoomsMembers);

                        #region  them nguoi vao trong customergroup_customer

                        string nameCustomerGroup_customer = "[" + customerType + "][" + aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Name + "]";

                        CustomerGroups_CustomersBO aCustomerGroups_CustomersBO = new CustomerGroups_CustomersBO();
                        CustomerGroups_Customers aCustomerGroups_Customers = new CustomerGroups_Customers();
                        if (nameCustomerGroup_customer.Length > 150)
                        {
                            aCustomerGroups_Customers.Name = nameCustomerGroup_customer.Substring(0, 150);
                        }
                        else
                        {
                            aCustomerGroups_Customers.Name = nameCustomerGroup_customer;
                        }

                        aCustomerGroups_Customers.Type = 1;
                        aCustomerGroups_Customers.Status = 1;
                        aCustomerGroups_Customers.Disable = false;
                        aCustomerGroups_Customers.FromDate = DateTime.Now;
                        aCustomerGroups_Customers.ToDate = DateTime.Now;
                        aCustomerGroups_Customers.IDCustomer = IDCustomer;
                        aCustomerGroups_Customers.IDCustomerGroup = IDCustomerGroup;
                        aCustomerGroups_CustomersBO.Insert(aCustomerGroups_Customers);
                        #endregion

                        // dung de cap nhap lai nguoi dai dien khi dat phong
                        if (aCheckInEN.aListRoomMembers[i].ListCustomer[ii].PepoleRepresentative == true)
                        {
                            aBookingRsBO = new BookingRsBO();
                            aBookingRs = new BookingRs();
                            aBookingRs = aBookingRsBO.Select_ByID(aCheckInEN.IDBookingR);
                            if (aBookingRs != null)
                            {
                                aBookingRs.IDCustomer = IDCustomer;
                                Result = aBookingRsBO.Update(aBookingRs);
                            }

                        }
                        else
                        {
                            if (ii == (aCheckInEN.aListRoomMembers[i].ListCustomer.Count - 1))
                            {
                                if (Result == 0)
                                {
                                    aBookingRsBO = new BookingRsBO();
                                    aBookingRs = new BookingRs();
                                    aBookingRs = aBookingRsBO.Select_ByID(aCheckInEN.IDBookingR);
                                    if (aBookingRs != null)
                                    {
                                        aBookingRs.IDCustomer = IDCustomer;
                                        aBookingRsBO.Update(aBookingRs);
                                    }
                                }
                            }
                        }

                    }
                }
                return true;

            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public int InsertCustomerIntoCustomerGroup(int IDCustomer, int IDCustomerGroup)
        {
            // Add customer vao group
            CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
            CustomerGroups aCustomerGroups = new CustomerGroups();
            aCustomerGroups = aCustomerGroupsBO.Select_ByID(IDCustomerGroup);

            CustomerGroups_CustomersBO aCustomerGroups_CustomersBO = new CustomerGroups_CustomersBO();
            CustomerGroups_Customers aCustomerGroups_Customers = new CustomerGroups_Customers();

            aCustomerGroups_Customers = aCustomerGroups_CustomersBO.Select_ByIDCustomer_ByIDCustomerGroup(IDCustomer, IDCustomerGroup);
            if (aCustomerGroups_Customers == null)
            {
                Customers aCustomers = (new CustomersBO()).Select_ByID(IDCustomer);
                aCustomerGroups_Customers.IDCustomer = IDCustomer;
                aCustomerGroups_Customers.IDCustomerGroup = aCustomerGroups.ID;
                aCustomerGroups_Customers.Name = aCustomerGroups.Name + "_" + aCustomers.Name + "_" + aCustomers.Identifier1 + "_" + DateTime.Now.ToShortDateString();
                return aCustomerGroups_CustomersBO.Insert(aCustomerGroups_Customers);
            }
            else
                return 0;
        }
 //=======================================================
 //Author: LinhTing
 //Function : Thêm CustomerGroup
 //=======================================================
 public int Insert(CustomerGroups CustomerGroups)
 {
     try
     {
         aDatabaseDA.CustomerGroups.Add(CustomerGroups);
         aDatabaseDA.SaveChanges();
         return CustomerGroups.ID;
     }
     catch (Exception ex)
     {
         throw new Exception(string.Format("CustomerGroupBO.Insert :"+ ex.Message.ToString()));
     }
 }
 //=======================================================
 //Author: LinhTing
 //Function : Update CustomerGroup
 //=======================================================
 public int Update(CustomerGroups CustomerGroups)
 {
     try
     {
         aDatabaseDA.CustomerGroups.AddOrUpdate(CustomerGroups);
         return aDatabaseDA.SaveChanges();
     }
     catch (Exception ex)
     {
         throw new Exception(string.Format("CustomerGroupBO.Update :"+ ex.Message.ToString()));
     }
 }
        // Ngoc
        public int InsertCustomerIntoCustomerGroup_ByIDBookingRs(int IDCustomer, int IDBookingRs)
        {
            // Add customer vao group
            CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
            CustomerGroups aCustomerGroups = new CustomerGroups();
            aCustomerGroups = aCustomerGroupsBO.Select_ByIDBookingR(IDBookingRs);

            CustomerGroups_CustomersBO aCustomerGroups_CustomersBO = new CustomerGroups_CustomersBO();
            //Kiem tra xe khach do da co trong custome group chua
            CustomerGroups_Customers aCustomerGroups_Customers = new CustomerGroups_Customers();
            aCustomerGroups_Customers = aCustomerGroups_CustomersBO.Select_ByIDCustomer_ByIDCustomerGroup(IDCustomer, aCustomerGroups.ID);
            if (aCustomerGroups_Customers == null)
            {
                aCustomerGroups_Customers = new CustomerGroups_Customers();
                Customers aCustomers = (new CustomersBO()).Select_ByID(IDCustomer);
                aCustomerGroups_Customers.IDCustomer = IDCustomer;
                aCustomerGroups_Customers.IDCustomerGroup = aCustomerGroups.ID;
                aCustomerGroups_Customers.Name = aCustomerGroups.Name + "_" + aCustomers.Name + "_" + aCustomers.Identifier1 + "_" + DateTime.Now.ToShortDateString();
                return aCustomerGroups_CustomersBO.Insert(aCustomerGroups_Customers);
            }
            else
            {
                return 0;
            }
        }
        //Hiennv     26/11/2014       ham dung de load toan bo du lieu theo IDBookingR
        public CheckInEN InitData(int IDBookingR)
        {
            try
            {
                CheckInEN aCheckInEN = new CheckInEN();
                BookingRsBO aBookingRsBO = new BookingRsBO();
                BookingRs aBookingRs = new BookingRs();
                aBookingRs = aBookingRsBO.Select_ByID(IDBookingR);
                if(aBookingRs != null)
                {
                    aCheckInEN.IDBookingR = aBookingRs.ID;
                    aCheckInEN.CustomerType = aBookingRs.CustomerType.GetValueOrDefault();
                    aCheckInEN.BookingType = aBookingRs.BookingType.GetValueOrDefault();
                    aCheckInEN.Note = aBookingRs.Note;
                    aCheckInEN.IDCustomerGroup = aBookingRs.IDCustomerGroup;
                    aCheckInEN.IDCustomer = aBookingRs.IDCustomer;
                    aCheckInEN.IDSystemUser = aBookingRs.IDSystemUser;
                    aCheckInEN.PayMenthod = aBookingRs.PayMenthod.GetValueOrDefault();
                    aCheckInEN.StatusPay = aBookingRs.StatusPay.GetValueOrDefault();
                    aCheckInEN.BookingMoney = aBookingRs.BookingMoney.GetValueOrDefault();
                    aCheckInEN.ExchangeRate = aBookingRs.ExchangeRate.GetValueOrDefault();
                    aCheckInEN.Status = aBookingRs.Status.GetValueOrDefault();
                    aCheckInEN.Type = aBookingRs.Type.GetValueOrDefault();
                    aCheckInEN.Disable = aBookingRs.Disable.GetValueOrDefault();
                    aCheckInEN.Level = aBookingRs.Level;
                    aCheckInEN.Subject = aBookingRs.Subject;
                    aCheckInEN.Description = aBookingRs.Description;
                    aCheckInEN.DatePay = aBookingRs.DatePay;
                    aCheckInEN.DateEdit = aBookingRs.DateEdit;
                    CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
                    CustomerGroups aCustomerGroups = new CustomerGroups();
                    aCustomerGroups = aCustomerGroupsBO.Select_ByID(aBookingRs.IDCustomerGroup);
                    if(aCustomerGroups !=null)
                    {
                        aCheckInEN.IDCompany = aCustomerGroups.IDCompany;
                    }

                }
                RoomsBO aRoomsBO = new RoomsBO();
                List<Rooms> aListRooms = new List<Rooms>();
                aListRooms = aRoomsBO.Select_All();

                BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                List<BookingRooms> aListBookingRooms = new List<BookingRooms>();
                aListBookingRooms = aBookingRoomsBO.Select_ByIDBookingRs(IDBookingR);
                for (int i = 0; i < aListBookingRooms.Count; i++ )
                {
                    RoomMemberEN aRoomMemberEN = new RoomMemberEN();
                    aRoomMemberEN.IDBookingRooms = aListBookingRooms[i].ID;
                    aRoomMemberEN.RoomCode = aListBookingRooms[i].CodeRoom;
                    aRoomMemberEN.RoomSku = aCheckInEN.GetInfoRooms(aListRooms, aListBookingRooms[i].CodeRoom).Sku;
                    aRoomMemberEN.RoomType = aCheckInEN.GetInfoRooms(aListRooms, aListBookingRooms[i].CodeRoom).Type.GetValueOrDefault();
                    aRoomMemberEN.RoomTypeDisplay = CORE.CONSTANTS.SelectedRoomsType(aCheckInEN.GetInfoRooms(aListRooms, aListBookingRooms[i].CodeRoom).Type.GetValueOrDefault()).Name;
                    aRoomMemberEN.RoomBed1 = aCheckInEN.GetInfoRooms(aListRooms, aListBookingRooms[i].CodeRoom).Bed1.GetValueOrDefault();
                    aRoomMemberEN.RoomBed2 = aCheckInEN.GetInfoRooms(aListRooms, aListBookingRooms[i].CodeRoom).Bed2.GetValueOrDefault();
                    aRoomMemberEN.RoomCostRef = aCheckInEN.GetInfoRooms(aListRooms, aListBookingRooms[i].CodeRoom).CostRef.GetValueOrDefault();
                    aRoomMemberEN.RoomCost = aListBookingRooms[i].Cost.GetValueOrDefault();
                    aCheckInEN.InsertRoom(aRoomMemberEN);
                }
                return aCheckInEN;
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_CheckInForRoomBooking.InitData()\n" + ex.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return null;
            }
        }
        public int DeleteCustomerFromCustomerGroup_ByIDBookingRs(int IDCustomer, int IDBookingRs)
        {
            CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
            CustomerGroups aCustomerGroups = new CustomerGroups();
            aCustomerGroups = aCustomerGroupsBO.Select_ByIDBookingR(IDBookingRs);

            CustomerGroups_CustomersBO aCustomerGroups_CustomersBO = new CustomerGroups_CustomersBO();

            return aCustomerGroups_CustomersBO.Delete(IDCustomer, aCustomerGroups.ID);
        }
        private void btnAddNew_Click(object sender, EventArgs e)
        {
            try
            {
                if (ValidateData() == true)
                {
                    CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
                    CustomerGroups aCustomerGroups = new CustomerGroups();
                    aCustomerGroups.IDCompany = Convert.ToInt32(lueCompany.EditValue);
                    aCustomerGroups.Name = txtName.Text;
                    aCustomerGroups.Type = cboType.SelectedIndex + 1;
                    aCustomerGroups.Status = cboStatus.SelectedIndex + 1;
                    aCustomerGroups.Disable = bool.Parse(cboDisable.Text);
                    aCustomerGroupsBO.Insert(aCustomerGroups);

                    if (this.afrmLst_CustomerGroups_Old != null)
                    {
                        afrmLst_CustomerGroups_Old.ReloadData();
                    }
                    else if (afrmIns_CustomerGroups_Customers_Old != null)
                    {
                        afrmIns_CustomerGroups_Customers_Old.Reload();
                    }
                    else if (afrmTsk_BookingHall_Goverment_Old != null)
                    {
                        afrmTsk_BookingHall_Goverment_Old.ReloadData();
                    }
                    else if (afrmTsk_BookingHall_Group != null)
                    {
                        this.afrmTsk_BookingHall_Group.ReloadData();
                    }
                    else if (afrmTsk_BookingHall_Customer != null)
                    {
                        this.afrmTsk_BookingHall_Customer.ReloadData();
                    }
                    else if (afrmTsk_UpdBooking != null)
                    {
                        this.afrmTsk_UpdBooking.ReloadData();
                    }
                    this.Close();
                    MessageBox.Show("Thêm mới thành công .", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmIns_CustomerGroups.btnAddNew_Click\n" + ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }