private void button2_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(tbYear.Text)) { MessageBox.Show("Error: Invalid Year. Please check your year", "Year Invalid.", MessageBoxButtons.OK, MessageBoxIcon.Error); tbYear.Focus(); return; } if (!cv.isInteger(tbYear.Text)) { MessageBox.Show("Error: Invalid Year. Please check your year", "Year Invalid.", MessageBoxButtons.OK, MessageBoxIcon.Error); tbYear.Focus(); return; } if (dtStart.Value > dtEnd.Value) { MessageBox.Show("Error: Date End must be greater than Date Start. Please check your Covered Date", "Year Invalid.", MessageBoxButtons.OK, MessageBoxIcon.Error); dtStart.Focus(); return; } DialogResult drSaveConfirm = MessageBox.Show("Are you sure you want to save this cutoff for month : " + cbMonth.Text + " " + tbYear.Text + "?", "Confirm to Save Cut-off for " + cbMonth.Text + " " + tbYear.Text + "?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (drSaveConfirm == DialogResult.Yes) { string PrimaryKey = tbYear.Text + ":" + cbMonth.Text; //(int.Parse(cbMonth.SelectedIndex.ToString()) + 1); string QueryInsert = "Insert into tbl_condo_cutoffinfo(PrimaryKey,Year,Month,BillStart,BillEnd,DueDate,isEnabled,CreatedBy)values('" + PrimaryKey + "'," + tbYear.Text + "," + (cbMonth.SelectedIndex + 1) + ",'" + dtStart.Value.ToString("yyyy-MM-dd 00:00:00") + "','" + dtEnd.Value.ToString("yyyy-MM-dd 00:00:00") + "','" + dtDueDate.Value.ToString("yyyy-MM-dd 00:00:00") + "'," + (cbIsEnabled.Checked ? 1 : 0) + "," + UserID + ")"; dtrans.InsertData(QueryInsert); LoadRecords(); } }
private int GetLastIDofBilling() { clsValidation cv = new clsValidation(); int result = 0; try { string Query = "SELECT sysID from tbl_condo_billinginfo order by sysID DESC LIMIT 1"; DataTable dtResult = dtrans.SelectData(Query); string ResultData = string.Empty; if (dtResult.Rows.Count > 0) { ResultData = dtResult.Rows[0]["sysId"].ToString(); } if (ResultData == "") { ResultData = "1"; return(int.Parse(ResultData)); } if (cv.isInteger(ResultData)) { return(int.Parse(ResultData) + 1); } } catch (Exception ex) { } return(result); }
private void button1_Click(object sender, EventArgs e) { clsValidation cv = new clsValidation(); if (dataGridView1.Rows.Count == 0) { MessageBox.Show("Error: No Details to save on this Billing. Please check", "Cannot save Billing Information", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (cbCutoff.Text == "") { MessageBox.Show("Error: No Cut-off defined on this Billing. Please check", "Cannot save Billing Information", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DialogResult dr = MessageBox.Show("Are you sure you want to save this Billing Information?", "Confirm Saving Billing Information", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { string PrimaryKey = GetLastIDofBilling().ToString("000000000000"); string checkUnitCutoff = "SELECT * FROM tbl_condo_billinginfo WHERE cutoffID = " + cv.GetSysID("where PrimaryKey ='" + cbCutoff.Text.ToString() + "'", "tbl_condo_cutoffinfo") + " AND unitno = " + cbUnitNo.SelectedValue; bool isUnitCheckAgainstCutoff = dtrans.SelectData(checkUnitCutoff).Rows.Count > 0 ? true : false; if (isUnitCheckAgainstCutoff) { MessageBox.Show("Error: Cannot save details for this cut-off. Please check", "Cut-off already exists", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string BillingInfoQuery = "Insert into tbl_condo_billinginfo(PrimaryKey,CutoffID,CustomerID,UnitNo,TotalAmountDue,PreviousBalanceAsOf,CurrentCharges,CreatedBy)Values('" + PrimaryKey + "'," + cv.isInteger(cv.GetSysID("where PrimaryKey ='" + cbCutoff.Text.ToString() + "'", "tbl_condo_cutoffinfo").ToString()) + "," + lblCustomerID.Text + "," + cbUnitNo.SelectedValue + "," + tbTotalAmount.Text + "," + PreviousBalance + "," + lblCurrenttotal.Text + "," + UserID + ")"; bool isErrorFound = false; if (dtrans.InsertData(BillingInfoQuery)) { if (dataGridView1.Rows.Count > 0) { string GetSySID = cv.GetSysID("where PrimaryKey='" + PrimaryKey + "'", "tbl_condo_billinginfo").ToString(); if (GetSySID == "0") { MessageBox.Show("Error: Cannot save billing. Please check", "Error Saving", MessageBoxButtons.OK, MessageBoxIcon.Error); string DeleteDetails = "Delete from tbl_condo_billinginfo where primarykey='" + PrimaryKey + "'"; dtrans.InsertData(DeleteDetails); isErrorFound = true; return; } foreach (DataGridViewRow dgrow in dataGridView1.Rows) { string GetManualNotes = string.IsNullOrEmpty(dgrow.Cells["ManualNotes"].Value.ToString()) ? dgrow.Cells["ManualNotes"].Value.ToString() : string.Empty; string BillingRefID = GetLastIDofBillingDetails(GetSySID).ToString(); string BillingDetailsQuery = "Insert into tbl_condo_billingdetails(PrimaryKey,BillingRefID,BillingDescription,BillingAmount,BillingNotes,CreatedBy)values('" + PrimaryKey + "_" + BillingRefID + "'," + GetSySID + ",'" + dgrow.Cells["Transaction"].Value.ToString() + "'," + dgrow.Cells["Amount"].Value.ToString() + ",'" + GetManualNotes + "'," + UserID + ")"; if (!dtrans.InsertData(BillingDetailsQuery)) { MessageBox.Show("Error: Cannot save billing details. Please check", "Error Saving", MessageBoxButtons.OK, MessageBoxIcon.Error); string DeleteDetails = "Delete from tbl_condo_billingdetails where billingRefID=" + GetSySID; dtrans.InsertData(DeleteDetails); isErrorFound = true; break; } } } if (!isErrorFound) { MessageBox.Show("Billing information saved", "Done Saving", MessageBoxButtons.OK, MessageBoxIcon.Information); } TransactionTable(); dataGridView1.DataSource = dtTransactions; } } }