Ejemplo n.º 1
0
        public ShippingRate[] GetShippingRatesSync(decimal weight, string originZipCode, string destinationZipCode)
        {
            // create object that will store results
            List<ShippingRate> rates = new List<ShippingRate>();

            // launch requests serially, waiting for each one
            using (WebResponse response = CreateFedExRequest(weight, originZipCode, destinationZipCode).GetResponse())
                rates.AddRange(GetFedExRates(response));

            using (WebResponse response = CreateUpsRequest(weight, originZipCode, destinationZipCode).GetResponse())
                rates.AddRange(GetUpsRates(response));

            using (WebResponse response = CreateUspsRequest(weight, originZipCode, destinationZipCode).GetResponse())
                rates.AddRange(GetUspsRates(response));

            return rates.ToArray();
        }
Ejemplo n.º 2
0
        public ShippingRate[] GetShippingRatesSyncParallel(decimal weight, string originZipCode, string destinationZipCode)
        {
            // create object that will store results
            List<ShippingRate> rates = new List<ShippingRate>();

            // launch asynchronous requests, which will complete in parallel
            WebRequest fedExRequest = CreateFedExRequest(weight, originZipCode, destinationZipCode);
            IAsyncResult fedExResult = fedExRequest.BeginGetResponse(null, null);

            WebRequest upsRequest = CreateUpsRequest(weight, originZipCode, destinationZipCode);
            IAsyncResult upsResult = upsRequest.BeginGetResponse(null, null);

            WebRequest uspsRequest = CreateUspsRequest(weight, originZipCode, destinationZipCode);
            IAsyncResult uspsResult = uspsRequest.BeginGetResponse(null, null);

            // wait for all requests; each EndGetResponse will block if the request hasn't completed

            using (WebResponse response = fedExRequest.EndGetResponse(fedExResult))
                rates.AddRange(GetFedExRates(response));

            using (WebResponse response = upsRequest.EndGetResponse(upsResult))
                rates.AddRange(GetUpsRates(response));

            using (WebResponse response = uspsRequest.EndGetResponse(uspsResult))
                rates.AddRange(GetUspsRates(response));

            return rates.ToArray();
        }
        /// <summary>
        /// Search Statement
        /// </summary>
        /// <param name="command">Telerik GridCommand</param>
        /// <param name="searchModel">RoutingMaster Search Model</param>
        /// <returns>Search Statement</returns>
        private SearchStatementModel PrepareSearchStatement(GridCommand command, ProductLineMapSearchModel searchModel)
        {
            string whereStatement = string.Empty;

            IList<object> param = new List<object>();
            HqlStatementHelper.AddEqStatement("Type", (int)com.Sconit.CodeMaster.ProductLineMapType.Van, "r", ref whereStatement, param);
            HqlStatementHelper.AddLikeStatement("SAPProductLine", searchModel.SAPProductLine, HqlStatementHelper.LikeMatchMode.Start, "r", ref whereStatement, param);
            HqlStatementHelper.AddEqStatement("IsActive", searchModel.SearchIsActive, "r", ref whereStatement, param);

            string sortingStatement = HqlStatementHelper.GetSortingStatement(command.SortDescriptors);

            SearchStatementModel searchStatementModel = new SearchStatementModel();
            searchStatementModel.SelectCountStatement = selectCountStatement;
            searchStatementModel.SelectStatement = selectStatement;
            searchStatementModel.WhereStatement = whereStatement;
            searchStatementModel.SortingStatement = sortingStatement;
            searchStatementModel.Parameters = param.ToArray<object>();

            return searchStatementModel;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Reading all readings from an OPC server.
        /// </summary>
        private void ProcessOPCServer(OOPCDAServer opcDaServer)
        {
            if (opcDaServer.AutomaticPollingEnabled == 0)
                return;

            XmlServer srv = null;
            try
            {
                srv = new XmlServer(opcDaServer.ObjectName);

                List<OPoint> points = TablesLogic.tPoint.LoadList(
                    TablesLogic.tPoint.OPCDAServerID == opcDaServer.ObjectID);
                if (points.Count == 0)
                    return;

                List<ReadRequestItem> readRequestItems = new List<ReadRequestItem>();
                Hashtable hash = new Hashtable();
                foreach (OPoint point in points)
                {
                    readRequestItems.Add(NewReadRequestItem(point.OPCItemName));
                    hash[point.OPCItemName] = point;
                }
                ReadRequestItemList readItemList = new ReadRequestItemList();
                readItemList.Items = readRequestItems.ToArray();

                ReplyBase reply;
                RequestOptions options = new RequestOptions();
                options.ReturnErrorText = true;
                options.ReturnItemName = true;
                ReplyItemList rslt;
                OPCError[] err;
                reply = srv.Read(options, readItemList, out rslt, out err);
                if (rslt == null)
                    throw new Exception(err[0].Text);
                else
                {
                    int count = 0;
                    foreach (ItemValue iv in rslt.Items)
                    {
                        if (iv.ResultID == null)
                        {
                            try
                            {
                                using (Connection c = new Connection())
                                {
                                    // Create the readings. 
                                    //
                                    OReading reading = TablesLogic.tReading.Create();
                                    OPoint point = hash[iv.ItemName] as OPoint;

                                    if (point != null)
                                    {
                                        reading.PointID = point.ObjectID;
                                        reading.LocationID = point.LocationID;
                                        //reading.LocationTypeParameterID = point.LocationTypeParameterID;
                                        reading.EquipmentID = point.EquipmentID;
                                        //reading.EquipmentTypeParameterID = point.EquipmentTypeParameterID;
                                        reading.DateOfReading = DateTime.Now;

                                        if (iv.Value is bool)
                                            reading.Reading = ((bool)iv.Value) ? 1 : 0;
                                        else
                                            reading.Reading = Convert.ToDecimal(iv.Value.ToString());
                                        reading.Source = ReadingSource.OPCServer;
                                        reading.CheckForBreachOfReading(point);
                                        reading.Save();
                                        count++;
                                    }
                                    c.Commit();
                                }
                            }
                            catch (Exception ex)
                            {
                                LogEvent(ex.Message + "\n\n" + ex.StackTrace, BackgroundLogMessageType.Error);
                            }
                        }
                        else
                            LogEvent("Error reading '" + iv.ItemName + "': " + iv.ResultID.Name, BackgroundLogMessageType.Error);
                    }
                    LogEvent(count + " points out of " + readItemList.Items.Length + " successfully read from server '" + opcDaServer.ObjectName + "'.");
                }
            }
            catch (Exception ex)
            {
                LogEvent(ex.Message + "\n\n" + ex.StackTrace, BackgroundLogMessageType.Error);
            }
            finally
            {
                if (srv != null)
                    srv.Dispose();
            }
            
        }
Ejemplo n.º 5
0
        public ActionResult Edit(SequenceGroup sequenceGroup)
        {
            ViewBag.HaveEditPrevTraceCode = CurrentUser.Permissions.Where(p => p.PermissionCode == "Url_SequenceGroup_EditPrevTraceCode").Count() > 0;
            if (ModelState.IsValid)
            {
                bool noenError = true;
                if (!ViewBag.HaveEditPrevTraceCode && !string.IsNullOrWhiteSpace(sequenceGroup.PreviousTraceCode))
                {
                    SaveErrorMessage("您没有修改前个Van号的权限。");
                    noenError = false;
                }
                if (sequenceGroup.IsActive && string.IsNullOrWhiteSpace(sequenceGroup.PreviousTraceCode))
                {
                    SaveErrorMessage("排序组有效的情况下,前面Van号不能为空。");
                     noenError = false;
                }
                IList<OrderSeq> orderSeqs = new List<OrderSeq>();
                if (!string.IsNullOrWhiteSpace(sequenceGroup.PreviousTraceCode))
                {
                     orderSeqs = this.genericMgr.FindAll<OrderSeq>("select o from OrderSeq as o where o.ProductLine=? and o.TraceCode=?", new object[] { sequenceGroup.ProductLine, sequenceGroup.PreviousTraceCode });
                    if (orderSeqs == null || orderSeqs.Count == 0)
                    {
                        SaveErrorMessage(string.Format("生产线{0}前面Van号{1}找不到有效的数据。", sequenceGroup.ProductLine, sequenceGroup.PreviousTraceCode));
                        noenError = false;
                    }
                }
                if (!string.IsNullOrWhiteSpace(sequenceGroup.OpReference))
                {
                    try
                    {
                        sequenceGroup.OpReference.Split('|');
                    }
                    catch (Exception)
                    {
                        SaveErrorMessage(string.Format("工位{0}填写有误,正确的格式为{1}。", sequenceGroup.OpReference, Resources.SCM.SequenceGroup.SequenceGroup_OpRefRemark));
                        noenError = false;
                    }
                }
                if (noenError)
                {
                    var dbSsequenceGroup = base.genericMgr.FindById<SequenceGroup>(sequenceGroup.Code);
                    //dbSsequenceGroup.SequenceBatch = sequenceGroup.SequenceBatch;
                    //dbSsequenceGroup.OpReference = sequenceGroup.OpReference;
                    //dbSsequenceGroup.IsActive = sequenceGroup.IsActive;
                    //if (!string.IsNullOrWhiteSpace(sequenceGroup.PreviousTraceCode))
                    //{
                    //    dbSsequenceGroup.PreviousTraceCode = sequenceGroup.PreviousTraceCode;
                    //    dbSsequenceGroup.PreviousOrderNo = orderSeqs.First().OrderNo;
                    //    dbSsequenceGroup.PreviousSeq = orderSeqs.First().Sequence;
                    //    dbSsequenceGroup.PreviousSubSeq = orderSeqs.First().SubSequence;
                    //}
                    //base.genericMgr.Update(dbSsequenceGroup);
                    string updateSql = "update SCM_SeqGroup set Version=Version+1,IsActive=?,SeqBatch=? ";
                    IList<object> parems = new List<object>();
                    parems.Add(sequenceGroup.IsActive);
                    parems.Add(sequenceGroup.SequenceBatch);
                    if (!string.IsNullOrWhiteSpace(sequenceGroup.OpReference))
                    {
                        updateSql += " ,OpRef=? ";
                        parems.Add(sequenceGroup.OpReference);
                    }
                    if (!string.IsNullOrWhiteSpace(sequenceGroup.PreviousTraceCode))
                    {
                        updateSql += ",PrevTraceCode=?,PrevOrderNo=?,PrevSeq=?,PrevSubSeq=? ";
                        parems.Add(sequenceGroup.PreviousTraceCode);
                        parems.Add(orderSeqs.First().OrderNo);
                        parems.Add(orderSeqs.First().Sequence);
                        parems.Add(orderSeqs.First().SubSequence);
                    }
                    updateSql += "  where Code=? and Version=? ";
                    parems.Add(sequenceGroup.Code);
                    parems.Add(sequenceGroup.Version);
                    this.genericMgr.UpdateWithNativeQuery(updateSql, parems.ToArray());
                    SaveSuccessMessage(Resources.SCM.SequenceGroup.SequenceGroup_Updated);
                    return View(dbSsequenceGroup);
                }
            }

            return View(sequenceGroup);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Search Statement
        /// </summary>
        /// <param name="command">Telerik GridCommand</param>
        /// <param name="searchModel">RoutingMaster Search Model</param>
        /// <returns>Search Statement</returns>
        private SearchStatementModel PrepareSearchStatement(GridCommand command, SequenceGroupSearchModel searchModel)
        {
            string whereStatement = string.Empty;

            IList<object> param = new List<object>();

            HqlStatementHelper.AddEqStatement("ProductLine", searchModel.ProdLine, "s", ref whereStatement, param);
            HqlStatementHelper.AddEqStatement("IsActive", searchModel.IsActive, "s", ref whereStatement, param);
            HqlStatementHelper.AddLikeStatement("Code", searchModel.Code, HqlStatementHelper.LikeMatchMode.Start, "s", ref whereStatement, param);

            string sortingStatement = HqlStatementHelper.GetSortingStatement(command.SortDescriptors);

            SearchStatementModel searchStatementModel = new SearchStatementModel();
            searchStatementModel.SelectCountStatement = selectCountStatement;
            searchStatementModel.SelectStatement = selectStatement;
            searchStatementModel.WhereStatement = whereStatement;
            searchStatementModel.SortingStatement = sortingStatement;
            searchStatementModel.Parameters = param.ToArray<object>();

            return searchStatementModel;
        }
Ejemplo n.º 7
0
        public override void OnExecute()
        {
            base.OnExecute();

            DateTime now  = DateTime.Now;
            List<ONotification> notifications =
                TablesLogic.tNotification.LoadList(
                TablesLogic.tNotification.NextNotificationDateTime < now);

            foreach (ONotification notification in notifications)
            {
                try
                {
                    // Load up the object and test if the expected
                    // field is null. 
                    // 
                    OActivity activity = TablesLogic.tActivity.Load(notification.ActivityID);
                    ONotificationProcess notificationProcess = TablesLogic.tNotificationProcess.Load(notification.NotificationProcessID);
                    ONotificationMilestones milestones = notificationProcess.NotificationMilestones;

                    // 2010.06.30
                    // Kim Foong
                    // Checks if any of the objects are null, if so, we terminate the
                    // notification.
                    //
                    if (activity == null || notificationProcess == null || milestones == null)
                    {
                        using (Connection c = new Connection())
                        {
                            notification.NextNotificationDateTime = null;
                            notification.Save();
                            c.Commit();
                        }
                        continue;
                    }

                    Type type = typeof(TablesLogic).Assembly.GetType("LogicLayer." + activity.ObjectTypeName);
                    LogicLayerPersistentObject obj = PersistentObject.LoadObject(type, activity.AttachedObjectID.Value) as LogicLayerPersistentObject;
                    if (obj == null)
                    {
                        // 2010.06.30
                        // Kim Foong
                        // Terminate the notification.
                        //
                        using (Connection c = new Connection())
                        {
                            notification.NextNotificationDateTime = null;
                            notification.Save();
                            c.Commit();
                        }
                        continue;
                    }

                    int milestoneNumber = notification.NextNotificationMilestone.Value;
                    int notificationLevel = notification.NextNotificationLevel.Value;
                    string expectedField = (string)milestones.DataRow["ExpectedField" + milestoneNumber];

                    object value = DataFrameworkBinder.GetValue(obj, expectedField, false);
                    using (Connection c = new Connection())
                    {
                        if (value == null)
                        {
                            // Now since this value is null, we must send a notification.
                            //
                            // But we need to first find out the list of all the recipients 
                            // configured to receive the notification.
                            //
                            ONotificationHierarchyLevel notificationHierarchyLevel =
                                notificationProcess.NotificationHierarchy.FindNotificationHierarchyLevelByLevel(notificationLevel);

                            StringBuilder email = new StringBuilder();
                            StringBuilder cellphone = new StringBuilder();

                            // Assign users/roles to the task.
                            //
                            StringBuilder emails = new StringBuilder();
                            StringBuilder cellphones = new StringBuilder();
                            if (notificationHierarchyLevel != null)
                            {
                                List<OUser> notifyUsers = new List<OUser>();
                                List<OPosition> notifyPositions = new List<OPosition>();

                                // Here we assigned the users
                                //
                                foreach (OUser user in notificationHierarchyLevel.Users)
                                    notifyUsers.Add(user);

                                // Then we assign the positions.
                                //
                                foreach (OPosition position in notificationHierarchyLevel.Positions)
                                    notifyPositions.Add(position);

                                // Then we assign the positions through the roles.
                                //
                                List<string> roleCodes = new List<string>();
                                foreach (ORole role in notificationHierarchyLevel.Roles)
                                    roleCodes.Add(role.RoleCode);
                                List<OPosition> assignedPositions = OPosition.GetPositionsByRoleCodesAndObject(obj, roleCodes.ToArray());
                                notifyPositions.AddRange(assignedPositions);

                                // Then we get a distinct list of users who will be
                                // the recipients to our notification.
                                //
                                List<OUser> users = TablesLogic.tUser.LoadList(
                                    TablesLogic.tUser.ObjectID.In(notifyUsers) |
                                    TablesLogic.tUser.Positions.ObjectID.In(notifyPositions));

                                // Construct the list of email and SMS recipients.
                                //
                                string emailRecipients = "";
                                string smsRecipients = "";
                                foreach (OUser user in users)
                                {
                                    if (user.UserBase.Email != null && user.UserBase.Email.Trim() != "")
                                        emailRecipients += user.UserBase.Email.Trim() + ";";
                                    if (user.UserBase.Cellphone != null && user.UserBase.Cellphone.Trim() != "")
                                        smsRecipients += user.UserBase.Cellphone.Trim() + ";";
                                }

                                // Generate and the send message to the users.
                                //
                                OMessageTemplate messageTemplate = null;
                                object messageTemplateId = notificationProcess.DataRow["MessageTemplate" + milestoneNumber + "ID"];
                                if (messageTemplateId != null && messageTemplateId != DBNull.Value)
                                    messageTemplate = TablesLogic.tMessageTemplate.Load((Guid)messageTemplateId);
                                if (messageTemplate != null)
                                    messageTemplate.GenerateAndSendMessage(obj, emailRecipients, smsRecipients);

                            }
                        }


                        // Now, determine the next notification date.
                        //
                        // Find out when is the next date/time the next
                        // notification should occur.
                        //
                        DateTime? nextNotificationDateTime = null;
                        int? nextNotificationLevel = null;
                        int? nextNotificationMilestone = null;

                        notificationProcess.GetNextNotificationDateTime(obj, notification.NextNotificationDateTime,
                            ref nextNotificationDateTime, ref nextNotificationMilestone, ref nextNotificationLevel);

                        notification.NextNotificationDateTime = nextNotificationDateTime;
                        notification.NextNotificationLevel = nextNotificationLevel;
                        notification.NextNotificationMilestone = nextNotificationMilestone;
                        notification.Save();
                        c.Commit();
                    }
                }
                catch (Exception ex)
                {
                    LogEvent("An error occured while performing notification ObjectID = '" + notification.ObjectID + "' " + ex.Message + "\n" + ex.StackTrace);
                }
            }
        }