首先-我知道据此有一些帖子,但我似乎不明白“导师制”
基本上,我想做的是从MySQL数据库中将字符串中的数据提供给Checkedlistbox
ListBox已准备就绪,包含所有可检查的值,现在我只想让字符串告诉它应该检查哪些项目。
我的字符串/数组..真的不知道正确的定义...(示例)如下:“ B,BE,C1E,”(驾驶执照类型)
我真的想分享我在这个问题上的最新成果,如果我真的第十次放弃我的想法的话,那么我真的很困惑。
我会强烈推荐所有提示,指出我现在迷失方向的方向
编辑:哦,是的,我使用c#btw
答案 0 :(得分:0)
“解决方案”
这并不是解决问题的真正方法,但是我想分享我的解决方法。
我将所有可检查项目的可能组合添加到db请求中,询问数据库条目是否为这些组合之一(例如代码中的示例)
MySqlCommand führerscheinab = conn.CreateCommand();
führerscheinab.CommandText = "SELECT count(*) FROM bewerber WHERE id = '" + textBoxrecruitingid.Text + "' and führerschein = 'A,B,'";
string countab = führerscheinab.ExecuteScalar().ToString();
MySqlCommand führerscheinabe = conn.CreateCommand();
führerscheinabe.CommandText = "SELECT count(*) FROM bewerber WHERE id = '" + textBoxrecruitingid.Text + "' and führerschein = 'A,BE,'";
string countabe = führerscheinabe.ExecuteScalar().ToString();
MySqlCommand führerscheinac1 = conn.CreateCommand();
führerscheinac1.CommandText = "SELECT count(*) FROM bewerber WHERE id = '" + textBoxrecruitingid.Text + "' and führerschein = 'A,C1,'";
string countac1 = führerscheinac1.ExecuteScalar().ToString();
MySqlCommand führerscheinac = conn.CreateCommand();
führerscheinac.CommandText = "SELECT count(*) FROM bewerber WHERE id = '" + textBoxrecruitingid.Text + "' and führerschein = 'A,C,'";
string countac = führerscheinac.ExecuteScalar().ToString();
MySqlCommand führerscheinac1e = conn.CreateCommand();
führerscheinac1e.CommandText = "SELECT count(*) FROM bewerber WHERE id = '" + textBoxrecruitingid.Text + "' and führerschein = 'A,C1E,'";
string countac1e = führerscheinac1e.ExecuteScalar().ToString();
剩下要做的就是为每个结果创建一个if语句,例如:
if (countab == 1)
{
check a and b
}
else if (countabe == 1)
{
check a and be
}
else if ( ... and so on
并不是我想要的解决方案,当然也不能在考虑资源的情况下做到最好,但是是的。.^^
答案 1 :(得分:0)
真正的解决方案
由于我对上一个“解决方案”不满意,因此我尝试了更多,并尝试使用以下方法:
def download(url, outputPath):
fileName = get_file_name(url)
logger.info("url: %s" %(url))
print("url: ", url)
curl = pycurl.Curl()
curl.setopt(pycurl.CAINFO, certifi.where())
curl.setopt(pycurl.URL, url)
curl.setopt(pycurl.NOPROGRESS, 0)
curl.setopt(pycurl.PROGRESSFUNCTION, downloadProgress)
curl.setopt(pycurl.FOLLOWLOCATION, 1)
curl.setopt(pycurl.MAXREDIRS, 5)
curl.setopt(pycurl.CONNECTTIMEOUT, 50)
curl.setopt(pycurl.TIMEOUT, timeOut)
curl.setopt(pycurl.FTP_RESPONSE_TIMEOUT, 600)
curl.setopt(pycurl.NOSIGNAL, 1)
curl.setopt(pycurl.HTTPAUTH, pycurl.HTTPAUTH_BASIC)
curl.setopt(pycurl.USERPWD, "Vthamburaj" + ':' + "Vicky@1987")
if os.path.exists(os.path.join(outputPath, fileName)):
curl.fp = open(os.path.join(outputPath, fileName), "ab")
curl.setopt(pycurl.RESUME_FROM, os.path.getsize(os.path.join(outputPath, fileName)))
else:
curl.fp = open(os.path.join(outputPath, fileName), "wb")
curl.setopt(pycurl.WRITEDATA, curl.fp)
try:
print("Start time: " + time.strftime("%c"))
logger.debug("Download start time: " + time.strftime("%c"))
curl.perform()
print("\nTotal-time: " + str(curl.getinfo(curl.TOTAL_TIME)))
print("Download speed: %.2f bytes/second" % (curl.getinfo(curl.SPEED_DOWNLOAD)))
print("Document size: %d bytes" % (curl.getinfo(curl.SIZE_DOWNLOAD)))
logger.debug("Total-time: " + str(curl.getinfo(curl.TOTAL_TIME)))
logger.debug("Download speed: %.2f bytes/second" % (curl.getinfo(curl.SPEED_DOWNLOAD)))
logger.debug("Document size: %d bytes" % (curl.getinfo(curl.SIZE_DOWNLOAD)))
except:
logger.error("download failed - ", exc_info=True)
print("download failed!!! check log for detailed message")
curl.close()
curl.fp.close()
sys.stdout.flush()
分配分割符char
MySqlCommand führerscheinstring = conn.CreateCommand();
führerscheinstring.CommandText = "SELECT führerschein FROM bewerber WHERE id = '" + textBoxrecruitingid.Text + "'";
string stringführerschein = führerscheinstring.ExecuteScalar().ToString();
char[] charSeparators = new char[] { ',' };
string[] result;
result = stringführerschein.Split(charSeparators, StringSplitOptions.None);
foreach (string entry in result)
{
if (entry == "A")
{
checkedListBoxrecruitingführerschein.SetItemChecked(0,true);
}
else if (entry == "B")
{
checkedListBoxrecruitingführerschein.SetItemChecked(1, true);
}
else if (entry == "BE")
{
checkedListBoxrecruitingführerschein.SetItemChecked(2, true);
}
else if (entry == "C1")
{
checkedListBoxrecruitingführerschein.SetItemChecked(3, true);
}
else if (entry == "C")
{
checkedListBoxrecruitingführerschein.SetItemChecked(4, true);
}
else if (entry == "C1E")
{
checkedListBoxrecruitingführerschein.SetItemChecked(5, true);
}
else if (entry == "CE")
{
checkedListBoxrecruitingführerschein.SetItemChecked(6, true);
}
else if (entry == "D1")
{
checkedListBoxrecruitingführerschein.SetItemChecked(7, true);
}
else if (entry == "D")
{
checkedListBoxrecruitingführerschein.SetItemChecked(8, true);
}
else if (entry == "D1E")
{
checkedListBoxrecruitingführerschein.SetItemChecked(9, true);
}
else if (entry == "DE")
{
checkedListBoxrecruitingführerschein.SetItemChecked(10, true);
}
else if (entry == "L")
{
checkedListBoxrecruitingführerschein.SetItemChecked(11, true);
}
else if (entry == "T")
{
checkedListBoxrecruitingführerschein.SetItemChecked(12, true);
}
else if (entry == "ADR")
{
checkedListBoxrecruitingführerschein.SetItemChecked(14, true);
}
else if (entry == "ADR Tank")
{
checkedListBoxrecruitingführerschein.SetItemChecked(15, true);
}
else if (entry == "Module vorhanden")
{
checkedListBoxrecruitingführerschein.SetItemChecked(16, true);
}
else if (entry == "Fahrerkarte vorhanden")
{
checkedListBoxrecruitingführerschein.SetItemChecked(17, true);
}
else
{
}
}
选择要检查的内容(17是项目ID(从0开始)为true表示将对项目进行检查)
char[] charSeparators = new char[] { ',' };