本文整理汇总了C#中Port.DoInsert方法的典型用法代码示例。如果您正苦于以下问题:C# Port.DoInsert方法的具体用法?C# Port.DoInsert怎么用?C# Port.DoInsert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Port
的用法示例。
在下文中一共展示了Port.DoInsert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImportFareDumpFile
public DataTable ImportFareDumpFile(string fileName)
{
DataTable dt = null;
DataTable dtErrInfo = new DataTable();
dtErrInfo.Columns.Add("RowNumber", typeof(int));
dtErrInfo.Columns.Add("ErrColumnName", typeof(string));
dtErrInfo.Columns.Add("ErrColumnData", typeof(string));
dtErrInfo.Columns.Add("ErrDescription", typeof(string));
dt = this.GetDataTableFromExcel(fileName);
//Check Column in imported Excel file match the template, no missing column
string columnNames;
columnNames = ",Dep,Arr,Dreg,Areg,Category,Facility,Minlength,Maxlength,Amount,Byfootamt,Startdate,Enddate,Recid,Description,";
int rowNumber = 0;
foreach (DataColumn column in dt.Columns)
{
if (columnNames.IndexOf("," + column.ColumnName + ",") < 0)
dtErrInfo.Rows.Add(new object[] { rowNumber, column.ColumnName, "Template Error", "The column in XLS file does not match orinigal template" });
}
if (dtErrInfo.Rows.Count > 0)
return dtErrInfo;
//Check if column “Dep” and “Arr”(Port Code) exists in Port table.
//If not then create port
foreach (DataRow row in dt.Rows)
{
string depPortId = row["Dep"].ToString();
string arrPortId = row["Arr"].ToString();
if (string.IsNullOrEmpty(depPortId) || string.IsNullOrEmpty(arrPortId))
continue;
Port dport = new Port().GetById(depPortId, false);
if (dport == null)
{
Port dp = new Port();
dp.DoInsert(depPortId, depPortId);
}
Port aport = new Port().GetById(arrPortId, false);
if (aport == null)
{
Port ap = new Port();
ap.DoInsert(arrPortId, arrPortId);
}
//Select distinct column “Dep” and “Arr” from Route table, if not exist, insert into Route table
Company c = Company.GetCompanyByShortName("AMHS");
int operatorId = c.ID;
Route r = Route.GetRouteByPortId(depPortId, arrPortId, operatorId);
int routeId;
if (r == null)
{
Route newRoute = new Route();
newRoute.OperatorId = operatorId;
newRoute.DeparturePortId = depPortId;
newRoute.ArriavlPortId = arrPortId;
newRoute.IsActive = true;
Route.DoInsert(newRoute);
routeId = newRoute.ID;
}
else
{
routeId = r.ID;
}
//Create a record in Fare table (RouteID, StartDate, EndDate)
string strStartDate = row["Startdate"].ToString();
string strEndDate = row["Enddate"].ToString();
DateTime startDate = DateTime.MaxValue;
DateTime endDate = DateTime.MaxValue;
if (string.IsNullOrEmpty(strStartDate) || string.IsNullOrEmpty(strEndDate))
{
dtErrInfo.Rows.Add(new object[] { rowNumber, "StartDate/EndDate", "Null", " StartDate/EndDate is worng format or value" });
continue;
}
if (DateTime.TryParse(strStartDate, out startDate) && DateTime.TryParse(strEndDate, out endDate))
{
int fareId;
Fare existingFare = Fare.GetFareByRouteAndDateRange(routeId, startDate, endDate);
if (existingFare == null)
{
Fare newFare = new Fare();
newFare.RoutesID = routeId;
newFare.StartDate = startDate;
newFare.EndDate = endDate;
Fare.DoInsert(newFare);
fareId = newFare.ID;
}
else
{
fareId = existingFare.ID;
}
string strCategory = row["Category"].ToString();
FareCategory fareCategory = FareCategory.GetCategoryByName(strCategory);
if (fareCategory == null)
{
dtErrInfo.Rows.Add(new object[] { rowNumber, "Fare Category", "Null", " Fare Category not found" });
continue;
//.........这里部分代码省略.........
示例2: InsertPort
private void InsertPort()
{
string portCode;
string portName;
TextBox txtPortCode = (TextBox)this.FV_Port.FindControl("txtPortCode");
TextBox txtPortName = (TextBox)this.FV_Port.FindControl("txtPortName");
portCode = (txtPortCode == null) ? "" : (string.IsNullOrEmpty(txtPortCode.Text) ? "" : txtPortCode.Text.Trim());
portName = (txtPortName == null) ? "" : (string.IsNullOrEmpty(txtPortName.Text) ? "" : txtPortName.Text.Trim());
Port existingPort = new Port().GetById(portCode, false);
if (existingPort == null)
{
Port port = new Port();
port.DoInsert(portCode, portName);
BindList();
this.lblMessage.Text = "Insert successfully";
this.lblMessage.ForeColor = Color.Green;
}
else
{
this.lblMessage.Text = "Deplicate Port Code found, please try another one.";
this.lblMessage.ForeColor = Color.Red;
}
if (txtPortCode != null)
txtPortCode.Text = string.Empty;
if (txtPortName != null)
txtPortName.Text = string.Empty;
}