示例#1
0
        /// <summary>
        /// Apply changes and raises domain events.
        /// </summary>
        void ApplyChanges(ServiceResponse response)
        {
            // Consolidate previous changes
            ModelTransaction transaction =
                ModelTransaction.Combine((Changes ?? new ChangeSet[0])
                                         .Where(cs => cs.Source != ChangeSource.Init)
                                         .Select(cs => cs.Changes));

            // Chain the transactions about to be applied to any previously applied initialization changes
            if (response.Changes != null && transaction != null)
            {
                response.Changes.Chain(transaction);
            }

            // Apply changes and raise domain events
            if (transaction != null)
            {
                response.Changes = transaction.Perform(() => RaiseEvents(response, transaction));
            }

            // Otherwise, just raise events
            else
            {
                response.Changes = (response.Changes ?? new ModelTransaction()).Record(() => RaiseEvents(response, null));
            }
        }
示例#2
0
            internal void LoadRoots(ModelTransaction transaction)
            {
                // Exit immediately if roots have already been loaded
                if (Roots != null)
                {
                    return;
                }

                // Create an array of roots to be loaded
                Roots = new ModelInstance[Ids == null ? 0 : Ids.Length];

                // Get the root instances
                for (int i = 0; i < Roots.Length; i++)
                {
                    // Create the root instance
                    Roots[i] = transaction == null?From.Create(Ids[i]) : transaction.GetInstance(From, Ids[i]);
                }

                // Access a property to force the instance to initialize.  Do a seperate pass so batched loading will work.
                for (int i = 0; i < Roots.Length; i++)
                {
                    var initProp = Roots[i].Type.Properties.FirstOrDefault(p => p is ModelValueProperty) ?? Roots[i].Type.Properties.FirstOrDefault(p => p is ModelReferenceProperty);
                    if (initProp == null)
                    {
                        throw new Exception(string.Format("Type \"{0}\" cannot be forced to initialize because it has no properties.", Roots[i].Type.Name));
                    }
                    Roots[i].OnPropertyGet(initProp);
                }
            }
示例#3
0
        /// <summary>
        /// Raises domain events.
        /// </summary>
        void RaiseEvents(ServiceResponse response, ModelTransaction transaction)
        {
            // Process each event in the request
            if (Events != null)
            {
                response.Events = Events
                                  .Select((domainEvent) =>
                {
                    // Restore the instance to be a valid model instance
                    if (domainEvent.Instance != null)
                    {
                        if (transaction != null)
                        {
                            domainEvent.Instance = transaction.GetInstance(domainEvent.Instance.Type, domainEvent.Instance.Id);
                        }
                        else
                        {
                            domainEvent.Instance = domainEvent.Instance.Type.Create(domainEvent.Instance.Id);
                        }
                    }

                    var result = domainEvent.Raise(transaction);

                    if (result == null)
                    {
                        return(null);
                    }

                    ModelType type;
                    ModelInstance[] roots;
                    bool isList;

                    if (ExoWeb.TryConvertQueryInstance(result, out type, out roots, out isList))
                    {
                        Query newQuery = new Query(type, roots, true, isList, domainEvent.Include);
                        newQuery.Prepare(response);

                        Query[] newQueries = new Query[] { newQuery };
                        Queries            = Queries == null ? newQueries : Queries.Union(newQueries).ToArray();

                        return(isList ? (object)roots : (object)roots[0]);
                    }
                    else if (domainEvent.Include != null && domainEvent.Include.Length > 0)
                    {
                        Query newQuery = new Query(domainEvent.Instance.Type, new[] { domainEvent.Instance }, true, false, domainEvent.Include);
                        newQuery.Prepare(response);

                        Query[] newQueries = new Query[] { newQuery };
                        Queries            = Queries == null ? newQueries : Queries.Union(newQueries).ToArray();

                        return(result);
                    }
                    else
                    {
                        return(result);
                    }
                })
                                  .ToArray();
            }
        }
示例#4
0
        public Boolean UpdateBeginDate(ModelTransaction model, int station_id)
        {
            try
            {
                string query =
                    "UPDATE tb_transaction_" + station_id + "" +
                    " SET" +
                    " begin_date = @begin_date" +
                    " WHERE id = @id;";
                using (MySqlConnection connection = new MySqlConnection(Configurations.MysqlStr))
                {
                    connection.Open();
                    //create mysql command
                    MySqlCommand cmd = new MySqlCommand();
                    cmd.Parameters.AddWithValue("@id", model.id);
                    cmd.Parameters.AddWithValue("@begin_date", model.begin_date);

                    //Assign the query using CommandText
                    cmd.CommandText = query;
                    //Assign the connection using Connection
                    cmd.Connection = connection;

                    //Execute query
                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                logger.Error("Update begin date fail::" + ex.InnerException);
                return(false);
            }
            return(true);
        }
示例#5
0
        //public int getMaxId()
        //{
        //    int result = 0;
        //    List<ModelTransaction> lists = Select(" order by id desc");
        //    if (lists != null)
        //    {
        //        if (lists.Count > 0)
        //        {
        //            result = lists[0].id + 1;
        //        }
        //    }
        //    return result;
        //}

        public List <DateTime> GetDateDistinct()
        {
            string query = "SELECT distinct(date(create_date)) as create_date FROM authencodedb.tb_transaction_7 order by create_date asc";

            //Create a list to store the result
            List <DateTime> lists = new List <DateTime>();

            using (MySqlConnection connection = new MySqlConnection(Configurations.MysqlStr))
            {
                connection.Open();
                //Create Command
                MySqlCommand cmd = new MySqlCommand(query, connection);
                //Create a data reader and Execute the command
                MySqlDataReader dr = cmd.ExecuteReader();

                //Read the data and store them in the list
                while (dr.Read())
                {
                    ModelTransaction transaction = new ModelTransaction();


                    DateTime dt = Convert.ToDateTime(dr["create_date"]);

                    lists.Add(dt);
                }

                //close Data Reader
                dr.Close();
            }

            //return list to be displayed
            return(lists);
        }
示例#6
0
        /// <summary>
        /// Restores the pending deletion status of the instance to the original value.
        /// </summary>
        /// <param name="transaction"></param>
        void ITransactedModelEvent.Rollback(ModelTransaction transaction)
        {
            // Ensure that the current instance has been resolved
            Instance = EnsureInstance(transaction, Instance);

            // Restore the pending deletion status of the instance to the original value
            Instance.IsPendingDelete = !IsPendingDelete;
        }
示例#7
0
        /// <summary>
        /// Changes the pending deletion status of the instance to the specified value.
        /// </summary>
        /// <param name="transaction"></param>
        void ITransactedModelEvent.Perform(ModelTransaction transaction)
        {
            // Ensure that the current instance has been resolved
            Instance = EnsureInstance(transaction, Instance);

            // Change the pending deletion status of the instance to the specified value
            Instance.IsPendingDelete = IsPendingDelete;
        }
示例#8
0
        /// <summary>
        /// Changes the pending deletion status of the instance to the specified value.
        /// </summary>
        /// <param name="transaction"></param>
        void ITransactedModelEvent.Perform(ModelTransaction transaction)
        {
            // Ensure that the current instance has been resolved
            Instance = EnsureInstance(transaction, Instance);

            // Change the pending deletion status of the instance to the specified value
            Instance.IsPendingDelete = IsPendingDelete;
        }
示例#9
0
        /// <summary>
        /// Restores the pending deletion status of the instance to the original value.
        /// </summary>
        /// <param name="transaction"></param>
        void ITransactedModelEvent.Rollback(ModelTransaction transaction)
        {
            // Ensure that the current instance has been resolved
            Instance = EnsureInstance(transaction, Instance);

            // Restore the pending deletion status of the instance to the original value
            Instance.IsPendingDelete = !IsPendingDelete;
        }
示例#10
0
        public static String getBoadingPass(ModelTransaction tran)
        {
            //M1HAMID/AHMED         E       BKKFCOTG 0944 209Y040E0070 100
            //M1GILJIMENEZ/PILA1 MS EKWGVQS BKKTDXPG 0305 207Y045A0016 300
            string fullName = tran.passenger_name + "                               ";
            string prefix   = "                               ";
            string fromTo   = tran.from_city + "" + tran.to_city;

            return(String.Format("{0} {1} {2} {3} {4} {5}",
                                 fullName.Substring(0, 21).ToUpper(),
                                 prefix.Substring(0, 7).ToUpper(), fromTo.ToUpper(), tran.flight_no.ToUpper(), DateTime.Now.DayOfYear.ToString("000") + "Y" + tran.seat_no, "9999"));
        }
示例#11
0
        /// <summary>
        /// Sets the reference property to the new value.
        /// </summary>
        void ITransactedModelEvent.Perform(ModelTransaction transaction)
        {
            Instance = EnsureInstance(transaction, Instance);

            if (OldValue != null)
                OldValue = EnsureInstance(transaction, OldValue);

            if (NewValue != null)
                NewValue = EnsureInstance(transaction, NewValue);

            Property.SetValue(Instance.Instance, NewValue == null ? null : NewValue.Instance);
        }
示例#12
0
            /// <summary>
            /// Deletes and removes the reference to the <see cref="ModelInstance"/> associated with
            /// the current event, which effectively removes the instance from existence.
            /// </summary>
            void ITransactedModelEvent.Rollback(ModelTransaction transaction)
            {
                // Ensure that the current instance has been resolved
                Instance = EnsureInstance(transaction, Instance);

                if (Instance.Instance != null)
                {
                    // Delete the current instance
                    Instance.IsPendingDelete = true;

                    // Create a new proxy reference to the instance
                    Instance = new ModelInstance(Instance.Type, Instance.Id);
                }
            }
示例#13
0
            /// <summary>
            /// Raises the domain event on the target <see cref="ModelInstance"/>.
            /// </summary>
            internal override object Raise(ModelTransaction transaction)
            {
                if (typeof(TEvent) == typeof(SaveEvent))
                {
                    Instance.Save();

                    return(null);
                }
                else
                {
                    Instance.RaiseEvent <TEvent>(Event);
                    return(Event);
                }
            }
        /// <summary>
        /// Sets the reference property back to the old value.
        /// </summary>
        void ITransactedModelEvent.Rollback(ModelTransaction transaction)
        {
            Instance = EnsureInstance(transaction, Instance);

            if (OldValue != null)
            {
                OldValue = EnsureInstance(transaction, OldValue);
            }

            if (NewValue != null)
            {
                NewValue = EnsureInstance(transaction, NewValue);
            }

            Property.SetValue(Instance.Instance, OldValue == null ? null : OldValue.Instance);
        }
示例#15
0
 private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.RowIndex != -1)
     {
         Cursor = Cursors.WaitCursor;
         int    id  = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());
         String cri = " where t.id=" + id;
         List <ModelTransaction> lists = (onlineStatus) ? dao.Select(cri, StationID) : dao.SelectOffine(cri, StationID);
         if (lists.Count > 0)
         {
             tran = lists[0];
             FrmDetail frmManualGen = new FrmDetail(this, tran);
             frmManualGen.ShowDialog();
         }
         Cursor = Cursors.Default;
     }
 }
