private void radButtonUpdateStore_Click(object sender, EventArgs e) { string StoreTypeID; string CategoryID; string RegionID; StoreTypeID = radComboBoxType.SelectedValue.ToString(); CategoryID = radComboBoxCategory.SelectedValue.ToString(); RegionID = radComboBoxRegion.SelectedValue.ToString(); string CustomName = ""; decimal tdWine = 0; decimal fdWine = 0; try { decimal.Parse((radTextBoxTdWine.Text.Length == 0) ? "0" : radTextBoxTdWine.Text); tdWine = Convert.ToDecimal((radTextBoxTdWine.Text.Length == 0) ? "0" : radTextBoxTdWine.Text); } catch { MessageBox.Show("Invalid TD WINE %. Please capture a numeric value.", "Invalid TD WINE %", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } try { decimal.Parse((radTextBoxFdWine.Text.Length == 0) ? "0" : radTextBoxFdWine.Text); fdWine = Convert.ToDecimal((radTextBoxFdWine.Text.Length == 0) ? "0" : radTextBoxFdWine.Text); } catch { MessageBox.Show("Invalid FD WINE %. Please capture a numeric value.", "Invalid FD WINE %", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } if (tdWine + fdWine != 100 && tdWine + fdWine != 0) { MessageBox.Show("TD WINE % and FD WINE % does not equate to a valid split %.", "Invalid TD WINE and FD WINE Split", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } if (radCheckBoxCustom.Checked == true) { if (radTextBoxName.Text == "") { MessageBox.Show("You have selected to use a Custom Name for this store but you have not captured the Name you would like to use.\n\nPlease correct your selection and try again.", "Custom Store Name", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } else { CustomName = "'" + radTextBoxName.Text + "'"; } } else { CustomName = "null"; } if (CategoryID == "") { MessageBox.Show("You are attempting to save a Store without selecting a Category. \n\nPlease select a Category and try again.", "No Category Selected", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } if (radTextBoxTradingHoursMonFri.Text.Length == 0 || radTextBoxTradingHoursSatSun.Text.Length == 0) { MessageBox.Show("You are attempting to create a new Store but you have not captured Trading Hours. \n\nPlease capture and try again.", "No Trading Hours Captured", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } if (RegionID == "0") { FormCreateRegion CreateRegionForm = new FormCreateRegion(); CreateRegionForm.ShowDialog(); RegionID = CreateRegionForm.RegionID.ToString(); if (RegionID == "0") { MessageBox.Show("You have selected to add a new region however you closed the Create Region screen without doing so. \n\nPlease correct your selection and try again.", "No Region Selected", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } } if (radGridViewOwnerGroup.Visible == true) { if (radGridViewOwnerGroup.RowCount > 0) { for (int i = 0; i < radGridViewOwnerGroup.RowCount; i++) { string OwnerGroupID = radGridViewOwnerGroup.Rows[i].Cells[1].Value.ToString(); if (OwnerGroupID == "0") { FormCreateOwnerGroup CreateOwnerGroupForm = new FormCreateOwnerGroup(); CreateOwnerGroupForm.ShowDialog(); int NewOwnerGroupID = CreateOwnerGroupForm.OwnerGroupID; if (NewOwnerGroupID == 0) { MessageBox.Show("You have selected to add a new owner group however you closed the Create Owner Group screen without doing so. \n\nPlease correct your selection and try again.", "No Owner Group Selected", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } radGridViewOwnerGroup.Rows[i].Cells[1].Value = NewOwnerGroupID; } } } } if (radGridViewOwner.Visible == true) { if (radGridViewOwner.RowCount > 0) { for (int i = 0; i < radGridViewOwner.RowCount; i++) { string OwnerID = radGridViewOwner.Rows[i].Cells[1].Value.ToString(); if (OwnerID == "0") { FormCreateOwner CreateOwnerForm = new FormCreateOwner(); CreateOwnerForm.ShowDialog(); int NewOwnerID = CreateOwnerForm.OwnerID; if (NewOwnerID == 0) { MessageBox.Show("You have selected to add a new owner however you closed the Create Owner screen without doing so. \n\nPlease correct your selection and try again.", "No Owner Selected", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } radGridViewOwner.Rows[i].Cells[1].Value = NewOwnerID; } } } } if (radGridViewDetail.RowCount > 0) { bool NullDate = false; for (int i = 0; i < radGridViewDetail.RowCount; i++) { string DateFrom = radGridViewDetail.Rows[i].Cells[1].Value.ToString(); if (DateFrom == "") { NullDate = true; } } if (NullDate) { MessageBox.Show("You have attempted to capture detail for the store however at least one of your detail lines is missing a date.\n\nPlease correct this and try again!", "No Dates Captured!", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } } bool NoMaster = true; bool ManyMaster = false; for (int i = 0; i < radGridViewLinkedAccounts.RowCount; i++) { string MasterIND = radGridViewLinkedAccounts.Rows[i].Cells[3].Value.ToString(); string LinkedIND = radGridViewLinkedAccounts.Rows[i].Cells[4].Value.ToString(); if (MasterIND.ToUpper() == "Y" && LinkedIND.ToUpper() == "Y") { if (NoMaster) { NoMaster = false; } else { ManyMaster = true; } } } if (NoMaster) { MessageBox.Show("You are attempting to save a Store without a Master Account, every Store MUST contain 1 Master Account.\n\nPlease rectify and try again.", "No Master Account", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } if (ManyMaster) { MessageBox.Show("You are attempting to save a Store with more than 1 Master Account, every Store MUST contain only 1 Master Account.\n\nPlease rectify and try again.", "More than 1 Master Account", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } if (radGridViewDetail.RowCount > 0) { for (int i = 0; i < radGridViewDetail.RowCount; i++) { string StoreDetailID = radGridViewDetail.Rows[i].Cells[0].Value.ToString(); DateTime DateFrom = (DateTime)radGridViewDetail.Rows[i].Cells[1].Value; string SquareMeters = radGridViewDetail.Rows[i].Cells[2].Value.ToString(); string UpdateDetailQuery = ""; if (StoreDetailID == "") { UpdateDetailQuery = "INSERT INTO redStoreDetail (redStoreID, DateFrom, SquareMeters) VALUES (" + StoreID + ", CONVERT(DateTime,'" + DateFrom.ToString("dd/MM/yyyy") + "',103), " + SquareMeters + ");"; } else { UpdateDetailQuery = "UPDATE redStoreDetail SET DateFrom = CONVERT(DateTime,'" + DateFrom.ToString("dd/MM/yyyy") + "',103), SquareMeters = " + SquareMeters + " WHERE redStoreDetailID = " + StoreDetailID + ";"; } Catman_Class_Library.SqlFunctions_RedReport.ExecuteSQLNoReturn(UpdateDetailQuery); } } for (int i = 0; i < radGridViewLinkedAccounts.RowCount; i++) { string AccStoreID = radGridViewLinkedAccounts.Rows[i].Cells[0].Value.ToString(); string MasterIND = radGridViewLinkedAccounts.Rows[i].Cells[3].Value.ToString(); string LinkedIND = radGridViewLinkedAccounts.Rows[i].Cells[4].Value.ToString(); string UpdateLinkedAccsQuery = ""; if (LinkedIND == "N") { UpdateLinkedAccsQuery = "DELETE redAccountStore WHERE redAccountStoreID = " + AccStoreID + ";"; } else { if (MasterIND == "N") { MasterIND = "null"; } else { MasterIND = "'Y'"; } UpdateLinkedAccsQuery = "UPDATE redAccountStore SET MasterIND = " + MasterIND + " WHERE redAccountStoreID = " + AccStoreID + ";"; } Catman_Class_Library.SqlFunctions_RedReport.ExecuteSQLNoReturn(UpdateLinkedAccsQuery); } if (radGridViewOwnerGroup.Visible == true) { if (radGridViewOwnerGroup.RowCount > 0) { for (int i = 0; i < radGridViewOwnerGroup.RowCount; i++) { string OwnerGroupID = radGridViewOwnerGroup.Rows[i].Cells[1].Value.ToString(); if (OwnerGroupID != "") { DateTime DateFrom = (DateTime)radGridViewOwnerGroup.Rows[i].Cells[2].Value; string OwnerGroupDetailID = radGridViewOwnerGroup.Rows[i].Cells[0].Value.ToString(); string OwnerGroupQuery; if (OwnerGroupDetailID == "") { OwnerGroupQuery = "INSERT INTO redStoreOwnerGroupDetail (redStoreID, redOwnerGroupID, DateFrom) VALUES (" + StoreID + ", " + OwnerGroupID + ", CONVERT(DateTime,'" + DateFrom.ToString("dd/MM/yyyy") + "',103));"; } else { OwnerGroupQuery = "UPDATE redStoreOwnerGroupDetail SET redOwnerGroupID = " + OwnerGroupID + ", DateFrom = CONVERT(DateTime,'" + DateFrom.ToString("dd/MM/yyyy") + "',103) WHERE redStoreOwnerGroupDetailID = " + OwnerGroupDetailID + ";"; } Catman_Class_Library.SqlFunctions_RedReport.ExecuteSQLNoReturn(OwnerGroupQuery); } } } } if (radGridViewOwner.Visible == true) { if (radGridViewOwner.RowCount > 0) { for (int i = 0; i < radGridViewOwner.RowCount; i++) { string OwnerID = radGridViewOwner.Rows[i].Cells[1].Value.ToString(); if (OwnerID != "") { DateTime DateFrom = (DateTime)radGridViewOwner.Rows[i].Cells[2].Value; string OwnerDetailID = radGridViewOwner.Rows[i].Cells[0].Value.ToString(); string OwnerQuery; if (OwnerDetailID == "") { OwnerQuery = "INSERT INTO redStoreOwnerDetail (redStoreID, redOwnerID, DateFrom) VALUES (" + StoreID + ", " + OwnerID + ", CONVERT(DateTime,'" + DateFrom.ToString("dd/MM/yyyy") + "',103));"; } else { OwnerQuery = "UPDATE redStoreOwnerDetail SET redOwnerID = " + OwnerID + ", DateFrom = CONVERT(DateTime,'" + DateFrom.ToString("dd/MM/yyyy") + "',103) WHERE redStoreOwnerDetailID = " + OwnerDetailID + ";"; } Catman_Class_Library.SqlFunctions_RedReport.ExecuteSQLNoReturn(OwnerQuery); } } } } if (RegionID == "") { RegionID = "null"; } String UpdateStoreQuery = "UPDATE redStore SET redStoreRegionID = " + RegionID + ", redStoreTypeID = " + StoreTypeID + ", redStoreCategoryID = " + CategoryID + ", Name = " + CustomName + ", Partners = '" + ((radTextBoxPartners.Text.Length == 0) ? "" : radTextBoxPartners.Text) + "', TradingHoursMonFri = '" + radTextBoxTradingHoursMonFri.Text + "', TradingHoursSatSun = '" + radTextBoxTradingHoursSatSun.Text + "', TdWine = '" + tdWine + "', FdWine = '" + fdWine + "' WHERE redStoreID = " + StoreID + ";"; Catman_Class_Library.SqlFunctions_RedReport.ExecuteSQLNoReturn(UpdateStoreQuery); //string LinkedAccountQuery = "SELECT rAS.redAccountStoreID, rA.redAccountId,rA.redAccountID as [Account ID], rA.StoreName as Name, ISNULL(rAS.MasterIND,'N') as [Master Account], 'Y' as Linked, rA.OwnersName, rA.Partners, rA.TradingHoursMonFri, rA.TradingHoursSatSun FROM redAccountStore rAS, redAccount rA WHERE rA.redAccountID = rAS.redAccountID AND rAS.redStoreID = " + StoreID + " ORDER BY ISNULL(rAS.MasterIND,'N') DESC;"; //LinkedAccountDT = Catman_Class_Library.SqlFunctions_RedReport.GetData(LinkedAccountQuery); //AccountDR = LinkedAccountDT.Rows[0]; //String UpdateAccountQuery = "UPDATE redAccount SET Partners = '" + ((radTextBoxPartners.Text.Length == 0) ? "" : radTextBoxPartners.Text) + "', TradingHoursMonFri = '" + radTextBoxTradingHoursMonFri.Text + "', TradingHoursSatSun = '" + radTextBoxTradingHoursSatSun.Text + "' WHERE redAccountId = " + AccountDR["redAccountID"] + ";"; //Catman_Class_Library.SqlFunctions_RedReport.ExecuteSQLNoReturn(UpdateAccountQuery); this.Close(); }
private void radButtonCreateStore_Click(object sender, EventArgs e) { string redAccountID = radComboBoxAccList.SelectedValue.ToString(); string TypeID = radComboBoxType.SelectedValue.ToString(); string CategoryID = radComboBoxCategory.SelectedValue.ToString(); string RegionID = radComboBoxRegion.SelectedValue.ToString(); decimal tdWine = 0; decimal fdWine = 0; try { decimal.Parse((radTextBoxTdWine.Text.Length == 0) ? "0" : radTextBoxTdWine.Text); tdWine = Convert.ToDecimal((radTextBoxTdWine.Text.Length == 0) ? "0" : radTextBoxTdWine.Text); } catch { MessageBox.Show("Invalid TD WINE %. Please capture a numeric value.", "Invalid TD WINE %", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } try { decimal.Parse((radTextBoxFdWine.Text.Length == 0) ? "0" : radTextBoxFdWine.Text); fdWine = Convert.ToDecimal((radTextBoxFdWine.Text.Length == 0) ? "0" : radTextBoxFdWine.Text); } catch { MessageBox.Show("Invalid FD WINE %. Please capture a numeric value.", "Invalid FD WINE %", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } if (tdWine + fdWine != 100 && tdWine + fdWine != 0) { MessageBox.Show("TD WINE % and FD WINE % does not equate to a valid split %.", "Invalid TD WINE and FD WINE Split", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } if (redAccountID == "") { MessageBox.Show("You are attempting to create a new Store without selecting an Account. \n\nPlease select an Account and try again.", "No Account Selected", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } if (radTextBoxTradingHoursMonFri.Text.Length == 0 || radTextBoxTradingHoursSatSun.Text.Length == 0) { MessageBox.Show("You are attempting to create a new Store but you have not captured Trading Hours. \n\nPlease capture and try again.", "No Trading Hours Captured", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } string CustomName = ""; if (radCheckBoxCustom.Checked == true) { if (radTextBoxCustom.Text == "") { MessageBox.Show("You have selected to use a Custom Name for this store but you have not captured the Name you would like to use.\n\nPlease correct your selection and try again.", "Custom Store Name", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } else { CustomName = "'" + radTextBoxCustom.Text + "'"; } } else { CustomName = "null"; } if (TypeID == "") { MessageBox.Show("You are attempting to create a new Store without selecting a Type. \n\nPlease select a Type and try again.", "No Type Selected", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } if (CategoryID == "") { MessageBox.Show("You are attempting to create a new Store without selecting a Category. \n\nPlease select a Category and try again.", "No Category Selected", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } string CheckMergedQuery = "SELECT ISNULL(MergedIND,'N') FROM redAccount where redAccountID = " + redAccountID + ";"; string AccountHasLinkQuery = "SELECT COUNT(*) FROM redAccountStore WHERE redAccountID = " + redAccountID + ";"; string Merged = Catman_Class_Library.SqlFunctions_RedReport.ExecuteSQL(CheckMergedQuery).ToString(); int AccountHasLink = (int)Catman_Class_Library.SqlFunctions_RedReport.ExecuteSQL(AccountHasLinkQuery); string AccountStoreExistsQuery = "SELECT count(*) FROM redAccountStore rAS, redStore rS WHERE rAS.redAccountID = " + redAccountID + " AND rAS.redStoreID = rS.redStoreID AND rS.redStoreTypeID = " + TypeID + ";"; int AccountStoreExists = (int)Catman_Class_Library.SqlFunctions_RedReport.ExecuteSQL(AccountStoreExistsQuery); if (AccountStoreExists > 0) { MessageBox.Show("You are attempting to create a new Store that already exists. \n\nPlease select a different account and/or type.", "Store Already Exists", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } if (RegionID == "0") { FormCreateRegion CreateRegionForm = new FormCreateRegion(); CreateRegionForm.ShowDialog(); RegionID = CreateRegionForm.RegionID.ToString(); if (RegionID == "0") { MessageBox.Show("You have selected to add a new region however you closed the Create Region screen without doing so. \n\nPlease correct your selection and try again.", "No Region Selected", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } } if (RegionID == "") { RegionID = "null"; } if (radGridViewOwnerGroup.Visible == true) { if (radGridViewOwnerGroup.RowCount > 0) { for (int i = 0; i < radGridViewOwnerGroup.RowCount; i++) { string OwnerGroupID = radGridViewOwnerGroup.Rows[i].Cells[0].Value.ToString(); if (OwnerGroupID == "0") { FormCreateOwnerGroup CreateOwnerGroupForm = new FormCreateOwnerGroup(); CreateOwnerGroupForm.ShowDialog(); int NewOwnerGroupID = CreateOwnerGroupForm.OwnerGroupID; if (NewOwnerGroupID == 0) { MessageBox.Show("You have selected to add a new owner group however you closed the Create Owner Group screen without doing so. \n\nPlease correct your selection and try again.", "No Owner Group Selected", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } radGridViewOwnerGroup.Rows[i].Cells[0].Value = NewOwnerGroupID; } } } } if (radGridViewOwner.Visible == true) { if (radGridViewOwner.RowCount > 0) { for (int i = 0; i < radGridViewOwner.RowCount; i++) { string OwnerID = radGridViewOwner.Rows[i].Cells[0].Value.ToString(); if (OwnerID == "0") { FormCreateOwner CreateOwnerForm = new FormCreateOwner(); CreateOwnerForm.ShowDialog(); int NewOwnerID = CreateOwnerForm.OwnerID; if (NewOwnerID == 0) { MessageBox.Show("You have selected to add a new owner however you closed the Create Owner screen without doing so. \n\nPlease correct your selection and try again.", "No Owner Selected", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } radGridViewOwner.Rows[i].Cells[0].Value = NewOwnerID; } } } } if (radGridViewDetail.RowCount > 0) { bool NullDate = false; for (int i = 0; i < radGridViewDetail.RowCount; i++) { string DateFrom = radGridViewDetail.Rows[i].Cells[0].Value.ToString(); if (DateFrom == "") { NullDate = true; } } if (NullDate) { MessageBox.Show("You have attempted to capture detail for the store however at least one of your detail lines is missing a date.\n\nPlease correct this and try again!", "No Dates Captured!", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } } if (AccountHasLink > 0 && Merged == "N") { MessageBox.Show("This Account is not flagged as merged therefore it may only be linked to 1 store.\n\nThis Account is already linked to a different store.\n\nPlease correct your selection and try again.", "Account", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } string InsertStoreQuery = "INSERT INTO redStore (redStoreTypeID, redStoreCategoryID, redStoreRegionID, Name, Partners, TradingHoursMonFri, TradingHoursSatSun, TdWine, FdWine) VALUES (" + TypeID + "," + CategoryID + "," + RegionID + "," + CustomName + ", '" + ((radTextBoxPartners.Text.Length == 0) ? "" : radTextBoxPartners.Text) + "', '" + radTextBoxTradingHoursMonFri.Text + "', '" + radTextBoxTradingHoursSatSun.Text + "', '" + tdWine + "', '" + fdWine + "');"; int StoreID = Catman_Class_Library.SqlFunctions_RedReport.ExecuteInsertReturnID(InsertStoreQuery); string InsertAccountStoreQuery = "INSERT INTO redAccountStore (redAccountID, redStoreID, MasterIND) VALUES (" + redAccountID + ", " + StoreID + ", 'Y');"; Catman_Class_Library.SqlFunctions_RedReport.ExecuteSQLNoReturn(InsertAccountStoreQuery); //string UpdateAccountQuery = "UPDATE redAccount SET Partners = '" + ((radTextBoxPartners.Text.Length == 0) ? "" : radTextBoxPartners.Text) + "'," + "TradingHoursMonFri = '" + radTextBoxTradingHoursMonFri.Text + "'," + "TradingHoursSatSun = '" + radTextBoxTradingHoursSatSun.Text + "' WHERE redAccountId = " + redAccountID + ";"; //Catman_Class_Library.SqlFunctions_RedReport.ExecuteSQLNoReturn(UpdateAccountQuery); if (radGridViewDetail.RowCount > 0) { for (int i = 0; i < radGridViewDetail.RowCount; i++) { DateTime DateFrom = (DateTime)radGridViewDetail.Rows[i].Cells[0].Value; string SquareMeters = radGridViewDetail.Rows[i].Cells[1].Value.ToString(); if (SquareMeters == "") { SquareMeters = "'null'"; } string InsertStoreDetailQuery = "INSERT INTO redStoreDetail (redStoreID, DateFrom, SquareMeters) VALUES (" + StoreID + ",convert(datetime,'" + DateFrom.ToString("dd/MM/yyyy") + "',103)," + SquareMeters + ");"; Catman_Class_Library.SqlFunctions_RedReport.ExecuteSQLNoReturn(InsertStoreDetailQuery); } } if (radGridViewOwnerGroup.Visible == true) { if (radGridViewOwnerGroup.RowCount > 0) { for (int i = 0; i < radGridViewOwnerGroup.RowCount; i++) { string OwnerGroupID = radGridViewOwnerGroup.Rows[i].Cells[0].Value.ToString(); DateTime DateFrom = (DateTime)radGridViewOwnerGroup.Rows[i].Cells[1].Value; string OwnerGroupQuery = "INSERT INTO redStoreOwnerGroupDetail (redStoreID, redOwnerGroupID, DateFrom) VALUES (" + StoreID + ", " + OwnerGroupID + ", CONVERT(DateTime,'" + DateFrom.ToString("dd/MM/yyyy") + "',103));"; Catman_Class_Library.SqlFunctions_RedReport.ExecuteSQLNoReturn(OwnerGroupQuery); } } } if (radGridViewOwner.Visible == true) { if (radGridViewOwner.RowCount > 0) { for (int i = 0; i < radGridViewOwner.RowCount; i++) { string OwnerID = radGridViewOwner.Rows[i].Cells[0].Value.ToString(); DateTime DateFrom = (DateTime)radGridViewOwner.Rows[i].Cells[1].Value; string OwnerQuery = "INSERT INTO redStoreOwnerDetail (redStoreID, redOwnerID, DateFrom) VALUES (" + StoreID + ", " + OwnerID + ", CONVERT(DateTime,'" + DateFrom.ToString("dd/MM/yyyy") + "',103));"; Catman_Class_Library.SqlFunctions_RedReport.ExecuteSQLNoReturn(OwnerQuery); } } } this.Close(); }