本文整理汇总了C#中DowntimeCollection_Demo.DB.SaveChanges方法的典型用法代码示例。如果您正苦于以下问题:C# DB.SaveChanges方法的具体用法?C# DB.SaveChanges怎么用?C# DB.SaveChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DowntimeCollection_Demo.DB
的用法示例。
在下文中一共展示了DB.SaveChanges方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddLine
public static DigestEmailLine AddLine(int emailId, string line)
{
using (DB db = new DB(DBHelper.GetConnectionString()))
{
DigestEmail email = (from o in db.DigestEmails
where o.Id == emailId
select o).FirstOrDefault();
if (email != null)
{
email.DigestEmailLines.Load();
DigestEmailLine emailLine = (from o in email.DigestEmailLines
where o.Line == line
select o).FirstOrDefault();
if (emailLine == null)
{
emailLine = new DigestEmailLine();
emailLine.Line = line;
emailLine.DigestEmail = email;
db.AddToDigestEmailLines(emailLine);
db.SaveChanges();
return emailLine;
}
}
}
return null;
}
示例2: CreateCaseCount
public bool CreateCaseCount(DateTime? eventStart, DateTime? eventStop, int caseCount, string line, string client)
{
try
{
using (DB db = new DB())
{
int id;
if (!eventStart.HasValue || !eventStop.HasValue)
return false;
CaseCount count = new CaseCount();
count.CaseCount1 = caseCount;
count.Client = client;
count.EventStart = eventStart;
count.EventStop = eventStop;
count.Line = line;
db.AddToCaseCountSet(count);
db.SaveChanges();
id = count.Id;
bool result = id > 0;
if (result)
{
DBHelper.UpdateAscommPing(client, DateTime.Now, line, true);
}
return result;
}
}
catch (Exception ex)
{
String fileName = this.Server.MapPath("~/App_Data/log.txt");
File.AppendAllText(fileName, ex.ToString());
throw;
}
}
示例3: SendClientDailyEmail
public string SendClientDailyEmail()
{
if (string.IsNullOrEmpty(_currentClient))
return string.Empty;
using (DB db = new DB(DBHelper.GetConnectionString(_currentClient)))
{
ClientEmail cEmail = (from o in db.ClientEmails
where o.Client == _currentClient
select o).FirstOrDefault();
if (cEmail == null)
{
cEmail = new ClientEmail {Client = _currentClient, SendDailyDigest = true};
db.AddToClientEmails(cEmail);
return (db.SaveChanges() > 0).ToString();
}
cEmail.SendDailyDigest = true;
return (db.SaveChanges() > 0).ToString();
}
}
示例4: LoginAndCreateDowntimeData
public bool LoginAndCreateDowntimeData(DateTime? eventStart, DateTime? eventStop, decimal? minutes, string reasonCode, int? reasonCodeID, string comment, string line, string client, string password)
{
bool result;
bool loggedIn = Login(client, password);
if (!loggedIn) return false;
if (eventStart.HasValue == false || eventStop.HasValue == false)
return false;
if (minutes.HasValue == false)
minutes = Convert.ToInt32(eventStop.Value.Subtract(eventStart.Value).TotalMinutes);
using (DB db = new DB())
{
DowntimeData latestDowntime = (from o in db.DowntimeDataSet
where o.Client == client && o.Line == line
orderby o.EventStop.Value descending
select o).FirstOrDefault();
DateTime? latestDate = null;
if (latestDowntime != null)
latestDate = latestDowntime.EventStop;
bool create = !latestDate.HasValue;
DowntimeData dd = new DowntimeData();
if (latestDate.HasValue)
{
create = !(latestDate.Value >= eventStop);
}
if (create)
{
//dd.EventStart = eventStart;
//dd.EventStop = eventStop;
dd.EventStart = eventStart;
dd.EventStop = eventStop;
dd.Minutes = minutes;
dd.ReasonCodeID = reasonCodeID;
dd.ReasonCode = reasonCode;
dd.Line = line;
dd.Comment = comment;
dd.Client = client;
dd.IsCreatedByAcromag = true;
db.AddToDowntimeDataSet(dd);
result = db.SaveChanges() > 0;
if (result)
{
DBHelper.UpdateAscommPing(client, DateTime.Now, line, true);
}
}
else
result = false;
}
return result;
}
示例5: InsertDevice
public bool InsertDevice(NodeLine device)
{
try
{
using (DB db = new DB())
{
NodeLine node = (from o in db.DeviceSetups
where o.Id == device.DeviceSetupId
select new NodeLine
{
DeviceSetupId = o.Id,
Client = o.LineSetup.DataCollectionNode.Client,
AddressType = o.AddressType,
DataType = o.DataType,
DowntimeThreshold = o.LineSetup.DowntimeThreshold,
UptimeThreshold = o.LineSetup.UptimeThreshold,
IPAddress = o.IpAddress,
Line = o.LineSetup.Line,
TagType = o.TagType,
TrackDowntime = o.TrackDowntime,
TrackingType = o.TrackingType,
TagName = o.TagName
}).FirstOrDefault();
if (node != null)//Already exists
{
DeviceSetup setup = (from o in db.DeviceSetups
where o.Id == node.DeviceSetupId
select o).FirstOrDefault();
if (setup != null)
{
setup.IpAddress = device.IPAddress;
setup.TagName = device.TagName;
setup.TagType = device.TagType;
setup.TrackDowntime = device.TrackDowntime;
setup.TrackingType = device.TrackingType;
setup.AddressType = device.AddressType;
setup.DataType = device.DataType;
setup.LineSetup.Line = device.Line;
setup.LineSetup.DowntimeThreshold = device.DowntimeThreshold;
setup.LineSetup.UptimeThreshold = device.UptimeThreshold;
setup.LineSetup.DataCollectionNode.Client = device.Client;
setup.LineSetup.DataCollectionNode.ServerName = device.ServerName;
return db.SaveChanges() > 0;
}
}
else
{
DeviceSetup setup = new DeviceSetup();
setup.IpAddress = device.IPAddress;
setup.TagName = device.TagName;
setup.TagType = device.TagType;
setup.TrackDowntime = device.TrackDowntime;
setup.TrackingType = device.TrackingType;
setup.AddressType = device.AddressType;
setup.DataType = device.DataType;
DataCollectionNode dataNode = (from o in db.DataCollectionNodes
where o.Client == device.Client
select o).FirstOrDefault();
if (dataNode == null)
{
dataNode = new DataCollectionNode();
dataNode.Password = "password";
setup.LineSetup.DataCollectionNode = dataNode;
}
setup.LineSetup.DataCollectionNode.Client = device.Client;
LineSetup lineSetup = (from o in db.LineSetups
where o.DataCollectionNode.Id == dataNode.Id
select o).FirstOrDefault();
if (lineSetup == null)
{
lineSetup = new LineSetup();
setup.LineSetup = lineSetup;
}
setup.LineSetup.Line = device.Line;
setup.LineSetup.DowntimeThreshold = device.DowntimeThreshold;
setup.LineSetup.UptimeThreshold = device.UptimeThreshold;
db.AddToLineSetups(lineSetup);
return db.SaveChanges() > 0;
}
}
return false;
}
catch (Exception ex)
//.........这里部分代码省略.........
示例6: CreateTComCaseCount
public int CreateTComCaseCount(string eStart, string eStop, int caseCount, string line, string client)
{
try
{
int result;
if (string.IsNullOrEmpty(eStart) || string.IsNullOrEmpty(eStop))
return -1;
DateTime eventStart;
DateTime eventStop;
if (!DateTime.TryParse(eStart, out eventStart))
return -1;
if (!DateTime.TryParse(eStop, out eventStop))
return -1;
if (eventStop < eventStart)
return -1;
using (DB db = new DB())
{
int id;
CaseCount count = new CaseCount();
count.CaseCount1 = caseCount;
count.Client = client;
count.EventStart = eventStart;
count.EventStop = eventStop;
count.Line = line;
db.AddToCaseCountSet(count);
db.SaveChanges();
id = count.Id;
result = id;
if (result > 0)
{
DBHelper.UpdateAscommPing(client, DateTime.Now, line, true);
}
return result;
}
}
catch (Exception ex)
{
String fileName = this.Server.MapPath("~/App_Data/log.txt");
File.AppendAllText(fileName, ex.ToString());
return -1;
}
}
示例7: CreateDowntimeDataWithTimeZone
public bool CreateDowntimeDataWithTimeZone(DateTime? eventStart, DateTime? eventStop, string strTimeZone, decimal? minutes, string reasonCode, int? reasonCodeID, string comment, string line, string client)
{
bool result = false;
if (eventStart.HasValue == false || eventStop.HasValue == false)
return false;
if (minutes.HasValue == false)
minutes = Convert.ToInt32(eventStop.Value.Subtract(eventStart.Value).TotalMinutes);
if (!string.IsNullOrEmpty(strTimeZone))
{
TimeZoneInfo timeZone = TimeZoneInfo.FromSerializedString(strTimeZone);
eventStart = TimeZoneInfo.ConvertTime(eventStart.Value, timeZone);
eventStop = TimeZoneInfo.ConvertTime(eventStop.Value, timeZone);
}
using (DB db = new DB())
{
DowntimeData latestDowntime = (from o in db.DowntimeDataSet
where o.Client == client && o.Line == line
orderby o.EventStop.Value descending
select o).FirstOrDefault();
DateTime? latestDate = null;
if (latestDowntime != null)
latestDate = latestDowntime.EventStop;
bool create = !latestDate.HasValue;
DowntimeData dd = new DowntimeData();
if (latestDate.HasValue)
{
create = !(latestDate.Value >= eventStop);
}
if (create)
{
//dd.EventStart = eventStart;
//dd.EventStop = eventStop;
dd.EventStart = eventStart;
dd.EventStop = eventStop;
dd.Minutes = minutes;
dd.ReasonCodeID = reasonCodeID;
dd.ReasonCode = reasonCode;
dd.Line = line;
dd.Comment = comment;
dd.Client = client;
dd.IsCreatedByAcromag = true;
db.AddToDowntimeDataSet(dd);
result = db.SaveChanges() > 0;
if (result == true)
{
DBHelper.UpdateAscommPing(client, DateTime.Now, line, true);
}
}
}
return result;
}
示例8: UpdateGlobalDowntimeThreshold
public int UpdateGlobalDowntimeThreshold(string client, int seconds)
{
using (DB db = new DB())
{
List<LineSetup> setups = (from o in db.LineSetups
where o.DataCollectionNode.Client == client
select o).ToList();
if (setups.Count > 0)
{
foreach(LineSetup setup in setups)
setup.DowntimeThreshold = seconds;
db.SaveChanges();
return seconds;
}
return -1;
}
}
示例9: Save
//.........这里部分代码省略.........
var q = from o in db.DowntimeDataSet
where o.ID == id
select o;
var dd = q.FirstOrDefault();
if (dd == null) return false.ToString().ToLower();
DowntimeReason reason = DCSDashboardDemoHelper.getReason(reasonId);
if (dd.EventStop.HasValue == false)
{
if (!DateTime.TryParse(request.Form["enddatetime"], out enddatetime))
{
context.Response.Write("end date time is empty.");
return "false";
}
dd.EventStop = enddatetime;
if (dd.EventStart != null)
dd.Minutes = Convert.ToDecimal(dd.EventStop.Value.Subtract(dd.EventStart.Value).TotalMinutes);
changeMinutes = false;
SwitchLineStatus(line, true);
}
dd.ReasonCodeID = reasonId;
dd.ReasonCode = reasonCode;
dd.Line = line;
dd.Comment = comment;
if(changeMinutes)
dd.Minutes = minutes;
dd.Client = client;
if (reason.HideReasonInReports && dd.Minutes > reason.Duration && reason.Duration > 0)//If Planned && duration is greater than 0
{
DowntimeChild child1 = (from o in db.DowntimeChildren
where o.ParentDowntimeId == dd.ID
select o).FirstOrDefault();
if (child1 == null)
{
if (dd.EventStart != null)
{
dd.EventStop = dd.EventStart.Value.AddMinutes(reason.Duration);
// Tim mark
DowntimeData dd2 = new DowntimeData
{
Client = dd.Client,
ReasonCode = null,
ReasonCodeID = null,
Line = dd.Line,
Minutes = dd.Minutes - reason.Duration,
Comment = string.Empty,
EventStart = dd.EventStop
};
dd2.EventStop = dd.EventStop.Value.AddMinutes(Convert.ToDouble(dd2.Minutes));
child1 = new DowntimeChild {ParentDowntimeId = dd.ID};
dd.Minutes = reason.Duration;//Change after setting dd2's minutes
db.AddToDowntimeDataSet(dd2);
db.SaveChanges();
child1.DowntimeId = dd2.ID;
child1.ReasonCodeId = reason.ID;
db.AddToDowntimeChildren(child1);
}
db.SaveChanges();
}
}
else
{
db.SaveChanges();
}
result = true;
if (reason.IsChangeOver && throughputId > 0)
{
DCSDashboardDemoHelper.CreateThroughPutHistory(throughputId, option1Id, option2Id, dd.EventStop.Value, line);
}
else if (option1Id > 0 || option2Id > 0)
{
if (option1Id > 0)
DCSDashboardDemoHelper.CreateNOS(dd.ID, option1Id);
if (option2Id > 0)
DCSDashboardDemoHelper.CreateNOS(dd.ID, option2Id);
}
}
return result.ToString().ToLower();
}
示例10: CreateDTWithNoStop
public string CreateDTWithNoStop()
{
DateTime sd;
if (!DateTime.TryParse(request.Params["sd"], out sd))
{
return null;
}
using (DB db = new DB(DBHelper.GetConnectionString(_currentClient)))
{
DowntimeData dt = new DowntimeData();
dt.Client = _currentClient;
dt.EventStart = sd;
dt.EventStop = null;
dt.Line = Line;
dt.Minutes = 0;
db.AddToDowntimeDataSet(dt);
db.SaveChanges();
SwitchLineStatus(Line, false);
return ConvertToJsonString(new
{
ID = dt.ID,
EventStart = (dt.EventStart.Value.ToString("MM/dd/yyyy hh:mm:ss tt")),
EventStop = "",
ReasonCodeID = dt.ReasonCodeID,
ReasonCode = dt.ReasonCode,
Minutes = (dt.Minutes.Value),
Line = dt.Line,
Comment = dt.Comment
});
}
}
示例11: delRecords
private string delRecords()
{
string ids = request["ids"];
if (string.IsNullOrEmpty(ids)) return "Invald args.";
using (DB db = new DB(DBHelper.GetConnectionString(_currentClient)))
{
foreach (var item in ids.Split(','))
{
int id;
if (!int.TryParse(item, out id)) continue;
var q = from o in db.DowntimeDataSet
where o.ID == id
select o;
var row = q.FirstOrDefault();
if (row != null)
{
db.DeleteObject(row);
}
}
db.SaveChanges();
}
return "true";
}
示例12: addNewEvent
private void addNewEvent(HttpContext context)
{
//reasonId&reasonCode&comment&startdatetime&minutes&line
int reasonId, occurences;
int throughputId, option1Id, option2Id = -1;
DateTime startdatetime;
decimal minutes;
var reasonCode = request.Form["reasonCode"];
var comment = request.Form["comment"];
var line = request.Form["line"];
line = line.Replace('#', ' ');
var client = _currentClient;
int.TryParse(request.Form["Occurences"], out occurences);
if (occurences == 0) occurences = 1;
int.TryParse(request.Form["throughput"], out throughputId);
int.TryParse(request.Form["option1"], out option1Id);
int.TryParse(request.Form["option2"], out option2Id);
if(!DateTime.TryParse(request.Form["startdatetime"],out startdatetime))
{
context.Response.Write("start date time is empty.");
return;
}
if(!int.TryParse(request.Form["reasonId"],out reasonId))
{
context.Response.Write("reason id is empty.");
return;
}
if(!decimal.TryParse(request.Form["minutes"],out minutes))
{
context.Response.Write("minutes id is empty.");
return;
}
if(string.IsNullOrEmpty(line))
{
context.Response.Write("line is empty.");
return;
}
if(string.IsNullOrEmpty(reasonCode))
{
context.Response.Write("reasonCode is empty.");
return;
}
var enddatetime = startdatetime.AddMinutes(Convert.ToDouble(minutes));
bool result = false;
using (DB db = new DB(DBHelper.GetConnectionString(_currentClient)))
{
int count = 0;
DowntimeReason reason = (from o in db.DowntimeReasonSet
where o.ID == reasonId
select o).FirstOrDefault();
if (reason == null)
context.Response.Write("Reason Code doesn't exist");
if (throughputId > 0 && reason.IsChangeOver)
{
var throughput = (from o in db.Throughput where o.Id == throughputId select o).FirstOrDefault();
reasonCode = string.Format("{0} [{1}]", reasonCode, throughput.Name);
}
List<DowntimeData> dts = new List<DowntimeData>();
for (int cpnum = count; cpnum < occurences; cpnum++)
{
DowntimeData dd = new DowntimeData();
dd.EventStart = startdatetime;
dd.EventStop = enddatetime;
dd.Minutes = minutes;
dd.ReasonCodeID = reasonId;
dd.ReasonCode = reasonCode;
dd.Line = line;
dd.Comment = comment;
dd.Client = client;
dd.IsCreatedByAcromag = false;
db.AddToDowntimeDataSet(dd);
dts.Add(dd);
}
int updatedRecords = db.SaveChanges();
if (throughputId > 0 && reason.IsChangeOver)
{
DCSDashboardDemoHelper.CreateThroughPutHistory(throughputId, option1Id, option2Id, enddatetime, line);
}
else if(option1Id > 0 || option2Id > 0)
//.........这里部分代码省略.........
示例13: UpdateThroughPut
public string UpdateThroughPut()
{
string name = request.Form["name"];
string description = request.Form["description"];
int perHour;
int id;
int.TryParse(request.Form["perhour"], out perHour);
int.TryParse(request.Form["id"], out id);
if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(description) || perHour <= -1 || id <= -1)
return "FAILED";
using (DB db = new DB(DBHelper.GetConnectionString(_currentClient)))
{
Throughput tp = (from o in db.Throughput
where o.Id == id
select o).FirstOrDefault();
if (tp == null) return "FAILED";
tp.Name = name;
tp.Description = description;
tp.PerHour = perHour;
int results = db.SaveChanges();
if (results >= 0)
return "SUCCESS";
}
return "FAILED";
}
示例14: UpdateOptionInfo
public string UpdateOptionInfo()
{
string op1Name = request.Params["opt1Name"];
string op1Required = request.Params["opt1Required"];
string op1Enabled = request.Params["opt1Enabled"];
string op2Name = request.Params["opt2Name"];
string op2Required = request.Params["opt2Required"];
string op2Enabled = request.Params["opt2Enabled"];
using (DB db = new DB(DBHelper.GetConnectionString(_currentClient)))
{
OptionInfo opt1 = (from o in db.OptionInfoes
where o.Number == 1
&& o.Client == _currentClient
select o).FirstOrDefault();
OptionInfo opt2 = (from o in db.OptionInfoes
where o.Number == 2
&& o.Client == _currentClient
select o).FirstOrDefault();
if (opt1 == null)
{
opt1 = new OptionInfo()
{
Client = _currentClient,
Number = 1
};
db.AddToOptionInfoes(opt1);
}
if (opt2 == null)
{
opt2 = new OptionInfo()
{
Client = _currentClient,
Number = 2
};
db.AddToOptionInfoes(opt2);
}
opt1.IsRequired = Convert.ToBoolean(op1Required);
opt1.Enabled = Convert.ToBoolean(op1Enabled);
opt1.Name = op1Name;
opt2.IsRequired = Convert.ToBoolean(op2Required);
opt2.Enabled = Convert.ToBoolean(op2Enabled);
opt2.Name = op2Name;
return (db.SaveChanges() > 0).ToString();
}
}
示例15: UpdateDTWithNoStop
public string UpdateDTWithNoStop()
{
DateTime es;
int id;
if (!DateTime.TryParse(request.Params["es"], out es))
{
return null;
}
if (!int.TryParse(request.Params["id"], out id))
{
return null;
}
using (DB db = new DB(DBHelper.GetConnectionString(_currentClient)))
{
DowntimeData dt = (from o in db.DowntimeDataSet
where o.ID == id
select o).FirstOrDefault();
if (dt == null)
return ConvertToJsonString(new
{
ID = -1,
EventStart = "",
EventStop = "",
ReasonCodeID = -1,
ReasonCode = "",
Minutes = 0,
Line = Line,
Comment = ""
});
dt.EventStop = es;
db.SaveChanges();
if (dt.EventStart != null && dt.Minutes != null)
return ConvertToJsonString(new
{
ID = dt.ID,
EventStart = dt.EventStart.Value.ToString("MM/dd/yyyy hh:mm:ss tt"),
EventStop = "",
ReasonCodeID = dt.ReasonCodeID,
ReasonCode = dt.ReasonCode,
Minutes = dt.Minutes.Value,
Line = dt.Line,
Comment = dt.Comment
});
return ConvertToJsonString(new {});
}
}