示例#16
0
            /// <summary>
            /// Creates a new <see cref="ModelInstance"/> of the specified <see cref="ModelType"/>.
            /// </summary>
            void ITransactedModelEvent.Perform(ModelTransaction transaction)
            {
                // Creates a new instance
                if (Instance.Instance == null)
                {
                    // Get the id of the instance surrogate
                    string id = Instance.Id;

                    // Create a new instance and assign this to the instance the event is for
                    Instance = Instance.Type.Create();

                    // Set the id of the new instance to the id of the original surrogate
                    Instance.Id = id;
                    Instance    = Instance;

                    // Force the new instance to initialize
                    Instance.OnAccess();
                }
            }
示例#17
0
            /// <summary>
            /// Creates a new <see cref="ModelInstance"/> of the specified <see cref="ModelType"/>.
            /// </summary>
            void ITransactedModelEvent.Perform(ModelTransaction transaction)
            {
                // Creates a new instance
                if (Instance.Instance == null)
                {
                    // Get the id of the instance surrogate
                    string id = Instance.Id;

                    // Create a new instance and assign this to the instance the event is for
                    Instance = Instance.Type.Create();

                    // Set the id of the new instance to the id of the original surrogate
                    Instance.Id = id;
                    Instance = Instance;

                    // Force the new instance to initialize
                    Instance.OnAccess();
                }
            }
示例#18
0
        //Delete statement
        public Boolean Delete(ModelTransaction model, int station_id)
        {
            try
            {
                string query = "DELETE FROM tb_transaction_" + station_id + " WHERE id=" + model.id;
                using (MySqlConnection connection = new MySqlConnection(Configurations.MysqlStr))
                {
                    connection.Open();
                    MySqlCommand cmd = new MySqlCommand(query, connection);
                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.InnerException);

                return(false);
            }
            return(true);
        }
示例#19
0
        public void CommitTest()
        {
            var model          = LoadRailwayModel(new ModelRepository());
            var referenceModel = LoadRailwayModel(new ModelRepository());

            using (var trans = new ModelTransaction(model))
            {
                var route = new Route()
                {
                    Id = 42
                };
                model.Routes.Add(route);
                model.Routes[0].DefinedBy.RemoveAt(0);
                model.Semaphores[0].Signal = Signal.FAILURE;
                trans.Commit();
            }

            Assert.AreNotEqual(model.Routes.Count, referenceModel.Routes.Count);
            Assert.AreNotEqual(model.Routes[0].DefinedBy.Count, referenceModel.Routes[0].DefinedBy.Count);
            Assert.AreNotEqual(model.Semaphores[0].Signal, referenceModel.Semaphores[0].Signal);
        }
示例#20
0
        void ITransactedModelEvent.Perform(ModelTransaction transaction)
        {
            Prepare(transaction);

            ModelEventScope.Perform(() =>
            {
                ModelContext context = Instance.Type.Context;
                ModelInstanceList list = Instance.GetList(Property);

                if (Added != null)
                {
                    foreach (ModelInstance item in Added)
                        list.Add(item);
                }
                if (Removed != null)
                {
                    foreach (ModelInstance item in Removed)
                        list.Remove(item);
                }
            });
        }
示例#21
0
            internal override object Raise(ModelTransaction transaction)
            {
                // Resolve reference arguments
                foreach (var p in method.Parameters)
                {
                    if (p.ReferenceType != null && args[p.Index] != null)
                    {
                        if (p.IsList)
                        {
                            args[p.Index] = ((ModelInstance[])args[p.Index]).Select(gi => transaction.GetInstance(gi.Type, gi.Id)).ToList(p.ReferenceType, p.ParameterType);
                        }
                        else
                        {
                            ModelInstance mi = (ModelInstance)args[p.Index];
                            mi            = transaction.GetInstance(mi.Type, mi.Id);
                            args[p.Index] = mi == null ? null : mi.Instance;
                        }
                    }
                }

                // Invoke the method
                return(method.Invoke(Instance, args));
            }
示例#22
0
            public object Deserialize(JsonReader reader)
            {
                string property;

                while (reader.ReadProperty(out property))
                {
                    switch (property)
                    {
                    case "source":
                        Source = reader.ReadValue <ChangeSource>();
                        break;

                    case "changes":
                        Changes = reader.ReadValue <List <ModelEvent> >();
                        break;

                    default:
                        throw new ArgumentException("The specified property could not be deserialized.", property);
                    }
                }

                return(this);
            }
示例#23
0
        public void RestoreReferencesTest()
        {
            var repository = new ModelRepository();
            var model      = repository.Resolve("debug.debug").Model;

            Assert.IsNotNull(model);
            var root = model.RootElements.Single() as Test;

            Assert.IsNotNull(root);

            using (var trans = new ModelTransaction(root))
            {
                var aElem = root.Invalids[0] as AClass;
                aElem.Cont1[0].Delete();
                aElem.Cont1[0].Delete();
                root.Invalids[1].Delete();
            }
            Assert.AreEqual((root.Invalids[1] as BClass).Ref1[0], (root.Invalids[0] as AClass).Cont1[0]);
            Assert.AreEqual((root.Invalids[1] as BClass).Ref2[0], (root.Invalids[0] as AClass).Cont1[1]);

            using (var trans = new ModelTransaction(root))
            {
                var aElem = root.Invalids[0] as AClass;
                aElem.Cont1[0].Delete();
                aElem.Cont1[0].Delete();
                root.Invalids[1].Delete();
            }
            Assert.AreEqual((root.Invalids[1] as BClass).Ref1[0], (root.Invalids[0] as AClass).Cont1[0]);
            Assert.AreEqual((root.Invalids[1] as BClass).Ref2[0], (root.Invalids[0] as AClass).Cont1[1]);

            using (var trans = new ModelTransaction(root))
            {
                root.Invalids[1].Delete();
            }
            Assert.AreEqual((root.Invalids[1] as BClass).Ref1[0], (root.Invalids[0] as AClass).Cont1[0]);
            Assert.AreEqual((root.Invalids[1] as BClass).Ref2[0], (root.Invalids[0] as AClass).Cont1[1]);
        }
