private void LoadContactData(System.Data.SqlClient.SortOrder SequenceSortOrder) { try { tblLayout.Controls.Clear(); Int64 intSequenceNoStart = 0; if (SequenceSortOrder == System.Data.SqlClient.SortOrder.Descending) try { intSequenceNoStart = long.Parse(cmdTableLeft.Tag.ToString()); } catch { } else try { intSequenceNoStart = long.Parse(cmdTableRight.Tag.ToString()); } catch { } // Sep 24, 2014 put an override if cmdSubGroupLeft.Tag = 0 // always do an asceding coz its already the end. if (intSequenceNoStart < Constants.C_RESTOPLUS_MAX_TABLES) intSequenceNoStart = 0; //reset to 0 if it's 1 if (intSequenceNoStart == 0) SequenceSortOrder = System.Data.SqlClient.SortOrder.Ascending; ContactColumns clsContactColumns = new ContactColumns(); clsContactColumns.ContactCode = true; clsContactColumns.LastCheckInDate = true; ContactColumns clsSearchColumns = new ContactColumns(); Contacts clsContact = new Contacts(); System.Data.DataTable dtContact; if (ContactGroupCategory == Data.ContactGroupCategory.TABLES) dtContact = clsContact.Tables(clsContactColumns, intSequenceNoStart, SequenceSortOrder, clsSearchColumns, string.Empty, SequenceSortOrder == System.Data.SqlClient.SortOrder.Descending ? Constants.C_RESTOPLUS_MAX_TABLES : Constants.C_RESTOPLUS_MAX_TABLES + 1, false, "SequenceNo", SequenceSortOrder); else dtContact = clsContact.Customers(clsContactColumns, intSequenceNoStart, SequenceSortOrder, clsSearchColumns, string.Empty, SequenceSortOrder == System.Data.SqlClient.SortOrder.Descending ? Constants.C_RESTOPLUS_MAX_TABLES : Constants.C_RESTOPLUS_MAX_TABLES + 1, false, "SequenceNo", SequenceSortOrder); // re-order the products by sequence no if (dtContact.Rows.Count > 0) { System.Data.DataView dv = dtContact.DefaultView; dv.Sort = "ContactCode"; dtContact = dv.ToTable(); } int iRow = 0; int iCol = 0; int iCtr = 1; Data.SalesTransactions clsSalesTransactions = new Data.SalesTransactions(clsContact.Connection, clsContact.Transaction); Data.SalesTransactionDetails clsSalesTransactionDetails = new Data.SalesTransactionDetails(); Data.MergeTable clsMergeTable = new Data.MergeTable(clsContact.Connection, clsContact.Transaction); Data.MergeTableDetails clsMergeTableDetails = new Data.MergeTableDetails(); if (dtContact.Rows.Count == 0) { cmdTableLeft.Tag = "0".ToString(); // reset the sequenceno to 0 if no record cmdTableRight.Tag = "0".ToString(); // reset the sequenceno to 0 if no record } foreach (System.Data.DataRow dr in dtContact.Rows) { //if (iCol == 5) { iCol = 0; iRow++; } if (iCtr > Constants.C_RESTOPLUS_MAX_TABLES) break; if (iCtr == 1) cmdTableLeft.Tag = dr[Data.ContactColumnNames.SequenceNo].ToString(); if (iCtr >= 1 && dtContact.Rows.Count > Constants.C_RESTOPLUS_MAX_TABLES) cmdTableRight.Tag = dr[Data.ContactColumnNames.SequenceNo].ToString(); ProductButton cmdTable = new ProductButton(); cmdTable.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; cmdTable.BackColor = System.Drawing.Color.Red; cmdTable.Dock = System.Windows.Forms.DockStyle.Fill; cmdTable.FlatAppearance.BorderColor = System.Drawing.Color.Gold; cmdTable.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); cmdTable.ForeColor = System.Drawing.SystemColors.ControlText; cmdTable.GradientBottom = System.Drawing.Color.DarkRed; cmdTable.GradientTop = System.Drawing.Color.Red; cmdTable.ImageAlign = System.Drawing.ContentAlignment.TopCenter; cmdTable.Location = new System.Drawing.Point(3, 3); cmdTable.Size = new System.Drawing.Size(245, 90); cmdTable.TabIndex = 118; cmdTable.TextAlign = System.Drawing.ContentAlignment.BottomCenter; cmdTable.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText; cmdTable.UseVisualStyleBackColor = false; cmdTable.Name = "cmdTable" + iCtr.ToString(); cmdTable.Text = dr[Data.ContactColumnNames.ContactCode].ToString(); cmdTable.Tag = dr[Data.ContactColumnNames.ContactID].ToString(); cmdTable.Click += new System.EventHandler(cmdTable_Click); if (DateTime.Parse(dr[Data.ContactColumnNames.LastCheckInDate].ToString()) != Constants.C_DATE_MIN_VALUE) { TimeSpan iLapse = DateTime.Now - DateTime.Parse(dr[Data.ContactColumnNames.LastCheckInDate].ToString()); Label lblLastCheckInDate = new System.Windows.Forms.Label(); lblLastCheckInDate.AutoSize = true; lblLastCheckInDate.BackColor = System.Drawing.Color.Transparent; lblLastCheckInDate.Font = new System.Drawing.Font("Tahoma", 7.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); lblLastCheckInDate.ForeColor = System.Drawing.Color.Blue; lblLastCheckInDate.Location = new System.Drawing.Point(5, 5); lblLastCheckInDate.Name = "lblLastCheckInDate" + iCtr.ToString(); lblLastCheckInDate.TabIndex = 1; lblLastCheckInDate.Text = "CheckIn: " + DateTime.Parse(dr[Data.ContactColumnNames.LastCheckInDate].ToString()).ToString("dd-MMM hh:mm tt") + " [" + iLapse.Hours.ToString("0#") + "hrs " + iLapse.Minutes.ToString("0#") + "mins]"; cmdTable.Controls.Add(lblLastCheckInDate); } string stTransactionNo = clsSalesTransactions.getSuspendedTransactionNo(long.Parse(dr[Data.ContactColumnNames.ContactID].ToString()), TerminalDetails.TerminalNo, TerminalDetails.BranchID); if (stTransactionNo != string.Empty) { clsSalesTransactionDetails = clsSalesTransactions.Details(stTransactionNo, TerminalDetails.TerminalNo, TerminalDetails.BranchID); cmdTable.Text = dr[Data.ContactColumnNames.ContactCode].ToString(); decimal decAmountDue = Convert.ToDecimal(clsSalesTransactionDetails.SubTotal + clsSalesTransactionDetails.Charge - clsSalesTransactionDetails.Discount); cmdTable.Text += Environment.NewLine + Environment.NewLine + "Amount Due:" + decAmountDue.ToString("#,###.#0"); Label lblNoOfPax = new System.Windows.Forms.Label(); lblNoOfPax.AutoSize = true; lblNoOfPax.BackColor = System.Drawing.Color.Transparent; lblNoOfPax.Font = new System.Drawing.Font("Tahoma", 7.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); lblNoOfPax.ForeColor = System.Drawing.Color.White; lblNoOfPax.Location = new System.Drawing.Point(210, 75); lblNoOfPax.Name = "lblNoOfPax" + iCtr.ToString(); lblNoOfPax.TabIndex = 1; lblNoOfPax.Text = clsSalesTransactionDetails.PaxNo.ToString() + "Pax"; cmdTable.Controls.Add(lblNoOfPax); if (mboShowAvailableTableOnly) { cmdTable.BackColor = System.Drawing.Color.DarkGray; cmdTable.GradientBottom = System.Drawing.Color.DarkGray; cmdTable.GradientTop = System.Drawing.Color.LightGray; cmdTable.Enabled = false; } else { cmdTable.BackColor = System.Drawing.Color.DarkBlue; cmdTable.GradientBottom = System.Drawing.Color.DarkBlue; cmdTable.GradientTop = System.Drawing.Color.LightBlue; } } Label lblMerge = new System.Windows.Forms.Label(); lblMerge.AutoSize = true; lblMerge.BackColor = System.Drawing.Color.Transparent; lblMerge.Font = new System.Drawing.Font("Tahoma", 7.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); lblMerge.ForeColor = System.Drawing.Color.White; lblMerge.Location = new System.Drawing.Point(5, 75); lblMerge.Name = "lblMerge" + iCtr.ToString(); lblMerge.TabIndex = 1; lblMerge.Text = "Merged"; lblMerge.Visible = false; cmdTable.Controls.Add(lblMerge); clsMergeTableDetails = clsMergeTable.Details(dr[Data.ContactColumnNames.ContactCode].ToString()); if (MainTableToMerge.ContactCode == dr[Data.ContactColumnNames.ContactCode].ToString()) { cmdTable.BackColor = System.Drawing.Color.LightGreen; cmdTable.GradientBottom = System.Drawing.Color.LightGreen; cmdTable.GradientTop = System.Drawing.Color.DarkGreen; cmdTable.Enabled = false; cmdTable.Controls["lblMerge" + cmdTable.Name.Replace("cmdTable", "")].Visible = true; cmdTable.Controls["lblMerge" + cmdTable.Name.Replace("cmdTable", "")].Text = "Merged to this table"; } else if (clsMergeTableDetails.MainTableCode == dr[Data.ContactColumnNames.ContactCode].ToString()) { cmdTable.BackColor = System.Drawing.Color.DarkGray; cmdTable.GradientBottom = System.Drawing.Color.DarkGray; cmdTable.GradientTop = System.Drawing.Color.LightGray; cmdTable.Enabled = false; cmdTable.Controls["lblMerge" + cmdTable.Name.Replace("cmdTable", "")].Visible = true; cmdTable.Controls["lblMerge" + cmdTable.Name.Replace("cmdTable", "")].Text = "Merged - Main Table"; } else if (clsMergeTableDetails.ChildTableCode == dr[Data.ContactColumnNames.ContactCode].ToString() && MainTableToMerge.ContactCode != clsMergeTableDetails.MainTableCode) { cmdTable.BackColor = System.Drawing.Color.DarkGray; cmdTable.GradientBottom = System.Drawing.Color.DarkGray; cmdTable.GradientTop = System.Drawing.Color.LightGray; cmdTable.Enabled = false; cmdTable.Controls["lblMerge" + cmdTable.Name.Replace("cmdTable", "")].Visible = true; cmdTable.Controls["lblMerge" + cmdTable.Name.Replace("cmdTable", "")].Text = "Merged to " + clsMergeTableDetails.MainTableCode; } else if (clsMergeTableDetails.ChildTableCode == dr[Data.ContactColumnNames.ContactCode].ToString() && MainTableToMerge.ContactCode == clsMergeTableDetails.MainTableCode) { Data.ContactDetails clsContactDetails = clsContact.Details(long.Parse(cmdTable.Tag.ToString())); mlstTables.Add(clsContactDetails); cmdTable.Controls["lblMerge" + cmdTable.Name.Replace("cmdTable", "")].Visible = true; cmdTable.Controls["lblMerge" + cmdTable.Name.Replace("cmdTable", "")].Text = "Merged to " + clsMergeTableDetails.MainTableCode; cmdTable.GradientTop = System.Drawing.Color.Orange; } tblLayout.Controls.Add(cmdTable, iCol, iRow); iCol++; iCtr++; } clsContact.CommitAndDispose(); } catch (IndexOutOfRangeException){} catch (Exception ex) { MessageBox.Show(ex.Message,"RetailPlus",MessageBoxButtons.OK,MessageBoxIcon.Error); } }