private void viewCustomerRewardPointsHistory(object sender, EventArgs e)
        {
            DataGridViewRow row    = grvCustomer.Rows[currentMouseOverRow];
            string          custID = row.Cells[0].Value.ToString();

            JSManagementDataSet.CustomerDataTable custData = customerTableAdapter.GetDataByCustomerId(int.Parse(custID));

            if (custData.Rows.Count == 0)
            {
                return;
            }
            string custName    = custData[0].CustomerName;
            string custAddress = custData[0].Address;
            string custPhone   = custData[0].Telephone;
            string custNote    = custData[0].Note;

            Form custEditForm = new Form();

            custEditForm.Text = "Sửa thông tin khách hàng";

            CustomerRewardPointsHistoryUserControl custUserControl = new CustomerRewardPointsHistoryUserControl();
            TextBox  txtCustName          = custUserControl.Controls.Find("txtCustName", true)[0] as TextBox;
            TextBox  txtCustAddress       = custUserControl.Controls.Find("txtCustAddress", true)[0] as TextBox;
            TextBox  txtNote              = custUserControl.Controls.Find("txtNote", true)[0] as TextBox;
            TextBox  txtPhone             = custUserControl.Controls.Find("txtPhone", true)[0] as TextBox;
            Label    lbCustId             = custUserControl.Controls.Find("lbCustId", true)[0] as Label;
            Label    lbHeader             = custUserControl.Controls.Find("lbHeader", true)[0] as Label;
            ComboBox comboBoxCustomerType = custUserControl.Controls.Find("comboBoxCustomerType", true)[0] as ComboBox;

            comboBoxCustomerType.DataSource    = customerTypeTableAdapter.GetData();
            comboBoxCustomerType.DisplayMember = CUST_TYPE_NAME;
            comboBoxCustomerType.ValueMember   = CUST_TYPE_ID;

            lbCustId.Text       = custID;
            txtCustName.Text    = custName;
            txtCustAddress.Text = custAddress;
            txtPhone.Text       = custPhone;
            txtNote.Text        = custNote;
            comboBoxCustomerType.SelectedValue = custData[0].CustTypeId;
            lbHeader.Text = string.Format("Sửa thông tin khách hàng").ToUpper();

            custEditForm.Controls.Add(custUserControl);
            custEditForm.Width  = custUserControl.Width;
            custEditForm.Height = custUserControl.Height;
            custEditForm.Show();

            custEditForm.FormClosed += custEditForm_FormClosed;
        }
        private bool CheckCustomerExisted(string telephone)
        {
            telephone.Trim();
            telephone = telephone.Replace(" ", string.Empty);
            telephone = telephone.Replace(".", string.Empty);
            customerTableAdapter.ClearBeforeFill = true;
            JSManagementDataSet.CustomerDataTable custData = customerTableAdapter.CheckCustomerExsited(telephone);

            if (custData != null)
            {
                if (custData.Rows.Count > 0)
                {
                    return(true);
                }
            }
            return(false);
        }
        private void BindDataToEdit(DataGridViewCellEventArgs e)
        {
            DataGridViewRow row = grvCustomer.Rows[e.RowIndex];

            if (row.IsNewRow)
            {
                return;
            }
            int custID = int.Parse(row.Cells[0].Value.ToString());

            JSManagementDataSet.CustomerDataTable custData = customerTableAdapter.GetDataByCustomerId(custID);
            string custName    = custData[0].CustomerName;
            string custAddress = custData[0].Address;
            string custPhone   = custData[0].Telephone;
            string custNote    = custData[0].Note;

            lbCustId.Text       = custID.ToString();
            txtCustName.Text    = custName;
            txtCustAddress.Text = custAddress;
            txtPhone.Text       = custPhone;
            txtNote.Text        = custNote;
            comboBoxCustomerType.SelectedValue = custData[0].CustTypeId;
            cboxIsContact.Checked = custData[0].IsContact;
            checkBoxIsAttendRewardPointProgram.Checked = custData[0].IsAttendRewardPointProgram;
            lbHeader.Text = string.Format("Sửa thông tin khách hàng").ToUpper();

            grvTransactionHistory.DataSource = getProductInOutDetailTableAdapter.GetProductInOutDetailByCustomerId(custID);
            //foreach(DataGridViewRow r in grvTransactionHistory.Rows)
            //{
            //    if (!Setting.GetBoolSetting("AllowUserViewAllCost") && !LoginInfor.IsAdmin)
            //    {
            //        if (r.Cells["Action"].Value != null)
            //        {
            //            if (r.Cells["IsReturnSupplier"].Selected && r.Cells["Action"].Value.ToString() == "xuất")
            //            {
            //                r.Cells["Price"].Value = 0;
            //                //r.Cells["ClosingBalance"].Value = 0;
            //            }
            //        }
            //    }

            //}

            grvRewardPointHistory.DataSource = rewardPointsByCustIdTableAdapter.GetRewardPointsHistoryByCustomerId(custID);

            if (!Setting.GetBoolSetting("AllowUserViewAllCost") && !LoginInfor.IsAdmin)
            {
                foreach (DataGridViewRow r in grvTransactionHistory.Rows)
                {
                    if (r.Cells["Action"].Value != null)
                    {
                        if (((bool.Parse(r.Cells["IsReturnSupplier"].Value.ToString())) && r.Cells["Action"].Value.ToString().Trim().ToLower() == "xuất") || r.Cells["Action"].Value.ToString() == "nhập")
                        {
                            r.Cells["Price"].Value = 0;
                            //r.Cells["Amount"].Value = 0;
                            //r.Cells["ClosingBalanceAmount"].Value = 0;
                            //r.Cells["ClosingBalance"].Value = 0;
                        }
                    }
                }
            }
        }