Beispiel #1
0
        public void LoadScheduledRoutine(int ScheduleID)
        {
            //execute procedure to get a routine and convert data tables to C# model
            using (SqlServer database = new SqlServer(WebConfigurationManager.ConnectionStrings["DefaultConnection"].ToString()))
            {
                List<SqlParameter> parameters = new List<SqlParameter>();

                parameters.Add(new SqlParameter("@ScheduleID", SqlDbType.Int) { Value = ScheduleID });

                using (DataSet routine = database.GetDataSet("dbo.ScheduledRoutineGet", parameters))
                {
                    DataTable checksheets = routine.Tables[1];
                    DataTable fields = routine.Tables[2];
                    DataTable records = routine.Tables[3];
                    DataTable fieldvalues = routine.Tables[4];

                    int fieldCounter = 0;
                    int recordCounter = 0;
                    int fieldValueCounter = 0;

                    this.ID = int.Parse(routine.Tables[0].Rows[0]["ID"].ToString());
                    Name = routine.Tables[0].Rows[0]["Name"].ToString();
                    Description = routine.Tables[0].Rows[0]["Description"].ToString();
                    Completed = routine.Tables[5].Rows[0]["Completed"].ToString();

                    foreach (DataRow csRow in checksheets.Rows)
                    {
                        int numFields = int.Parse(csRow["FieldCount"].ToString());
                        int numRecords = int.Parse(csRow["RecordCount"].ToString());
                        ChecksheetModel checksheet = new ChecksheetModel();

                        checksheet.Name = csRow["ChecksheetName"].ToString();

                        for (int i = 0; i < numFields; i++)
                        {
                            Field field = new Field();

                            field.Name = fields.Rows[fieldCounter]["FieldName"].ToString();
                            field.TypeID = int.Parse(fields.Rows[fieldCounter++]["FieldTypeID"].ToString());

                            checksheet.Fields.Add(field);
                        }

                        for (int i = 0; i < numRecords; i++)
                        {
                            Record record = new Record();

                            record.Name = records.Rows[recordCounter++]["RecordName"].ToString();

                            if (i > 0)
                            {
                                for (int j = 0; j < numFields; j++)
                                {
                                    FieldValue fieldValue = new FieldValue();
                                    fieldValue.Editable = fieldvalues.Rows[fieldValueCounter]["Editable"].ToString() == "true";
                                    fieldValue.Value = fieldvalues.Rows[fieldValueCounter++]["Value"].ToString();
                                    record.FieldValues.Add(fieldValue);
                                }
                            }

                            checksheet.Records.Add(record);
                        }

                        Checksheets.Add(checksheet);
                    }
                }
            }
        }