TaiZhouChangChu/Assets/Script/Task.cs

190 lines
7.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
public class Task : MonoBehaviour
{
public int Mode;//模式 0引导 1操作 2考核
public int Course;//
public Text Text_Task, Text_Task_Smail;//任务
int i;
DateTime dtNow;
//
//数据库
SqlConnection sqlCon;
SqlCommand sqlComm;
SqlDataAdapter sqlAdapter;
SqlDataReader sqlReader;
string sqlStr;
string Str_ServerIP, Str_DataBase, Str_ServerId, Str_ServerPwd;
void Start()
{
//数据
Str_ServerIP = PlayerPrefs.GetString("ServerIP", "192.168.1.1").Trim();
Str_DataBase = PlayerPrefs.GetString("DataBase", "ChengJiChaXun").Trim();
Str_ServerId = PlayerPrefs.GetString("ServerId", "sa").Trim();
Str_ServerPwd = PlayerPrefs.GetString("ServerPwd", "147258").Trim();
sqlCon = new SqlConnection(@"server=" + Str_ServerIP + ";database=" + Str_DataBase + ";uid=" + Str_ServerId + ";pwd=" + Str_ServerPwd);
//
Mode = PlayerPrefs.GetInt("Mode", 0);
dtNow = DateTime.Now;
//引导/操作
if (Mode < 2)
{
Course = PlayerPrefs.GetInt("Course", 0);
if (CourceAlert[Course] != null)
CourceAlert[Course].SetActive(true);//引导点击提示
CargoCount = UnityEngine.Random.Range(2, 6);//随机数量2-5
CargoChoose = UnityEngine.Random.Range(0, Cargos.Length);//随机货物
}
else//考核--从服务器读取数据
{
//sqlStr = "SELECT * FROM ExamSet_Operation WHERE id='1'";
//sqlComm = new SqlCommand(sqlStr, sqlCon);
//sqlCon.Open();
//sqlReader = sqlComm.ExecuteReader();
//if (sqlReader.Read())
//{
// if (sqlReader["CargoName"].ToString().Trim() == "变压器")
// CargoChoose = 0;
// else
// CargoChoose = 1;
// CargoCount = int.Parse(sqlReader["CargoCount"].ToString().Trim());
// Course = int.Parse(sqlReader["Kind"].ToString().Trim());
// //["LimitTime"].ToString();
//}
//sqlReader.Close();
//sqlCon.Close();
CargoCount = 5;
Course = 0;
}
CompanyChoose = UnityEngine.Random.Range(0, Companys.Length);//随机公司
DriverChoose = UnityEngine.Random.Range(0, Drivers.Length);//随机姓名
Text_Task.text = "  今天是<color='#F00'>" + dtNow.Year.ToString() + "年" + dtNow.Month.ToString() + "月" + dtNow.Day.ToString() + "日</color>";
Text_Task.text += "一辆来自<color='#F00'>" + Companys[CompanyChoose] + "</color>的货车,车牌号:<color='#F00'>" + Cars[DriverChoose] + "</color>,装载<color='#F00'>" + CargoCount.ToString() + "</color>件<color='#F00'>" + Cargos[CargoChoose] + "</color>";
Text_Task.text += "已到达仓库大门,业务单号:<color='#F00'>" + 20200122 + "</color>,司机是<color='#F00'>" + Drivers[DriverChoose] + "师傅</color>,联系电话:<color='#F00'>" + Phones[DriverChoose] + "</color>,请为其办理<color='#F00'>" + Courses[Course] + "</color>。";
Text_Task_Smail.text = Text_Task.text;
//货物准备
if (CargoChoose == 0)//变压器
{
for (i = 0; i < CargoCount; i++)
{
Objs_BYQ_InCar[i].SetActive(true);//装车状态
Objs_BYQ_Discharge[i].SetActive(true);//卸货状态
}
}
else if (CargoChoose == 1)//电缆
{
for (i = 0; i < CargoCount; i++)
{
Objs_DL_InCar[i].SetActive(true);//装车状态
Objs_DL_Discharge[i].SetActive(true);//卸货状态
}
}
else
{ }
Car_Out.SetActive(true);//场外汽车显示
}
int CargoCount;//随机货物数量
int CargoChoose;//货物类型
string[] Cargos = new string[2] { "变压器", "电缆" };
public GameObject Car_Out, Car_In;//场内 场外
public GameObject[] Objs_BYQ_InCar;//变压器(装车状态)
public GameObject[] Objs_BYQ_Discharge;//变压器(卸货状态)
public GameObject[] Objs_DL_InCar;//电缆(装车状态)
public GameObject[] Objs_DL_Discharge;//电缆(卸货状态)
//任务名称
public string[] Courses = new string[9] { "采购物资入库", "调拨物资入库", "工程结余物资入库", "可用退役代保管入库", "借用物资归还", "废旧物资入库", "委托代保管物资入库", "寄存物资入库", "抽检样品返库" };
public GameObject[] CourceAlert;//点击提示
public int InputKind;//输入的类型
public void SelectKind(int sKind)//输入的类型
{
InputKind = sKind;
}
//公司名称
int CompanyChoose;//选中的
string[] Companys = new string[22]
{
"江苏联坚机电设备有限公司",
"江苏亿科商业贸易有限公司",
"江苏优永机电设备有限公司",
"上海福吉电器有限公司",
"上海中飞电力科技有限公司",
"上海正贸精密设备科技有限公司",
"浙江辉优机电科技有限公司",
"浙江尚益信息科技有限公司",
"浙江吉展机电设备有限公司",
"福建圣克商业贸易有限公司",
"福建百格电力科技有限公司",
"福建益思信息科技有限公司",
"江西艾友贸易有限公司",
"江西华源电器有限公司",
"江西升永贸易有限公司",
"安徽亚西精密设备科技有限公司",
"安徽特佳贸易有限公司",
"安徽时久电器有限公司",
"山东航磊电力科技有限公司",
"山东益宝机电科技有限公司",
"山东汇美信息科技有限公司",
"山东领建机电科技有限公司"
};
int DriverChoose;//选中的
string[] Drivers = new string[22] { "李","王","张","刘","陈","杨","赵","黄","周","吴","徐","孙","胡","朱","高","林","何","郭","罗","宋","郑","冯" };
string[] Phones = new string[22]
{
"13854695242",
"13765249657",
"18369874566",
"18103660154",
"15947785520",
"15766932085",
"15325475877",
"13965663011",
"13745896540",
"13165142239",
"13544126996",
"13630258754",
"13966302987",
"15265483674",
"15965854456",
"18048456876",
"18365645641",
"18265654263",
"18526456524",
"15846544216",
"15896245445",
"13845647454"
};
string[] Cars = new string[22]
{
"苏AD653E",
"苏CS4722",
"苏B65T23",
"沪A78545",
"沪BF9638",
"沪CK2P5D",
"浙A6K354",
"浙BS8546",
"浙C59W4",
"闽A4G789",
"闽B66984",
"闽C4578D",
"赣B4V752",
"赣C46467",
"赣D98E48",
"皖F46S54",
"皖A69877",
"皖M465E3",
"鲁D3U545",
"鲁F8E532",
"鲁E47652",
"鲁D94S08"
};
}