public void Save(GmConnection conn) { GmCommand cmd = conn.CreateCommand(); cmd.AddInt("Id", id); cmd.AddInt("ParentId", (int)parentId); cmd.AddDateTime("Date", date); cmd.AddString("Person", person); cmd.AddString("Title", title); cmd.AddString("Preview", preview); cmd.AddString("Header", header); cmd.AddString("Text", text); cmd.AddString("Company", company); cmd.AddInt("CityId", cityId); cmd.AddString("Address", address); cmd.AddString("Phone", phone); cmd.AddString("Link", link); cmd.AddString("Email", email); cmd.AddInt("Status", (int)status); cmd.AddString("Tag", tag); cmd.AddBoolean("IsGroup", isGroup); if (id == 0) { cmd.CommandText = "insert into Articles values (@ParentId,@Date,@Person,@Title,@Preview,@Header,@Text,@Company,@CityId,@Address,@Phone,@Link,@Email, @Status,@Tag,@IsGroup) select @@Identity"; id = (int)(decimal)cmd.ExecuteScalar(); } else { cmd.CommandText = "update Articles set ParentId=@ParentId,Date=@Date,Person=@Person,Title=@Title,Preview=@Preview,Header=@Header,Text=@Text,Company=@Company,CityId=@CityId,Address=@Address,Phone=@Phone,Link=@Link,Email=@Email,Status=@Status, Tag=@Tag, IsGroup=@IsGroup where Id=@Id"; cmd.ExecuteNonQuery(); } }
public void Save(GmConnection conn, DbTransaction trans) { GmCommand cmd = conn.CreateCommand(trans); cmd.AddInt("Id", id); cmd.AddDateTime("Date", date); cmd.AddInt("UserId", userId); cmd.AddInt("DocumentTypeId", (int)documentTypeId); cmd.AddBoolean("Completed", completed); cmd.AddInt("StorekeeperId", storekeeperId); cmd.AddInt("NDays", nDays); cmd.AddString("DocumentData", documentData.GetXmlString()); if (id == 0) { cmd.CommandText = "insert into Documents values (@Date,@UserId,@DocumentTypeId,@Completed,@StorekeeperId,@NDays,@DocumentData) select @@Identity"; id = (int)(decimal)cmd.ExecuteScalar(); } else { cmd.CommandText = "update Documents set Date=@Date,UserId=@UserId,DocumentTypeId=@DocumentTypeId,Completed=@Completed,StorekeeperId=@StorekeeperId,NDays=@NDays,DocumentData=@DocumentData where Id=@Id"; cmd.ExecuteNonQuery(); } }
public static void GetPrescriptions(GmConnection conn, List <Prescription> prescriptions, IEnumerable <int> patients, IEnumerable <int> prescriptionTypes, DateTime startDate, DateTime endDate, bool reanimationFlag) { string cmdText = @"select * from Prescriptions where PatientId in ({0}) and PrescriptionTypeId in ({1}) and StartDate<@EndDate and EndDate>@StartDate and ReanimationFlag=@ReanimationFlag "; cmdText = string.Format(cmdText, CollectionUtils.GetCommaSeparatedList(patients), CollectionUtils.GetCommaSeparatedList(prescriptionTypes)); GmCommand cmd = conn.CreateCommand(cmdText); cmd.AddDateTime("StartDate", startDate); cmd.AddDateTime("EndDate", endDate); cmd.AddBoolean("ReanimationFlag", reanimationFlag); using (DbDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { prescriptions.Add(new Prescription(dr)); } } }