示例#24
0
        private void TXT_BARCODE_DATA_KeyUp(object sender, KeyEventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            if (e.KeyValue == (char)Keys.Return)
            {
                e.Handled = true;

                if (!TXT_BARCODE_DATA.Text.Equals(""))
                {
                    try
                    {
                        TXT_BARCODE_DATA.Text = TXT_BARCODE_DATA.Text.Replace("\r\n", "");
                        string strCode   = TXT_BARCODE_DATA.Text;
                        int    dayOfYear = Convert.ToInt32(strCode.Substring(44, 3));

                        if (strCode.Substring(0, 2).Equals("M1") && (DateTime.Now.DayOfYear == dayOfYear || DateTime.Now.DayOfYear + 1 == dayOfYear))
                        {
                            TXT_BARCODE_DATA.Enabled = false;
                            logger.Debug("Boarding pass:"******"S";//Self
                            tran.group_id       = 16;
                            tran.passenger_name = strCode.Substring(2, 20);
                            tran.from_city      = strCode.Substring(30, 3);
                            tran.to_city        = strCode.Substring(33, 3);
                            tran.airline_code   = strCode.Substring(36, 2);
                            tran.flight_no      = strCode.Substring(39, 4);
                            tran.date_of_flight = DateTime.Now;
                            tran.seat_no        = strCode.Substring(48, 4);
                            tran.remark         = "";
                            tran.remakr2        = "";

                            tran.LoungePlace = Convert.ToInt32(StationID);
                            tran.LoungeType  = lounge;
                            tran.LoungeArea  = area;

                            tran.begin_date  = DateTime.Now;
                            tran.create_by   = staffId;
                            tran.create_date = DateTime.Now;
                            tran.update_date = DateTime.Now;
                            tran.update_by   = staffId;

                            /*
                             * List<ModelTransaction> tmps = (onlineStatus) ? tranDao.Select(" Where boardingpass='******' order by t.create_date desc", StationID) : tranDao.SelectOffine(" Where boardingpass='******' order by t.create_date desc", StationID);
                             *
                             * //Generate Access Code ใหม่ถ้ามีอายุการใช้งานเกิน 5 ชั่วโมง
                             * if (tmps.Count > 0 && ((DateTime.Now.Hour - tmps[0].create_date.Hour) <= 5))
                             * {
                             *
                             *  tran.ath_id = tmps[0].ath_id;
                             *  tran.create_date = DateTime.Now;
                             *
                             *  if ((onlineStatus) ? tranDao.Insert(tran, StationID) : tranDao.InsertOffine(tran, StationID))
                             *  {
                             *      Console.Beep();
                             *      TXT_ACCESS_CODE.Text = tran.ath_id;
                             *      TXT_BARCODE_DATA.Enabled = false;
                             *      //Auto print
                             *      if (ManageLOG.getValueFromRegistry(Configurations.AppRegName, "AutoPrint") != null)
                             *      {
                             *          if (!ManageLOG.getValueFromRegistry(Configurations.AppRegName, "AutoPrint").Equals(""))
                             *          {
                             *              Boolean bPrint = ManageLOG.getValueFromRegistry(Configurations.AppRegName, "AutoPrint").Equals("False") ? false : true;
                             *              if (bPrint)
                             *              {
                             *                  if (!TXT_ACCESS_CODE.Text.Equals(""))
                             *                  {
                             *                      TXT_BARCODE_DATA.Enabled = false;
                             *                      printDocument1.Print();
                             *                  }
                             *              }
                             *          }
                             *      }
                             *      success = true;
                             *  }
                             *  else
                             *  {
                             *      TXT_BARCODE_DATA.Enabled = true;
                             *      TXT_ACCESS_CODE.Text = "CAN'T CREATE PLEASE TRY AGAIN!";
                             *      TXT_BARCODE_DATA.Text = "";
                             *      TXT_BARCODE_DATA.Focus();
                             *      Cursor = Cursors.Default;
                             *  }
                             * }
                             * else
                             * {
                             */
                            //get authen code
                            String cri = "where ath_use = 0";
                            List <ModelAuthenCode> lists = (onlineStatus) ? authenCodeDao.Select(cri, StationID) : authenCodeDao.SelectOffine(cri, StationID);
                            if (lists != null)
                            {
                                if (lists.Count > 0)
                                {
                                    ModelAuthenCode tmpAuthenModel = lists[0];
                                    tran.ath_id      = tmpAuthenModel.ath_code;
                                    tran.create_date = DateTime.Now;

                                    if ((onlineStatus) ? tranDao.Insert(tran, StationID) : tranDao.InsertOffine(tran, StationID))
                                    {
                                        tmpAuthenModel.ath_use = "1";
                                        Boolean result = (onlineStatus) ? authenCodeDao.Update(tmpAuthenModel) : authenCodeDao.UpdateOffine(tmpAuthenModel);
                                        if (result)
                                        {
                                            Console.Beep();
                                            TXT_ACCESS_CODE.Text = tmpAuthenModel.ath_code;
                                            //Auto print
                                            if (ManageLOG.getValueFromRegistry(Configurations.AppRegName, "AutoPrint") != null)
                                            {
                                                if (!ManageLOG.getValueFromRegistry(Configurations.AppRegName, "AutoPrint").Equals(""))
                                                {
                                                    Boolean bPrint = ManageLOG.getValueFromRegistry(Configurations.AppRegName, "AutoPrint").Equals("False") ? false : true;
                                                    if (bPrint)
                                                    {
                                                        if (!TXT_ACCESS_CODE.Text.Equals(""))
                                                        {
                                                            printDocument1.Print();
                                                            TXT_BARCODE_DATA.Enabled = false;
                                                            TXT_BARCODE_DATA.Text    = string.Empty;
                                                            TXT_ACCESS_CODE.Text     = string.Empty;
                                                            success = true;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            TXT_ACCESS_CODE.Text     = "CAN'T CREATE PLEASE TRY AGAIN!";
                                            TXT_BARCODE_DATA.Enabled = true;
                                            TXT_BARCODE_DATA.Text    = "";
                                            TXT_BARCODE_DATA.Focus();
                                            Cursor = Cursors.Default;
                                        }
                                    }
                                    else
                                    {
                                        TXT_ACCESS_CODE.Text     = "CAN'T CREATE PLEASE TRY AGAIN!";
                                        TXT_BARCODE_DATA.Enabled = true;
                                        TXT_BARCODE_DATA.Text    = "";
                                        TXT_BARCODE_DATA.Focus();
                                        Cursor = Cursors.Default;
                                    }
                                }
                                else
                                {
                                    logger.Error("Out of access code!");
                                    TXT_ACCESS_CODE.Text     = "OUT OF ACCESS CODE!";
                                    TXT_BARCODE_DATA.Enabled = true;
                                    TXT_BARCODE_DATA.Text    = "";
                                    TXT_BARCODE_DATA.Focus();
                                    Cursor = Cursors.Default;
                                }
                            }
                            else
                            {
                                logger.Error("Out of access code!");
                            }
                            //}
                        }
                        else
                        {
                            TXT_ACCESS_CODE.Text     = "BoardingPass is expired or incorrect data format.";
                            TXT_BARCODE_DATA.Enabled = true;
                            TXT_BARCODE_DATA.Text    = "";
                            TXT_BARCODE_DATA.Focus();
                            Cursor = Cursors.Default;
                        }
                        Cursor = Cursors.Default;
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                        logger.Error(ex.StackTrace);
                        TXT_ACCESS_CODE.Text     = "INCORRECT DATA FORMAT!";
                        TXT_BARCODE_DATA.Enabled = true;
                        TXT_BARCODE_DATA.Text    = "";
                        TXT_BARCODE_DATA.Focus();
                        Cursor = Cursors.Default;
                    }

                    TXT_BARCODE_DATA.Enabled = false;
                    if (success)
                    {
                        timer1.Enabled = true;
                        timer1.Start();
                    }
                    else
                    {
                        timer1.Enabled = false;
                        timer1.Stop();
                    }
                }
            }

            TXT_BARCODE_DATA.Enabled = true;
            TXT_BARCODE_DATA.Focus();
            Cursor = Cursors.Default;
        }
示例#25
0
 void ITransactedModelEvent.Perform(ModelTransaction transaction)
 {
     Instance = EnsureInstance(transaction, Instance);
     Instance.SetValue(Property, NewValue);
 }
示例#26
0
            internal void LoadRoots(ModelTransaction transaction)
            {
                // Exit immediately if roots have already been loaded
                if (Roots != null)
                    return;

                // Create an array of roots to be loaded
                Roots = new ModelInstance[Ids == null ? 0 : Ids.Length];

                // Get the root instances
                for (int i = 0; i < Roots.Length; i++)
                {
                    // Create the root instance
                    Roots[i] = transaction == null ? From.Create(Ids[i]) : transaction.GetInstance(From, Ids[i]);
                }

                // Access a property to force the instance to initialize.  Do a seperate pass so batched loading will work.
                for (int i = 0; i < Roots.Length; i++)
                {
                    var initProp = Roots[i].Type.Properties.FirstOrDefault(p => p is ModelValueProperty) ?? Roots[i].Type.Properties.FirstOrDefault(p => p is ModelReferenceProperty);
                    if (initProp == null)
                        throw new Exception(string.Format("Type \"{0}\" cannot be forced to initialize because it has no properties.", Roots[i].Type.Name));
                    Roots[i].OnPropertyGet(initProp);
                }
            }
示例#27
0
        /// <summary>
        /// Generates a script tag to embed a model including instance data into a server-rendered view.
        /// Supports initial customization of the model via an initialization delegate.
        /// </summary>
        /// <param name="query"></param>
        /// <param name="init"></param>
        /// <returns></returns>
        static void Model(TextWriter writer, object query, Delegate init)
        {
            // Raise the begin model event
            if (BeginModel != null)
            {
                BeginModel(query, EventArgs.Empty);
            }

            // Get the roots for each query
            var roots = new List <KeyValuePair <string, ServiceRequest.Query> >();

            foreach (var prop in query.GetType().GetProperties())
            {
                // Get the value of the model property
                var m = prop.GetValue(query, null);
                if (m == null)
                {
                    continue;
                }

                // Convert the value into a query, if necessary
                var q = m as ServiceRequest.Query ?? Query(m);
                if (q != null)
                {
                    q.LoadRoots(null);
                    roots.Add(new KeyValuePair <string, ServiceRequest.Query>(prop.Name, q));
                }
            }

            // Create the request object
            ServiceRequest request = new ServiceRequest(roots.Select(r => r.Value).ToArray());

            // Synthesize init new changes for new query roots
            ModelTransaction initChanges = (ModelTransaction)request.Queries
                                           .SelectMany(q => q.Roots)
                                           .Where(i => i.IsNew)
                                           .Select(i => new ModelInitEvent.InitNew(i))
                                           .Cast <ModelEvent>()
                                           .ToList();

            // Perform the initialization action, if specified
            if (init != null)
            {
                // Determine matching parameters
                var parameters = new object[init.Method.GetParameters().Length];
                foreach (var p in init.Method.GetParameters())
                {
                    foreach (var root in roots)
                    {
                        if (p.Name.Equals(root.Key, StringComparison.InvariantCultureIgnoreCase))
                        {
                            // List parameter
                            if (p.ParameterType.IsArray)
                            {
                                parameters[p.Position] = root.Value.Roots.Select(r => r.Instance).ToArray();
                            }

                            // Instance parameter
                            else
                            {
                                parameters[p.Position] = root.Value.Roots.Select(r => r.Instance).FirstOrDefault();
                            }

                            break;
                        }
                    }

                    // Throw an exception if the model property value cannot be cast to the corresponding initialization parameter
                    if (parameters[p.Position] != null && !p.ParameterType.IsAssignableFrom(parameters[p.Position].GetType()))
                    {
                        throw new ArgumentException(String.Format("The model property '{0}' cannot be converted into the initialization parameter type of '{1}'.", p.Name, p.ParameterType.FullName));
                    }

                    // Throw an exception if a valid model parameter could not be found to pass to the initialization delegate
                    if (parameters[p.Position] == null && query.GetType().GetProperty(p.Name, BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance) == null)
                    {
                        throw new ArgumentException(String.Format("A model property could not be found to pass to the initialization parameter '{0}'.", p.Name));
                    }
                }

                // Perform initialization while capturing changes
                initChanges.Record(() =>
                {
                    // Prevent property change rules from running until after initialization
                    ModelEventScope.Perform(() => init.DynamicInvoke(parameters));
                });
            }

            // Invoke the request queries
            ServiceResponse response = request.Invoke(initChanges);

            response.Model = roots.ToDictionary(r => r.Key, r => r.Value);
            foreach (var q in response.Model.Values)
            {
                q.ReducePaths();
            }

            // Track the current model roots to support server template rendering
            foreach (var root in response.Model)
            {
                Templates.Page.Current.Model[root.Key] = root.Value.IsList ? (object)root.Value.Roots : (root.Value.Roots.Length == 1 ?root.Value.Roots[0] : null);
            }

            // Write the model embed script to the writer
            writer.Write("<script type=\"text/javascript\">$exoweb(");
            JsonUtility.Serialize(writer, response);
            writer.Write(");</script>");

            // Raise the end model event
            if (EndModel != null)
            {
                EndModel(query, EventArgs.Empty);
            }
        }
 void ITransactedModelEvent.Perform(ModelTransaction transaction)
 {
     Instance = EnsureInstance(transaction, Instance);
     Instance.SetValue(Property, NewValue);
 }
示例#29
0
 public void Rollback(ModelTransaction transaction)
 {
     throw new NotSupportedException("Rollback is not supported by the ModelSaveEvent.");
 }
示例#30
0
        public Boolean InsertOffine(ModelTransaction model, int station_id)
        {
            try
            {
                string query =
                    "INSERT INTO tb_transaction_" + station_id + "" +
                    "(" +
                    "group_id,boardingpass," +
                    "passenger_name," +
                    "from_city," +
                    "to_city," +
                    "airline_code," +
                    "flight_no," +
                    "date_of_flight," +
                    "seat_no," +
                    "remark," +
                    "remakr2," +
                    "ath_id," +

                    "create_by," +
                    "create_date," +
                    "update_by," +
                    "update_date," +
                    "LoungePlace," +
                    "LoungeType," +
                    "LoungeArea," +

                    "type," +
                    "duration," +
                    "begin_date," +
                    "status" +
                    ")" +
                    " VALUES" +
                    "(" +
                    //"@id," +
                    "@group_id,@boardingpass," +
                    "@passenger_name," +
                    "@from_city," +
                    "@to_city," +
                    "@airline_code," +
                    "@flight_no," +
                    "@date_of_flight," +
                    "@seat_no," +
                    "@remark," +
                    "@remakr2," +
                    "@ath_id," +

                    "@create_by," +
                    "@create_date," +
                    "@update_by," +
                    "@update_date," +
                    "@LoungePlace," +
                    "@LoungeType," +
                    "@LoungeArea," +

                    "@type," +
                    "@duration," +
                    "@begin_date," +
                    "@status" +
                    ");";

                using (SQLiteConnection conn = new SQLiteConnection(Configurations.SqLiteStr))
                {
                    conn.Open();
                    //create command and assign the query and connection from the constructor
                    SQLiteCommand cmd = new SQLiteCommand(query, conn);

                    //cmd.Parameters.AddWithValue("@id", model.id);
                    cmd.Parameters.AddWithValue("@boardingpass", model.boardingpass);
                    cmd.Parameters.AddWithValue("@group_id", model.group_id);
                    cmd.Parameters.AddWithValue("@passenger_name", model.passenger_name);
                    cmd.Parameters.AddWithValue("@from_city", model.from_city);
                    cmd.Parameters.AddWithValue("@to_city", model.to_city);
                    cmd.Parameters.AddWithValue("@airline_code", model.airline_code);
                    cmd.Parameters.AddWithValue("@flight_no", model.flight_no);
                    cmd.Parameters.AddWithValue("@date_of_flight", model.date_of_flight);
                    cmd.Parameters.AddWithValue("@seat_no", model.seat_no);
                    cmd.Parameters.AddWithValue("@remark", model.remark);
                    cmd.Parameters.AddWithValue("@remakr2", model.remakr2);
                    cmd.Parameters.AddWithValue("@ath_id", model.ath_id);


                    cmd.Parameters.AddWithValue("@create_by", model.create_by);
                    cmd.Parameters.AddWithValue("@create_date", model.create_date);
                    cmd.Parameters.AddWithValue("@update_by", model.update_by);
                    cmd.Parameters.AddWithValue("@update_date", model.update_date);
                    cmd.Parameters.AddWithValue("@LoungePlace", model.LoungePlace);
                    cmd.Parameters.AddWithValue("@LoungeType", model.LoungeType);
                    cmd.Parameters.AddWithValue("@LoungeArea", model.LoungeArea);
                    cmd.Parameters.AddWithValue("@type", model.type);
                    cmd.Parameters.AddWithValue("@duration", model.duration);
                    cmd.Parameters.AddWithValue("@begin_date", model.begin_date);
                    cmd.Parameters.AddWithValue("@status", model.status);


                    //Execute command
                    int result = cmd.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.InnerException);
                return(false);
            }
            return(true);
        }
示例#31
0
 /// <summary>
 /// Verifies that the specified <see cref="ModelInstance"/> refers to a valid real instance
 /// and if not, uses the type and id information to look up the real instance.
 /// </summary>
 /// <param name="transaction"></param>
 /// <param name="instance"></param>
 /// <returns></returns>
 protected ModelInstance EnsureInstance(ModelTransaction transaction, ModelInstance instance)
 {
     return instance.Instance == null ? transaction.GetInstance(instance.Type, instance.Id) : instance;
 }
示例#32
0
 internal virtual object Raise(ModelTransaction transaction)
 {
     throw new NotImplementedException();
 }
示例#33
0
            /// <summary>
            /// Deletes and removes the reference to the <see cref="ModelInstance"/> associated with
            /// the current event, which effectively removes the instance from existence.
            /// </summary>
            void ITransactedModelEvent.Rollback(ModelTransaction transaction)
            {
                // Ensure that the current instance has been resolved
                Instance = EnsureInstance(transaction, Instance);

                if (Instance.Instance != null)
                {
                    // Delete the current instance
                    Instance.IsPendingDelete = true;

                    // Create a new proxy reference to the instance
                    Instance = new ModelInstance(Instance.Type, Instance.Id);
                }
            }
 /// <summary>
 /// Restores the property to the old value.
 /// </summary>
 void ITransactedModelEvent.Rollback(ModelTransaction transaction)
 {
     Instance = EnsureInstance(transaction, Instance);
     Instance.SetValue(Property, OldValue);
 }
示例#35
0
        /// <summary>
        /// Outputs the JSON for the specified instance to the response stream.
        /// </summary>
        /// <param name="response"></param>
        internal ServiceResponse Invoke(ModelTransaction initChanges)
        {
            // Raise the begin request event
            ExoWeb.OnBeginRequest(this);

            // Create a response for the request
            ServiceResponse response = new ServiceResponse();
            response.ServerInfo = new ServerInformation();
            response.Changes = initChanges;

            try
            {
                // Set the types to return from the request
                response.Types = Types;

                // Apply view initialization changes
                if (Changes != null && Changes.Length > 0 && Changes[0].Source == ChangeSource.Init)
                {
                    response.Changes = Changes[0].Changes;
                    response.Changes.Perform();
                }

                // Load root instances
                if (Queries != null)
                {
                    foreach (var query in Queries)
                    {
                        query.Prepare(response);
                        query.LoadRoots(response.Changes);
                    }
                }

                // Preload the scope of work before applying changes
                PerformQueries(response, false, initChanges != null);

                // Apply additional changes and raise domain events
                ApplyChanges(response);

                // Load instances specified by load queries
                PerformQueries(response, true, initChanges != null);

                // Condense the transaction log
                if (response.Changes != null)
                    response.Changes.Condense();

                // Send conditions for instances loaded in the request
                if (response.Instances != null || response.Changes != null)
                {
                    // Add instances created during the request
                    if (response.Changes != null)
                    {
                        foreach (var instance in response.Changes.OfType<ModelInitEvent.InitNew>().Select(modelEvent => modelEvent.Instance))
                            response.inScopeInstances.Add(instance);
                    }

                    // Ensure conditions are evaluated before extracting them
                    ExoWeb.OnEnsureConditions(response, response.inScopeInstances);

                    // Extract conditions for all instances involved in the request
                    Dictionary<string, List<Condition>> conditionsByType = new Dictionary<string, List<Condition>>();
                    foreach (var condition in response.inScopeInstances.SelectMany(instance => Condition.GetConditions(instance)))
                    {
                        List<Condition> conditions;
                        if (!conditionsByType.TryGetValue(condition.Type.Code, out conditions))
                            conditionsByType[condition.Type.Code] = conditions = new List<Condition>();

                        if (!conditions.Contains(condition))
                            conditions.Add(condition);
                    }
                    response.Conditions = conditionsByType;
                }
            }
            finally
            {
                // Raise the end request event
                ExoWeb.OnEndRequest(this, response);
            }

            // Return the response
            return response;
        }
示例#36
0
 internal virtual object Raise(ModelTransaction transaction)
 {
     throw new NotImplementedException();
 }
示例#37
0
        public Boolean UpdateOffline(ModelTransaction model, int station_id)
        {
            try
            {
                string query =
                    "UPDATE tb_transaction_" + station_id + "" +
                    " SET" +
                    " group_id = @group_id," +
                    "passenger_name = @passenger_name," +
                    "from_city = @from_city," +
                    "to_city = @to_city," +
                    "airline_code = @airline_code," +
                    "flight_no = @flight_no," +
                    "date_of_flight = @date_of_flight," +
                    "seat_no = @seat_no," +
                    "remark = @remark," +
                    "remakr2 = @remakr2," +
                    "ath_id = @ath_id," +

                    "update_by = @update_by," +
                    "update_date = @update_date," +
                    "LoungePlace = @LoungePlace," +
                    "LoungeType = @LoungeType," +
                    "LoungeArea = @LoungeArea," +
                    "type = @type," +
                    "duration = @duration," +
                    "begin_date = @begin_date," +
                    "status = @status " +
                    "WHERE id = @id;";
                using (SQLiteConnection conn = new SQLiteConnection(Configurations.SqLiteStr))
                {
                    conn.Open();
                    //create command and assign the query and connection from the constructor
                    SQLiteCommand cmd = new SQLiteCommand(query, conn);
                    cmd.Parameters.AddWithValue("@id", model.id);
                    cmd.Parameters.AddWithValue("@group_id", model.group_id);
                    cmd.Parameters.AddWithValue("@passenger_name", model.passenger_name);
                    cmd.Parameters.AddWithValue("@from_city", model.from_city);
                    cmd.Parameters.AddWithValue("@to_city", model.to_city);
                    cmd.Parameters.AddWithValue("@airline_code", model.airline_code);
                    cmd.Parameters.AddWithValue("@flight_no", model.flight_no);
                    cmd.Parameters.AddWithValue("@date_of_flight", model.date_of_flight);
                    cmd.Parameters.AddWithValue("@seat_no", model.seat_no);
                    cmd.Parameters.AddWithValue("@remark", model.remark);
                    cmd.Parameters.AddWithValue("@remakr2", model.remakr2);
                    cmd.Parameters.AddWithValue("@ath_id", model.ath_id);

                    cmd.Parameters.AddWithValue("@create_by", model.create_by);
                    cmd.Parameters.AddWithValue("@create_date", model.create_date);
                    cmd.Parameters.AddWithValue("@update_by", model.update_by);
                    cmd.Parameters.AddWithValue("@update_date", model.update_date);
                    cmd.Parameters.AddWithValue("@LoungePlace", model.LoungePlace);
                    cmd.Parameters.AddWithValue("@LoungeType", model.LoungeType);
                    cmd.Parameters.AddWithValue("@LoungeArea", model.LoungeArea);
                    cmd.Parameters.AddWithValue("@type", model.type);
                    cmd.Parameters.AddWithValue("@duration", model.duration);
                    cmd.Parameters.AddWithValue("@begin_date", model.begin_date);
                    cmd.Parameters.AddWithValue("@status", model.status);

                    //Execute query
                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.InnerException);
                return(false);
            }
            return(true);
        }
示例#38
0
 public void Perform(ModelTransaction transaction)
 {
     Instance = EnsureInstance(transaction, Instance);
     Instance.Save();
 }
示例#39
0
        void Prepare(ModelTransaction transaction)
        {
            // Resolve the root instance
            Instance = EnsureInstance(transaction, Instance);

            // Resolve added instances
            var added = (ModelInstance[])Added;
            for (int i = 0; i < added.Length; i++)
                added[i] = EnsureInstance(transaction, added[i]);

            // Resolve removed instances
            var removed = (ModelInstance[])Removed;
            for (int i = 0; i < removed.Length; i++)
                removed[i] = EnsureInstance(transaction, removed[i]);
        }
示例#40
0
        public List <ModelTransaction> SelectOffine(String cri, int station_id)
        {
            string query =
                "select" +
                "                    t.id, " +
                "                    t.type," +
                "                    t.group_id," +
                "					 g.group_description,"+
                "                    t.passenger_name," +
                "                    t.from_city," +
                "                    t.to_city," +
                "                    t.airline_code," +
                "                    t.flight_no," +
                "                    t.date_of_flight," +
                "                    t.seat_no," +
                "                    t.remark," +
                "                    t.remakr2," +
                "                    t.ath_id," +
                "                    t.create_by," +
                "					 u.user_name,"+
                "                    t.create_date," +
                "                    t.update_by," +
                "					(select user_name from tb_users where id= t.update_by) update_byName,"+
                "                    t.update_date," +
                "                    t.LoungePlace," +
                "					 s.site_name,"+
                "					 s.site_code,"+
                "                    t.LoungeType," +
                "					 l.lounge_name,"+
                "                    t.LoungeArea," +
                "					 a.area_name,"+
                "                    t.type," +
                "                    t.duration," +
                "                    t.begin_date" +
                " from tb_transaction_" + station_id + " t " +
                " left join tb_group g on t.group_id = g.id" +
                " left join tb_users u on t.create_by = u.id" +
                " left join tb_station s on t.LoungePlace = s.id" +
                " left join tb_lounge l on t.LoungeType =  l.id" +
                " left join tb_area a on t.LoungeArea = a.id " + cri;

            //Create a list to store the result
            List <ModelTransaction> lists = new List <ModelTransaction>();

            using (SQLiteConnection conn = new SQLiteConnection(Configurations.SqLiteStr))
            {
                conn.Open();
                SQLiteCommand cmd = new SQLiteCommand(query, conn);
                //Create a data reader and Execute the command
                SQLiteDataReader dr = cmd.ExecuteReader();

                //Read the data and store them in the list
                while (dr.Read())
                {
                    ModelTransaction transaction = new ModelTransaction();

                    transaction.id                    = (DBNull.Value == dr["id"]) ? -1 : Convert.ToInt32(dr["id"]);
                    transaction.group_id              = (DBNull.Value == dr["group_id"]) ? -1 : Convert.ToInt32(dr["group_id"]);
                    transaction.group_idName          = (DBNull.Value == dr["group_description"]) ? "" : Convert.ToString(dr["group_description"]);
                    transaction.passenger_name        = (DBNull.Value == dr["passenger_name"]) ? "" : Convert.ToString(dr["passenger_name"]);
                    transaction.from_city             = (DBNull.Value == dr["from_city"]) ? "" : Convert.ToString(dr["from_city"]);
                    transaction.to_city               = (DBNull.Value == dr["to_city"]) ? "" : Convert.ToString(dr["to_city"]);
                    transaction.airline_code          = (DBNull.Value == dr["airline_code"]) ? "" : Convert.ToString(dr["airline_code"]);
                    transaction.flight_no             = (DBNull.Value == dr["flight_no"]) ? "" : Convert.ToString(dr["flight_no"]);
                    transaction.date_of_flight        = Convert.ToDateTime(dr["date_of_flight"]);
                    transaction.date_of_flight_custom = transaction.date_of_flight.ToString("dd-MM-yyyy HH:mm");
                    transaction.seat_no               = (DBNull.Value == dr["seat_no"]) ? "" : Convert.ToString(dr["seat_no"]);
                    transaction.remark                = (DBNull.Value == dr["remark"]) ? "" : Convert.ToString(dr["remark"]);
                    transaction.remakr2               = (DBNull.Value == dr["remakr2"]) ? "" : Convert.ToString(dr["remakr2"]);
                    transaction.ath_id                = (DBNull.Value == dr["ath_id"]) ? "" : Convert.ToString(dr["ath_id"]);
                    transaction.create_by             = (DBNull.Value == dr["create_by"]) ? -1 : Convert.ToInt32(dr["create_by"]);
                    transaction.create_byName         = (DBNull.Value == dr["user_name"]) ? "" : Convert.ToString(dr["user_name"]);
                    transaction.create_date           = Convert.ToDateTime(dr["create_date"]);
                    transaction.create_date_custom    = transaction.create_date.ToString("dd-MM-yyyy HH:mm");
                    transaction.update_by             = (DBNull.Value == dr["update_by"]) ? -1 : Convert.ToInt32(dr["update_by"]);
                    transaction.update_byName         = (DBNull.Value == dr["update_byName"]) ? "" : Convert.ToString(dr["update_byName"]);
                    transaction.update_date           = Convert.ToDateTime(dr["update_date"]);
                    transaction.update_date_custom    = transaction.update_date.ToString("dd-MM-yyyy HH:mm");
                    transaction.LoungePlace           = (DBNull.Value == dr["LoungePlace"]) ? -1 : Convert.ToInt32(dr["LoungePlace"]);
                    transaction.LoungeSite            = (DBNull.Value == dr["site_name"]) ? "" : Convert.ToString(dr["site_name"]);
                    transaction.LoungeSiteCode        = (DBNull.Value == dr["site_code"]) ? "" : Convert.ToString(dr["site_code"]);
                    transaction.LoungeType            = (DBNull.Value == dr["LoungeType"]) ? -1 : Convert.ToInt32(dr["LoungeType"]);
                    transaction.LoungeName            = (DBNull.Value == dr["lounge_name"]) ? "" : Convert.ToString(dr["lounge_name"]);
                    transaction.LoungeArea            = (DBNull.Value == dr["LoungeArea"]) ? -1 : Convert.ToInt32(dr["LoungeArea"]);
                    transaction.LoungeAreaName        = (DBNull.Value == dr["area_name"]) ? "" : Convert.ToString(dr["area_name"]);
                    transaction.type                  = (DBNull.Value == dr["type"]) ? "" : Convert.ToString(dr["type"]);
                    transaction.duration              = (DBNull.Value == dr["duration"]) ? -1 : Convert.ToInt32(dr["duration"]);
                    transaction.begin_date            = Convert.ToDateTime(dr["begin_date"]);
                    transaction.begin_date_custom     = transaction.begin_date.ToString("dd-MM-yyyy HH:mm");
                    transaction.status                = "ACTIVE";
                    lists.Add(transaction);
                }

                //close Data Reader
                dr.Close();
            }
            return(lists);
        }
示例#41
0
 /// <summary>
 /// Restores the property to the old value.
 /// </summary>
 void ITransactedModelEvent.Rollback(ModelTransaction transaction)
 {
     Instance = EnsureInstance(transaction, Instance);
     Instance.SetValue(Property, OldValue);
 }
示例#42
0
        /// <summary>
        /// Raises domain events.
        /// </summary>
        void RaiseEvents(ServiceResponse response, ModelTransaction transaction)
        {
            // Process each event in the request
            if (Events != null)
            {
                response.Events = Events
                    .Select((domainEvent) =>
                    {
                        // Restore the instance to be a valid model instance
                        if (domainEvent.Instance != null)
                        {
                            if (transaction != null)
                                domainEvent.Instance = transaction.GetInstance(domainEvent.Instance.Type, domainEvent.Instance.Id);
                            else
                                domainEvent.Instance = domainEvent.Instance.Type.Create(domainEvent.Instance.Id);
                        }

                        var result = domainEvent.Raise(transaction);

                        if (result == null)
                            return null;

                        ModelType type;
                        ModelInstance[] roots;
                        bool isList;

                        if (ExoWeb.TryConvertQueryInstance(result, out type, out roots, out isList))
                        {
                            Query newQuery = new Query(type, roots, true, isList, domainEvent.Include);
                            newQuery.Prepare(response);

                            Query[] newQueries = new Query[] { newQuery };
                            Queries = Queries == null ? newQueries : Queries.Union(newQueries).ToArray();

                            return isList ? (object)roots : (object)roots[0];
                        }
                        else if (domainEvent.Include != null && domainEvent.Include.Length > 0)
                        {
                            Query newQuery = new Query(domainEvent.Instance.Type, new[] { domainEvent.Instance }, true, false, domainEvent.Include);
                            newQuery.Prepare(response);

                            Query[] newQueries = new Query[] { newQuery };
                            Queries = Queries == null ? newQueries : Queries.Union(newQueries).ToArray();

                            return result;
                        }
                        else
                            return result;
                    })
                    .ToArray();
            }
        }
示例#43
0
        /// <summary>
        /// Outputs the JSON for the specified instance to the response stream.
        /// </summary>
        /// <param name="response"></param>
        internal ServiceResponse Invoke(ModelTransaction initChanges)
        {
            // Raise the begin request event
            ExoWeb.OnBeginRequest(this);

            // Create a response for the request
            ServiceResponse response = new ServiceResponse();

            response.ServerInfo = new ServerInformation();
            response.Changes    = initChanges;

            try
            {
                // Set the types to return from the request
                response.Types = Types;

                // Apply view initialization changes
                if (Changes != null && Changes.Length > 0 && Changes[0].Source == ChangeSource.Init)
                {
                    response.Changes = Changes[0].Changes;
                    response.Changes.Perform();
                }

                // Load root instances
                if (Queries != null)
                {
                    foreach (var query in Queries)
                    {
                        query.Prepare(response);
                        query.LoadRoots(response.Changes);
                    }
                }

                // Preload the scope of work before applying changes
                PerformQueries(response, false, initChanges != null);

                // Apply additional changes and raise domain events
                ApplyChanges(response);

                // Load instances specified by load queries
                PerformQueries(response, true, initChanges != null);

                // Condense the transaction log
                if (response.Changes != null)
                {
                    response.Changes.Condense();
                }

                // Send conditions for instances loaded in the request
                if (response.Instances != null || response.Changes != null)
                {
                    // Add instances created during the request
                    if (response.Changes != null)
                    {
                        foreach (var instance in response.Changes.OfType <ModelInitEvent.InitNew>().Select(modelEvent => modelEvent.Instance))
                        {
                            response.inScopeInstances.Add(instance);
                        }
                    }

                    // Ensure conditions are evaluated before extracting them
                    ExoWeb.OnEnsureConditions(response, response.inScopeInstances);

                    // Extract conditions for all instances involved in the request
                    Dictionary <string, List <Condition> > conditionsByType = new Dictionary <string, List <Condition> >();
                    foreach (var condition in response.inScopeInstances.SelectMany(instance => Condition.GetConditions(instance)))
                    {
                        List <Condition> conditions;
                        if (!conditionsByType.TryGetValue(condition.Type.Code, out conditions))
                        {
                            conditionsByType[condition.Type.Code] = conditions = new List <Condition>();
                        }

                        if (!conditions.Contains(condition))
                        {
                            conditions.Add(condition);
                        }
                    }
                    response.Conditions = conditionsByType;
                }
            }
            finally
            {
                // Raise the end request event
                ExoWeb.OnEndRequest(this, response);
            }

            // Return the response
            return(response);
        }
示例#44
0
 public FrmDetail(FrmMain _main, ModelTransaction _model)
 {
     InitializeComponent();
     this.main  = _main;
     this.model = _model;
 }
示例#45
0
        private void B_SAVE_Click(object sender, EventArgs e)
        {
            //Validate
            if (passenger_name.Text.Equals(""))
            {
                MessageBox.Show("ยังไม่ได้ป้อนข้อมูล Passenger Name");
                passenger_name.Select();
                return;
            }
            if (airlineCode.Text.Equals(""))
            {
                MessageBox.Show("ยังไม่ได้ป้อนข้อมูล Airline Code");
                airlineCode.Select();
                return;
            }
            if (flight_no.Text.Equals(""))
            {
                MessageBox.Show("ยังไม่ได้ป้อนข้อมูล Flight No");
                flight_no.Select();
                return;
            }
            if (date_of_flight.Value.Equals(""))
            {
                MessageBox.Show("ยังไม่ได้ป้อนข้อมูล Date Of flight");
                date_of_flight.Select();
                return;
            }
            if (seat_no.Text.Equals(""))
            {
                MessageBox.Show("ยังไม่ได้ป้อนข้อมูล Seat No");
                seat_no.Select();
                return;
            }
            //if (fromcity.Text.Equals(""))
            //{
            //    MessageBox.Show("ยังไม่ได้ป้อนข้อมูล From City");
            //    fromcity.Select();
            //    return;
            //}
            //if (tocity.Text.Equals(""))
            //{
            //    MessageBox.Show("ยังไม่ได้ป้อนข้อมูล To City");
            //    tocity.Select();
            //    return;
            //}


            if (group_id.Text.Equals(""))
            {
                MessageBox.Show("ยังไม่ได้เลือกข้อมูล Group");
                group_id.Select();
                return;
            }

            Boolean result = false;

            String cri = "where ath_use = 0";
            List <ModelAuthenCode> lists = (onlineStatus) ? authenDao.Select(cri, StationID) : authenDao.SelectOffine(cri, StationID);

            if (lists.Count > 0)
            {
                ModelAuthenCode  accessCode = lists[0];
                ModelTransaction tran       = new ModelTransaction();

                tran.type = "M";


                tran.group_id       = (group_id.Text.Equals("")) ? -1 : Convert.ToInt32(group_id.SelectedValue);
                tran.passenger_name = passenger_name.Text;
                tran.from_city      = fromcity.Text;
                tran.to_city        = tocity.Text;
                tran.airline_code   = airlineCode.Text;

                tran.flight_no      = flight_no.Text;
                tran.date_of_flight = date_of_flight.Value;
                tran.seat_no        = ((seat_no.Text.Length > 4) ? seat_no.Text.Substring(0, 4) : seat_no.Text);
                tran.remark         = remark.Text;
                tran.remakr2        = remark2.Text;

                tran.LoungePlace = StationID;
                tran.LoungeType  = lounge;
                tran.LoungeArea  = area;

                tran.begin_date  = DateTime.Now;
                tran.ath_id      = accessCode.ath_code;
                tran.create_by   = staffId;
                tran.create_date = DateTime.Now;

                tran.update_date = DateTime.Now;
                tran.update_by   = staffId;
                //M1GILJIMENEZ/PILA9 MS EKWGVQS BKKTDXPG 0305 078Y045A0016 300
                tran.boardingpass = MyFunction.getBoadingPass(tran);// passenger_name.Text + "" + fromcity.Text + tocity.Text + airlineCode.Text + date_of_flight.Value + seat_no.Text;

                logger.Debug("MANUAL->INPUT :" +
                             tran.passenger_name + "" + tran.flight_no + "" + tran.seat_no + "," +
                             tran.type + "," +                        //Type
                             tran.create_date.ToString("yyyy-MM-dd HH:MM:ss") + "," +
                             tran.group_idName + "," +                //GroupName
                             tran.duration + "," +                    //Duration
                             tran.passenger_name + "," +              //PassengerName
                             tran.from_city + "," +                   //FromCity
                             tran.to_city + "," +                     //ToCity
                             tran.airline_code + "," +                //AirlineCode
                             tran.flight_no + "," +                   //FlightNo
                             tran.date_of_flight.ToString("yyyy-MM-dd HH:MM:ss") + "," +
                             tran.seat_no + "," +                     //SeatNo
                             tran.LoungeSiteCode + "," +              //LoungePlace
                             tran.LoungeName + "," +                  //LoungeType
                             tran.LoungeAreaName + "," +              //LoungeArea
                             tran.create_byName + "," +               //Owner
                             tran.begin_date.ToString("yyyy-MM-dd HH:MM:ss") + "," +
                             tran.status + "," +                      //Status
                             tran.remark + "," +                      //Remark
                             tran.ath_id + "," +                      //AccessCode
                             tran.remakr2 + "," +                     //Remark2
                             tran.update_date.ToString("yyyy-MM-dd HH:MM:ss") + "," +
                             tran.update_byName                       //LastUpdateBy
                             );
                //auto save
                if ((onlineStatus) ? tranDao.Insert(tran, StationID) : tranDao.InsertOffine(tran, StationID))
                {
                    accessCode.ath_use = "1";
                    result             = (onlineStatus) ? authenDao.Update(accessCode) : authenDao.UpdateOffine(accessCode);
                    if (result)
                    {
                        lbMessage.Text         = "บันทึกข้อมูลเรียบร้อยแล้ว";
                        CMD_PRINT.Enabled      = true;
                        lbAccessCode.Text      = String.Format("{0}", accessCode.ath_code);
                        lbAccessCode.ForeColor = Color.Green;
                        //Auto print
                        if (ManageLOG.getValueFromRegistry(Configurations.AppRegName, "ManualGenAutoPrint") != null)
                        {
                            if (!ManageLOG.getValueFromRegistry(Configurations.AppRegName, "ManualGenAutoPrint").Equals(""))
                            {
                                Boolean bPrint = ManageLOG.getValueFromRegistry(Configurations.AppRegName, "ManualGenAutoPrint").Equals("False") ? false : true;
                                if (bPrint)
                                {
                                    if (!lbAccessCode.Text.Equals(""))
                                    {
                                        printDocument1.Print();
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        lbMessage.Text = "";
                        lbMessage.Text = "เกิดข้อผิดพลาดในการปรับปรุงค่า Access Code";
                    }
                }
            }
            else
            {
                lbMessage.Text         = "";
                lbAccessCode.Text      = String.Format("Access Code is not enought!");
                lbAccessCode.ForeColor = Color.Red;
            }
            clearData();
        }
示例#46
0
        private void txt_barcode_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == (char)Keys.Return)
            {
                if (group_id.Text.Equals(""))
                {
                    MessageBox.Show("ยังไม่ได้เลือกข้อมูล Group");
                    txt_barcode.Text = string.Empty;
                    group_id.Select();
                    return;
                }

                try
                {
                    txt_barcode.Text = txt_barcode.Text.Replace("\r\n", "");
                    string strCode = txt_barcode.Text;

                    int dayOfYear = Convert.ToInt32(strCode.Substring(44, 3));
                    if (cbDisableVaridate.Checked || strCode.Substring(0, 2).Equals("M1") && (DateTime.Now.DayOfYear == dayOfYear || DateTime.Now.DayOfYear + 1 == dayOfYear))
                    {
                        ModelTransaction tran = new ModelTransaction();
                        tran.id             = 0;
                        tran.boardingpass   = txt_barcode.Text;
                        tran.type           = "A";
                        tran.group_id       = Convert.ToInt32(group_id.SelectedValue);
                        tran.passenger_name = strCode.Substring(2, 20);
                        tran.from_city      = strCode.Substring(30, 3);
                        tran.to_city        = strCode.Substring(33, 3);
                        tran.airline_code   = strCode.Substring(36, 2);
                        tran.flight_no      = strCode.Substring(39, 4);
                        tran.date_of_flight = new DateTime(Convert.ToInt32(date_of_flight.SelectedValue), DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
                        tran.seat_no        = strCode.Substring(48, 4);
                        tran.remark         = remark.Text;
                        tran.remakr2        = remark2.Text;

                        tran.LoungePlace = StationID;
                        tran.LoungeType  = lounge;
                        tran.LoungeArea  = area;


                        tran.begin_date = DateTime.Now;

                        tran.create_by   = staffId;
                        tran.create_date = DateTime.Now;
                        tran.update_by   = staffId;
                        tran.update_date = DateTime.Now;

                        logger.Debug("AUTO->INPUT :" +
                                     tran.passenger_name + "" + tran.flight_no + "" + tran.seat_no + "," +
                                     tran.type + "," +           //Type
                                     tran.create_date.ToString("yyyy-MM-dd HH:MM:ss") + "," +
                                     tran.group_idName + "," +   //GroupName
                                     tran.duration + "," +       //Duration
                                     tran.passenger_name + "," + //PassengerName
                                     tran.from_city + "," +      //FromCity
                                     tran.to_city + "," +        //ToCity
                                     tran.airline_code + "," +   //AirlineCode
                                     tran.flight_no + "," +      //FlightNo
                                     tran.date_of_flight.ToString("yyyy-MM-dd HH:MM:ss") + "," +
                                     tran.seat_no + "," +        //SeatNo
                                     tran.LoungeSiteCode + "," + //LoungePlace
                                     tran.LoungeName + "," +     //LoungeType
                                     tran.LoungeAreaName + "," + //LoungeArea
                                     tran.create_byName + "," +  //Owner
                                     tran.begin_date.ToString("yyyy-MM-dd HH:MM:ss") + "," +
                                     tran.status + "," +         //Status
                                     tran.remark + "," +         //Remark
                                     tran.ath_id + "," +         //AccessCode
                                     tran.remakr2 + "," +        //Remark2
                                     tran.update_date.ToString("yyyy-MM-dd HH:MM:ss") + "," +
                                     tran.update_byName          //LastUpdateBy
                                     );

                        /*
                         * List<ModelTransaction> tmps = (onlineStatus) ? tranDao.Select(" Where boardingpass='******'  order by t.create_date desc", StationID) : tranDao.SelectOffine(" Where boardingpass='******'  order by t.create_date desc", StationID);
                         * //Generate Access Code ใหม่ถ้ามีอายุการใช้งานเกิน 5 ชั่วโมง
                         * if (tmps.Count > 0 && ((DateTime.Now.Hour - tmps[0].create_date.Hour) <= 5))
                         * {
                         *
                         *  tran.ath_id = tmps[0].ath_id;
                         *  if ((onlineStatus) ? tranDao.Insert(tran, StationID) : tranDao.InsertOffine(tran, StationID))
                         *  {
                         *      CMD_PRINT.Enabled = true;
                         *      lbMessage.Text = "บันทึกข้อมูลเรียบร้อยแล้ว";
                         *
                         *      lbAccessCode.Text = String.Format("{0}", tmps[0].ath_id);
                         *      lbAccessCode.ForeColor = Color.Green;
                         *      txt_barcode.Select();
                         *      //Auto print
                         *      if (ManageLOG.getValueFromRegistry(Configurations.AppRegName, "AutoGenAutoPrint") != null)
                         *      {
                         *          if (!ManageLOG.getValueFromRegistry(Configurations.AppRegName, "AutoGenAutoPrint").Equals(""))
                         *          {
                         *              Boolean bPrint = ManageLOG.getValueFromRegistry(Configurations.AppRegName, "AutoGenAutoPrint").Equals("False") ? false : true;
                         *              if (bPrint)
                         *              {
                         *                  if (!lbAccessCode.Text.Equals(""))
                         *                  {
                         *                      printDocument1.Print();
                         *                  }
                         *              }
                         *          }
                         *      }
                         *  }
                         * }
                         * else
                         * {
                         */
                        String cri = "where ath_use = 0";
                        List <ModelAuthenCode> lists = (onlineStatus) ? authenDao.Select(cri, StationID) : authenDao.SelectOffine(cri, StationID);
                        if (lists != null)
                        {
                            if (lists.Count > 0)
                            {
                                //
                                ModelAuthenCode accessCode = lists[0];
                                //
                                tran.ath_id = lists[0].ath_code;

                                //auto save
                                if ((onlineStatus) ? tranDao.Insert(tran, StationID) : tranDao.InsertOffine(tran, StationID))
                                {
                                    accessCode.ath_use = "1";
                                    Boolean result = (onlineStatus) ? authenDao.Update(accessCode) : authenDao.UpdateOffine(accessCode);
                                    if (result)
                                    {
                                        CMD_PRINT.Enabled = true;
                                        lbMessage.Text    = "บันทึกข้อมูลเรียบร้อยแล้ว";

                                        lbAccessCode.Text      = String.Format("{0}", accessCode.ath_code);
                                        lbAccessCode.ForeColor = Color.Green;
                                        txt_barcode.Select();
                                        //Auto print
                                        if (ManageLOG.getValueFromRegistry(Configurations.AppRegName, "AutoGenAutoPrint") != null)
                                        {
                                            if (!ManageLOG.getValueFromRegistry(Configurations.AppRegName, "AutoGenAutoPrint").Equals(""))
                                            {
                                                Boolean bPrint = ManageLOG.getValueFromRegistry(Configurations.AppRegName, "AutoGenAutoPrint").Equals("False") ? false : true;
                                                if (bPrint)
                                                {
                                                    if (!lbAccessCode.Text.Equals(""))
                                                    {
                                                        printDocument1.Print();
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        lbMessage.Text = "เกิดข้อผิดพลาดในการปรับปรุงค่า Access Code";
                                    }
                                }
                            }
                            else
                            {
                                logger.Error("Out of access code!");
                                lbMessage.Text         = "";
                                lbAccessCode.Text      = String.Format("Access Code is not enought!");
                                lbAccessCode.ForeColor = Color.Red;
                                txt_barcode.Select();
                            }
                        }
                        else
                        {
                            logger.Error("Out of access code!");
                        }
                        //}
                    }
                    else
                    {
                        lbMessage.Text         = "";
                        lbAccessCode.Text      = String.Format("BoardingPass is expired or incorrect data format.");
                        lbAccessCode.ForeColor = Color.Red;
                        txt_barcode.Select();
                    }

                    //Clear Barcode Value
                    clearData();
                }
                catch (Exception ex)
                {
                    logger.Error(ex.InnerException);
                    e.Handled = false;
                    ManageLOG.writeLoginLogs(-1, ModelUserLogs.EVENT_EXCEPTION, this.Name + "-passenger_name_KeyUp:" + ex.Message);
                    txt_barcode.Text = "";
                    txt_barcode.Focus();
                }
            }
        }
示例#47
0
            internal override object Raise(ModelTransaction transaction)
            {
                // Resolve reference arguments
                foreach (var p in method.Parameters)
                {
                    if (p.ReferenceType != null && args[p.Index] != null)
                    {
                        if (p.IsList)
                            args[p.Index] = ((ModelInstance[])args[p.Index]).Select(gi => transaction.GetInstance(gi.Type, gi.Id)).ToList(p.ReferenceType, p.ParameterType);
                        else
                        {
                            ModelInstance mi = (ModelInstance)args[p.Index];
                            mi = transaction.GetInstance(mi.Type, mi.Id);
                            args[p.Index] = mi == null ? null : mi.Instance;
                        }
                    }
                }

                // Invoke the method
                return method.Invoke(Instance, args);
            }