From 2b3c234aaa7e1dfe7777154b980e34f0b94655ea Mon Sep 17 00:00:00 2001 From: Garritt McCune Date: Tue, 17 Jan 2017 14:15:21 -0600 Subject: [PATCH] Fixed a bug on the modify record form where updating an existing row's ad item wouldn't mark the other APC tables as dirty. --- AdvertsingProfitControl/APCDatabase.accdb | Bin 2932736 -> 2932736 bytes AdvertsingProfitControl/FrmMain.Designer.cs | 12 +- AdvertsingProfitControl/FrmMain.cs | 14 +- AdvertsingProfitControl/FrmModifyRecord.cs | 4 +- AdvertsingProfitControl/NewModifyRecord.cs | 225 ++++++++++++++++-- ...AdvertsingProfitControl.vshost.application | 2 +- ...dvertsingProfitControl.vshost.exe.manifest | 6 +- 7 files changed, 237 insertions(+), 26 deletions(-) diff --git a/AdvertsingProfitControl/APCDatabase.accdb b/AdvertsingProfitControl/APCDatabase.accdb index 2cfb1845b6566f15b970038d5f2869ab49222f8c..763f5848acf08f4ba006ad601fff5d1cafa58a72 100644 GIT binary patch delta 4589 zcmZo@*vtsR8<_Yw|0?WcVq#=uWZW#s_nvXG0w3EZfgSvu3@i)`47?08{!czAZ^80^ z{r~@)|H^auvNJF^a5Ob0OmhjKf&JYzezJkxe=dFG857)7`5eb4MF!2O0}1tS9(NKWNt zF=W!=+_>-!hdUR8Bm)D(gJ;}eDFaI`FkR5Z45kAZy}-1>GJYlyL&1O*L@`X5!V9Js z@U?-({kIo$vh=fY@8s%)TB0?bSAZp$Nt%1(!kt_u%nVu#3=IAZ3=HB73=Lqd3=9na z|AnL$mt^LpD|jX5l_nM?Rw|g6Wa#NKa4|44uy6O5X4%Zbt`xj zG3$Jui5oh3Siweuqz~L{FV$t)UaHGF{}SWMt)gtA@@$L@3`{Hv(+}R|6rQ+&bGp4h z3-9zuc{ZWx3j5jE+l%Dcwin5>&l6yk0y%BEr~$hkqyO{(0}j>gnFj1L^_gGs7EfF# z&dS8XA)qk*<2AUr$0z!H)Qo^U~rP$E|$dpNtYvP`D}4U1|6P_3l(^#8_Z!> zVUt*K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4488 100644 --- a/AdvertsingProfitControl/FrmMain.Designer.cs +++ b/AdvertsingProfitControl/FrmMain.Designer.cs @@ -85,6 +85,7 @@ this.taxableDataGridView = new System.Windows.Forms.DataGridView(); this.debugTabPage = new System.Windows.Forms.TabPage(); this.monthCalendar = new System.Windows.Forms.MonthCalendar(); + this.newModifyRecordToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.mainTableLayoutPanel.SuspendLayout(); this.mainMenu.SuspendLayout(); this.commentMainTableLayoutPanel.SuspendLayout(); @@ -164,7 +165,8 @@ this.addRecordsToolStripMenuItem, this.modifyRecordMainMenu, this.deleteRecordsMainMenu, - this.newFormTestToolStripMenuItem}); + this.newFormTestToolStripMenuItem, + this.newModifyRecordToolStripMenuItem}); this.recordsToolStripMenuItem.Name = "recordsToolStripMenuItem"; this.recordsToolStripMenuItem.Size = new System.Drawing.Size(98, 35); this.recordsToolStripMenuItem.Text = "&Records"; @@ -760,6 +762,13 @@ this.monthCalendar.TabIndex = 0; this.monthCalendar.TabStop = false; // + // newModifyRecordToolStripMenuItem + // + this.newModifyRecordToolStripMenuItem.Name = "newModifyRecordToolStripMenuItem"; + this.newModifyRecordToolStripMenuItem.Size = new System.Drawing.Size(323, 34); + this.newModifyRecordToolStripMenuItem.Text = "New Modify Record"; + this.newModifyRecordToolStripMenuItem.Click += new System.EventHandler(this.newModifyRecordToolStripMenuItem_Click); + // // FrmMain // this.AutoScaleDimensions = new System.Drawing.SizeF(168F, 168F); @@ -865,6 +874,7 @@ private System.Windows.Forms.DataGridView taxableDataGridView; private System.Windows.Forms.TabPage debugTabPage; private System.Windows.Forms.MonthCalendar monthCalendar; + private System.Windows.Forms.ToolStripMenuItem newModifyRecordToolStripMenuItem; } } diff --git a/AdvertsingProfitControl/FrmMain.cs b/AdvertsingProfitControl/FrmMain.cs index 5c19020..5d674fd 100644 --- a/AdvertsingProfitControl/FrmMain.cs +++ b/AdvertsingProfitControl/FrmMain.cs @@ -647,14 +647,11 @@ namespace AdvertsingProfitControl private void modifyRecordMainMenu_Click(object sender, EventArgs e) { - //var modifyForm = new FrmModifyRecord(); - //modifyForm.ShowDialog(); + var modifyForm = new FrmModifyRecord(); + modifyForm.ShowDialog(); //BuildAndFillDataGridTables(); //CalculateProfitAnalysis(); //CalculateGrossProfit(); - var date = DateTime.Parse(monthComboBox.SelectedItem + @"/" + dayComboBox.SelectedItem + @"/" + yearComboBox.SelectedItem); - var form = new NewModifyRecord(date); - form.ShowDialog(); } private void manageItemsToolsMainMenu_Click(object sender, EventArgs e) @@ -761,6 +758,13 @@ namespace AdvertsingProfitControl form.ShowDialog(); } + + private void newModifyRecordToolStripMenuItem_Click(object sender, EventArgs e) + { + var date = DateTime.Parse(monthComboBox.SelectedItem + @"/" + dayComboBox.SelectedItem + @"/" + yearComboBox.SelectedItem); + var form = new NewModifyRecord(date); + form.ShowDialog(); + } } //http://stackoverflow.com/questions/487661/how-do-i-suspend-painting-for-a-control-and-its-children diff --git a/AdvertsingProfitControl/FrmModifyRecord.cs b/AdvertsingProfitControl/FrmModifyRecord.cs index e2dc1b6..d33a64c 100644 --- a/AdvertsingProfitControl/FrmModifyRecord.cs +++ b/AdvertsingProfitControl/FrmModifyRecord.cs @@ -404,7 +404,7 @@ namespace AdvertsingProfitControl invoicesDataGridView.Rows.Add(row.ItemArray); } inventoryDataGridView.Columns.Remove("RowAttribute"); - inventoryDataGridView.Columns.Remove("FK_GroupID"); + //inventoryDataGridView.Columns.Remove("FK_GroupID"); var weeklySalesTable = databaseReader.ReturnWeeklySalesFromDateId(dateId, databaseTracker.DatabaseConnectionString); @@ -563,7 +563,7 @@ namespace AdvertsingProfitControl } } dataGridView.Columns.Remove("RowAttribute"); - dataGridView.Columns.Remove("Fk_GroupID"); + //dataGridView.Columns.Remove("FK_AdSpecialName"); } private void BuildDataGridViewInventoryTable(DataTable dataTable, DataGridView dataGridView) diff --git a/AdvertsingProfitControl/NewModifyRecord.cs b/AdvertsingProfitControl/NewModifyRecord.cs index 938d54e..abe57ea 100644 --- a/AdvertsingProfitControl/NewModifyRecord.cs +++ b/AdvertsingProfitControl/NewModifyRecord.cs @@ -1027,7 +1027,11 @@ namespace AdvertsingProfitControl { var adItemText = projectionsDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString(); actualSalesDataGridView.Rows[e.RowIndex].Cells[adItemIndex].Value = adItemText; + actualSalesDataGridView.Rows[e.RowIndex].Cells[(int) SalesTableColumns.IsDirty].Value = true; + actualSalesDataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit; inventoryDataGridView.Rows[e.RowIndex].Cells[adItemIndex].Value = adItemText; + inventoryDataGridView.Rows[e.RowIndex].Cells[(int) InventoryTableColumns.IsDirty].Value = true; + inventoryDataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit; projectionsDataGridView.RefreshEdit(); //Remove the last ad item from the UsedAdItem array, the new one will be added in the OnRowLeave event handler. if (_adSpecialIndex == -1 || e.RowIndex < _adSpecialIndex) @@ -1385,7 +1389,11 @@ namespace AdvertsingProfitControl { var adItemText = inventoryDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString(); projectionsDataGridView.Rows[e.RowIndex].Cells[adItemIndex].Value = adItemText; + projectionsDataGridView.Rows[e.RowIndex].Cells[(int) SalesTableColumns.IsDirty].Value = true; + projectionsDataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit; actualSalesDataGridView.Rows[e.RowIndex].Cells[adItemIndex].Value = adItemText; + actualSalesDataGridView.Rows[e.RowIndex].Cells[(int) SalesTableColumns.IsDirty].Value = true; + actualSalesDataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit; //inventoryDataGridView.RefreshEdit(); //Remove the last ad item from the UsedAdItem array, the new one will be added in the OnRowLeave event handler. if (_adSpecialIndex == -1 || e.RowIndex < _adSpecialIndex) @@ -1542,7 +1550,11 @@ namespace AdvertsingProfitControl { var adItemText = actualSalesDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString(); projectionsDataGridView.Rows[e.RowIndex].Cells[adItemIndex].Value = adItemText; + projectionsDataGridView.Rows[e.RowIndex].Cells[(int) SalesTableColumns.IsDirty].Value = true; + projectionsDataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit; inventoryDataGridView.Rows[e.RowIndex].Cells[adItemIndex].Value = adItemText; + inventoryDataGridView.Rows[e.RowIndex].Cells[(int) InventoryTableColumns.IsDirty].Value = true; + inventoryDataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit; //projectionsDataGridView.RefreshEdit(); //Remove the last ad item from the UsedAdItem array, the new one will be added in the OnRowLeave event handler. if (_adSpecialIndex == -1 || e.RowIndex < _adSpecialIndex) @@ -2127,15 +2139,27 @@ namespace AdvertsingProfitControl var projections = databaseReader.ReturnProjectionsTable(dateId, databaseTracker.DatabaseConnectionString); var inventory = databaseReader.ReturnInventoryTable(dateId, databaseTracker.DatabaseConnectionString); var actualSales = databaseReader.ReturnActualSales(dateId, databaseTracker.DatabaseConnectionString); - LoadApcTables(projections, inventory, actualSales); + LoadProjectionsTable(projections); + LoadInventory(inventory); + LoadActualSales(actualSales); var invoices = databaseReader.ReturnInvoiceTable(dateId, databaseTracker.DatabaseConnectionString); + + //Re-enable the events projectionsDataGridView.CellEnter += StoreBeginningCellValue; projectionsDataGridView.RowLeave += UpdateUsedAdItemCollectionOnRowLeave; projectionsDataGridView.CellValidating += ValidateSalesDataGridViewCellContents; projectionsDataGridView.RowValidating += ValidateProjectedRow; + inventoryDataGridView.CellEnter += StoreBeginningCellValue; + inventoryDataGridView.RowLeave += UpdateUsedAdItemCollectionOnRowLeave; + inventoryDataGridView.CellValidating += ValidateInventoryCellContents; + inventoryDataGridView.RowValidating += ValidateInventoryRow; + actualSalesDataGridView.CellEnter += StoreBeginningCellValue; + actualSalesDataGridView.RowLeave += UpdateUsedAdItemCollectionOnRowLeave; + actualSalesDataGridView.CellValidating += ValidateSalesDataGridViewCellContents; + actualSalesDataGridView.RowValidating += ValidateActualSalesRow; } - private void LoadApcTables(DataTable projections, DataTable inventory, DataTable actualSales) + private void LoadProjectionsTable(DataTable projections) { //Assuming all the tables are correctly aligned. //Disable the relevant events in the DataGridViews @@ -2144,17 +2168,17 @@ namespace AdvertsingProfitControl projectionsDataGridView.CellValidating -= ValidateSalesDataGridViewCellContents; projectionsDataGridView.RowValidating -= ValidateProjectedRow; - for(var i = 0; i < projections.Rows.Count; i++) + for(var rowIndex = 0; rowIndex < projections.Rows.Count; rowIndex++) { var newRow = new DataGridViewRow(); - for (var cellIndex = 0; cellIndex < projections.Rows[i].ItemArray.Length; cellIndex++) + for (var cellIndex = 0; cellIndex < projections.Rows[rowIndex].ItemArray.Length; cellIndex++) { //ID and Ad Item. if (cellIndex <= 1) { var cell = new DataGridViewTextBoxCell { - Value = projections.Rows[i].ItemArray[cellIndex].ToString() + Value = projections.Rows[rowIndex].ItemArray[cellIndex].ToString() }; newRow.Cells.Add(cell); continue; @@ -2162,14 +2186,14 @@ namespace AdvertsingProfitControl //Everything in between the ad item cell and the row attribute cells. if (cellIndex > 1 && cellIndex <= 7) { - if (projections.Rows[i].ItemArray[cellIndex].ToString() == "0") + if (projections.Rows[rowIndex].ItemArray[cellIndex].ToString() == "0") { var cell = new DataGridViewTextBoxCell {Value = ""}; newRow.Cells.Add(cell); } else { - var cell = new DataGridViewTextBoxCell { Value = projections.Rows[i].ItemArray[cellIndex].ToString() }; + var cell = new DataGridViewTextBoxCell { Value = projections.Rows[rowIndex].ItemArray[cellIndex].ToString() }; newRow.Cells.Add(cell); } continue; @@ -2179,7 +2203,7 @@ namespace AdvertsingProfitControl { var isHeaderCell = new DataGridViewCheckBoxCell(false); var isMemberCell = new DataGridViewCheckBoxCell(false); - var rowAttribute = int.Parse(projections.Rows[i].ItemArray[cellIndex].ToString()); + var rowAttribute = int.Parse(projections.Rows[rowIndex].ItemArray[cellIndex].ToString()); switch (rowAttribute) { case 1: @@ -2200,25 +2224,198 @@ namespace AdvertsingProfitControl //Check the group it is part of if any. if (cellIndex == 9) { - if (projections.Rows[i].ItemArray[cellIndex].ToString() != "0" && _adSpecialIndex == -1) + if (projections.Rows[rowIndex].ItemArray[cellIndex].ToString() != "0" && _adSpecialIndex == -1) { var databaseTracker = new DatabaseTracker(); var databaseReader = new DatabaseReader(); var groupName = databaseReader.ReturnGroupNameFromGroupId( - projections.Rows[i].ItemArray[cellIndex].ToString(), + projections.Rows[rowIndex].ItemArray[cellIndex].ToString(), databaseTracker.DatabaseConnectionString); var adSpecialRow = new DataGridViewRow(); projectionsDataGridView.Rows.Add(adSpecialRow); - projectionsDataGridView.Rows[i].Cells[1].Value = groupName; - projectionsDataGridView.Rows[i].DefaultCellStyle.BackColor = ApplicationColors.AdSpecial; - _adSpecialIndex = i; + projectionsDataGridView.Rows[rowIndex].Cells[1].Value = groupName; + projectionsDataGridView.Rows[rowIndex].DefaultCellStyle.BackColor = ApplicationColors.AdSpecial; + _adSpecialIndex = rowIndex; } } } projectionsDataGridView.Rows.Add(newRow); } - //Re-enable the events + } + + private void LoadInventory(DataTable inventoryTable) + { + //Assuming all the tables are correctly aligned. + //Disable the relevant events in the DataGridViews + inventoryDataGridView.CellEnter -= StoreBeginningCellValue; + inventoryDataGridView.RowLeave -= UpdateUsedAdItemCollectionOnRowLeave; + inventoryDataGridView.CellValidating -= ValidateInventoryCellContents; + inventoryDataGridView.RowValidating -= ValidateInventoryRow; + //Create a local ad special index since Projections should have filled the ad special index in for the class. + var adSpecialIndex = -1; + + for (var rowIndex = 0; rowIndex < inventoryTable.Rows.Count; rowIndex++) + { + var newRow = new DataGridViewRow(); + for (var cellIndex = 0; cellIndex < inventoryTable.Rows[rowIndex].ItemArray.Length; cellIndex++) + { + //ID and Ad Item. + if (cellIndex <= 1) + { + var cell = new DataGridViewTextBoxCell + { + Value = inventoryTable.Rows[rowIndex].ItemArray[cellIndex].ToString() + }; + newRow.Cells.Add(cell); + continue; + } + //Everything in between the ad item cell and the row attribute cells. + if (cellIndex > 1 && cellIndex <= 5) + { + if (inventoryTable.Rows[rowIndex].ItemArray[cellIndex].ToString() == "0") + { + var cell = new DataGridViewTextBoxCell { Value = "" }; + newRow.Cells.Add(cell); + } + else + { + var cell = new DataGridViewTextBoxCell { Value = inventoryTable.Rows[rowIndex].ItemArray[cellIndex].ToString() }; + newRow.Cells.Add(cell); + } + continue; + } + //Check the attribute cell. + if (cellIndex == 6) + { + var isHeaderCell = new DataGridViewCheckBoxCell(false); + var isMemberCell = new DataGridViewCheckBoxCell(false); + var rowAttribute = int.Parse(inventoryTable.Rows[rowIndex].ItemArray[cellIndex].ToString()); + switch (rowAttribute) + { + case 1: + //Header row + isHeaderCell.Value = true; + newRow.DefaultCellStyle.BackColor = ApplicationColors.HeaderRow; + break; + case 2: + //Member Row + isMemberCell.Value = true; + newRow.DefaultCellStyle.BackColor = ApplicationColors.MemberRow; + break; + } + newRow.Cells.Add(isHeaderCell); + newRow.Cells.Add(isMemberCell); + continue; + } + //Check the group it is part of if any. + if (cellIndex == 7) + { + if (inventoryTable.Rows[rowIndex].ItemArray[cellIndex].ToString() != "0" && adSpecialIndex == -1) + { + var databaseTracker = new DatabaseTracker(); + var databaseReader = new DatabaseReader(); + var groupName = + databaseReader.ReturnGroupNameFromGroupId( + inventoryTable.Rows[rowIndex].ItemArray[cellIndex].ToString(), + databaseTracker.DatabaseConnectionString); + var adSpecialRow = new DataGridViewRow(); + inventoryDataGridView.Rows.Add(adSpecialRow); + inventoryDataGridView.Rows[rowIndex].Cells[1].Value = groupName; + inventoryDataGridView.Rows[rowIndex].DefaultCellStyle.BackColor = ApplicationColors.AdSpecial; + adSpecialIndex = rowIndex; + } + } + } + inventoryDataGridView.Rows.Add(newRow); + } + } + + public void LoadActualSales(DataTable actualSales) + { + //Assuming all the tables are correctly aligned. + //Disable the relevant events in the DataGridViews + actualSalesDataGridView.CellEnter -= StoreBeginningCellValue; + actualSalesDataGridView.RowLeave -= UpdateUsedAdItemCollectionOnRowLeave; + actualSalesDataGridView.CellValidating -= ValidateSalesDataGridViewCellContents; + actualSalesDataGridView.RowValidating -= ValidateActualSalesRow; + //Create a local ad special index since Projections should have filled the ad special index in for the class. + var adSpecialIndex = -1; + + for (var rowIndex = 0; rowIndex < actualSales.Rows.Count; rowIndex++) + { + var newRow = new DataGridViewRow(); + for (var cellIndex = 0; cellIndex < actualSales.Rows[rowIndex].ItemArray.Length; cellIndex++) + { + //ID and Ad Item. + if (cellIndex <= 1) + { + var cell = new DataGridViewTextBoxCell + { + Value = actualSales.Rows[rowIndex].ItemArray[cellIndex].ToString() + }; + newRow.Cells.Add(cell); + continue; + } + //Everything in between the ad item cell and the row attribute cells. + if (cellIndex > 1 && cellIndex <= 7) + { + if (actualSales.Rows[rowIndex].ItemArray[cellIndex].ToString() == "0") + { + var cell = new DataGridViewTextBoxCell { Value = "" }; + newRow.Cells.Add(cell); + } + else + { + var cell = new DataGridViewTextBoxCell { Value = actualSales.Rows[rowIndex].ItemArray[cellIndex].ToString() }; + newRow.Cells.Add(cell); + } + continue; + } + //Check the attribute cell. + if (cellIndex == 8) + { + var isHeaderCell = new DataGridViewCheckBoxCell(false); + var isMemberCell = new DataGridViewCheckBoxCell(false); + var rowAttribute = int.Parse(actualSales.Rows[rowIndex].ItemArray[cellIndex].ToString()); + switch (rowAttribute) + { + case 1: + //Header row + isHeaderCell.Value = true; + newRow.DefaultCellStyle.BackColor = ApplicationColors.HeaderRow; + break; + case 2: + //Member Row + isMemberCell.Value = true; + newRow.DefaultCellStyle.BackColor = ApplicationColors.MemberRow; + break; + } + newRow.Cells.Add(isHeaderCell); + newRow.Cells.Add(isMemberCell); + continue; + } + //Check the group it is part of if any. + if (cellIndex == 9) + { + if (actualSales.Rows[rowIndex].ItemArray[cellIndex].ToString() != "0" && adSpecialIndex == -1) + { + var databaseTracker = new DatabaseTracker(); + var databaseReader = new DatabaseReader(); + var groupName = + databaseReader.ReturnGroupNameFromGroupId( + actualSales.Rows[rowIndex].ItemArray[cellIndex].ToString(), + databaseTracker.DatabaseConnectionString); + var adSpecialRow = new DataGridViewRow(); + actualSalesDataGridView.Rows.Add(adSpecialRow); + actualSalesDataGridView.Rows[rowIndex].Cells[1].Value = groupName; + actualSalesDataGridView.Rows[rowIndex].DefaultCellStyle.BackColor = ApplicationColors.AdSpecial; + adSpecialIndex = rowIndex; + } + } + } + actualSalesDataGridView.Rows.Add(newRow); + } } private void NormalizeApcTables(DataTable projetions, DataTable inventory, DataTable actualSales, string dateId) diff --git a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application index a398cd7..1e6f4da 100644 --- a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application +++ b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application @@ -14,7 +14,7 @@ - BL2VwteFPdU1C5eFgLcNJB6t71bYUCKbAJpayKyfE2c= + hjoJ6F3S2mx0T7+16nfA9mg2vO2CJ4FO+GQ/EyPYf58= diff --git a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest index 0f96fbd..e78bcf3 100644 --- a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest +++ b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest @@ -43,14 +43,14 @@ - + - E5XDgx2BUQtUy2BTSxYDHOSv9/kMPusOEpgSdyhYHzk= + vZ/15zn6UnQyxvEn4XYMV+E1MUxIXiQdJmnSal6RNFc= @@ -93,7 +93,7 @@ - UQFU3HlwUiJQK2YXuAkDK9mSdSFJnVT3pbRsOpcjnAg= + ZGKhdhvn6U66O06l/eGiap8UW45ciijpPInT3o/xuMc=