计时器的onTick事件无法按asp.net中的标准时钟运行

时间:2018-07-09 04:52:21

标签: timer

在本地计算机上,已发布代码的计时器在服务器端部署已发布代码之后,按照标准时钟时间运行得更快,因此,它按照标准时钟时间运行得很慢。

我需要回答应按标准时间调用ontick事件

 //front end code for timer will call timer after 1 sec
    <div class="bottomamt">
                                                        <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick">
                                                        </asp:Timer>
                                                        <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                                                            <ContentTemplate>
                                                                <div class="row">
                                                                    <div class="col-md-12">
                                                                        <p>
                                                                            Current Winner : <span class="item_price">
                                                                                <asp:LinkButton ID="lblUPrice" runat="server" CommandName="cmdname" CommandArgument='<%#Eval("BidProductID")%>' /></span></p>
                                                                    </div>
                                                                </div>
                                                                 <div class="row">
                                                                    <div class="col-md-12">
                                                                <h3>
                                                                    <asp:Label ID="lblname" runat="server" /></h3>
                                                                    </div>
                                                                    </div>
                                                                <div class="row">
                                                                    <div class="col-md-12">
                                                                        <p>
                                                                            <asp:HiddenField ID="hdn" runat="server" ViewStateMode="Enabled" Value='<%#Eval("BidProductID")%>' />
                                                                            <asp:Label ID="lbl" runat="server" Visible="false" Text='<%#Eval("BidProductID")%>' />
                                                                            <asp:Label ID="lblmin" runat="server" Visible="false" Text='<%#Eval("Minute")%>' />
                                                                            <asp:Label ID="lblsec" runat="server" Visible="false" Text='<%#Eval("Second")%>' />
                                                                            <asp:Label runat="server" ID="Label1" Font-Bold="True" Text='<%#Eval("HoursBid")%>' />
                                                                        </p>
                                                                    </div>
                                                                    <div class="col-md-12">
                                                                        <p>
                                                                            <span class="item_price">
                                                                                <asp:Label ID="lblAdminFee" runat="server" /></span></p>
                                                                    </div>
                                                                </div>
                                                            </ContentTemplate>
                                                            <Triggers>
                                                                <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
                                                            </Triggers>
                                                        </asp:UpdatePanel>
                                                        <div class="bidbtn">
                                                            <asp:LinkButton ID='LinkButton3' CssClass="hvr-outline-out button2" runat="server"
                                                                CommandArgument='<%#Eval("BidProductID")%>' OnClick="btnBid_Click">BID</asp:LinkButton>
                                                        </div>
                                                    </div>

//Back end code  that timer event get called 

