Skip to content

Instantly share code, notes, and snippets.

@FilipDeVos
Created February 28, 2012 14:03
Show Gist options
  • Select an option

  • Save FilipDeVos/1932722 to your computer and use it in GitHub Desktop.

Select an option

Save FilipDeVos/1932722 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlServerCe;
using System.IO;
using System.Linq;
using System.Text;
namespace Stack9482012
{
class Program
{
static void Main(string[] args)
{
const string sqlString1 =
@"CREATE TABLE WorkOrderComment ( WorkOrderCommentID uniqueidentifier NOT NULL CONSTRAINT WorkOrderCommentPK Primary Key,
WOInstructionID uniqueidentifier NOT NULL,
WorkOrderID_Update uniqueidentifier NULL,
TextData NTEXT NULL,
Value float NULL,
Category nvarchar(50) NULL,
BarcodeScanned bit NULL,
Timestamp DateTime NULL,
Time float NULL,
UserID uniqueidentifier NULL,
Void bit NULL,
VoidTimeStamp DateTime NULL,
FaultComplaintID uniqueidentifier NULL,
ClientChange bit NOT NULL)";
const string sqlString2 =
@"INSERT INTO WorkOrderComment ( WOInstructionID, WorkOrderCommentID, ClientChange, Void, UserID, VoidTimestamp)
SELECT WOInstructionID, WOInstructionID, 1, @VoidBit, @VoidUser, @VoidTimeStamp
FROM WorkOrderInstruction
WHERE InstructionGroupQuestion = 0
AND InstructionGroupNumber = @insGroupNo
AND WorkOrderID = @WoID";
const string sqlString3 = @"create table WorkOrderInstruction (WOInstructionID uniqueidentifier, InstructionGroupQuestion int, InstructionGroupNumber int, WorkOrderID uniqueidentifier)";
var connStr = @"Data Source = .\db.sdf;File Mode=Shared Read;Persist Security Info=False";
if (File.Exists(@".\db.sdf"))
File.Delete(@".\db.sdf");
using (var engine = new SqlCeEngine(connStr))
{
engine.CreateDatabase();
}
createtable(connStr, sqlString1);
createtable(connStr, sqlString3);
var action = 0;
var workOrderID = Guid.NewGuid();
var instructionGroupNumber = 10;
using (var sqlConn = new SqlCeConnection(connStr))
using (var sqlCmd = new SqlCeCommand(sqlString2, sqlConn))
{
sqlConn.Open();
sqlCmd.Parameters.Add("@VoidBit", SqlDbType.Bit).Value = action;
sqlCmd.Parameters.Add("@VoidUser", SqlDbType.UniqueIdentifier).Value = DBNull.Value;
sqlCmd.Parameters.Add("@VoidTimeStamp", SqlDbType.DateTime).Value = DBNull.Value;
sqlCmd.Parameters.Add("@WoID", SqlDbType.UniqueIdentifier).Value = workOrderID;
sqlCmd.Parameters.Add("@insGroupNo", SqlDbType.Int).Value = instructionGroupNumber;
sqlCmd.ExecuteNonQuery();
}
}
private static void createtable(string connStr, string sqlString1)
{
using (var sqlConn = new SqlCeConnection(connStr))
using (var sqlCmd = new SqlCeCommand(sqlString1, sqlConn))
{
sqlConn.Open();
sqlCmd.ExecuteNonQuery();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment