“连接到 MPP 并查找现有驱动程序 ID”下的 If Else 块导致我的主 Razor 块中的大括号不匹配。我知道我错过了一些东西,但无法弄清楚。调试器忽略最后一个大括号,将倒数第二个大括号与 @{ 左大括号匹配。
@{
Layout = "~/Shared/_Layout.cshtml";
Page.Title = "Register";
// Setup field validation
Validation.RequireField("driverfirstname", "Cannot be blank.");
Validation.RequireField("driverlastname", "Cannot be blank.");
Validation.RequireField("driverssn", "Cannot be blank.");
// Initialize variables
var driverfirstname = "";
var driverlastname = "";
var driverssn = "";
// If validation is OK
if (IsPost && Validation.IsValid())
{
driverfirstname = @Request.Form["driverfirstname"];
driverlastname = @Request.Form["driverlastname"];
driverssn = @Request.Form["driverssn"];
// Create Driver ID and Password
string first = driverfirstname.Substring(0, 3);
string last = driverlastname.Substring(0, 3);
string lastFour = driverssn.Substring(7, 4);
string drivercodetest = (last + first).ToUpper();
// Connect to MPP and look for existing Driver IDs
var dbs = Database.Open("other_db");
var drivercodempp = dbs.Query("SELECT mpp_id FROM profile WHERE mpp_id = @drivercodetest");
var drivercode = "";
if (drivercodempp == null)
{
drivercode = (last + first).ToUpper();
}
else if (drivercodempp.Contains("01"))
{
drivercode = (last + first).ToUpper() + "02";
}
else if (drivercodempp.Contains("02"))
{
drivercode = (last + first).ToUpper() + "03";
}
else if (drivercodempp.Contains("03"))
{
drivercode = (last + first).ToUpper() + "04";
}
else if (drivercodempp.Contains("04"))
{
drivercode = (last + first).ToUpper() + "05";
}
else if (drivercodempp.Contains("05"))
{
drivercode = (last + first).ToUpper() + "06";
}
else
{
drivercode = (last + first).ToUpper() + "07";
}
// Submit to database
var dbi = Database.Open("MainDB");
var insertCommand = "INSERT INTO driver (drivercode, driverfirstname, driverlastname, driverssn) VALUES(@0, @1, @2, @3)";
dbi.Execute(insertCommand, drivercode, driverfirstname, driverlastname, driverssn);
Response.Redirect("~/confirm_register");
}
}