C#編寫影院售票系統(A project with a higher amount of gold )(2:相關代碼)

来源:https://www.cnblogs.com/lsy131479/archive/2018/01/27/8367314.html
-Advertisement-
Play Games

此篇文章為項目代碼,,,需要項目需求 ,思路分析與窗體效果請訪問:http://www.cnblogs.com/lsy131479/p/8367304.html ...


此篇文章為項目代碼,,,需要項目需求 ,思路分析與窗體效果請訪問:http://www.cnblogs.com/lsy131479/p/8367304.html

 

 

項目類圖:

 影院類:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;

namespace Theater_Ticket_Selling_System
{
    /// <summary>
    /// 影院類
    /// 保存放映計劃和座位類
    /// </summary>
    [Serializable]
    public class Cinema
    {
        //座位集合
        private Dictionary<string, Seat> seats;

        //放映計劃
        private Schedule schedule;

        //已售出電影票的集合
        private List<Ticket> soldTickets;

        public Cinema()
        {
            Schedule = new Schedule();
            Schedule.LoadItems();
            Seats = new Dictionary<string, Seat>();
            SoldTickets = new List<Ticket>();
        }

        public Cinema(Dictionary<string, Seat> seats, Schedule schedule, List<Ticket> soldTickets)
        {
            Seats = seats;
            Schedule = schedule;
            SoldTickets = soldTickets;
        }

        public Dictionary<string, Seat> Seats { get => seats; set => seats = value; }
        public Schedule Schedule { get => schedule; set => schedule = value; }
        public List<Ticket> SoldTickets { get => soldTickets; set => soldTickets = value; }


        //保存售票情況
        public void Save(Dictionary<string, Cinema> dictionary)
        {
            //創建文件流派
            Stream stream = new FileStream("save.bin", FileMode.Create);
            //二進位序列化
            BinaryFormatter bf = new BinaryFormatter();
            //將對象或具有指定頂級 (根)、 對象圖序列化到給定的流
            bf.Serialize(stream, dictionary);
            //關閉流
            stream.Close();
        }

        //讀取售票情況
        public Dictionary<string, Cinema> Load(Dictionary<string, Cinema> dictionary)
        {
            //創建文件流派
            Stream stream = new FileStream("save.bin", FileMode.Open);
            //二進位序列化
            BinaryFormatter bf = new BinaryFormatter();
            //指定的流反序列化對象圖
            dictionary = (Dictionary<string, Cinema>)bf.Deserialize(stream);
            //關閉流
            stream.Close();
            return dictionary;
        }
    }
}

電影票類:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Theater_Ticket_Selling_System
{
    /// <summary>
    /// 電影票(父類)
    /// 保存電影信息
    /// </summary>
    [Serializable]
    public class Ticket
    {
        //放映場次
        private ScheduleItem scheduleItem;

        //所屬座位對象
        private Seat seat;

        //票價
        private int price;

        public Ticket()
        {
            
        }

        public Ticket(ScheduleItem scheduleItem, Seat seat, int price)
        {
            ScheduleItem = scheduleItem;
            Seat = seat;
            Price = price;
        }

        public ScheduleItem ScheduleItem { get => scheduleItem; set => scheduleItem = value; }
        public Seat Seat { get => seat; set => seat = value; }
        public int Price { get => price; set => price = value; }

        //計算票價
        public virtual double CalcPrice()
        {
            return Price;
        }

        //列印售票
        public virtual void Print()
        {

        }

        //顯示當前出票信息
        public virtual string Show()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("*****************************************");
            sb.AppendLine("\t  " + "青鳥影院(普通票)");
            sb.AppendLine("-----------------------------------------");
            sb.AppendLine("電影名:" + ScheduleItem.Movie.MovieName);
            sb.AppendLine("時間:" + ScheduleItem.Time);
            string text = Seat.SeatNum.Remove(0, Seat.SeatNum.Length - 3);
            sb.AppendLine("座位號:" + text);
            sb.AppendLine("價格:" + Price);
            sb.AppendLine("*****************************************");
            sb.AppendLine("\t  " + "(a)普通票");
            return sb.ToString();

        }
    }
}

