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.Threading;
using System.Net.NetworkInformation;
using System.IO;
namespace Cash_Register_System.V1._00
{
public partial class Main_Windows : Form
{
public String[] DataBase_Connect_Info= { SERVER, @"E_Commodity_Data_Warehouse", USER,PASSWORD};//數據庫連接信息存儲
public String[] DataBase_Table_Name = { @"Commodity_Info_Cfg"};//數據庫數據表名存儲
public List<String[]> Get_DataBse_UserInfo;//數據庫用戶信息存儲
public String DataBase_Connect_Str=String.Empty;//數據庫連接字符串
public List<String> Mac_Address;
public List<MemoryStream> User_Image;//用戶照片
public int Mode_Item = 0;//啓動模式
public Boolean IsConnectionPass=false;//網絡連接是否正常
public List<String> Weather_Information;//存儲天氣信息
public String UserName = String.Empty;//用戶名
public String UserPassword = String.Empty;//用戶密碼
public Main_Windows()
{
InitializeComponent();
//Data_Processing_Interface MyData_Processing_Interface = new Data_Processing_Interface(this);
//MyData_Processing_Interface.Show();
GetSystemAllMacAddress();//獲取Mac信息
if (!GetUserInfo())
{
//System.Environment.Exit(0);
}
//Thread MyData_Processing_Interface = new Thread(threadPro_Data_Processing_Interface_Windows);//創建新線程
//MyData_Processing_Interface.Start();
//Data_Processing_Interface DaPrIf = new Data_Processing_Interface(this);
//DaPrIf.Show();
//this.Hide();
GetThe_Weather_Information();//獲取天氣信息
//this.ShowInTaskbar = false;
}
private void Main_Windows_Load(object sender, EventArgs e)
{
if (Check_Program_Whether_To_Start_The())//檢查程式是否啓動
{
ClosePreForm();
OpenForm(new login(this));
}
}
public Boolean Check_Program_Whether_To_Start_The()//確認程式是否啓動
{
Boolean Flag = true;
String strFullPath = Application.ExecutablePath;//讀取執行路徑
String strFileName = System.IO.Path.GetFileName(strFullPath);//讀取程式名稱
String FileName = strFileName.Substring(0, strFileName.Length - 4);
System.Diagnostics.Process[] myProcesses = System.Diagnostics.Process.GetProcessesByName(FileName);
if (myProcesses.Length > 1)//判斷程式是否啓動
{
Flag = false;
MessageBox.Show("系統已啓動....", "系統提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning);
System.Environment.Exit(0);
}
return Flag;
}
public Boolean GetUserInfo()//獲取用戶信息
{
Boolean Flag = true;
User_Image = new List<MemoryStream>();
DataBase_Source GetUserInfo = new DataBase_Source(DataBase_Connect_Info[0],DataBase_Connect_Info[1],DataBase_Connect_Info[2], DataBase_Connect_Info[3], @"SELECT * FROM Commodity_Info_Cfg");
Get_DataBse_UserInfo = new List<string[]>();
if (!GetUserInfo.GetUser_Info(Get_DataBse_UserInfo, User_Image))
Flag = false;
return Flag;
}
public void OpenForm(Form objFrm)//打開設置窗體
{
//嵌入子窗體到父窗體中,把添加學員信息嵌入到主窗體右側
//this.IsMdiContainer = true;//設置父窗體是容器
objFrm.TopLevel = false; //將子窗體設置成非最高層,非頂級控件
objFrm.WindowState = FormWindowState.Maximized;//將當前窗口設置成最大化
objFrm.FormBorderStyle = FormBorderStyle.None;//去掉窗體邊框
objFrm.Parent = this.panel1;//指定子窗體顯示的容器
objFrm.Show();
}
public void GetThe_Weather_Information()//獲取天氣信息
{
Weather_Information = new List<string>();
DataBase_Source Querying_WeatherInfo = new DataBase_Source(DataBase_Connect_Info[0], DataBase_Connect_Info[1], DataBase_Connect_Info[2], DataBase_Connect_Info[3], @"SELECT * FROM Weather_Data where Province='廣東' AND City='深圳'");//查詢讀取數據
if (!Querying_WeatherInfo.Querying_Weather_Data(Weather_Information))
{
try
{
Cash_Register_System.V1._00.cn.com.webxml.www.WeatherWebService w = new Cash_Register_System.V1._00.cn.com.webxml.www.WeatherWebService();
String[] r = w.getWeatherbyCityName("深圳");
int n = 0;
foreach (String ss in r)
{
if (n == 0 || n == 1 || n == 7 || n == 5 || n == 6)
Weather_Information.Add(ss);
n++;
}
DataBase_Source Insert_WeatherInfo = new DataBase_Source(DataBase_Connect_Info[0], DataBase_Connect_Info[1], DataBase_Connect_Info[2], DataBase_Connect_Info[3], @"Usp_Insert_Weather_Data");
Insert_WeatherInfo.Insert_Weather_Data(Weather_Information);//寫入數據
IsConnectionPass = true;
}
catch (Exception Ex)
{
Weather_Information = new List<string>();
Weather_Information.Add("N/A");
Weather_Information.Add("..");
Weather_Information.Add("N/A");
Weather_Information.Add("N/A");
Weather_Information.Add("N/A");
//MessageBox.Show(Ex.Message, "系統提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
//System.Environment.Exit(0);
}
}
}
public void Create_Data_Processing_Interface_Windows()//創建主窗體線程
{
//this.Hide();
Data_Processing_Interface DaPrIf = new Data_Processing_Interface(this);
DaPrIf.Show();
}
public void threadPro_Data_Processing_Interface_Windows()//創建線程
{
MethodInvoker MethInvo = new MethodInvoker(Create_Data_Processing_Interface_Windows);
BeginInvoke(MethInvo);
}
public void ClosePreForm()//關閉所有載入的窗體
{
foreach (Control item in this.panel1.Controls)
{
if (item is Form)
{
Form objControl = (Form)item;
objControl.Close();
}
}
}
private void Main_Windows_FormClosed(object sender, FormClosedEventArgs e)
{
this.Hide();
}
private void Main_Windows_FormClosing(object sender, FormClosingEventArgs e)//最小化改爲隱藏
{
this.Hide();
e.Cancel = true;
this.WindowState =FormWindowState.Minimized;
}
private void NotifyIcon1_MouseClick(object sender, MouseEventArgs e)//單擊事件
{
if (e.Button == MouseButtons.Left)//判斷鼠標的按鍵
{
//點擊時判斷form是否顯示,顯示就隱藏,隱藏就顯示
if (this.WindowState == FormWindowState.Normal)
{
this.WindowState = FormWindowState.Minimized;
this.Hide();
}
else if (this.WindowState == FormWindowState.Minimized)
{
this.Show();
this.WindowState = FormWindowState.Normal;
this.Activate();
}
}
}
public Boolean GetSystemAllMacAddress()//讀取Mac_Address
{
Boolean Flag = true;
try
{
NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();//讀取所有網卡信息
Mac_Address = new List<string>();
foreach (NetworkInterface adapter in adapters)
{
if (adapter.GetPhysicalAddress().ToString() != " " && adapter.GetPhysicalAddress().ToString() != String.Empty)
{
Mac_Address.Add(adapter.GetPhysicalAddress().ToString().ToUpper());
}
}
if (Mac_Address.Count < 1)
{
MessageBox.Show("無法獲取到計算機信息!!","系統提醒",MessageBoxButtons.OK,MessageBoxIcon.Error);
Flag = false;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "系統提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
Flag = false;
}
return Flag;
}
private void 退出EToolStripMenuItem_Click(object sender, EventArgs e)
{
//關閉窗口
DialogResult = DialogResult.No;
Dispose();
Close();
}
}
}
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;
namespace Cash_Register_System.V1._00
{
public partial class login : Form
{
public Main_Windows mw1;
public login(Main_Windows mainwin1)
{
InitializeComponent();
this.mw1 = mainwin1;//獲取委託父窗體
SetWindows_Show_Effect();//設置啓動模式
}
public void SetWindows_Show_Effect()//設置窗體顯示效果
{
Boolean IsMacAddress = false;
foreach (String[] ii in this.mw1.Get_DataBse_UserInfo)//判斷是否綁定PC Mac Address
{
foreach (String mm in this.mw1.Mac_Address)
{
if (mm.ToUpper() == ii[3].ToUpper())
{
this.mw1.Mac_Address[0] = mm;//設置MAC1爲指定網卡
IsMacAddress = true;
break;
}
}
if (IsMacAddress)
break;
/*foreach (String iii in ii)
{
}*/
}
if (IsMacAddress) this.mw1.Mode_Item = 1;//正常模式
else this.mw1.Mode_Item = 2;//授權模式
if (this.mw1.Mode_Item == 2)//授權模式
{
this.BackColor = Color.Black;
label3.ForeColor = Color.Red;
label3.Text = "模式狀態:軟件授權";
}
}
private void Button1_Click(object sender, EventArgs e)
{
this.mw1.ClosePreForm();
this.mw1.OpenForm(new Main_Menu_Windows(this.mw1));//傳遞父窗體
}
private void TextBox1_KeyPress(object sender, KeyPressEventArgs e)//密碼
{
if (e.KeyChar == (char)Keys.Enter)
{
if (textBox1.Text != String.Empty && textBox1.Text != null && textBox1.Text != "")
{
button1.Focus();
}
}
}
private void TextBox2_KeyPress(object sender, KeyPressEventArgs e)//用戶名
{
if (e.KeyChar == (char)Keys.Enter)
{
if (textBox2.Text != String.Empty && textBox2.Text != null && textBox2.Text != "")
{
textBox1.Focus();
textBox1.SelectAll();
}
}
}
private void Button1_Click_1(object sender, EventArgs e)//登陸
{
Boolean IsUserName = false;//判斷用戶名
Boolean IsUserPassword = false;//判斷用戶密碼
Boolean IsMacAddress = false;//判斷MacAddress
Boolean IsAllPass = false;//所有項測試Pass
if (this.mw1.Mode_Item == 2)
{
DataBase_Source CheckUserInfo = new DataBase_Source(this.mw1.DataBase_Connect_Info[0], this.mw1.DataBase_Connect_Info[1], this.mw1.DataBase_Connect_Info[2], this.mw1.DataBase_Connect_Info[3], @"Usp_Check_Authorization_Account_Number");
if (CheckUserInfo.Check_Authorization_Account_Number(textBox2.Text, textBox1.Text, textBox2))
{
mw1.ClosePreForm();
mw1.OpenForm(new Impower_Mode(mw1));
}
}
else
{
foreach (String[] ui in mw1.Get_DataBse_UserInfo)
{
if (!IsMacAddress)//先判斷ID是否正確
{
foreach (String mm in mw1.Mac_Address)
{
if (ui[3].ToUpper() == mm.ToUpper())
{
IsMacAddress = true;
break;
}
}
if (IsMacAddress)
{
if (!IsUserName)
{
if (ui[1].ToUpper() == textBox2.Text.ToUpper())
IsUserName = true;
}
if (!IsUserPassword)
{
if (ui[2].ToUpper() == textBox1.Text.ToUpper())
IsUserPassword = true;
}
}
}
if (IsUserName && IsUserPassword && IsMacAddress)
{
IsAllPass = true;
break;
}
}
if (IsAllPass)
{
this.mw1.UserName = textBox2.Text;//用戶名
this.mw1.UserPassword = textBox1.Text;//用戶密碼
mw1.ClosePreForm();
mw1.OpenForm(new Main_Menu_Windows(mw1));
}
else if (!IsUserName)
{
//label1.BackColor = Color.Red;
label1.ForeColor = Color.Red;
label1.Text = "輸入用戶名錯誤!!";
textBox2.Focus();
textBox2.SelectAll();
}
else if (!IsUserPassword)
{
//label2.BackColor = Color.Red;
label2.ForeColor = Color.Red;
label2.Text = "輸入密碼錯誤!!";
textBox1.Focus();
textBox1.SelectAll();
}
/*else if (!IsMacAddress)
{
MessageBox.Show("機算計未授於軟件使用版權", "系統提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
System.Environment.Exit(0);
}*/
}
}
private void TextBox2_TextChanged(object sender, EventArgs e)//用戶名
{
label1.Text = "";
}
private void TextBox1_TextChanged(object sender, EventArgs e)//用戶密碼
{
label2.Text = "";
}
private void Login_Load(object sender, EventArgs e)
{
}
}
}
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.Threading;
namespace Cash_Register_System.V1._00
{
public partial class Main_Menu_Windows : Form
{
public Main_Windows mw1;
public Form ItemUser_Windows = null;
public Main_Menu_Windows(Main_Windows mainwindows1)
{
InitializeComponent();
this.mw1 = mainwindows1;
}
private void TabControl1_DrawItem(object sender, DrawItemEventArgs e)//重繪TabControll控件表頭顏色
{
//設置筆刷
SolidBrush blue = new SolidBrush(Color.FromArgb(95, 162, 211));//設置淺藍色筆刷
StringFormat stringFormat = new StringFormat();
//設置標籤文字居中對齊
stringFormat.Alignment = StringAlignment.Center;
//逐個繪製各個標籤頁的背景顏色
String[] Title_Name = {"導航","微訊","設置"};
for (int i = 0; i<tabControl1.TabPages.Count; i++)
{
Rectangle Rec1 = tabControl1.GetTabRect(i);
e.Graphics.FillRectangle(blue,Rec1);
}
//設置文字顏色,並設置標籤文字字體和文字大小
for (int i = 0; i < tabControl1.TabPages.Count; i++)
{
Rectangle Rec = tabControl1.GetTabRect(i);
e.Graphics.DrawString(tabControl1.TabPages[i].Text, new Font("宋體", 10), new SolidBrush(Color.Black), Rec, stringFormat);
}
}
public void SetTitle()//設置窗口標題
{
/*if (this.mw1.User_Image[0] != null)//設置人像
{
pictureBox1.Image = new Bitmap(this.mw1.User_Image[0]);
}*/
bool IsSetCommodity_Name = false;//設置商鋪名稱
int n = 0;
foreach (String[] dd in this.mw1.Get_DataBse_UserInfo)
{
foreach (String mm in this.mw1.Mac_Address)
{
if (mm.ToUpper() == dd[3].ToUpper())
{
label2.Text = dd[0];//設置店名
IsSetCommodity_Name = true;
pictureBox1.Image = new Bitmap(this.mw1.User_Image[n]);//設置人像
}
}
if (IsSetCommodity_Name)
break;
n++;
}
label3.Text = this.mw1.Weather_Information[0] + "." + this.mw1.Weather_Information[1];
label4.Text = this.mw1.Weather_Information[2];
label5.Text = this.mw1.Weather_Information[3];
if (label5.Text.Contains("晴"))
{
pictureBox2.Image = imageList2.Images[0];
}
else if (label5.Text.Contains("晴") && label5.Text.Contains("陰"))
{
pictureBox2.Image = imageList2.Images[1];
}
else if (label5.Text.Contains("雨") && label5.Text.Contains("陰"))
{
pictureBox2.Image = imageList2.Images[3];
}
else if (label5.Text.Contains("多雲"))
{
pictureBox2.Image = imageList2.Images[2];
}
else if (label5.Text.Contains("陰"))
{
pictureBox2.Image = imageList2.Images[2];
}
else if (label5.Text.Contains("雨") && label5.Text.Contains("晴"))
{
pictureBox2.Image = imageList2.Images[5];
}
else if (label5.Text.Contains("雨") && label5.Text.Contains("雷"))
{
pictureBox2.Image = imageList2.Images[4];
}
else if (label5.Text.Contains("雨"))
{
pictureBox2.Image = imageList2.Images[3];
}
else if (label5.Text.Contains("雪"))
{
pictureBox2.Image = imageList2.Images[6];
}
else if (label5.Text.Contains("冰"))
{
pictureBox2.Image = imageList2.Images[7];
}
}
private void Main_Menu_Windows_Load(object sender, EventArgs e)
{
SetTitle();//裝飾窗體
//textBox1.Text = "訂單查詢";
//textBox1.ForeColor = Color.Silver;
}
private void TextBox1_Leave(object sender, EventArgs e)
{
//textBox1.Text = "訂單查詢";
//textBox1.ForeColor = Color.Silver;
}
private void TextBox1_MouseClick(object sender, MouseEventArgs e)//鼠標點擊進
{
//textBox1.Text = "";
//textBox1.ForeColor = Color.Black;
}
private void CTreeTaskBox_11_AfterSelect(object sender, TreeViewEventArgs e)
{
//Select_Node_Name = e.Node.Text.ToString();
/*if (Name.Contains("導入商品入庫單據"))
{
ItemUser_Windows = new Invoices_Main_Windows(this.mw1);
Thread Start_Windows = new Thread(threadPro_Data_Processing_Interface_Windows);
Start_Windows.Start();
}
else if (Name.Contains("導出商品入庫單據"))
{
}
else if (Name.Contains("導入商品出庫單據"))
{
}
else if (Name.Contains("導出商品出庫單據"))
{
}
else if (Name.Contains("新品入庫"))
{
}
else if (Name.Contains("商品補庫存"))
{
}
else if (Name.Contains("銷售出庫"))
{
}
else if (Name.Contains("商品退貨"))
{
}
else if (Name.Contains("週報"))
{
}
else if (Name.Contains("月報"))
{
}
else if (Name.Contains("年報"))
{
}
else if (Name.Contains("年終盤點"))
{
}
else if (Name.Contains("月度盤點"))
{
}*/
}
public void Create_Data_Processing_Interface_Windows()//創建主窗體線程
{
//this.Hide();
ItemUser_Windows.Show();
}
public void threadPro_Data_Processing_Interface_Windows()//創建線程
{
MethodInvoker MethInvo = new MethodInvoker(Create_Data_Processing_Interface_Windows);
BeginInvoke(MethInvo);
}
private void CTreeTaskBox_11_MouseClick(object sender, MouseEventArgs e)
{
//String Name = e.Node.Text.ToString();
//CTreeTaskBox_1 ii = this.cTreeTaskBox_11;
String Name =cTreeTaskBox_11.Select_Node_Name;
if (Name.Contains("導入商品入庫單據"))
{
ItemUser_Windows = new Invoices_Main_Windows(this.mw1);
Thread Start_Windows = new Thread(threadPro_Data_Processing_Interface_Windows);
Start_Windows.Start();
}
else if (Name.Contains("導出商品入庫單據"))
{
ItemUser_Windows = new Export_Template(this.mw1);
Thread Start_Windows = new Thread(threadPro_Data_Processing_Interface_Windows);
Start_Windows.Start();
}
else if (Name.Contains("導入商品出庫單據"))
{
}
else if (Name.Contains("導出商品出庫單據"))
{
}
else if (Name.Contains("新品入庫"))
{
ItemUser_Windows = new Commodity_Type(this.mw1);
Thread Start_Windows = new Thread(threadPro_Data_Processing_Interface_Windows);
Start_Windows.Start();
}
else if (Name.Contains("商品補庫存"))
{
ItemUser_Windows = new Commodity_Re_stocking(this.mw1);
Thread Start_Windows = new Thread(threadPro_Data_Processing_Interface_Windows);
Start_Windows.Start();
}
else if (Name.Contains("銷售出庫"))
{
ItemUser_Windows = new Stock_Removal_Windows(this.mw1);
Thread Start_Windows = new Thread(threadPro_Data_Processing_Interface_Windows);
Start_Windows.Start();
}
else if (Name.Contains("商品退貨"))
{
ItemUser_Windows = new Sales_Return(this.mw1);
Thread Start_Windows = new Thread(threadPro_Data_Processing_Interface_Windows);
Start_Windows.Start();
}
else if (Name.Contains("日報"))
{
ItemUser_Windows = new Commodity_Day_Collect(this.mw1);
Thread Start_Windows = new Thread(threadPro_Data_Processing_Interface_Windows);
Start_Windows.Start();
}
else if (Name.Contains("月報"))
{
ItemUser_Windows = new Commodity_Month_Collect(this.mw1);
Thread Start_Windows = new Thread(threadPro_Data_Processing_Interface_Windows);
Start_Windows.Start();
}
else if (Name.Contains("年報"))
{
ItemUser_Windows = new Commodity_Year_Collect(this.mw1);
Thread Start_Windows = new Thread(threadPro_Data_Processing_Interface_Windows);
Start_Windows.Start();
}
else if (Name.Contains("年終盤點"))
{
}
else if (Name.Contains("月度盤點"))
{
}
cTreeTaskBox_11.Select_Node_Name ="NULL";//清空歷史
}
private void TabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
if (tabControl1.SelectedTab == tabPage3)//選擇設置項
{
button2.BackColor = Color.White;
button1.BackColor = Color.IndianRed;
ClosePreForm(this.panel2);
OpenForm(new SetWindows_Demo2(this.mw1),this.panel2);
}
}
public void ClosePreForm(Panel Item)//關閉所有載入的窗體
{
foreach (Control item in Item.Controls)
{
if (item is Form)
{
Form objControl = (Form)item;
objControl.Close();
}
}
}
public void OpenForm(Form objFrm,Panel Item)//打開設置窗體
{
//嵌入子窗體到父窗體中,把添加學員信息嵌入到主窗體右側
//this.IsMdiContainer = true;//設置父窗體是容器
objFrm.TopLevel = false; //將子窗體設置成非最高層,非頂級控件
objFrm.WindowState = FormWindowState.Maximized;//將當前窗口設置成最大化
objFrm.FormBorderStyle = FormBorderStyle.None;//去掉窗體邊框
objFrm.Parent = Item;//指定子窗體顯示的容器
objFrm.Show();
}
private void Button1_Click(object sender, EventArgs e)//按鈕1
{
button2.BackColor = Color.White;
button1.BackColor = Color.IndianRed;
ClosePreForm(this.panel2);
OpenForm(new SetWindows_Demo2(this.mw1), this.panel2);
}
private void Button2_Click(object sender, EventArgs e)//按鈕2
{
button2.BackColor = Color.IndianRed;
button1.BackColor = Color.White;
ClosePreForm(this.panel2);
OpenForm(new Setting_Windows_Demo1(this.mw1), this.panel2);
}
}
}
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.Data.OleDb;
namespace Cash_Register_System.V1._00
{
public partial class Invoices_Windows_Demo1 : Form
{
public List<List<String>> order_Table;//存儲讀取的表單
public List<Control> Read_TableData;//讀取表單
public String[] ItemName = { "貨號", "品名", "顏色", "進貨價", "零售價", "進貨數" };
public Main_Windows mw1;
public List<List<String>> Be_PutInStorageData;//入庫數據
public String Order_NO = String.Empty;
public Invoices_Windows_Demo1(Main_Windows mainwindows1)
{
InitializeComponent();
this.mw1 = mainwindows1;
}
private void Button4_Click(object sender, EventArgs e)//打開目錄
{
listView1.Clear();
SetTable();
OpenFileDialog ofd = new OpenFileDialog();
ofd.ShowDialog();
ofd.Title = "選擇讀取表單..";
//ofd.Filter = "AllFiles(*.xls)|*.xlsx|*.xls";
textBox7.ForeColor = Color.Black;
textBox7.Text = ofd.FileName;
if (ofd.FileName != null && ofd.FileName != String.Empty && ofd.FileName != "")
{
order_Table = new List<List<string>>();
String connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + textBox7.Text + ";" + ";Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1\"";
//1.創建OLEDBCONNECTION的連接,加入對應文件類型的連接字符串
OleDbConnection connection = new OleDbConnection(connectionString);
//2.打開連接
connection.Open();
String sql = "SELECT * FROM [Sheet1$]";//Sql查詢命令
//OleDbDataAdapter用於填充DataSet 和更新數據源的一組數據命令和一個數據庫連接。
//3.指定查詢的連接,以及SQL語句
OleDbDataAdapter adapter = new OleDbDataAdapter(sql,connection);//它的查詢結果就是一個dataTable表格
//4.將查詢結果填充到dataSet裏(結果是一張表)
DataSet dataSet = new DataSet();//用來存放數據,可以放很多張表格
adapter.Fill(dataSet);//Fill是把查詢的結果(datatable)填充到dataset裏
//5關閉連接
connection.Close();
//取得DataSet中的DataTableCollection表格數據
DataTableCollection tableCollection = dataSet.Tables;//獲取當前dataSet中全部的表格
DataTable table = tableCollection[0];//因爲只有一張表,所以索引爲0
//取得表格DataTable中的所有行的數據
DataRowCollection rowCollection = table.Rows;
int n = 0;
foreach (DataRow temp in rowCollection)
{
if (n > 1)
{
List<String> Temp = new List<string>();
//取得row中的前8列數據,索引0-7
for (int i = 0; i <temp.Table.Columns.Count; i++)
{
Temp.Add(temp[i].ToString());
//MessageBox.Show(temp[i] + " ");//使用索引器訪問各個值
}
order_Table.Add(Temp);
}
n++;
}
foreach (List<String> RowData in order_Table)
{
int x = 0;
ListViewItem lvi = new ListViewItem();
this.listView1.BeginUpdate();
foreach (String Cell_Data in RowData)
{
if (x == 0) lvi.SubItems[0].Text = Cell_Data;
else lvi.SubItems.Add(Cell_Data);
x++;
}
this.listView1.EndUpdate();
listView1.Items.Add(lvi);
}
button1.Enabled = true;//啓動保存
button1.Focus();
}
}
private void Invoices_Windows_Demo1_Load(object sender, EventArgs e)//裝載
{
Read_TableData = new List<Control>();
Read_TableData.Add(textBox1);
Read_TableData.Add(textBox2);
Read_TableData.Add(textBox3);
Read_TableData.Add(textBox4);
Read_TableData.Add(textBox5);
Read_TableData.Add(textBox6);
Read_TableData.Add(button2);
Read_TableData.Add(button3);
Order_NO= this.mw1.Mac_Address[0] + "-" + DateTime.Now.ToString("yyyyMMddHHmmss");
label7.Text = "Order_NO:" + Order_NO + @"(入庫數據導入.模板一)";
SetTable();//設置表格
}
public void SetTable()
{
String[] Temp = { "貨號", "品名", "吊牌價", "零售價", "零售折扣", "結算價",
"結算折扣","顏色","顏色說明","內長","合計","結算額"};
this.listView1.Clear();
this.listView1.GridLines = true; //顯示錶格線
this.listView1.View = View.Details;//表格在窗體顯示細節的格式,如果做成表格,這個視圖必須選擇Details
this.listView1.Scrollable = true;//滾動條
this.listView1.HeaderStyle = ColumnHeaderStyle.Clickable;//表頭樣式
this.listView1.FullRowSelect = true;//表示在控件上,是否可以選擇一整行
this.listView1.LabelEdit = true;//是否可編輯,ListView只可編輯第一列。
this.listView1.MultiSelect = true;//是否可以選擇多個項。
this.listView1.HotTracking = true;
/*當鼠標指針經過某個項或者子項的文本時,文本的外觀是否變成超鏈接形式。當選擇此屬性時則**HoverSelection**自動爲true和**Activation**屬性爲oneClick*/
this.listView1.HoverSelection = true;//該鼠標指針在該項停留幾秒後自動選中。
// this.listView1.Activation = ItemActivation.Standard;//激活某一項時,必須執行的操作是(如:
//設置名稱
foreach (String In in Temp)//添加文件名
this.listView1.Columns.Add(In);
for (int i = 0; i < Temp.Length; i++)
this.listView1.Columns[i].Width = 100;//添加寬度
}
private void ListView1_SelectedIndexChanged(object sender, EventArgs e)//點擊選擇
{
if (listView1.SelectedItems.Count > 0)
{
textBox1.Text = listView1.SelectedItems[0].SubItems[0].Text;
textBox2.Text = listView1.SelectedItems[0].SubItems[1].Text;
textBox3.Text = listView1.SelectedItems[0].SubItems[8].Text;
textBox4.Text = listView1.SelectedItems[0].SubItems[2].Text;
textBox5.Text = listView1.SelectedItems[0].SubItems[3].Text;
textBox6.Text = listView1.SelectedItems[0].SubItems[10].Text;
foreach (Control Item in Read_TableData)
Item.Enabled = true;
}
else
{
foreach (Control Item in Read_TableData)
{
Item.Enabled = false;
if (Item.GetType().ToString() == "System.Windows.Forms.TextBox")
Item.Text = "";
}
}
}
private void Invoices_Windows_Demo1_FormClosed(object sender, FormClosedEventArgs e)
{
//System.Environment.Exit(0);
//關閉窗口
DialogResult = DialogResult.No;
Dispose();
Close();
}
public void Statistical_Table_Data()//統計表格數據
{
int Commodity_Total = 0;
double Commodity_Purchases_Total_Price = 0.0;
double Commodity_Retail_Total_Price = 0.0;
double Commodity_Retail_Total_Discount = 0.0;
for (int i = 0; i < listView1.Items.Count - 1; i++)
{
Commodity_Total += Convert.ToInt32(listView1.Items[i].SubItems[10].Text);//商品件數
Commodity_Purchases_Total_Price += Convert.ToDouble(listView1.Items[i].SubItems[5].Text) * Convert.ToInt32(listView1.Items[i].SubItems[10].Text);//商品進貨總價
Commodity_Retail_Total_Price += Convert.ToDouble(listView1.Items[i].SubItems[3].Text) * Convert.ToInt32(listView1.Items[i].SubItems[10].Text);//商品零售總價
Commodity_Retail_Total_Discount += Convert.ToDouble(listView1.Items[i].SubItems[4].Text);//零售折扣
}
listView1.Items[listView1.Items.Count - 1].SubItems[11].Text = Commodity_Purchases_Total_Price.ToString();//商品進貨總價
listView1.Items[listView1.Items.Count - 1].SubItems[3].Text = Commodity_Retail_Total_Price.ToString();//商品零售總價
listView1.Items[listView1.Items.Count - 1].SubItems[10].Text = Commodity_Total.ToString();//商品總件數
listView1.Items[listView1.Items.Count - 1].SubItems[4].Text = Commodity_Retail_Total_Discount.ToString();//商品總折扣
}
public Boolean Affirm_InputData()//確認錄入的內容
{
int n = 0;
bool Upate_DataPass = true;
foreach (Control Item in Read_TableData)
{
if (Item.GetType().ToString() == "System.Windows.Forms.TextBox")
{
if (Item.Text == "" || Item.Text == String.Empty || Item.Text == null)
{
MessageBox.Show(ItemName[n] + "項輸入的內容不能爲空!!", "系統提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
Item.Focus();
Upate_DataPass = false;
break;
}
if (n > 2)
{
try
{
double Tcount = Convert.ToDouble(Item.Text);
}
catch (Exception)
{
MessageBox.Show(ItemName[n] + "項錄入的內容不是數值!!", "系統提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
Item.Focus();
Upate_DataPass = false;
break;
}
}
}
n++;
}
return Upate_DataPass;
}
private void Button2_Click(object sender, EventArgs e)//更新
{
if (Affirm_InputData())
{
listView1.SelectedItems[0].SubItems[0].Text = textBox1.Text;
listView1.SelectedItems[0].SubItems[1].Text = textBox2.Text;
listView1.SelectedItems[0].SubItems[8].Text = textBox3.Text;
listView1.SelectedItems[0].SubItems[2].Text = textBox4.Text;
listView1.SelectedItems[0].SubItems[3].Text = textBox5.Text;
listView1.SelectedItems[0].SubItems[10].Text = textBox6.Text;
Statistical_Table_Data();//更新總值
foreach (Control Item in Read_TableData)
{
Item.Enabled = false;
if (Item.GetType().ToString() == "System.Windows.Forms.TextBox")
Item.Text = "";
}
}
}
private void Button3_Click(object sender, EventArgs e)//刪除
{
for (int n = 0; n < listView1.Items.Count; n++)
{
if (textBox1.Text == listView1.Items[n].SubItems[0].Text && textBox2.Text == listView1.Items[n].SubItems[1].Text &&
textBox3.Text == listView1.Items[n].SubItems[8].Text)
{
listView1.Items[n].Remove();
Statistical_Table_Data();
foreach (Control Item in Read_TableData)
{
Item.Enabled = false;
if (Item.GetType().ToString() == "System.Windows.Forms.TextBox")
Item.Text = "";
}
break;
}
}
}
private void TextBox7_Leave(object sender, EventArgs e)//焦表離開
{
}
public Boolean Get_Be_PutInStorageData()//獲取進貨數據
{
Boolean Flag = true;
try
{
Be_PutInStorageData = new List<List<string>>();
for (int n = 0; n < listView1.Items.Count - 1; n++)
{
List<String> Temp = new List<string>();
Temp.Add(Order_NO);//訂單號
Temp.Add(listView1.Items[n].SubItems[1].Text);//品名
Temp.Add(listView1.Items[n].SubItems[0].Text);//產品型號
String StrArray = String.Empty;
StrArray = listView1.Items[n].SubItems[2].Text +","+
listView1.Items[n].SubItems[4].Text + "," +
listView1.Items[n].SubItems[6].Text + "," +
listView1.Items[n].SubItems[7].Text + "," +
listView1.Items[n].SubItems[8].Text + "," +
listView1.Items[n].SubItems[9].Text;
Temp.Add(StrArray);//規格信息
Temp.Add(listView1.Items[n].SubItems[5].Text);//零售價
Temp.Add(listView1.Items[n].SubItems[3].Text);//零售價
Temp.Add(listView1.Items[n].SubItems[10].Text);//進貨數
Be_PutInStorageData.Add(Temp);//添加數據
}
}
catch (Exception ex)
{
Flag = false;
MessageBox.Show(ex.Message,"系統提醒",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
return Flag;
}
private void Button1_Click(object sender, EventArgs e)//存儲
{
if (Get_Be_PutInStorageData())
{
Boolean Flag = true;
foreach (List<String> gbp in Be_PutInStorageData)
{
DataBase_Source Uploading_Be_PutInStorageData = new DataBase_Source(this.mw1.DataBase_Connect_Info[0], this.mw1.DataBase_Connect_Info[1],
this.mw1.DataBase_Connect_Info[2], this.mw1.DataBase_Connect_Info[3], @"Usp_Insert_Be_PutInStorage");
if (!Uploading_Be_PutInStorageData.Insert_Be_PutInStorageData(gbp,this.mw1.Mac_Address[0]))
{
Flag = false;
MessageBox.Show("訂單號:" + Order_NO + @",品名"+ gbp[1]+ "商品入庫信息,存儲失敗!!", "系統提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
if (Flag)
{
MessageBox.Show("訂單號:" + Order_NO + "入庫信息,存儲成功!!", "系統提醒", MessageBoxButtons.OK);
Order_NO = this.mw1.Mac_Address[0] + "-" + DateTime.Now.ToString("yyyyMMddHHmmss");
label7.Text = "Order_NO:" + Order_NO + @"(入庫數據導入.模板一)";
button1.Enabled = false;
button4.Enabled = true;
}
}
}
}
}
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 NPOI.SS.UserModel;
using NPOI.HSSF.UserModel;
using NPOI.XSSF.UserModel;
using System.IO;
using System.Windows;
namespace Cash_Register_System.V1._00
{
public partial class Export_Template_Demo1 : Form
{
public Main_Windows mw1;
public String Querying_Str = String.Empty;//查詢語句
//public List<String> Querying_Item_Name;
public Export_Template_Demo1(Main_Windows mainwindows1)
{
InitializeComponent();
this.mw1 = mainwindows1;
}
private void Export_Template_Demo1_Load(object sender, EventArgs e)
{
SetTable();
this.dateTimePicker1.Format = DateTimePickerFormat.Custom;
this.dateTimePicker1.CustomFormat = "yyyy-MM-dd";
}
public void SetTable()//設置表格
{
String[] Temp = { "貨號", "品名", "吊牌價", "零售價", "零售折扣", "結算價",
"結算折扣","顏色","顏色說明","內長","合計","結算額"};
this.listView1.Clear();
this.listView1.GridLines = true; //顯示錶格線
this.listView1.View = View.Details;//表格在窗體顯示細節的格式,如果做成表格,這個視圖必須選擇Details
this.listView1.Scrollable = true;//滾動條
this.listView1.HeaderStyle = ColumnHeaderStyle.Clickable;//表頭樣式
this.listView1.FullRowSelect = true;//表示在控件上,是否可以選擇一整行
this.listView1.LabelEdit = true;//是否可編輯,ListView只可編輯第一列。
this.listView1.MultiSelect = true;//是否可以選擇多個項。
this.listView1.HotTracking = true;
/*當鼠標指針經過某個項或者子項的文本時,文本的外觀是否變成超鏈接形式。當選擇此屬性時則**HoverSelection**自動爲true和**Activation**屬性爲oneClick*/
this.listView1.HoverSelection = true;//該鼠標指針在該項停留幾秒後自動選中。
// this.listView1.Activation = ItemActivation.Standard;//激活某一項時,必須執行的操作是(如:
//設置名稱
foreach (String In in Temp)//添加文件名
this.listView1.Columns.Add(In);
for (int i = 0; i < Temp.Length; i++)
this.listView1.Columns[i].Width = 100;//添加寬度
}
private void ComboBox1_SelectedIndexChanged(object sender, EventArgs e)//選擇查詢項
{
Querying_Str = @"SELECT * FROM Be_PutInStorage_In_detail_Info WHERE ";
if (comboBox1.Text == "訂單號")
{
DataBase_Source Querying_KeyInfo = new DataBase_Source(this.mw1.DataBase_Connect_Info[0], this.mw1.DataBase_Connect_Info[1],
this.mw1.DataBase_Connect_Info[2], this.mw1.DataBase_Connect_Info[3], @"SELECT * FROM Be_PutInStorage_In_detail_Info WHERE Shop_ID='"+this.mw1.Mac_Address[0]+@"'");
if (Querying_KeyInfo.Querying_KeYinformation(comboBox2, "Order_Name"))
{
comboBox2.Enabled = true;
dateTimePicker1.Enabled = false;
Querying_Str += @"Order_Name='";
}
}
else if (comboBox1.Text == "品名")
{
DataBase_Source Querying_KeyInfo = new DataBase_Source(this.mw1.DataBase_Connect_Info[0], this.mw1.DataBase_Connect_Info[1],
this.mw1.DataBase_Connect_Info[2], this.mw1.DataBase_Connect_Info[3], @"SELECT * FROM Be_PutInStorage_In_detail_Info WHERE Shop_ID='" + this.mw1.Mac_Address[0] + @"'");
if (Querying_KeyInfo.Querying_KeYinformation(comboBox2, "Commodity_Name"))
{
comboBox2.Enabled = true;
dateTimePicker1.Enabled = false;
Querying_Str += @"Commodity_Name='";
}
}
else if (comboBox1.Text == "日期")
{
comboBox2.Enabled = false;
dateTimePicker1.Enabled = true;
Querying_Str += @"Date_Time like '";
}
}
private void ComboBox2_SelectedIndexChanged(object sender, EventArgs e)//選擇查詢的關鍵信息
{
if (comboBox2.Text != null && comboBox2.Text != String.Empty && comboBox2.Text != "")
{
Querying_Str +=comboBox2.Text + @"'";
button1.Enabled = true;
button1.Focus();
}
}
private void DateTimePicker1_ValueChanged(object sender, EventArgs e)//設置日期信息
{
if (dateTimePicker1.Text != null && dateTimePicker1.Text != String.Empty && dateTimePicker1.Text != "")
{
//this.dateTimePicker1.Format = DateTimePickerFormat.Custom;
//this.dateTimePicker1.CustomFormat = "yyyy-MM-dd";
//MessageBox.Show(this.dateTimePicker1.Text);
Querying_Str += dateTimePicker1.Text + @"%'";
button1.Enabled = true;
button1.Focus();
}
}
private void Button1_Click(object sender, EventArgs e)//查詢
{
DataBase_Source Querying_Data = new DataBase_Source(this.mw1.DataBase_Connect_Info[0], this.mw1.DataBase_Connect_Info[1],
this.mw1.DataBase_Connect_Info[2], this.mw1.DataBase_Connect_Info[3], Querying_Str);
if (Querying_Data.Full_Querying_Export_Template_Data(listView1))
{
button1.Enabled = false;
button2.Enabled = true;
button2.Focus();
}
}
public Boolean ExcelText(String FilePath)
{
Boolean Flag = true;
try
{
//導出:將數據庫中的數據,存儲到一個excel中
//1.查詢數據庫數據
//2.生成sheet
//2_1、生成workbook
//2_2、生成sheet
//2_3、遍歷集合、成生行
//2_4、根據對象生成單元格
String[] Table_Title_Name = {"貨號", "品名", "吊牌價", "零售價", "零售折扣", "結算價",
"結算折扣","顏色","顏色說明","內長","合計","結算額"};
HSSFWorkbook workbook = new HSSFWorkbook();
//創建工作表
var sheet = workbook.CreateSheet("sheet1");
//創建標題行(重點)
var row = sheet.CreateRow(0);
//創建單元格
//添加表頭
int n = 0;
foreach (String ss in Table_Title_Name)
{
var cellid = row.CreateCell(n);
cellid.SetCellValue(ss);
n++;
}
//添加數據
int index = 1;
for (int i = 0; i < listView1.Items.Count; i++)
{
var rowi = sheet.CreateRow(index);
for (int x = 0; x < listView1.Columns.Count; x++)
{
var id = rowi.CreateCell(x);
id.SetCellValue(listView1.Items[i].SubItems[x].Text);
}
index++;
}
//保存
FileStream file = new FileStream(FilePath, FileMode.CreateNew, FileAccess.Write);
workbook.Write(file);//寫入
file.Dispose();//處理並關閉
//for(int x=0;x<listView1.Columns.Count;x++)
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"系統提醒",MessageBoxButtons.OK,MessageBoxIcon.Error);
Flag = false;
}
return Flag;
}
private void Button2_Click(object sender, EventArgs e)//保存
{
SaveFileDialog FilePaht = new SaveFileDialog();
FilePaht.Filter = "xls files(*.xls)|*.xls|All files(*.*)|*.*";
FilePaht.FilterIndex = 2;
FilePaht.RestoreDirectory = true;
if (FilePaht.ShowDialog() == DialogResult.OK)
{
if (ExcelText(FilePaht.FileName + @".xls"))
{
MessageBox.Show(FilePaht.FileName+@".xls"+"文件數據導出成功!!","系統提醒",MessageBoxButtons.OK);
button2.Enabled = false;
comboBox1.Focus();
}
}
}
}
}
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;
namespace Cash_Register_System.V1._00
{
public partial class Commodity_Type : Form
{
public List<Control> Demo_Table_Control;
public Main_Windows mw1;
public Commodity_Type(Main_Windows mainwindows1)
{
InitializeComponent();
this.mw1 = mainwindows1;
}
private void Button1_Click(object sender, EventArgs e)//鞋子
{
Set_Select_Demo_Control_State(button1);
ClosePreForm();
OpenForm(new CommodityType_Item_Shoe(this.mw1));
}
private void Button3_Click(object sender, EventArgs e)//揹包
{
Set_Select_Demo_Control_State(button3);
ClosePreForm();
OpenForm(new CommodityType_Item_Backpack(this.mw1));
}
private void Commodity_Type_Load(object sender, EventArgs e)
{
Demo_Table_Control = new List<Control>();
Demo_Table_Control.Add(button1);
Demo_Table_Control.Add(button3);
Demo_Table_Control.Add(button2);
}
private void Button2_Click(object sender, EventArgs e)//服裝
{
Set_Select_Demo_Control_State(button2);
ClosePreForm();
OpenForm(new Commodity_Item_Clothing(this.mw1));
}
public void Set_Select_Demo_Control_State(Button Item)//設置選擇模板控件顏色
{
foreach (Control Cn in Demo_Table_Control)
Cn.BackColor = Color.White;
Item.BackColor = Color.IndianRed;
}
public void ClosePreForm()//關閉所有載入的窗體
{
foreach (Control item in this.panel1.Controls)
{
if (item is Form)
{
Form objControl = (Form)item;
objControl.Close();
}
}
}
public void OpenForm(Form objFrm)//打開設置窗體
{
//嵌入子窗體到父窗體中,把添加學員信息嵌入到主窗體右側
//this.IsMdiContainer = true;//設置父窗體是容器
objFrm.TopLevel = false; //將子窗體設置成非最高層,非頂級控件
objFrm.WindowState = FormWindowState.Maximized;//將當前窗口設置成最大化
objFrm.FormBorderStyle = FormBorderStyle.None;//去掉窗體邊框
objFrm.Parent = this.panel1;//指定子窗體顯示的容器
objFrm.Show();
}
}
}
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.Threading;
namespace Cash_Register_System.V1._00
{
public partial class Commodity_Re_stocking : Form
{
public Form ItemUser_Windows = null;
public Main_Windows mw1;
public String Order_ON = String.Empty;
public String []Control_Name = { "品牌", "商品名稱", "商品規格", "商品進貨價", "商品零售價", "入庫數" };
public List<Control> Add_Control_ID;//添加存庫按鈕ID
public List<Control> Add_Button_ID;//添加點擊控件
public List<List<String>> Save_ReadCommodity_Info;//讀取的商品信息
public List<List<String>> Rework_Commodity_Info;//修正的商品信息
public List<List<String>> Upadte_Commodity_Data;//更新商品數據
public List<List<String>> NewAdd_Commodity_Data;//新增的商品數據
public int Status_Index = 0;
public Commodity_Re_stocking(Main_Windows mainwindows1)
{
InitializeComponent();
this.mw1 = mainwindows1;
}
private void Commodity_Re_stocking_Load(object sender, EventArgs e)
{
Order_ON = this.mw1.Mac_Address[0] + "-" + DateTime.Now.ToString("yyyyMMddHHmmss");
label1.Text="Order_ON:"+ Order_ON+@"(補充庫存)";
if (GetCommdity_Info_FullTable())
{
//錄入控件
Add_Control_ID = new List<Control>();
Add_Control_ID.Add(textBox1);
Add_Control_ID.Add(textBox2);
Add_Control_ID.Add(textBox3);
Add_Control_ID.Add(textBox4);
Add_Control_ID.Add(textBox5);
Add_Control_ID.Add(textBox6);
//點擊控件
Add_Button_ID = new List<Control>();
Add_Button_ID.Add(button1);
Add_Button_ID.Add(button2);
Add_Button_ID.Add(button3);
Add_Button_ID.Add(button4);
Add_Button_ID.Add(button5);
Add_Button_ID.Add(button6);
//添加或新增數據存儲
Rework_Commodity_Info = new List<List<string>>();
//添加更新或添加數據
Upadte_Commodity_Data = new List<List<string>>();
NewAdd_Commodity_Data = new List<List<string>>();
}
else
{
//System.Environment.Exit(0);
//關閉窗口
DialogResult = DialogResult.No;
Dispose();
Close();
}
}
public Boolean GetCommdity_Info_FullTable()//讀取商品信息填數據表
{
Boolean Flag = true;
Save_ReadCommodity_Info = new List<List<string>>();
DataBase_Source GetCommdityData = new DataBase_Source(this.mw1.DataBase_Connect_Info[0], this.mw1.DataBase_Connect_Info[1],
this.mw1.DataBase_Connect_Info[2], this.mw1.DataBase_Connect_Info[3], @"SELECT * FROM Be_PutInStorage_Table WHERE Shop_ID='"+this.mw1.Mac_Address[0]+@"'");
if (GetCommdityData.GetCommodity_Info(Save_ReadCommodity_Info))
{
try
{
this.listView1.Clear();//表格清空
SetTable();//設置表頭
int n = 1;
foreach (List<String> cmif in Save_ReadCommodity_Info)
{
ListViewItem lvi = new ListViewItem();
this.listView1.BeginUpdate();
lvi.SubItems[0].Text = n.ToString();
foreach (String cf in cmif)
{
lvi.SubItems.Add(cf);
}
this.listView1.EndUpdate();
listView1.Items.Add(lvi);
n++;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"系統提醒",MessageBoxButtons.OK,MessageBoxIcon.Error);
Flag = false;
}
}
else
Flag = false;
return Flag;
}
public void SetTable()
{
String[] Temp = { "NO","品牌", "商品名稱", "商品規格", "商品進貨價(元)", "商品零售價(元)", "庫存數(PCS)"};
this.listView1.Clear();
this.listView1.GridLines = true; //顯示錶格線
this.listView1.View = View.Details;//表格在窗體顯示細節的格式,如果做成表格,這個視圖必須選擇Details
this.listView1.Scrollable = true;//滾動條
this.listView1.HeaderStyle = ColumnHeaderStyle.Clickable;//表頭樣式
this.listView1.FullRowSelect = true;//表示在控件上,是否可以選擇一整行
this.listView1.LabelEdit = true;//是否可編輯,ListView只可編輯第一列。
this.listView1.MultiSelect = true;//是否可以選擇多個項。
this.listView1.HotTracking = true;
/*當鼠標指針經過某個項或者子項的文本時,文本的外觀是否變成超鏈接形式。當選擇此屬性時則**HoverSelection**自動爲true和**Activation**屬性爲oneClick*/
this.listView1.HoverSelection = true;//該鼠標指針在該項停留幾秒後自動選中。
// this.listView1.Activation = ItemActivation.Standard;//激活某一項時,必須執行的操作是(如:
//設置名稱
foreach (String In in Temp)//添加文件名
this.listView1.Columns.Add(In);
this.listView1.Columns[0].Width = 30;//序號
this.listView1.Columns[1].Width = 160;//品牌
this.listView1.Columns[2].Width = 160;//商品名稱
this.listView1.Columns[3].Width = 380;//商品規格
this.listView1.Columns[4].Width = 140;//商品進貨價
this.listView1.Columns[5].Width = 140;//商品零售價
this.listView1.Columns[6].Width = 100;//入庫數(PCS)
}
private void GroupBox3_Paint(object sender, PaintEventArgs e)//去掉邊框線
{
e.Graphics.Clear(this.BackColor);
e.Graphics.DrawString(groupBox3.Text, groupBox3.Font, Brushes.Black, 8, 1);
}
private void GroupBox4_Paint(object sender, PaintEventArgs e)//去掉邊框線
{
e.Graphics.Clear(this.BackColor);
e.Graphics.DrawString(groupBox4.Text, groupBox4.Font, Brushes.Black, 8, 1);
}
private void GroupBox5_Paint(object sender, PaintEventArgs e)//去掉邊框線
{
e.Graphics.Clear(this.BackColor);
e.Graphics.DrawString(groupBox5.Text, groupBox5.Font, Brushes.Black, 8, 1);
}
private void GroupBox6_Paint(object sender, PaintEventArgs e)//去掉邊框線
{
e.Graphics.Clear(this.BackColor);
e.Graphics.DrawString(groupBox6.Text, groupBox6.Font, Brushes.Black, 8, 1);
}
private void GroupBox7_Paint(object sender, PaintEventArgs e)//去掉邊框線
{
e.Graphics.Clear(this.BackColor);
e.Graphics.DrawString(groupBox7.Text, groupBox7.Font, Brushes.Black, 8, 1);
}
private void GroupBox8_Paint(object sender, PaintEventArgs e)//去掉邊框線
{
e.Graphics.Clear(this.BackColor);
e.Graphics.DrawString(groupBox8.Text, groupBox8.Font, Brushes.Black, 8, 1);
}
private void ListView1_SelectedIndexChanged(object sender, EventArgs e)//點擊事件
{
if (listView1.SelectedItems.Count > 0)
{
int n = 1;
foreach (Control ii in Add_Control_ID)
{
ii.Text = listView1.SelectedItems[0].SubItems[n].Text;
n++;
}
textBox6.Text = "0";
foreach (Control ss in Add_Button_ID)
ss.Enabled = true;
button7.Enabled = true;
//button8.Enabled = true;
}
else
{
Close_ControlStatus();//清空控件狀態
}
}
public void Set_Control(Color B_Item,Color I_Item, TextBox Input_Item,Button But_Item,int Status)//設置控件
{
But_Item.BackColor = B_Item;
Input_Item.BackColor = I_Item;
if (Status == 1)
{
Input_Item.Enabled = true;
Input_Item.Focus();
Input_Item.SelectAll();
}
else
Input_Item.Enabled = false;
}
private void Button1_Click(object sender, EventArgs e)//控件1單擊事件
{
//if (Status_Index == 0)
//{
Set_Control(Color.White, Color.Pink, textBox1, button1, 1);
// Status_Index = 1;
// }
/*else
{
Set_Control(Color.Pink, Color.White, textBox1, button1, 2);
Status_Index = 0;
}*/
}
private void TextBox1_Leave(object sender, EventArgs e)//焦點離開
{
Set_Control(Color.Pink, Color.White, textBox1, button1, 2);
Status_Index = 0;
}
private void Button2_Click(object sender, EventArgs e)//控件2單擊事件
{
//if (Status_Index == 0)
// {
Set_Control(Color.White, Color.LightGreen, textBox2, button2, 1);
// Status_Index = 1;
// }
/*else
{
Set_Control(Color.LightGreen, Color.White, textBox2, button2, 2);
Status_Index = 0;
}*/
}
private void TextBox2_Leave(object sender, EventArgs e)//控件2焦點離開
{
Set_Control(Color.LightGreen, Color.White, textBox2, button2, 2);
Status_Index = 0;
}
private void Button3_Click(object sender, EventArgs e)//控件3單擊事件
{
// if (Status_Index == 0)
// {
// Status_Index = 1;
Set_Control(Color.White, Color.Thistle, textBox3, button3, 1);
// }
// else
// {
// Set_Control(Color.Thistle, Color.White, textBox3, button3, 2);
// Status_Index = 0;
// }
}
private void TextBox3_Leave(object sender, EventArgs e)//控件3焦點離開
{
Set_Control(Color.Thistle, Color.White, textBox3, button3, 2);
Status_Index = 0;
}
private void Button4_Click(object sender, EventArgs e)//控件4單擊事件
{
//if (Status_Index == 0)
// {
Set_Control(Color.White, Color.NavajoWhite, textBox4, button4, 1);
// Status_Index = 1;
// }
// else
// {
// Set_Control(Color.NavajoWhite, Color.White, textBox4, button4, 2);
// Status_Index = 0;
//}
}
private void TextBox4_Leave(object sender, EventArgs e)//控件4焦點離開
{
Set_Control(Color.NavajoWhite, Color.White, textBox4, button4, 2);
Status_Index = 0;
}
private void Button5_Click(object sender, EventArgs e)//控件5單擊事件
{
//if (Status_Index == 0)
//{
Set_Control(Color.White, Color.Plum, textBox5, button5, 1);
// Status_Index = 1;
// }
//else
// {
// Set_Control(Color.Plum, Color.White, textBox5, button5, 2);
// Status_Index = 0;
// }
}
private void TextBox5_Leave(object sender, EventArgs e)//控件5焦點離開
{
Set_Control(Color.Plum, Color.White, textBox5, button5, 2);
Status_Index = 0;
}
private void Button6_Click(object sender, EventArgs e)//控件6單擊事件
{
//if (Status_Index == 0)
// {
Set_Control(Color.White, Color.LightCoral, textBox6, button6, 1);
// Status_Index = 1;
// }
// else
// {
// Set_Control(Color.LightCoral, Color.White, textBox6, button6, 2);
// Status_Index = 0;
//}
}
private void TextBox6_Leave(object sender, EventArgs e)//控件6焦點離開
{
Set_Control(Color.LightCoral, Color.White, textBox6, button6, 2);
Status_Index = 0;
}
public Boolean Input_Info_Check()//錄入欄信息確認
{
Boolean Flag = true;
int i = 0;
foreach (Control cc in Add_Control_ID)
{
if (cc.Text != null && cc.Text != String.Empty && cc.Text != "")
{
if (cc.Name.ToString() == "textBox6")
{
if (Convert.ToInt32(cc.Text) <= 0)
{
Flag = false;
MessageBox.Show(Control_Name[i]+@"->的數值不能小於或等於零!!","系統提醒",MessageBoxButtons.OK,MessageBoxIcon.Warning);
cc.Enabled = true;
cc.Focus();
return Flag;
}
}
}
else
{
MessageBox.Show(Control_Name[i]+@"->的內容不能爲空!!","系統提醒",MessageBoxButtons.OK,MessageBoxIcon.Warning);
cc.Enabled = true;
cc.Focus();
Flag = false;
break;
}
i++;
}
return Flag;
}
public Boolean Add_Rework_CommdityData(List<String>Item)//添加商品或者修正數據
{
Boolean Flag = false;
for (int n = 0; n <this.listView1.Items.Count; n++)
{
Flag = false;
if (this.listView1.Items[n].SubItems[1].Text.Trim() == Item[0].Trim() &&
this.listView1.Items[n].SubItems[2].Text.Trim() == Item[1].Trim() &&
this.listView1.Items[n].SubItems[3].Text.Trim() == Item[2].Trim())
{
this.listView1.Items[n].SubItems[4].Text = Item[3];
this.listView1.Items[n].SubItems[5].Text = Item[4];
this.listView1.Items[n].SubItems[6].Text = (Convert.ToInt32(this.listView1.Items[n].SubItems[6].Text.ToString()) +
Convert.ToInt32(Item[5])).ToString();//計算總值
Item[5] = this.listView1.Items[n].SubItems[6].Text;
Upadte_Commodity_Data.Add(Item);
Flag = true;
break;
}
}
if (!Flag)
{
ListViewItem lvi = new ListViewItem();
this.listView1.BeginUpdate();
lvi.SubItems[0].Text = (this.listView1.Columns.Count + 1).ToString();
foreach (String cf in Item)
{
lvi.SubItems.Add(cf);
}
this.listView1.EndUpdate();
listView1.Items.Add(lvi);
NewAdd_Commodity_Data.Add(Item);
Flag = true;
}
return Flag;
}
public void Close_ControlStatus()//清空按鈕狀態
{
foreach (Control bb in Add_Button_ID)//關閉切換按鈕
bb.Enabled = false;
foreach (Control ii in Add_Control_ID)//關閉錄入接口
{
ii.Enabled = false;
ii.Text = "";
}
button7.Enabled = false;
}
private void Button7_Click(object sender, EventArgs e)//更新或添加
{
if (Input_Info_Check())
{
List<String> Temp = new List<string>();
foreach (Control ii in Add_Control_ID)
Temp.Add(ii.Text);
if (Add_Rework_CommdityData(Temp))
{
Rework_Commodity_Info.Add(Temp);
Close_ControlStatus();
if (button8.Enabled == false)
button8.Enabled = true;
}
}
}
private void Button8_Click(object sender, EventArgs e)//存儲商品入庫數據
{
if (Rework_Commodity_Info.Count > 0)
{
foreach (List<String> Rci in Rework_Commodity_Info)
{
DataBase_Source UpdateOrAdd_CommdityData = new DataBase_Source(this.mw1.DataBase_Connect_Info[0], this.mw1.DataBase_Connect_Info[1],
this.mw1.DataBase_Connect_Info[2], this.mw1.DataBase_Connect_Info[3], @"Usp_UpdateCommodity_BePutInStorage_Info");
if (UpdateOrAdd_CommdityData.UpdateOrInsert_Commodity_Re_stockingData(Rci,this.mw1.Mac_Address[0]))
{
ItemUser_Windows = new Commodity_Re_stocking_List(this);
Thread Start_Windows = new Thread(threadPro_Data_Processing_Interface_Windows);
Start_Windows.Start();
button8.Enabled = false;
}
}
}
else
{
MessageBox.Show("沒有可使用的:更新或新增入庫數據!!","系統提醒",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}
public void Create_Data_Processing_Interface_Windows()//創建主窗體線程
{
//this.Hide();
ItemUser_Windows.Show();
}
public void threadPro_Data_Processing_Interface_Windows()//創建線程
{
MethodInvoker MethInvo = new MethodInvoker(Create_Data_Processing_Interface_Windows);
BeginInvoke(MethInvo);
}
}
}
待補全。。。。。。