Exemple #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (!checkBox1.Checked && !checkBox2.Checked)
            {
                MessageBox.Show("請勾選商品代碼");
                return;
            }
            string Products_Code = string.Empty;

            if (checkBox1.Checked)
            {
                if (Products_Code != string.Empty)
                {
                    Products_Code += "|" + checkBox1.Text;
                }
                else
                {
                    Products_Code += checkBox1.Text;
                }
            }
            if (checkBox2.Checked)
            {
                if (Products_Code != string.Empty)
                {
                    Products_Code += "|" + checkBox2.Text;
                }
                else
                {
                    Products_Code += checkBox2.Text;
                }
            }
            DateTime   dtS    = DateTime.Parse(textBox1.Text.Trim() + " 00:00:00");
            DateTime   dtE    = DateTime.Parse(textBox2.Text.Trim() + " 00:00:00");
            int        days   = new TimeSpan(dtE.Ticks - dtS.Ticks).Days;
            GetTickets ticket = new GetTickets();

            for (int i = 0; i <= days; i++)
            {
                ticket.ProductsCode = Products_Code;
                ticket.OrdersSTime  = String.Format("{0:yyyyMMdd}", dtS) + "000000";
                ticket.OrdersETime  = String.Format("{0:yyyyMMdd}", dtS) + "235959";
                var httpWebRequest = (HttpWebRequest)WebRequest.Create(ConfigurationManager.AppSettings["GetTicketsURL"].ToString() + new JavaScriptSerializer().Serialize(ticket));
                httpWebRequest.ContentType = "application/json; charset=utf-8";
                httpWebRequest.Method      = "POST";

                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    streamWriter.Write(new JavaScriptSerializer().Serialize(ticket));
                }

                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    var    result = streamReader.ReadToEnd();
                    string sql    = "";
                    try
                    {
                        GetTicketsResp deserialized = JsonConvert.DeserializeObject <GetTicketsResp>(result);
                        if (deserialized.ErrCode == "S1" && deserialized.RowCount > 0)
                        {
                            using (SqlConnection _con = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString))
                            {
                                _con.Open();
                                string TK_STATUS = string.Empty;
                                foreach (GetTicketsDataResp resp in deserialized.Data)
                                {
                                    if (!GetDataDB(resp.QRCode, resp.OrdersNo))
                                    {
                                        if (resp.OrderType == "R")
                                        {
                                            TK_STATUS = "X";
                                        }
                                        else
                                        {
                                            TK_STATUS = "1";
                                        }
                                        string OrderDatetime = string.Empty;
                                        OrderDatetime = resp.OrderDatetime.Substring(0, 4) + "-" + resp.OrderDatetime.Substring(4, 2) + "-" + resp.OrderDatetime.Substring(6, 2) + " " + resp.OrderDatetime.Substring(8, 2) + ":" + resp.OrderDatetime.Substring(10, 2) + ":" + resp.OrderDatetime.Substring(12, 2);
                                        sql           = string.Format(@"insert into cTicketWhitelist
                                                        (TK_QRCODE
                                                        ,TK_ORDERNO
                                                        ,TK_PRICETYPES
                                                        ,TK_PRICE
                                                        ,TK_ORDERDT
                                                        ,TK_PLACE
                                                        ,TK_STATUS
                                                        ,TK_USED_DT
                                                        ,TK_END_DT
                                                        ,TK_FEEDBACK
                                                        ,TK_FEEDBACKMEMO
                                                        ,CREATEDT
                                                        ,CREATEID
                                                        ,MODIFYDT
                                                        ,MODIFYID) 
                                                         values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}')"
                                                                      , resp.QRCode
                                                                      , resp.OrdersNo
                                                                      , resp.PriceTypes
                                                                      , Convert.ToInt32(resp.Price)
                                                                      , OrderDatetime
                                                                      , "udn"
                                                                      , TK_STATUS //1:售出  2:已使用  X:作廢
                                                                      , ""
                                                                      , ""
                                                                      , ""
                                                                      , ""
                                                                      , string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now)
                                                                      , "admin"
                                                                      , null
                                                                      , null);
                                        SqlCommand cmd = new SqlCommand(sql, _con);
                                        cmd.ExecuteNonQuery();
                                    }
                                    else
                                    {
                                        if (resp.OrderType == "R")
                                        {
                                            TK_STATUS = "X";
                                            string OrderDatetime = string.Empty;
                                            OrderDatetime = resp.OrderDatetime.Substring(0, 4) + "-" + resp.OrderDatetime.Substring(4, 2) + "-" + resp.OrderDatetime.Substring(6, 2) + " " + resp.OrderDatetime.Substring(8, 2) + ":" + resp.OrderDatetime.Substring(10, 2) + ":" + resp.OrderDatetime.Substring(12, 2);
                                            sql           = string.Format(@"update cTicketWhitelist
                                                              set TK_ORDERDT='{0}',
                                                                  TK_STATUS='{1}',
                                                                  MODIFYDT='{2}',
                                                                  MODIFYID='{3}'
                                                              where TK_QRCODE='{4}'
                                                              and TK_ORDERNO='{5}'
                                                              and TK_STATUS<>'X'"
                                                                          , OrderDatetime
                                                                          , TK_STATUS
                                                                          , string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now)
                                                                          , "udn"
                                                                          , resp.QRCode
                                                                          , resp.OrdersNo);
                                            SqlCommand cmd = new SqlCommand(sql, _con);
                                            cmd.ExecuteNonQuery();
                                        }
                                    }
                                }
                            }
                        }
                        dtS = dtS.AddDays(1);
                        writeLog.Write_Log("GetTickets " + ticket.OrdersSTime + " ~ " + ticket.OrdersETime + ": ErrCode = " + deserialized.ErrCode + " , RowCount = " + deserialized.RowCount);
                    }
                    catch (Exception ex)
                    {
                        return;
                    }
                }
            }
            label10.Visible = true;
            ini.IniWriteValue("Setup", "LastTime", String.Format("{0:yyyy/MM/dd}", dtS) + " 00:00:00");//儲存最後一次排程的時間
        }