贈票類:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Theater_Ticket_Selling_System
{
    /// <summary>
    /// 贈票(子類)
    /// 保存特殊的增票信息
    /// </summary>
    public class FreeTicket:Ticket
    {
        //贈票者名字
        private string customerName;

        public FreeTicket()
        {
        }

        public FreeTicket(ScheduleItem scheduleItem, Seat seat, int price, string customerName) : base(scheduleItem, seat, price)
        {
            this.CustomerName = customerName;
        }

        public string CustomerName { get => customerName; set => customerName = value; }


        //計算票價
        public override double CalcPrice()
        {
            return 0;
        }

        //列印售票信息
        public override void Print()
        {
            base.Print();
        }

        //顯示當前出票信息
        public override string Show()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("*****************************************");
            sb.AppendLine("\t  " + "青鳥影院(贈票)");
            sb.AppendLine("-----------------------------------------");
            sb.AppendLine("電影名:" + ScheduleItem.Movie.MovieName);
            sb.AppendLine("時間:" + ScheduleItem.Time);
            string text = Seat.SeatNum.Remove(0, Seat.SeatNum.Length - 3);
            sb.AppendLine("座位號:" + text);
            sb.AppendLine("價格:" + CalcPrice());
            sb.AppendLine("*****************************************");
            sb.AppendLine("\t  " + "(a)贈票");
            return sb.ToString();
        }

    }
}

學生票類:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Theater_Ticket_Selling_System
{
    /// <summary>
    /// 學生票(子類)
    /// 保存特殊的學生票信息
    /// </summary>
    public class StudentTicket : Ticket
    {
        //學生折扣
        private int discount;

        public StudentTicket()
        {
        }

        public StudentTicket(ScheduleItem scheduleItem, Seat seat, int price, int discount) : base(scheduleItem, seat, price)
        {
            this.Discount = discount;
        }

        public int Discount { get => discount; set => discount = value; }

        //計算票價
        public override double CalcPrice()
        {
            return Price * Discount/10;
        }

        //列印售票信息
        public override void Print()
        {
            base.Print();
        }

        //顯示當前出票信息
        public override string Show()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("*****************************************");
            sb.AppendLine("\t  " + "青鳥影院(學生票)");
            sb.AppendLine("-----------------------------------------");
            sb.AppendLine("電影名:" + ScheduleItem.Movie.MovieName);
            sb.AppendLine("時間:" + ScheduleItem.Time);
            string text = Seat.SeatNum.Remove(0, Seat.SeatNum.Length - 3);
            sb.AppendLine("座位號:" + text);
            sb.AppendLine("價格:" + CalcPrice());
            sb.AppendLine("*****************************************");
            sb.AppendLine("\t  " + "(a)學生票");
            return sb.ToString();
        }
    }
}

電影類:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Theater_Ticket_Selling_System
{
    /// <summary>
    /// 電影類
    /// </summary>
    [Serializable]
    public class Movie
    {
        //電影名
        private string movieName;

        //海報圖片名
        private string poster;

        //導演名
        private string director;

        //主演
        private string actor;

        //電影類型
        private MovieType movieType;

        //定價
        private int price;

        public Movie()
        {
        }

        public Movie(string movieName, string poster, string director, string actor, MovieType movieType, int price)
        {
            MovieName = movieName;
            Poster = poster;
            Director = director;
            Actor = actor;
            MovieType = movieType;
            Price = price;
        }

        public string MovieName { get => movieName; set => movieName = value; }
        public string Poster { get => poster; set => poster = value; }
        public string Director { get => director; set => director = value; }
        public string Actor { get => actor; set => actor = value; }
        public MovieType MovieType { get => movieType; set => movieType = value; }
        public int Price { get => price; set => price = value; }
    }
}

電影類型類(枚舉):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Theater_Ticket_Selling_System
{
    /// <summary>
    /// 電影類型
    /// </summary>
    public enum MovieType
    {
        //喜劇片
        Comedy,
        //戰爭片
        War,
        //浪漫片
        Romance,
        //動作片
        Action,
        //卡通片
        Cartoon,
        //驚悚片
        Thriller,
        //冒險
        Adventure
    }
}

