//Insert New Record private void btnSave_Click(object sender, System.EventArgs e) { clsPOSDB dp = new clsPOSDB(); DPDetails dpDetailRec = new DPDetails(0, txtDeliveryPointName.Text, txtDeliveryPointAddress.Text); EnableButtons(); int iEmpId = dp.InsertDeliveryPoint(dpDetailRec); if (iEmpId != -1) { //FrmMain.statusBarMain.Text = "Record Saved Successfully"; //Refresh Display after addition of record and //Display last record inserted UnBindControls(); ShowAllRecords(); BindControls(); this.BindingContext[dpInfo].Position = dpInfo.Length - 1; } else { //FrmMain.statusBarMain.Text = "Save Operation Failed"; } }
//Returns Specific Record private void ShowRecord(int RecordId) { clsPOSDB dp = new clsPOSDB(); DPDetails dpDetailRec = dp.GetDeliveryPoint(RecordId); if (dpDetailRec != null) { txtDeliveryPointId.Text = dpDetailRec.DeliveryPointId.ToString(); txtDeliveryPointName.Text = dpDetailRec.DeliveryPointName; txtDeliveryPointAddress.Text = dpDetailRec.DeliveryPointAddress; } else { //FrmMain.statusBarMain.Text = "Record Not Found"; } }
private void ShowRecsDataGrid() { clsPOSDB dp = new clsPOSDB(); DPDetails[] dpInfo = dp.GetAllDeliveryPoint(); if (dpInfo != null) { dgvDeliveryPoints.DataSource = dpInfo; dgvDeliveryPoints.CaptionText = "Delivery Points :: Records(" + dpInfo.Length.ToString() + ")"; } else { dgvDeliveryPoints.CaptionText += " :: No Records Found"; } }
//Update Record private void btnUpdate_Click(object sender, System.EventArgs e) { clsPOSDB dp = new clsPOSDB(); DPDetails dpDetailRec = new DPDetails(Convert.ToInt32(txtDeliveryPointId.Text), txtDeliveryPointName.Text, txtDeliveryPointAddress.Text); int iRecAffected = dp.UpdateDeliveryPoint(dpDetailRec); if (iRecAffected != 0) { //FrmMain.statusBarMain.Text = "Record Updated Successfully"; } else { //FrmMain.statusBarMain.Text = "Update Operation Failed"; } }
//Returns All Record private void ShowAllRecords() { this.Cursor = Cursors.WaitCursor; clsPOSDB dp = new clsPOSDB(); dpInfo = dp.GetAllDeliveryPoint(); int recPos = this.BindingContext[dpInfo].Position; if (dpInfo != null) { txtDeliveryPointId.Text = dpInfo[recPos].DeliveryPointId.ToString(); txtDeliveryPointName.Text = dpInfo[recPos].DeliveryPointName; txtDeliveryPointAddress.Text = dpInfo[recPos].DeliveryPointAddress; } else { //FrmMain.statusBarMain.Text = "Record Not Found"; } this.Cursor = Cursors.Default; }
private void btnDelete_Click(object sender, System.EventArgs e) { clsPOSDB dp = new clsPOSDB(); int iRecDeleted = this.BindingContext[dpInfo].Position; int iRecAffected = dp.DeleteDeliveryPoint(Convert.ToInt32(txtDeliveryPointId.Text)); if (iRecAffected != 0) { //FrmMain.statusBarMain.Text = "Record Deleted Successfully"; //Refresh Display after deletion of record and if (dpInfo != null) { UnBindControls(); ShowAllRecords(); BindControls(); if (iRecDeleted == dpInfo.Length) //If record deleted at last position thn display previous record. { this.BindingContext[dpInfo].Position = iRecDeleted - 1; } else //display next record { this.BindingContext[dpInfo].Position = iRecDeleted + 1; } } else { //FrmMain.statusBarMain.Text = "No Records Found"; } } else { //FrmMain.statusBarMain.Text = "Delete Operation Failed"; } }