private void cmbPolicy_EditValueChanged(object sender, EventArgs e) { if (cmbPolicy.EditValue != null) { frmLoading _loading = new frmLoading(); _loading.Show(); dsMembers.Members.Clear(); dsMembers.Members.Merge(DataHelper.GetTableData(dsMembers.Members, " Where IID = '" + cmbPolicy.GetColumnValue("MemberID").ToString() + "'").Tables[0]); DataRow dr = dsMembers.Members.Rows[0]; // MemberID = dr["IID"].ToString(); txtFatherHusbandName.Text = dr["FatherHusbandName"].ToString(); txtFullName.Text = dr["FullName"].ToString(); txtLAddress.Text = dr["LLocation"].ToString(); txtLDistrict.Text = dr["LDistrict"].ToString(); txtLpostCode.Text = dr["LPostCode"].ToString(); txtLPostOffice.Text = dr["LPostOffice"].ToString(); txtLThana.Text = dr["LThana"].ToString(); txtLVillage.Text = dr["LVillage"].ToString(); if (dr["Photo"].ToString() != "") { byte[] image = (byte[])dr["Photo"]; System.IO.MemoryStream stream = new System.IO.MemoryStream(image, 0, image.Length, false); this.imgPhoto.Image = System.Drawing.Image.FromStream(stream); } else { imgPhoto.Image = null; } dsMembers.Policy.Clear(); dsMembers.Policy.Merge(DataHelper.GetTableData(dsMembers.Policy, " WHERE IID = '" + cmbPolicy.EditValue.ToString() + "'").Tables[0]); dtpEnlistedDate.DateTime = (DateTime)dsMembers.Policy.Rows[0]["EnlistedDate"]; txtDepositRatio.Text = dsMembers.Policy.Rows[0]["SavingRatio"].ToString(); DataTable dt = DataHelper.GetData("SELECT COUNT(*) AS TotalDeposite FROM dbo.DepositDetails Where MasterID = '" + cmbPolicy.EditValue.ToString() + "' AND Description = 'Deposit'").Tables[0]; double TInstall = double.Parse(dt.Rows[0][0].ToString()); dt = DataHelper.GetData("SELECT COUNT(*) AS TotalDeposite FROM dbo.DepositDetails Where MasterID = '" + cmbPolicy.EditValue.ToString() + "' AND Description = 'Withdraw'").Tables[0]; double TWithdraw = double.Parse(dt.Rows[0][0].ToString()); dt = DataHelper.GetData("SELECT ISNULL(SUM(DepositProfit), 0) AS TotalDeposit, ISNULL(SUM(Withdrawal), 0) AS TotalWithdraw FROM dbo.DepositDetails Where MasterID = '" + cmbPolicy.EditValue.ToString() + "'").Tables[0]; double TInAmount = double.Parse(dt.Rows[0]["TotalDeposit"].ToString()); double TWthAmount = double.Parse(dt.Rows[0]["TotalWithdraw"].ToString()); txtTotalInstall.Text = TInstall.ToString(); txtTotalWithdraw.Text = TWithdraw.ToString(); txtTotalDepositAmount.Text = TInAmount.ToString(); txtTotalWithdrawAmount.Text = TWthAmount.ToString(); txtNetDepositAmount.Text = (TInAmount - TWthAmount).ToString(); txtNetDepositAmount2.Text = txtNetDepositAmount.Text; txtAvgInstall.Text = ((TInAmount - TWthAmount) / double.Parse(txtDepositRatio.Text)).ToString(); _loading.Dispose(); LoanDataset dsLoan = new LoanDataset(); dsLoan.LoanStatus.Clear(); dsLoan.LoanStatus.Merge(DataHelper.GetTableData(dsLoan.LoanStatus, " Where PolicyID = '" + cmbPolicy.EditValue.ToString() + "' AND Status = 'true'").Tables[0]); if (!(bool)dsMembers.Policy.Rows[0]["Status"]) { MessageBox.Show("This is a closed policy...", "Disposed Policy", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); btnSave.Enabled = false; return; } if (dsLoan.LoanStatus.Rows.Count > 0) { MessageBox.Show("This Policy is Continuing a loan... You can not despose this policy...", "Loan Exist", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); btnSave.Enabled = false; return; } btnSave.Enabled = true; } }