放映計劃類:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace Theater_Ticket_Selling_System
{
    /// <summary>
    /// 放映計劃
    /// 保存影院當天的放映計劃集合
    /// </summary>
    [Serializable]

    public class Schedule
    {
        //放映場次
        private Dictionary<string, ScheduleItem> item;

        public Dictionary<string, ScheduleItem> Item { get => item; set => item = value; }

        public Schedule()
        {
            Item = new Dictionary<string, ScheduleItem>();
        }

        public Schedule(Dictionary<string, ScheduleItem> item)
        {
            Item = item;
        }

        //讀取XML文件
        public void LoadItems()
        {
            XmlDocument doc = new XmlDocument();
            doc.Load("ShowList.xml");
            XmlNode xml = doc.DocumentElement;
            ScheduleItem scheduleItem = null;
            foreach (XmlNode item in xml.ChildNodes)
            {
                Movie movie = new Movie();
                movie.MovieName = item["Name"].InnerText;
                movie.Poster = item["Poster"].InnerText;
                movie.Director = item["Director"].InnerText;
                movie.Actor = item["Actor"].InnerText;
                movie.MovieType = (MovieType)Enum.Parse(typeof(MovieType), item["Type"].InnerText);
                movie.Price = Convert.ToInt32(item["Price"].InnerText);
                foreach (XmlNode items in item["Schedule"].ChildNodes)
                {
                    scheduleItem = new ScheduleItem();
                    scheduleItem.Movie = movie;
                    scheduleItem.Time = items.InnerText;
                    Item.Add(scheduleItem.Time, scheduleItem);
                }
            }
        }
    }
}

座位類:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;

namespace Theater_Ticket_Selling_System
{
    /// <summary>
    /// 保存影院座位信息
    /// </summary>
    [Serializable]
    public class Seat
    {
        //座位號
        private string seatNum;

        //座位賣出狀態顏色
        private Color color;

        public Seat()
        {
        }

        public Seat(string seatNum, Color color)
        {
            SeatNum = seatNum;
            Color = color;
        }

        public string SeatNum { get => seatNum; set => seatNum = value; }
        public Color Color { get => color; set => color = value; }
    }
}

工具類(設計模式:簡單工廠):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Theater_Ticket_Selling_System
{
    /// <summary>
    /// 工具類
    /// 根據輸入的值,判斷創建不同的電影票對象
    /// </summary>
    public class TicketTtil
    {
        public static Ticket CreateTicket(string type)
        {
            Ticket ticket = null;
            switch (type)
            {
                case "贈票":
                    ticket = new FreeTicket();
                    break;
                case "學生票":
                    ticket = new StudentTicket();
                    break;
                default:
                    ticket = new Ticket();
                    break;
            }
            return ticket;
        }
    }
}

