代码1:正确 public void TimerReloadStores(int currentPage, int pageCount) { DataTable storeParm = bo.GetStoreParamSqlServer(currentPage, pageCount, "1", pageTotal); //如果只有一页数据 if (currentPage == 1) { storeLogoSecond1.Visible = false; storeLogo1.Visible = true; StoreLogo sLogo = this.pnlParent.Controls["storeLogo" + 1] as StoreLogo; Panel pnlContainer = sLogo.Controls["pnlParent"] as Panel; for (int i = 0; i < pageCount; i++) { try { //string storeID = ""; //string OnlineStatus = ""; //string ipaddress = ""; //int nport = 1433; //bool bOK_1 = false; //DataTable allStore = bo.GetAllEnabledStore(); //Panel pnl = this.pnl_queue.Controls["pnl_q" + i] as Panel; //Panel pnl_offline = pnl.Controls["pnl_offline" + i] as Panel; //QueueStore qs = pnl.Controls["queueStore" + i] as QueueStore; //storeID = qs.StoreID; //if (string.IsNullOrEmpty(storeID)) // continue; //OnlineStatus = qs.OnlineStatus; int index = i + 1; Panel pnl = pnlContainer.Controls["panel" + index] as Panel; string strStoreLogo = Application.StartupPath + "/Resources/store_default.png"; string filepath = storeParm.Rows[i]["FILE_PATH"].ToString().Replace("~", ""); string filename = storeParm.Rows[i]["FILE_NAME"].ToString(); if (!string.IsNullOrEmpty(filepath) && !string.IsNullOrEmpty(filename)) { filepath = Application.StartupPath + "/" + filepath + "/" + filename; if (File.Exists(filepath)) { strStoreLogo = filepath; } } pnl.BackgroundImage = Image.FromFile(strStoreLogo); pnl.BackgroundImageLayout = ImageLayout.Stretch; } catch (Exception errs) { LogCommon.WriteLogInfo(errs.ToString()); } } } //如果大于一页数据 if (currentPage != 1) { storeLogo1.Visible = false; storeLogoSecond1.Visible = true; StoreLogoSecond sLogo = this.pnlParent.Controls["storeLogoSecond" + 1] as StoreLogoSecond; for (int i = 0; i < pageCount; i++) { try { int index = i + 1; Panel pnl = sLogo.Controls["panel" + index] as Panel; string strStoreLogo = Application.StartupPath + "/Resources/store_default.png"; string filepath = storeParm.Rows[i]["FILE_PATH"].ToString().Replace("~", ""); string filename = storeParm.Rows[i]["FILE_NAME"].ToString(); if (!string.IsNullOrEmpty(filepath) && !string.IsNullOrEmpty(filename)) { filepath = Application.StartupPath + "/" + filepath + "/" + filename; if (File.Exists(filepath)) { strStoreLogo = filepath; } } pnl.BackgroundImage = Image.FromFile(strStoreLogo); pnl.BackgroundImageLayout = ImageLayout.Stretch; } catch (Exception errs) { LogCommon.WriteLogInfo(errs.ToString()); } } } }
代码2: 错误,浪费很长时间 public void TimerReloadStores(int currentPage, int pageCount) { DataTable storeParm = bo.GetStoreParamSqlServer(currentPage, pageCount, "1", pageTotal); //如果只有一页数据 if (currentPage == 1) { storeLogoSecond1.Visible = false; storeLogo1.Visible = true; for (int i = 0; i < pageCount; i++) { try { StoreLogo sLogo = this.pnlParent.Controls["storeLogo" + 1] as StoreLogo; Panel pnlContainer = sLogo.Controls["pnlParent"] as Panel; int index = i + 1; Panel pnl = pnlContainer.Controls["panel" + index] as Panel; string strStoreLogo = Application.StartupPath + "/Resources/store_default.png"; string filepath = storeParm.Rows[i]["FILE_PATH"].ToString().Replace("~", ""); string filename = storeParm.Rows[i]["FILE_NAME"].ToString(); if (!string.IsNullOrEmpty(filepath) && !string.IsNullOrEmpty(filename)) { filepath = Application.StartupPath + "/" + filepath + "/" + filename; if (File.Exists(filepath)) { strStoreLogo = filepath; } } pnl.BackgroundImage = Image.FromFile(strStoreLogo); pnl.BackgroundImageLayout = ImageLayout.Stretch; } catch (Exception errs) { LogCommon.WriteLogInfo(errs.ToString()); } } } //如果大于一页数据 if (currentPage != 1) { storeLogo1.Visible = false; storeLogoSecond1.Visible = true; for (int i = 0; i < pageCount; i++) { try { StoreLogoSecond sLogo = this.pnlParent.Controls["storeLogoSecond" + 1] as StoreLogoSecond; int index = i + 1; Panel pnl = sLogo.Controls["panel" + index] as Panel; string strStoreLogo = Application.StartupPath + "/Resources/store_default.png"; string filepath = storeParm.Rows[i]["FILE_PATH"].ToString().Replace("~", ""); string filename = storeParm.Rows[i]["FILE_NAME"].ToString(); if (!string.IsNullOrEmpty(filepath) && !string.IsNullOrEmpty(filename)) { filepath = Application.StartupPath + "/" + filepath + "/" + filename; if (File.Exists(filepath)) { strStoreLogo = filepath; } } pnl.BackgroundImage = Image.FromFile(strStoreLogo); pnl.BackgroundImageLayout = ImageLayout.Stretch; } catch (Exception errs) { LogCommon.WriteLogInfo(errs.ToString()); } } } }
代码3:最笨 public void ReloadStores(int currentPage, int pageCount) { DataTable storeParm = bo.GetStoreParamSqlServer(currentPage, pageCount, "1", pageTotal); //如果只有一页数据 if (currentPage == 1) { storeLogoSecond1.Visible = false; storeLogo1.Visible = true; for (int i = 0; i < pageCount; i++) { try { string storeID = storeParm.Rows[i]["STORE_ID"].ToString(); string onlineStatus = storeParm.Rows[i]["ONLINE_STATUS"].ToString(); string strStoreLogo = Application.StartupPath + "/Resources/store_default.png"; string filepath = storeParm.Rows[i]["FILE_PATH"].ToString().Replace("~", ""); string filename = storeParm.Rows[i]["FILE_NAME"].ToString(); if (!string.IsNullOrEmpty(filepath) && !string.IsNullOrEmpty(filename)) { filepath = Application.StartupPath + "/" + filepath + "/" + filename; if (File.Exists(filepath)) { strStoreLogo = filepath; } } if (i == 0) { storeLogo1.panel1.BackgroundImage = Image.FromFile(strStoreLogo); if (onlineStatus == "0") { storeLogo1.panel1.Enabled = true; storeLogo1.myOpaqueLayer1.Visible = false; } else { storeLogo1.panel1.Enabled = false; storeLogo1.myOpaqueLayer1.Visible = true; } } if (i == 1) { storeLogo1.panel2.BackgroundImage = Image.FromFile(strStoreLogo); if (onlineStatus == "0") { storeLogo1.panel2.Enabled = true; storeLogo1.myOpaqueLayer2.Visible = false; } else { storeLogo1.panel2.Enabled = false; storeLogo1.myOpaqueLayer2.Visible = true; } } if (i == 2) { storeLogo1.panel3.BackgroundImage = Image.FromFile(strStoreLogo); if (onlineStatus == "0") { storeLogo1.panel3.Enabled = true; storeLogo1.myOpaqueLayer3.Visible = false; } else { storeLogo1.panel3.Enabled = false; storeLogo1.myOpaqueLayer3.Visible = true; } } if (i == 3) { storeLogo1.panel4.BackgroundImage = Image.FromFile(strStoreLogo); if (onlineStatus == "0") { storeLogo1.panel4.Enabled = true; storeLogo1.myOpaqueLayer4.Visible = false; } else { storeLogo1.panel4.Enabled = false; storeLogo1.myOpaqueLayer4.Visible = true; } } if (i == 4) { storeLogo1.panel5.BackgroundImage = Image.FromFile(strStoreLogo); if (onlineStatus == "0") { storeLogo1.panel5.Enabled = true; storeLogo1.myOpaqueLayer5.Visible = false; } else { storeLogo1.panel5.Enabled = false; storeLogo1.myOpaqueLayer5.Visible = true; } } if (i == 5) { storeLogo1.panel6.BackgroundImage = Image.FromFile(strStoreLogo); if (onlineStatus == "0") { storeLogo1.panel6.Enabled = true; storeLogo1.myOpaqueLayer6.Visible = false; } else { storeLogo1.panel6.Enabled = false; storeLogo1.myOpaqueLayer6.Visible = true; } } } catch (Exception errs) { LogCommon.WriteLogInfo(errs.ToString()); } } } //如果大于一页数据 if (currentPage != 1) { storeLogo1.Visible = false; storeLogoSecond1.Visible = true; for (int i = 0; i < pageCount; i++) { try { string storeID = storeParm.Rows[i]["STORE_ID"].ToString(); string onlineStatus = storeParm.Rows[i]["ONLINE_STATUS"].ToString(); string strStoreLogo = Application.StartupPath + "/Resources/store_default.png"; string filepath = storeParm.Rows[i]["FILE_PATH"].ToString().Replace("~", ""); string filename = storeParm.Rows[i]["FILE_NAME"].ToString(); if (!string.IsNullOrEmpty(filepath) && !string.IsNullOrEmpty(filename)) { filepath = Application.StartupPath + "/" + filepath + "/" + filename; if (File.Exists(filepath)) { strStoreLogo = filepath; } } if (i == 0) { storeLogoSecond1.panel1.BackgroundImage = Image.FromFile(strStoreLogo); if (onlineStatus == "0") { storeLogoSecond1.panel1.Enabled = true; storeLogoSecond1.myOpaqueLayer1.Visible = false; } else { storeLogoSecond1.panel1.Enabled = false; storeLogoSecond1.myOpaqueLayer1.Visible = true; } } if (i == 1) { storeLogoSecond1.panel2.BackgroundImage = Image.FromFile(strStoreLogo); if (onlineStatus == "0") { storeLogoSecond1.panel2.Enabled = true; storeLogoSecond1.myOpaqueLayer2.Visible = false; } else { storeLogoSecond1.panel2.Enabled = false; storeLogoSecond1.myOpaqueLayer2.Visible = true; } } if (i == 2) { storeLogoSecond1.panel3.BackgroundImage = Image.FromFile(strStoreLogo); if (onlineStatus == "0") { storeLogoSecond1.panel3.Enabled = true; storeLogoSecond1.myOpaqueLayer3.Visible = false; } else { storeLogoSecond1.panel3.Enabled = false; storeLogoSecond1.myOpaqueLayer3.Visible = true; } } if (i == 3) { storeLogoSecond1.panel4.BackgroundImage = Image.FromFile(strStoreLogo); if (onlineStatus == "0") { storeLogoSecond1.panel4.Enabled = true; storeLogoSecond1.myOpaqueLayer4.Visible = false; } else { storeLogoSecond1.panel4.Enabled = false; storeLogoSecond1.myOpaqueLayer4.Visible = true; } } if (i == 4) { storeLogoSecond1.panel5.BackgroundImage = Image.FromFile(strStoreLogo); if (onlineStatus == "0") { storeLogoSecond1.panel5.Enabled = true; storeLogoSecond1.myOpaqueLayer5.Visible = false; } else { storeLogoSecond1.panel5.Enabled = false; storeLogoSecond1.myOpaqueLayer5.Visible = true; } } if (i == 5) { storeLogoSecond1.panel6.BackgroundImage = Image.FromFile(strStoreLogo); if (onlineStatus == "0") { storeLogoSecond1.panel6.Enabled = true; storeLogoSecond1.myOpaqueLayer6.Visible = false; } else { storeLogoSecond1.panel6.Enabled = false; storeLogoSecond1.myOpaqueLayer6.Visible = true; } } if (i == 6) { storeLogoSecond1.panel7.BackgroundImage = Image.FromFile(strStoreLogo); if (onlineStatus == "0") { storeLogoSecond1.panel7.Enabled = true; storeLogoSecond1.myOpaqueLayer7.Visible = false; } else { storeLogoSecond1.panel7.Enabled = false; storeLogoSecond1.myOpaqueLayer7.Visible = true; } } if (i == 7) { storeLogoSecond1.panel8.BackgroundImage = Image.FromFile(strStoreLogo); if (onlineStatus == "0") { storeLogoSecond1.panel8.Enabled = true; storeLogoSecond1.myOpaqueLayer8.Visible = false; } else { storeLogoSecond1.panel8.Enabled = false; storeLogoSecond1.myOpaqueLayer8.Visible = true; } } if (i == 8) { storeLogoSecond1.panel9.BackgroundImage = Image.FromFile(strStoreLogo); if (onlineStatus == "0") { storeLogoSecond1.panel9.Enabled = true; storeLogoSecond1.myOpaqueLayer9.Visible = false; } else { storeLogoSecond1.panel9.Enabled = false; storeLogoSecond1.myOpaqueLayer9.Visible = true; } } if (i == 9) { storeLogoSecond1.panel10.BackgroundImage = Image.FromFile(strStoreLogo); if (onlineStatus == "0") { storeLogoSecond1.panel10.Enabled = true; storeLogoSecond1.myOpaqueLayer10.Visible = false; } else { storeLogoSecond1.panel10.Enabled = false; storeLogoSecond1.myOpaqueLayer10.Visible = true; } } if (i == 10) { storeLogoSecond1.panel11.BackgroundImage = Image.FromFile(strStoreLogo); if (onlineStatus == "0") { storeLogoSecond1.panel11.Enabled = true; storeLogoSecond1.myOpaqueLayer11.Visible = false; } else { storeLogoSecond1.panel11.Enabled = false; storeLogoSecond1.myOpaqueLayer11.Visible = true; } } if (i == 11) { storeLogoSecond1.panel12.BackgroundImage = Image.FromFile(strStoreLogo); if (onlineStatus == "0") { storeLogoSecond1.panel12.Enabled = true; storeLogoSecond1.myOpaqueLayer12.Visible = false; } else { storeLogoSecond1.panel12.Enabled = false; storeLogoSecond1.myOpaqueLayer12.Visible = true; } } } catch (Exception errs) { LogCommon.WriteLogInfo(errs.ToString()); } } } }
时间: 2024-09-30 06:26:00