Exemple #2
0
        private void GetTickets_timer_Tick(object sender, EventArgs e)
        {
            DateTime dt = DateTime.Now;

            if (File.Exists(StartupPath + "\\Setup.ini"))
            {
                dt = DateTime.Parse(ini.IniReadValue("Setup", "LastTime"));
            }
            string Products_Code = string.Empty;

            if (checkBox1.Checked)
            {
                if (Products_Code != string.Empty)
                {
                    Products_Code += "|" + checkBox1.Text;
                }
                else
                {
                    Products_Code += checkBox1.Text;
                }
            }
            if (checkBox2.Checked)
            {
                if (Products_Code != string.Empty)
                {
                    Products_Code += "|" + checkBox2.Text;
                }
                else
                {
                    Products_Code += checkBox2.Text;
                }
            }
            GetTickets ticket = new GetTickets
            {
                ProductsCode = Products_Code,
                OrdersSTime  = String.Format("{0:yyyyMMddHHmmss}", dt.AddMinutes(-6)),
                OrdersETime  = String.Format("{0:yyyyMMddHHmmss}", dt),
            };
            var httpWebRequest = (HttpWebRequest)WebRequest.Create(ConfigurationManager.AppSettings["GetTicketsURL"].ToString() + new JavaScriptSerializer().Serialize(ticket));

            httpWebRequest.ContentType = "application/json; charset=utf-8";
            httpWebRequest.Method      = "POST";

            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                streamWriter.Write(new JavaScriptSerializer().Serialize(ticket));
            }

            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                var result = streamReader.ReadToEnd();
                label6.Text = result;
                string sql = "";
                try
                {
                    GetTicketsResp deserialized = JsonConvert.DeserializeObject <GetTicketsResp>(result);
                    if (deserialized.ErrCode == "S1" && deserialized.RowCount > 0)
                    {
                        using (SqlConnection _con = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString))
                        {
                            _con.Open();
                            string TK_STATUS = string.Empty;
                            foreach (GetTicketsDataResp resp in deserialized.Data)
                            {
                                if (!GetDataDB(resp.QRCode, resp.OrdersNo))
                                {
                                    if (resp.OrderType == "R")
                                    {
                                        TK_STATUS = "X";
                                    }
                                    else
                                    {
                                        TK_STATUS = "1";
                                    }
                                    string OrderDatetime = string.Empty;
                                    OrderDatetime = resp.OrderDatetime.Substring(0, 4) + "-" + resp.OrderDatetime.Substring(4, 2) + "-" + resp.OrderDatetime.Substring(6, 2) + " " + resp.OrderDatetime.Substring(8, 2) + ":" + resp.OrderDatetime.Substring(10, 2) + ":" + resp.OrderDatetime.Substring(12, 2);
                                    sql           = string.Format(@"insert into cTicketWhitelist
                                                        (TK_QRCODE
                                                        ,TK_ORDERNO
                                                        ,TK_PRICETYPES
                                                        ,TK_PRICE
                                                        ,TK_ORDERDT
                                                        ,TK_PLACE
                                                        ,TK_STATUS
                                                        ,TK_USED_DT
                                                        ,TK_END_DT
                                                        ,TK_FEEDBACK
                                                        ,TK_FEEDBACKMEMO
                                                        ,CREATEDT
                                                        ,CREATEID
                                                        ,MODIFYDT
                                                        ,MODIFYID) 
                                                         values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}')"
                                                                  , resp.QRCode
                                                                  , resp.OrdersNo
                                                                  , resp.PriceTypes
                                                                  , Convert.ToInt32(resp.Price)
                                                                  , OrderDatetime
                                                                  , "udn"
                                                                  , TK_STATUS //1:售出  2:已使用  X:作廢
                                                                  , ""
                                                                  , ""
                                                                  , ""
                                                                  , ""
                                                                  , string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now)
                                                                  , "admin"
                                                                  , null
                                                                  , null);
                                    SqlCommand cmd = new SqlCommand(sql, _con);
                                    cmd.ExecuteNonQuery();
                                }
                                else
                                {
                                    if (resp.OrderType == "R")
                                    {
                                        TK_STATUS = "X";
                                        string OrderDatetime = string.Empty;
                                        OrderDatetime = resp.OrderDatetime.Substring(0, 4) + "-" + resp.OrderDatetime.Substring(4, 2) + "-" + resp.OrderDatetime.Substring(6, 2) + " " + resp.OrderDatetime.Substring(8, 2) + ":" + resp.OrderDatetime.Substring(10, 2) + ":" + resp.OrderDatetime.Substring(12, 2);
                                        sql           = string.Format(@"update cTicketWhitelist
                                                              set TK_ORDERDT='{0}',
                                                                  TK_STATUS='{1}',
                                                                  MODIFYDT='{2}',
                                                                  MODIFYID='{3}'
                                                              where TK_QRCODE='{4}'
                                                              and TK_ORDERNO='{5}'
                                                              and TK_STATUS<>'X'"
                                                                      , OrderDatetime
                                                                      , TK_STATUS
                                                                      , string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now)
                                                                      , "udn"
                                                                      , resp.QRCode
                                                                      , resp.OrdersNo);
                                        SqlCommand cmd = new SqlCommand(sql, _con);
                                        cmd.ExecuteNonQuery();
                                    }
                                }
                            }
                        }
                    }
                    ini.IniWriteValue("Setup", "LastTime", String.Format("{0:yyyy/MM/dd HH:mm:ss}", DateTime.Now));//儲存最後一次排程的時間
                }
                catch (Exception ex)
                {
                    return;
                }
            }
        }