主窗體類:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace Theater_Ticket_Selling_System
{
    /// <summary>
    /// 影院售票系統
    /// </summary>
    public partial class FrmMain : Form
    {
        public FrmMain()
        {
            InitializeComponent();
        }
        //實例化影院類(所有存儲都是以影院類為基礎)
        Cinema cinema = new Cinema();
        //保存已售座位
        Dictionary<string, Cinema> dictionary = new Dictionary<string, Cinema>();
        //存儲所有lable控制項信息(方便改變控制項狀態)
        Dictionary<string, Label> labels = new Dictionary<string, Label>();


        //清空所有控制項
        public void Information_Emptying()
        {
            lblName.Text = null;
            lblDirector.Text = null;
            lblActor.Text = null;
            lblType.Text = null;
            lblTime.Text = null;
            lblPrice.Text = null;
            lblCalcPrice.Text = null;
            picMovie.Image = null;
        }

        //選中影片場次時,對所有控制項賦相應的值,顯示影片信息
        public void Information_Filling()
        {
            ScheduleItem schedule = (ScheduleItem)tvMovies.SelectedNode.Tag;
            lblName.Text = schedule.Movie.MovieName;
            lblDirector.Text = schedule.Movie.Director;
            lblActor.Text = schedule.Movie.Actor;
            lblType.Text = schedule.Movie.MovieType.ToString();
            lblTime.Text = tvMovies.SelectedNode.Text;
            lblPrice.Text = schedule.Movie.Price.ToString();
            lblCalcPrice.Text = schedule.Movie.Price.ToString();
            picMovie.Image = Image.FromFile(schedule.Movie.Poster);
        }

        private void FrmMain_Load(object sender, EventArgs e)
        {
            Information_Emptying();
            Butten();
        }
        
        //為TreeView控制項動態賦值
        public void AddTree()
        {
            tvMovies.BeginUpdate();
            tvMovies.Nodes.Clear();
            TreeNode treeNode = null;
            string movieName = null;
            foreach (KeyValuePair<string, ScheduleItem> item in cinema.Schedule.Item)
            {
                if (movieName != item.Value.Movie.MovieName)
                {
                    treeNode = new TreeNode();
                    treeNode.Text = item.Value.Movie.MovieName;
                    treeNode.Tag = null;
                    tvMovies.Nodes.Add(treeNode);
                }
                TreeNode tree = new TreeNode();
                tree.Text = item.Key;
                tree.Tag = item.Value;
                treeNode.Nodes.Add(tree);
                movieName = item.Value.Movie.MovieName;
            }
            tvMovies.EndUpdate();
        }

        //動態綁定所有lable控制項
        public void Butten()
        {
            cinema.Seats.Clear();
            labels.Clear();
            tpCinema.Controls.Clear();
            Seat seat = null;
            Label label = null;
            int seatRow = 7;
            int seatLine = 5;
            for (int i = 0; i < seatRow; i++)
            {
                for (int j = 0; j < seatLine; j++)
                {
                    label = new Label();
                    label.BackColor = Color.Yellow;
                    label.Font = new Font("宋體", 14.25F, FontStyle.Regular, GraphicsUnit.Point, ((byte)134));
                    label.AutoSize = false;
                    label.Size = new Size(50, 25);
                    label.Text = (j + 1).ToString() + "-" + (i + 1).ToString();
                    label.TextAlign = ContentAlignment.MiddleCenter;
                    label.Location = new Point(60 + (i * 90), 60 + (j * 60));
                    label.Click += new EventHandler(lblSeat_Click);
                    labels.Add(label.Text, label);
                    tpCinema.Controls.Add(labels[label.Text]);
                    seat = new Seat(label.Text, Color.Yellow);
                    cinema.Seats.Add(seat.SeatNum, seat);
                }
            }

        }

        //當確認買票時為已售票集合添加相應場次,座位的信息
        public void AddSold(object sender)
        {
            Label label = (Label)sender;
            Ticket ticket = TicketTtil.CreateTicket(tvMovies.SelectedNode.Parent.Text);
            ticket.ScheduleItem = (ScheduleItem)tvMovies.SelectedNode.Tag;
            ticket.Seat = cinema.Seats[label.Text];
            ticket.Seat.Color = Color.Red;
            ticket.Price = Convert.ToInt32(this.lblCalcPrice.Text);
            dictionary[tvMovies.SelectedNode.Text].SoldTickets.Add(ticket);
        }


        private void lblSeat_Click(object sender, EventArgs e)
        {
            if (!Not_Null())
            {
                return;
            }
            string print = Print(sender);
            if (string.IsNullOrEmpty(print))
            {
                return;
            }
            MessageBox.Show(print);
        }
        public string Print(object sender)
        {
            /*
             * 買票
             * */
            Label label = (Label)sender;
            if (label.BackColor == Color.Red)
            {
                MessageBox.Show("已售!");
                return null;
            }

            DialogResult result = MessageBox.Show("是否購買?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
            if (result == DialogResult.No)
            {
                return null;
            }
            AddSold(sender);
            Change_Color();
            UpdateSeat();
            MessageBox.Show("購買成功!");
            Ticket ticket = Chose_Rdo();

            ticket.ScheduleItem = cinema.Schedule.Item[tvMovies.SelectedNode.Text];
            ticket.Seat = cinema.Seats[label.Text];
            ticket.Price = cinema.Schedule.Item[tvMovies.SelectedNode.Text].Movie.Price;

            /*
             * 在電腦硬碟記憶體儲已買座位的小票(方便列印)
             * */
            string time = (ticket.ScheduleItem.Time).Replace(':', '-');
            string num = ticket.Seat.SeatNum;
            string PrintStr = ticket.Show();
            string nowTime = (DateTime.Now.ToShortDateString().ToString()).Replace(':', '-').Replace('/', '-');
            string path = "Ticket\\" + nowTime + " ^ " + time + " " + num + ".txt";
            FileStream fs = new FileStream(path, FileMode.Create);
            StreamWriter sw = new StreamWriter(fs);
            sw.Write(PrintStr);
            sw.Close();
            fs.Close();
            return PrintStr;
        }
        
        /*
         * 遍歷已售票集合與座位集合,,將已售出的相應座位標記到座位集合中
         * */
        public void Change_Color()
        {
            string key = this.tvMovies.SelectedNode.Text;
            foreach (Ticket item in dictionary[tvMovies.SelectedNode.Text].SoldTickets)
            {
                foreach (Seat items in cinema.Seats.Values)
                {
                    if (item.ScheduleItem.Time == key && item.Seat.SeatNum == items.SeatNum)
                    {
                        /*
                         * 這裡將Color屬性賦值為Red作為已售出的座位
                         * */
                        //MessageBox.Show("Test");
                        items.Color = Color.Red;
                    }
                }
            }
        }

        //遍歷座位集合。。為控制項改變狀態,表示此座位已售出,(方便用戶)
        public void UpdateSeat()
        {
            foreach (string key in cinema.Seats.Keys)
            {
                labels[key].BackColor = cinema.Seats[key].Color;
            }
        }

        /*
         * 買票時要作出的相應的非空判斷
         * */
        public bool Not_Null()
        {
            if (tvMovies.SelectedNode == null)
            {
                MessageBox.Show("請選擇影片");
                return false;
            }

            if (tvMovies.SelectedNode.Tag == null)
            {
                MessageBox.Show("請選擇影片放映時間");
                return false	   

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 當我們使用properties文件作為Spring Boot的配置文件而不是yaml文件時,怎樣實現多環境使用不同的配置信息呢? 在Spring Boot中,多環境配置的文件名需要滿足application-{profile}.properties的格式,其中{profile}對應你的環境標識,如下 ...
  • 最近打算將之前學習過的小練習分享出來,算是鞏固知識。雖然是小練習,但是越看越覺得有趣,溫故而知新。 練習:功能跳水比賽,8個評委評分。運動員成績去掉最高和最低之後的平均分 代碼實例: 1.導包 2.測試類 3.Judge類(封裝方法,很好的面向對象編程) 另外,最近覺得泛型真的是一個很神奇的存在。設 ...
  • 註:練習題目均出自《明解C語言 入門篇》 一、do語句 1,求多個整數的和及平均值 二、whie語句 1,遞增顯示從0到輸入的正整數為止的各個整數 2,編寫一段程式,按照升序顯示出小於輸入值的所有正偶數 3,編寫一段程式,使之交替顯示+和-,總個數等於所輸入的整數值 4,逆向顯示正整數 三、for語 ...
  • 1、匿名函數 一般的屌絲函數是這樣定義的 而匿名函數是這樣的 使用匿名函數的好處 1、可以使函數更加簡潔 2、無需考慮命名,不用為孩子起名字絞盡腦汁了哈哈哈哈哈 3、簡化代碼,提高代碼的可讀性 2、兩個常用的內置函數 1)filter(參數1,參數2) 參數2帶入參數1中計算如果為真最後返回輸出為真 ...
  • 欄位 一個模型最重要也是唯一必需的部分,是它定義的資料庫欄位 欄位名稱限制 1、欄位名不能是pythohn保留字,這樣會導致python語法錯誤 2、欄位不能包含連續一個以上的下劃線,這樣會和Django查詢語句語法衝突 資料庫列的類型 AutoField 指一個能夠根據可用ID自增的 Intege ...
  • 1、global 關鍵字 如果在函數內部需要修改全局變數那麼需要使用global關鍵字 2、內嵌函數(內部函數) 內部函數的的作用域在外部函數作用於之內,及只能在外部函數內調用內部函數 3、閉包(closure) 在內部函數中只能對外部函數的局部變數進行訪問,但是不能修改,如果需要修改則需要用到no ...
  • 產生野指針原因的本質:指針變數和它所指記憶體空間變數是兩個不同的概念。 解決辦法:三步曲 1、定義指針時,把指針變數賦值成NULL 2、釋放記憶體時,先判斷指針變數是否為NULL 3、釋放完記憶體後,把指針變數重新複製成NUL #define _CRT_SECURE_NO_WARNINGS #includ ...
  • 在整理自己的代碼的時候,考慮到我寫的代碼從一至終都是在一個cpp文件裡面。於是,想把自己的代碼中的各個模塊分離開來,以便更好地閱讀和管理。可在分離的時候出現了xxx變數已經在*.obj中定義的問題,即我定義的全局變數出現了重覆定義的現象。深究編譯鏈接的過程,發現static關鍵字的方法不可行,唯獨好... ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...