//此方法以小时,分钟,秒为单位更新标签中提到的时间字段//格式         受保护的void Timer1_Tick(对象发送者,EventArgs e)         {             this.MaintainScrollPositionOnPostBack = true;             #region出价产品清单             foreach(dlBidProduct.Items中的RepeaterItem项)//(dlBidProduct.Items中的Repeater项)             {

            Label Label1 = (Label)(item.FindControl("Label1"));
            Label lbl = (Label)(item.FindControl("lbl"));

            string TimerData1 = Label1.Text;
            string[] TimerData = null;

            TimerData = TimerData1.Split(':');
            //string lblHour = "";
            //string lblMinute = "";
            //string lblSeconds = "";
            int hour = 0;
            int minutes = 0;
            int seconds = 0;

            if (TimerData1 != "")
            {

                hour = int.Parse(Convert.ToString(TimerData.ElementAt(0)));
                minutes = int.Parse(Convert.ToString(TimerData.ElementAt(1)));
                seconds = int.Parse(Convert.ToString(TimerData.ElementAt(2)));


                // 
                //lblHour = Convert.ToString(TimerData.ElementAt(0));
                //lblMinute = Convert.ToString(TimerData.ElementAt(1));
                //lblSeconds = Convert.ToString(TimerData.ElementAt(2));

            }



            //int hour = int.Parse(lblHour);
            //int minutes = int.Parse(lblMinute);
            //int seconds = int.Parse(lblSeconds);
            //int counter = 60;

            // while (counter > 0)

            if (seconds > 0)
            {
                seconds = seconds - 1;
            }
            else if (seconds == 0 && minutes > 0)
            {
                //counter -= 1;
                minutes = minutes - 1;
                seconds = 60;
            }
            else if (minutes == 0 && hour > 0)
            {
                //counter -= 1;
                hour = hour - 1;
                minutes = 60;
            }



            Label1.Text = hour + ":" + minutes + ":" + seconds;



            SqlParameter[] arrparam = new SqlParameter[]


                {
                    new SqlParameter("@BidProductID",Convert.ToInt32(lbl.Text)),
                      new SqlParameter("@Hour",Convert.ToString(hour)),
                      new SqlParameter("@HoursBid",Convert.ToString(hour)),
                     new SqlParameter("@Minute",Convert.ToString(minutes)),
                            new SqlParameter("@Second",Convert.ToString(seconds))


                };

            _bussinessLayer.insertRecordBySP("spUpdateTimer", arrparam);

            //Bidding of product has stopped





            if (hour == 0 && minutes == 0 && seconds == 0)
            {
                //Check whether it is new Bid Product
                DataTable NewBid = new DataTable();
                SqlParameter[] BidP4 = new SqlParameter[]
                    {
                       new SqlParameter("@BidProductID",Convert.ToInt32(lbl.Text))
                    };
                NewBid = _bussinessLayer.getRecordFromSPDTWP("CheckNewlyAddedBid", BidP4);
                if (NewBid.Rows.Count>0)
                if (Convert.ToString(NewBid.Rows[0]["isEarlyChecked"]) == "1")
                {
                    //Check Bidding of Product  done or not based on BidAmount.



                    DataTable Bid = new DataTable();
                    SqlParameter[] BidP = new SqlParameter[]
                    {
                       new SqlParameter("@BidProductID",Convert.ToInt32(lbl.Text))
                    };
                    Bid = _bussinessLayer.getRecordFromSPDTWP("CheckBidAmountData", BidP);

                    if (Bid.Rows.Count > 0)
                    {
                        DataTable SendMail = new DataTable();
                        SqlParameter[] BidId1 = new SqlParameter[]
                    {
                       new SqlParameter("@BidProductID",Convert.ToInt32(lbl.Text))
                    };
                        SendMail = _bussinessLayer.getRecordFromSPDTWP("GetSendMailData", BidId1);

                        if (Convert.ToInt32(SendMail.Rows[0]["SendMail"]) == 0)//Check for given Bid Mail Send or Not
                        {
                            //Calculate Highest Bidder
                            DataTable HightestBid = new DataTable();
                            SqlParameter[] BidId = new SqlParameter[]
                    {
                       new SqlParameter("@BidProductID",Convert.ToInt32(lbl.Text))
                    };
                            HightestBid = _bussinessLayer.getRecordFromSPDTWP("GetHightestBidder", BidId);



                            if (HightestBid.Rows.Count > 0)
                            {
                                //Insert into Payment Pending List
                                DateTime PaymentLastDate = DateTime.Now.AddHours(48);
                                SqlParameter[] insertP = new SqlParameter[]
                        {
                            new SqlParameter("@BidProductId",Convert.ToInt32(HightestBid.Rows[0]["Bidproductid"])),
                            new SqlParameter("@UserId",Convert.ToInt32(HightestBid.Rows[0]["CustomerId"])),
                            new SqlParameter("@PaymentLastDate",PaymentLastDate)

                        };

                                _bussinessLayer.insertRecordBySP("spInsertPendingPaymentUserList", insertP);

                                string Username = Convert.ToString(ConfigurationSettings.AppSettings["TempemailID"]);
                                string Pwd = Convert.ToString(ConfigurationSettings.AppSettings["TempPassword"]);
                                int Port = Convert.ToInt32(ConfigurationSettings.AppSettings["SubsmtpPortNo"]);
                                string SmtpServerName = Convert.ToString(ConfigurationSettings.AppSettings["SubsmtpServerName"]);


                                /*Confirmation email of being out-bidded of the Current Highest Bid*/

                                MailMessage mail = new MailMessage();
                                SmtpClient SmtpServer = new SmtpClient(SmtpServerName);
                                mail.From = new MailAddress(Username);
                                mail.To.Add(Convert.ToString(HightestBid.Rows[0]["EmailId"]));
                                mail.Subject = "Highest Bid on product";
                                //string Link = "http://localhost:2690/Dealies_VSS/CustomerSignIn.aspx?BidProductId=" + Convert.ToInt32(HightestBid.Rows[0]["Bidproductid"]);
                                string Link = "" + verifictn.Trim() + "CustomerSignIn.aspx?BidProductId=" + Convert.ToInt32(HightestBid.Rows[0]["Bidproductid"]);
                                mail.IsBodyHtml = true;
                                string msgBody = "Hello " + Convert.ToString(HightestBid.Rows[0]["UserName"]) + ",<br/>" + "Now You are at Highest bid Position.<br/>Your username :'" + Convert.ToString(HightestBid.Rows[0]["UserName"]) + "' and product is :'" + Convert.ToString(HightestBid.Rows[0]["ProductName"]) + "'" +
                                            "<br/>and Price :'" + Convert.ToDouble(HightestBid.Rows[0]["Amount"]) + "' <br/> purchase within 48 Hours " + "<br/>Link : " + Link + "<br/><br/>Thanks and regards,<br/>My Custom Bid";

                                mail.Body = msgBody.ToString();




                                SmtpServer.Port = Port;
                                SmtpServer.Credentials = new System.Net.NetworkCredential(Username, Pwd);
                                SmtpServer.Host = SmtpServerName;
                                SmtpServer.EnableSsl = true;

                                SmtpServer.Send(mail);
                                //Update Send Mail Status for Bid Product
                                SqlParameter[] arrparam9 = new SqlParameter[]
                                {
                                    new SqlParameter("@BidProductID",Convert.ToInt32(lbl.Text)),


                                };

                                _bussinessLayer.insertRecordBySP("UpdateSendMailStatusForBid", arrparam9);



                            }
                        }
                    }
                    else if (hour == 0 && minutes == 0 && seconds == 0 && Bid.Rows.Count == 0)
                    {
                        //Bidding of Product Not Done then set its status As Closed
                        DataTable CloseBid = new DataTable();
                        SqlParameter[] BidId15 = new SqlParameter[]
                    {
                       new SqlParameter("@BidProductID",Convert.ToInt32(lbl.Text))
                    };
                        CloseBid = _bussinessLayer.getRecordFromSPDTWP("UpdateCloseBidProductStatus", BidId15);

                    }
                }
            }



        }
        #endregion





    }

0 个答案:

没有答案