private void GetCostIdToIncomeForm(DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1 || e.RowIndex == grvReceivableFromCustomer.Rows.Count - 1)
            {
                return;
            }
            DataGridViewRow row          = grvReceivableFromCustomer.Rows[e.RowIndex];
            string          amount       = row.Cells[3].Value.ToString();
            string          incomeAmount = row.Cells[4].Value.ToString();

            if (decimal.Parse(amount) - decimal.Parse(incomeAmount) == 0)
            {
                MessageBox.Show("Công nợ này đã thanh toán hết!");
                return;
            }

            FormCollection activeForms = Application.OpenForms;
            Form           incomeForm  = new Form();

            foreach (Form f in activeForms)
            {
                if (f.Name == "IncomeForm")
                {
                    incomeForm = f;
                }
            }

            Label lbCostId = incomeForm.Controls.Find("lbCostId", true)[0] as Label;

            lbCostId.Text = row.Cells[0].Value.ToString();
            Label lbOrderId = incomeForm.Controls.Find("lbOrderId", true)[0] as Label;

            lbOrderId.Text = "0";
            TextBox txtreason = incomeForm.Controls.Find("txtReason", true)[0] as TextBox;

            txtreason.Text = string.Format("Thu nợ/tạm ứng ngày {0} / {1}", DateTime.Parse(row.Cells[2].Value.ToString()).ToShortDateString(), row.Cells[1].Value.ToString());
            UCTextBoxCurrency txtAmount = incomeForm.Controls.Find("ucTextBoxCurrency1", true)[0] as UCTextBoxCurrency;

            txtAmount.Text = (decimal.Parse(amount) - decimal.Parse(incomeAmount)).ToString();
            this.Close();
        }
        private void GetOrderIdToIncomeForm(DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1 || e.RowIndex == grvReceivableFromCustomer.Rows.Count - 1)
            {
                return;
            }
            DataGridViewRow row             = grvReceivableFromCustomer.Rows[e.RowIndex];
            string          amount          = row.Cells["Amount"].Value.ToString();
            string          incomeAmount    = row.Cells["IncomeAmount"].Value.ToString();
            int             purchaseOrderId = int.Parse(row.Cells["PurchaseReceiptOrderId"].Value.ToString());

            if (decimal.Parse(amount) - decimal.Parse(incomeAmount) == 0)
            {
                MessageBox.Show("Công nợ này đã thanh toán hết!");
                return;
            }

            FormCollection activeForms = Application.OpenForms;
            Form           incomeForm  = new Form();

            foreach (Form f in activeForms)
            {
                if (f.Name == "IncomeForm")
                {
                    incomeForm = f;
                }
            }
            Label lbCostId = incomeForm.Controls.Find("lbCostId", true)[0] as Label;

            lbCostId.Text = "0";

            Label lbOrderId = incomeForm.Controls.Find("lbOrderId", true)[0] as Label;

            JSManagementDataSet.ReceivableFromCustomersDataTable receivableFromCustDataTable = receivableCustomerAdapter.GetReceivableFromCustomersByPurchaseOrderId(purchaseOrderId);

            decimal totalAmount = 0;
            decimal totalIncome = 0;
            int     custId      = 0;

            foreach (DataRow r in receivableFromCustDataTable.Rows)
            {
                totalAmount += decimal.Parse(r.ItemArray[3].ToString());
                totalIncome += decimal.Parse(r.ItemArray[4].ToString());
                custId       = int.Parse(r.ItemArray[6].ToString());
            }

            lbOrderId.Text = purchaseOrderId.ToString();
            TextBox txtreason    = incomeForm.Controls.Find("txtReason", true)[0] as TextBox;
            Label   incomeHeader = incomeForm.Controls.Find(Constant.Income.LABEL_INCOME_HEADER_CONTROL_NAME, true)[0] as Label;

            txtreason.Text = string.Format("Lập {0} tiền ... ngày {1} / Mã số bưu gửi: {2} / Đơn hàng: {3}", incomeHeader.Text, DateTime.Parse(row.Cells["OrderDate"].Value.ToString()).ToShortDateString(), row.Cells["BillNumber"].Value.ToString(), row.Cells["PurchaseReceiptOrderId"].Value.ToString());
            UCTextBoxCurrency txtAmount = incomeForm.Controls.Find("ucTextBoxCurrency1", true)[0] as UCTextBoxCurrency;

            txtAmount.Value = totalAmount - totalIncome;

            CustomerSelectUserControl customerSelectUserControl = incomeForm.Controls.Find("customerSelectUserControl1", true)[0] as CustomerSelectUserControl;

            customerSelectUserControl.Enabled = false;
            customerSelectUserControl.CustId  = custId;

            this.Close();
        }