此前我们创建了员工表,现在我们要根据员工表中的权限,来创建权限表,用来储存不同权限可以做的事情。
如图,我们先创建一个空的WorkPanel当做工作区,在创建一个titlepanel存放权限所带来的功能按键。
代码如下:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using UnityEngine;
using UnityEngine.UI;
public class WorkSpace : MonoBehaviour {
public GameObject FatherPanel;
public GameObject TitlePanel;
LoginBtn logid;
string Error;
List whatcanido;
// Use this for initialization
void Start () {
logid = GameObject.Find("Canvas").GetComponent();
whatcanido = new List();
Swap();
}
///
/// 卵生功能----读取功能list
///
public void Swap()
{
try
{
SqlserverManager sql2 = new SqlserverManager();
DataSet ds2 = sql2.SelectWhere("JurisdictionTables", new string[] { "ROOT","Sell","CheckNum","Buy" }, new string[] { "Jurisdiction" }, new string[] { "=" }, new string[] { logid.myjurisdiction.ToString() });
if (ds2 != null)
{
DataTable table2 = ds2.Tables[0];
foreach (DataRow row2 in table2.Rows)
{
foreach (DataColumn column2 in table2.Columns)
{
Debug.Log(row2[column2]);
whatcanido.Add((bool)row2[column2]);
}
}
if(whatcanido[0])
{
GameObject obj = Resources.Load("ROOT") as GameObject;
GameObject root = Instantiate(obj, TitlePanel.transform);
root.GetComponent
这样,我们完成了老板权限,与进货功能界面的实现。
下面是售货与查业绩界面:
//售货
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using UnityEngine;
using UnityEngine.UI;
public class ShowDrugs : MonoBehaviour {
public List drugrows;
List drugcolumn = new List();
string[] array;
LoginBtn logid;
public InputField whatdoiwanttoselect;
public InputField whatdoiwanttoselect1;
//drug父节点
public GameObject FatherPanel;
//IP列表
public Dropdown Howcaniselect;
//显示选择的内容
public Text Text_Howcaniselect;
public Text whicthpage;
public int page;
public int maxpage;
//存储Dropdown 控件中的内容,为删除使用
private Dictionary _DicDropDown;
private string Error;
void Start()
{
logid = GameObject.Find("Canvas").GetComponent();
_DicDropDown = new Dictionary();
//清空默认节点
Howcaniselect.options.Clear();
//初始化
Dropdown.OptionData op1 = new Dropdown.OptionData();
op1.text = "药品编号";
Howcaniselect.options.Add(op1);
Dropdown.OptionData op2 = new Dropdown.OptionData();
op2.text = "药品名称";
Howcaniselect.options.Add(op2);
Dropdown.OptionData op3 = new Dropdown.OptionData();
op3.text = "药品价格区间";
Howcaniselect.options.Add(op3);
Text_Howcaniselect.text = op1.text;
//初始化节点暂存集合中。
_DicDropDown.Add(op1.text, op1);
_DicDropDown.Add(op2.text, op2);
_DicDropDown.Add(op3.text, op3);
Selectinfo();
}
public void SelectOnClick()
{
drugcolumn.Clear();
string str = Text_Howcaniselect.text;
switch (str)
{
case "药品编号":
{
try
{
string s = "%%" + whatdoiwanttoselect.text + "%%";
SqlserverManager sql1 = new SqlserverManager();
DataSet ds1 = sql1.SelectWhere("DrugTables", new string[] { "No", "Name", "Count", "Price" }, new string[] { "No" }, new string[] { " Like " }, new string[] { s });
if (ds1 != null)
{
Debug.Log("1");
DataTable table = ds1.Tables[0];
for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
{
for (int j = 0; j < ds1.Tables[0].Columns.Count; j++)
{
print(ds1.Tables[0].Rows[i][j].ToString());
drugcolumn.Add(ds1.Tables[0].Rows[i][j].ToString());
}
}
page = 1;
maxpage = (drugcolumn.Count % 32 == 0) ? (drugcolumn.Count / 32) : ((drugcolumn.Count / 32) + 1);
Debug.Log(maxpage);
Show(page, maxpage);
}
else
{
Debug.Log("账号不存在");
logid.ShowMistake("数据库异常", AddWorkerBack);
//报错窗口
}
}
catch (Exception e)
{
Error = e.Message;
logid.ShowMistake(Error, AddWorkerBack);
}
break;
}
case "药品名称":
{
Debug.Log("2");
try
{
string s = "%%" + whatdoiwanttoselect.text + "%%";
SqlserverManager sql2 = new SqlserverManager();
DataSet ds2 = sql2.SelectWhere("DrugTables", new string[] { "No", "Name", "Count", "Price" }, new string[] { "Name" }, new string[] { " Like " }, new string[] { s });
if (ds2 != null)
{
DataTable table = ds2.Tables[0];
for (int i = 0; i < ds2.Tables[0].Rows.Count; i++)
{
for (int j = 0; j < ds2.Tables[0].Columns.Count; j++)
{
drugcolumn.Add(ds2.Tables[0].Rows[i][j].ToString());
}
}
page = 1;
maxpage = (drugcolumn.Count % 32 == 0) ? (drugcolumn.Count / 32) : ((drugcolumn.Count / 32) + 1);
Debug.Log(maxpage);
Show(page, maxpage);
}
else
{
Debug.Log("账号不存在");
logid.ShowMistake("数据库异常", AddWorkerBack);
//报错窗口
}
}
catch (Exception e)
{
Error = e.Message;
logid.ShowMistake(Error, AddWorkerBack);
}
break;
}
case "药品价格区间":
{
Debug.Log(float.Parse(whatdoiwanttoselect.text));
if (float.Parse(whatdoiwanttoselect.text) > float.Parse(whatdoiwanttoselect1.text))
logid.ShowMistake("价格区间输入有误", Priceback);
else
{
try
{
SqlserverManager sql3 = new SqlserverManager();
DataSet ds3 = sql3.SelectWhere("DrugTables", new string[] { "No", "Name", "Count", "Price" }, new string[] { "Price", "Price" }, new string[] { ">=", "<=" }, new string[] { whatdoiwanttoselect.text, whatdoiwanttoselect1.text });
if (ds3 != null)
{
DataTable table = ds3.Tables[0];
for (int i = 0; i < ds3.Tables[0].Rows.Count; i++)
{
for (int j = 0; j < ds3.Tables[0].Columns.Count; j++)
{
drugcolumn.Add(ds3.Tables[0].Rows[i][j].ToString());
}
}
page = 1;
maxpage = (drugcolumn.Count % 32 == 0) ? (drugcolumn.Count / 32) : ((drugcolumn.Count / 32) + 1);
Debug.Log(maxpage);
Show(page, maxpage);
}
else
{
Debug.Log("账号不存在");
logid.ShowMistake("数据库异常", AddWorkerBack);
//报错窗口
}
}
catch (Exception e)
{
Error = e.Message;
logid.ShowMistake(Error, AddWorkerBack);
}
}
break;
}
}
}
///
/// 获取当前节点
///
public void GetCurrentNode()
{
Text_Howcaniselect.text = Howcaniselect.options[Howcaniselect.value].text;
}
///
/// 删除节点
///
public void RemoveNode(string key)
{
//Drd_IPList.options.Remove(); //必须删除“OptionDate 类型”
if (_DicDropDown.ContainsKey(key))
{
Howcaniselect.options.Remove(_DicDropDown[key]);
}
}
// Update is called once per frame
void Selectinfo()
{
drugcolumn.Clear();
try
{
SqlserverManager sql = new SqlserverManager();
DataSet ds = sql.SelectWhere("DrugTables", new string[] { "No","Name","Count","Price" });
if (ds != null)
{
DataTable table = ds.Tables[0];
for(int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
{
drugcolumn.Add(ds.Tables[0].Rows[i][j].ToString());
}
}
//foreach (DataRow row in table.Rows)
//{
// //foreach (DataColumn column in table.Columns)
// //{
// // drugcolumn.Add(row[column].ToString());
// //}
//}
page = 1;
maxpage = (drugcolumn.Count % 32 == 0)?(drugcolumn.Count/32): ((drugcolumn.Count / 32)+1);
Show(page, maxpage);
}
else
{
Debug.Log("账号不存在");
logid.ShowMistake("数据库异常", AddWorkerBack);
//报错窗口
}
}
catch (Exception e)
{
Error = e.Message;
logid.ShowMistake(Error, AddWorkerBack);
}
}
public void Show(int p,int maxp)
{
int childcount = FatherPanel.transform.childCount;
for (int i = childcount-1; i>=0; i--)
{
Destroy(FatherPanel.transform.GetChild(i).gameObject);
}
childcount = FatherPanel.transform.childCount;
if (maxp > 0)
{
for (int a = p * 32 - 32; a < p * 32; a = a + 4)
{
if (a >= drugcolumn.Count)
break;
GameObject obj = Resources.Load("Drug") as GameObject;
GameObject root = Instantiate(obj, FatherPanel.transform);
root.GetComponent().id.text = drugcolumn[a];
root.GetComponent().drugname.text = drugcolumn[a + 1];
root.GetComponent().count.text = drugcolumn[a + 2];
root.GetComponent().price.text = drugcolumn[a + 3];
// root.GetComponent().id.text = drugrow[a][0];
// root.GetComponent().drugname.text = drugrow[a][1];
// root.GetComponent().count.text = drugrow[a][2];
// root.GetComponent().price.text = drugrow[a][3];
}
}
}
public void LastPageOnClick()
{
if(page > 1)
{
page--;
Show(page, maxpage);
}
}
public void NextPageOnClick()
{
if (page < maxpage)
{
page++;
Show(page, maxpage);
}
}
private void Update()
{
if (Text_Howcaniselect.text == "药品价格区间")
{
whatdoiwanttoselect1.gameObject.SetActive(true);
}
else
whatdoiwanttoselect1.gameObject.SetActive(false);
whicthpage.text = "第" + page.ToString() + "页/第" + maxpage.ToString() + "页";
}
void rewrite()
{
Destroy(transform.gameObject);
logid.warning.SetActive(false);
}
void reprice()
{
whatdoiwanttoselect.text = whatdoiwanttoselect1.text = string.Empty;
logid.warning.SetActive(false);
}
void Priceback()
{
logid.back.onClick.AddListener(reprice);
}
void AddWorkerBack()
{
logid.back.onClick.AddListener(rewrite);
}
}
//看交易记录
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using UnityEngine;
using UnityEngine.UI;
public class ShowCheck : MonoBehaviour
{
LoginBtn logid;
public List drugrows;
List drugcolumn = new List();
public InputField whatdoiwanttoselect;
public InputField whatdoiwanttoselect1;
//drug父节点
public GameObject FatherPanel;
//IP列表
public Dropdown Howcaniselect;
//显示选择的内容
public Text Text_Howcaniselect;
public Text whicthpage;
//存储Dropdown 控件中的内容,为删除使用
private Dictionary _DicDropDown;
private int page;
private int maxpage;
private string Error;
void Start()
{
logid = GameObject.Find("Canvas").GetComponent();
_DicDropDown = new Dictionary();
//清空默认节点
Howcaniselect.options.Clear();
//初始化
Dropdown.OptionData op1 = new Dropdown.OptionData();
op1.text = "药品编号";
Howcaniselect.options.Add(op1);
Dropdown.OptionData op2 = new Dropdown.OptionData();
op2.text = "员工姓名";
Howcaniselect.options.Add(op2);
Dropdown.OptionData op3 = new Dropdown.OptionData();
op3.text = "时间区间(日)";
Howcaniselect.options.Add(op3);
Text_Howcaniselect.text = op1.text;
//初始化节点暂存集合中。
_DicDropDown.Add(op1.text, op1);
_DicDropDown.Add(op2.text, op2);
_DicDropDown.Add(op3.text, op3);
Selectinfo();
}
public void SelectOnClick()
{
drugcolumn.Clear();
string str = Text_Howcaniselect.text;
switch (str)
{
case "药品编号":
{
try
{
string s = "%%" + whatdoiwanttoselect.text + "%%";
SqlserverManager sql1 = new SqlserverManager();
DataSet ds1 = sql1.SelectWhere("DetailTables", new string[] { "No", "Name", "Count", "Id", "YuangongName", "Selltime" }, new string[] { "No" }, new string[] { " Like " }, new string[] { s });
if (ds1 != null)
{
Debug.Log("1");
DataTable table = ds1.Tables[0];
for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
{
for (int j = 0; j < ds1.Tables[0].Columns.Count; j++)
{
print(ds1.Tables[0].Rows[i][j].ToString());
drugcolumn.Add(ds1.Tables[0].Rows[i][j].ToString());
}
}
page = 1;
maxpage = (drugcolumn.Count % 48 == 0) ? (drugcolumn.Count / 48) : ((drugcolumn.Count / 48) + 1);
Show(page, maxpage);
}
else
{
logid.ShowMistake("数据库异常", AddWorkerBack);
//报错窗口
}
}
catch (Exception e)
{
Error = e.Message;
logid.ShowMistake(Error, AddWorkerBack);
}
break;
}
case "员工姓名":
{
try
{
string s = "%%" + whatdoiwanttoselect.text + "%%";
SqlserverManager sql2 = new SqlserverManager();
DataSet ds2 = sql2.SelectWhere("DetailTables", new string[] { "No", "Name", "Count", "Id", "YuangongName", "Selltime" }, new string[] { "YuangongName" }, new string[] { " Like " }, new string[] { s });
if (ds2 != null)
{
DataTable table = ds2.Tables[0];
for (int i = 0; i < ds2.Tables[0].Rows.Count; i++)
{
for (int j = 0; j < ds2.Tables[0].Columns.Count; j++)
{
drugcolumn.Add(ds2.Tables[0].Rows[i][j].ToString());
}
}
page = 1;
maxpage = (drugcolumn.Count % 48 == 0) ? (drugcolumn.Count / 48) : ((drugcolumn.Count / 48) + 1);
Show(page, maxpage);
}
else
{
logid.ShowMistake("数据库异常", AddWorkerBack);
//报错窗口
}
}
catch (Exception e)
{
Error = e.Message;
logid.ShowMistake(Error, AddWorkerBack);
}
break;
}
case "时间区间(日)":
{
DateTime time1 = Convert.ToDateTime(whatdoiwanttoselect.text);
DateTime time2 = Convert.ToDateTime(whatdoiwanttoselect1.text);
if (time1 > time2)
logid.ShowMistake("时间区间输入有误", TimeBack);
else
{
try
{
SqlserverManager sql3 = new SqlserverManager();
DataSet ds3 = sql3.SelectBetween("DetailTables", new string[] { "No", "Name", "Count", "Id", "YuangongName", "Selltime" }, "Selltime" , whatdoiwanttoselect.text, whatdoiwanttoselect1.text );
if (ds3 != null)
{
DataTable table = ds3.Tables[0];
for (int i = 0; i < ds3.Tables[0].Rows.Count; i++)
{
for (int j = 0; j < ds3.Tables[0].Columns.Count; j++)
{
drugcolumn.Add(ds3.Tables[0].Rows[i][j].ToString());
}
}
page = 1;
maxpage = (drugcolumn.Count % 48 == 0) ? (drugcolumn.Count / 48) : ((drugcolumn.Count / 48) + 1);
Show(page, maxpage);
}
else
{
Debug.Log("账号不存在");
logid.ShowMistake("数据库异常", AddWorkerBack);
//报错窗口
}
}
catch (Exception e)
{
Error = e.Message;
logid.ShowMistake(Error, AddWorkerBack);
}
}
break;
}
}
}
///
/// 获取当前节点
///
public void GetCurrentNode()
{
Text_Howcaniselect.text = Howcaniselect.options[Howcaniselect.value].text;
}
///
/// 删除节点
///
public void RemoveNode(string key)
{
//Drd_IPList.options.Remove(); //必须删除“OptionDate 类型”
if (_DicDropDown.ContainsKey(key))
{
Howcaniselect.options.Remove(_DicDropDown[key]);
}
}
// Update is called once per frame
void Selectinfo()
{
drugcolumn.Clear();
try
{
SqlserverManager sql = new SqlserverManager();
DataSet ds = sql.SelectWhere("DetailTables", new string[] { "No", "Name", "Count", "Id", "YuangongName", "Selltime" });
if (ds != null)
{
DataTable table = ds.Tables[0];
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
{
drugcolumn.Add(ds.Tables[0].Rows[i][j].ToString());
}
}
//foreach (DataRow row in table.Rows)
//{
// //foreach (DataColumn column in table.Columns)
// //{
// // drugcolumn.Add(row[column].ToString());
// //}
//}
page = 1;
maxpage = (drugcolumn.Count % 48 == 0) ? (drugcolumn.Count / 48) : ((drugcolumn.Count / 48) + 1);
Show(page, maxpage);
}
else
{
Debug.Log("账号不存在");
logid.ShowMistake("数据库异常", AddWorkerBack);
//报错窗口
}
}
catch (Exception e)
{
Error = e.Message;
logid.ShowMistake(Error, AddWorkerBack);
}
}
void Show(int p, int maxp)
{
int childcount = FatherPanel.transform.childCount;
for (int i = childcount - 1; i >= 0; i--)
{
Destroy(FatherPanel.transform.GetChild(i).gameObject);
}
childcount = FatherPanel.transform.childCount;
if (maxp > 0)
{
for (int a = p * 48 - 48; a < p * 48; a = a + 6)
{
if (a >= drugcolumn.Count)
break;
GameObject obj = Resources.Load("Check") as GameObject;
GameObject root = Instantiate(obj, FatherPanel.transform);
root.GetComponent().No.text = drugcolumn[a];
root.GetComponent().Name.text = drugcolumn[a + 1];
root.GetComponent().Count.text = drugcolumn[a + 2];
root.GetComponent().Id.text = drugcolumn[a + 3];
root.GetComponent().YuangongName.text = drugcolumn[a + 4];
root.GetComponent().Selltime.text = drugcolumn[a + 5];
}
}
}
public void LastPageOnClick()
{
if (page > 1)
{
page--;
Show(page, maxpage);
}
}
public void NextPageOnClick()
{
if (page < maxpage)
{
page++;
Show(page, maxpage);
}
}
private void Update()
{
if (Text_Howcaniselect.text == "时间区间(日)")
{
whatdoiwanttoselect1.gameObject.SetActive(true);
}
else
whatdoiwanttoselect1.gameObject.SetActive(false);
whicthpage.text = "第" + page.ToString() + "页/第" + maxpage.ToString() + "页";
}
void rewrite()
{
Destroy(transform.gameObject);
logid.warning.SetActive(false);
}
void reprice()
{
whatdoiwanttoselect.text = whatdoiwanttoselect1.text = string.Empty;
logid.warning.SetActive(false);
}
void AddWorkerBack()
{
logid.back.onClick.AddListener(rewrite);
}
void TimeBack()
{
logid.back.onClick.AddListener(reprice);
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using UnityEngine;
using UnityEngine.UI;
public class ShowDrugInfo : MonoBehaviour {
public Text id;
public Text drugname;
public Text count;
public Text price;
public InputField number;
string Error;
LoginBtn logid;
ShowDrugs show;
// Use this for initialization
void Start()
{
logid = GameObject.Find("Canvas").GetComponent();
show = GameObject.Find("SellPanel(Clone)").GetComponent();
}
public void BuyOnClick()
{
if (int.Parse(number.text) > int.Parse(count.text))
logid.ShowMistake("库存不足", AddWorkerBack);
//库存不足
else
{
int newcount = int.Parse(count.text) - int.Parse(number.text);
count.text = newcount.ToString();
number.text = string.Empty;
DateTime now = DateTime.Now;
SqlserverManager sql = new SqlserverManager();
sql.UpdateInto("DrugTables", new string[] { "Count" }, new string[] { newcount.ToString() }, "No", id.text);
sql.InsertInto("DetailTables", new string[] { logid.userid.ToString(), id.text, drugname.text, number.text, now.ToString(), logid.myname });
show.SelectOnClick();
}
}
void rewrite()
{
number.text = string.Empty;
logid.warning.SetActive(false);
}
void AddWorkerBack()
{
logid.back.onClick.AddListener(rewrite);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ShowCheckInfo : MonoBehaviour
{
public Text No;
public Text Name;
public Text Count;
public Text Id;
public Text YuangongName;
public Text Selltime;
}
到这儿,系统已经差不多完成了,后续我会加上错误操作的报警功能。