c#1.1代码(二)
/// <summary>
///
/// </summary>
/// <param name="Fid"></param>
/// <param name="fname"></param>
/// <param name="FPath"></param>
/// <param name="IsDel"></param>
public void RemoteDownData(string Fid,string fname,string FPath,bool IsDel)
{
DirectoryInfo Dir = new DirectoryInfo(FPath);
if(!Dir.Exists)
Dir.Create();
else
{
if(IsDel)
{
foreach(FileInfo file in Dir.GetFiles())
{
file.Delete();
}
}
}
PbaseUpdate Pbase = new PbaseUpdate();
DataTable DtCode =Pbase.GetDatetable(null,"select FCODE,FID from DNC_PRODUCTPROGRAM_CODE where fid='"+Fid+"'");
if(DtCode.Rows.Count<=0)return;
byte[] buffer=(byte[])DtCode.Rows[0][0];
FPath = FPath + fname;
FileStream Fs = File.OpenWrite(FPath);
Fs.Write(buffer,0,buffer.Length);
Fs.Close();
DtCode.Dispose();
}
/// <summary>
///
/// </summary>
/// <param name="FPath"></param>
public bool RemoteDelDir(string FPath)
{
FileInfo RFile = new FileInfo(FPath);
if( RFile.Exists)
{
return SigleFileDel(FPath);
}
else
{
DirectoryInfo Dir = new DirectoryInfo(FPath);
if(!Dir.Exists)return false;
if(Dir.GetFiles().Length <= 0)
{
Dir.Delete();
return true;
}
else
{
foreach(FileInfo file in Dir.GetFiles())
{
string FilePath = file.FullName;
if(!SigleFileDel(FilePath))
return false;
}
Dir.Delete();
return true;
}
}
}
private bool SigleFileDel(string FilePath)
{
FileInfo file = new FileInfo(FilePath);
if(file.Exists)
{
file.Delete();
return true;
}
else
{
return false;
}
}
------------------------------------------------------------------------------------------------------------
private string GetTcpip()
{
System.Net.IPHostEntry ipHostInfo=System.Net.Dns.Resolve(System.Net.Dns.GetHostName());
return ipHostInfo.AddressList[0].ToString();
}
---------------------------------------------------------------------------------------------------------
public string DisposeDirc(string SendPath,bool DisposeType)
{
try
{
if(SendPath.Substring(SendPath.Length - 1,1) != @"\")
SendPath = SendPath + @"\";
DirectoryInfo dirc = new DirectoryInfo(SendPath);
string DircSum = "";
if(dirc.Exists)
{
if(DisposeType)
{
foreach(DirectoryInfo Dic in dirc.GetDirectories())
{
if(DircSum == "")
DircSum = Dic.Name;
else
DircSum = DircSum + '|' + Dic.Name;
}
}
else
{
dirc.Delete(true);
DircSum = " ";
}
}
return DircSum;
}
catch(Exception ex)
{
throw ex;
}
}
public void GetRemoteFile(ref ArrayList ArrL,string Path)
{
try
{
if(Path.Substring(Path.Length - 1,1) != @"\")
Path = Path + @"\";
string AddressIp = (GetTcpip()).ToString();
DirectoryInfo dirc = new DirectoryInfo(Path);
if(dirc.Exists)
{
foreach(FileInfo file in dirc.GetFiles())
{
ListViewProperty Lvp = new ListViewProperty();
Lvp.FName = file.Name;
Lvp.FSize = file.Length.ToString();
Lvp.AddIp = AddressIp;
Lvp.CreateTime = file.CreationTime.ToString();
Lvp.ChangeTime = file.LastAccessTime.ToString();
Lvp.SaveDir = file.DirectoryName;
Lvp.FileDir = file.FullName;
int Index = Lvp.SaveDir.LastIndexOf(@"\");
Lvp.FMachine= Lvp.SaveDir.Substring( Index + 1);
ArrL.Add(Lvp);
}
}
}
catch(Exception ex)
{
throw ex;
return ;
}
}
public void GetFileStream(ref StreamReader Sr,string Path)
{
try
{
FileInfo file = new FileInfo(Path);
if(file.Exists)
{
Sr = new StreamReader(Path);
}
}
catch(Exception ex)
{
throw ex;
}
}
--------------------------------------------------------------------------------------------------------
public void SaveIsStorage(string SendPath,string GetPaht)
{
IsolatedStorageFile isf;
try
{
isf = IsolatedStorageFile.GetUserStoreForAssembly();
}
catch(Exception ex)
{
throw ex;
}
BinaryWriter isfwriter = null;
try
{
IsolatedStorageFileStream isfStream = new IsolatedStorageFileStream("FormState",FileMode.OpenOrCreate,isf);
isfwriter = new BinaryWriter(isfStream);
isfwriter.Write(SendPath);
isfwriter.Write(GetPaht);
}
catch(Exception ex)
{
throw ex;
}
finally
{
if(isfwriter != null)
isfwriter.Close();
}
}
---------------------------------------------------------------------------------------------------
public class DataSetDown
{
DataChinnel DChannel = null;
public DataSetDown()
{
//
// TODO: 在此处添加构造函数逻辑
//
try
{
TcpClientChannel channelClient;
if(ChannelServices.RegisteredChannels.Length > 0)
{
channelClient = (TcpClientChannel)ChannelServices.GetChannel("tcp");
}
else
{
channelClient = new TcpClientChannel();
ChannelServices.RegisterChannel(channelClient);
}
PbaseUpdate Pbase = new PbaseUpdate();
string PublishPort = Pbase.GetConf("PublishPort");
if(IPAddress == "")
IPAddress = Pbase.GetConf("ServerAdd");
IPAddress = "tcp://"+IPAddress+':'+PublishPort+"/NCBase";
DChannel = (DataChinnel)Activator.GetObject(typeof(ServerMarshal.DataChinnel),IPAddress);
if(DChannel == null)
{
return;
}
}
catch(Exception ex)
{
throw ex;
return ;
}
}
static string IPAddress="";
public static string ServerAddress
{
set
{
IPAddress = value;
}
}
public void RemoteDownData(string Fid,string fname,string FPath,bool IsDel)
{
if(DChannel != null)
DChannel.RemoteDownData(Fid,fname,FPath,IsDel);
}
public bool RemoteDelDir(string FPath)
{
if(DChannel != null)
return DChannel.RemoteDelDir(FPath);
else
return false;
}
public void DataCommit(string FProductFid,string EValue)
{
if(DChannel != null)
DChannel.DataCommit(FProductFid,EValue);
}
public void ProgramRemoteDown(string FProgramFid,string FPlantFid,int fisimport,string SendPath,bool IsReturn,string FMachineFid)
{
// if(IsCommon)
// {
if(DChannel != null)
DChannel.ProgramRemoteDown(FProgramFid,FPlantFid,fisimport,SendPath,IsReturn,FMachineFid);
// }
// else
// {
// CollectionTranfer Coll = new CollectionTranfer(FPlantFid,"","");
// Coll.DataLoad(FProgramFid,true);
// }
}
public string DisposeDic(string SendPath,bool DisposeType)
{
if(DChannel != null)
return DChannel.DisposeDirc(SendPath,DisposeType);
else
return "";
}
public void GetRemFile(ref ArrayList ArrL,string Path)
{
try
{
if(DChannel != null)
DChannel.GetRemoteFile(ref ArrL,Path);
}
catch(Exception ex)
{
// MessageBox.Show("服务端程序没有启动,无法处理收发件箱里的程序!","提示信息",MessageBoxButtons.OK ,MessageBoxIcon.Information);
// throw ex;
return ;
}
}
public void GetFileStream(ref StreamReader Sr,string Path)
{
if(DChannel != null)
DChannel.GetFileStream(ref Sr,Path);
}
}
}
-------------------------------------------------------------------------------------------------------------
PbaseUpdate Pbase = new PbaseUpdate();
private void SysInit()
{
string sql = "select Fid,FTaskName,FName,FTASKFID,FPROGRAMFID from DNC_Flow_TransferList where FSenderFid ='"
+CGlobe.Gfid +"' and FSIGN = 0 order by ftime" ;
DataTable dt= Pbase.GetDatetable(null,sql);
TreeNode Root = new TreeNode("可改签业务流程",2,3);
Root.Tag = "0";
this.treeView1.Nodes.Add(Root);
if(dt.Rows.Count > 0)
{
for(int i = 0;i< dt.Rows.Count;i++)
{
SortedList sl = new SortedList();
sl.Add("FID",dt.Rows[i]["Fid"].ToString());
sl.Add("FTASKFID",dt.Rows[i]["FTASKFID"].ToString());
sl.Add("FPROGRAMFID",dt.Rows[i]["FPROGRAMFID"].ToString());
string Name = dt.Rows[i]["FTaskName"].ToString()+"[" + dt.Rows[i]["FName"].ToString()+"]";
TreeNode SubNode = new TreeNode(Name,4,5);
SubNode.Tag = sl;
Root.Nodes.Add(SubNode);
}
}
sql = "select Fid,FName,FProgramFid from DNC_Flow_CreateTask where FSign = 0 and FCreaterFid='"
+ CGlobe.Gfid + "'";
dt = Pbase.GetDatetable(null,sql);
TreeNode SRoot = new TreeNode("没有完成任务",2,3);
SRoot.Tag = "0";
this.treeView2.Nodes.Add(SRoot);
if(dt.Rows.Count > 0)
{
for(int i=0;i<dt.Rows.Count;i++)
{
SortedList sl = new SortedList();
sl.Add("FID",dt.Rows[i]["Fid"].ToString());
sl.Add("FPROGRAMFID",dt.Rows[i]["FProgramFid"].ToString());
TreeNode NSubNode = new TreeNode(dt.Rows[i]["FName"].ToString(),4,5);
NSubNode.Tag = sl;
SRoot.Nodes.Add(NSubNode);
}
}
}
------------------------------------------------------------------------------------------------------------
TreeNode OSelNode,SelNode ;
string FID;
private void treeView1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
// DataInit();
//
// TreeNode SelNode = null;
Point P = new Point(e.X,e.Y);
if(this.treeView1.Focused)
{
SelNode = this.treeView1.GetNodeAt(P);
}
if(this.treeView2.Focused)
{
SelNode = this.treeView2.GetNodeAt(P);
}
if(e.Button == MouseButtons.Right)
{
if(this.treeView1.Focused)
{
this.treeView1.ContextMenu = this.contextMenu1;
}
if(this.treeView2.Focused)
{
this.treeView2.ContextMenu = this.contextMenu1;
}
}
if(e.Button == MouseButtons.Left)
{
if(OSelNode != null && OSelNode.Parent != null)
{
OSelNode.BackColor = System.Drawing.SystemColors.Window;
}
if(SelNode==null || SelNode.Parent == null)return;
SelNode.BackColor = Color.SkyBlue;
listView1.Items.Clear();
OSelNode = SelNode;
SortedList sl = (SortedList)SelNode.Tag;
DataWatch(sl);
}
}
private void menuItem2_Click(object sender, System.EventArgs e)
{
if(SelNode==null || SelNode.Parent == null)return;
SortedList sl = (SortedList)SelNode.Tag;
FID = sl["FID"].ToString();
string FTaskFid="",FPROGRAMFID="";
if(this.treeView1.Focused)
{
if(sl.Contains("FTASKFID"))
FTaskFid = sl["FTASKFID"].ToString();
}
if(this.treeView2.Focused)
{
FTaskFid = FID;
}
if(sl.Contains("FPROGRAMFID"))
FPROGRAMFID = sl["FPROGRAMFID"].ToString();
string sql="select fisimport from dnc_productprogram where fid='"
+FPROGRAMFID+"'";
string Fimport = Pbase.GetDatetable(null,sql).Rows[0][0].ToString();
bool Judge = false;
if(Convert.ToInt32(Fimport) == 3)
{
MessageBox.Show("程序正在试切,追回(作废)操作请慎重!",CGlobe.Gmsg);
// return;
Judge = true;
}
// this.treeView1
if(this.treeView1.Focused)
{
if(sl.Contains("FTASKFID"))
{
sql = "delete from DNC_FLOW_TRANSFERLIST where fid='"+FID+"'";
Pbase.ExecuteSql(null,sql,rulebase.SqlResultEnum.No);
sql="select fid from DNC_FLOW_TRANSFERLIST where FTASKFID='"
+ FTaskFid +"' order by FTEMPORDER desc";
Object Obj = Pbase.ExecuteSql(null,sql,rulebase.SqlResultEnum.Have);
if(Obj != null && Obj != System.DBNull.Value)
{
sl.Clear();
sl.Add("FID",Obj.ToString());
sl.Add("FSign",0);
if(Pbase.Save(null,sl,rulebase.EntityTypeEnum.DNC_Flow_TransferList,"FID",rulebase.SaveOptionEnum.Update))
{
if(Judge)
{
sql = "update dnc_productprogram set fisimport=0 where fid='"
+ FPROGRAMFID+"'";
Pbase.ExecuteSql(null,sql,rulebase.SqlResultEnum.No);
}
MessageBox.Show("您所签发的业务已经追回!",CGlobe.Gmsg);
SelNode.Remove();
this.SelNode = null;
return;
}
}
}
}
// this.treeView2
if(this.treeView2.Focused)
{
sql = "update dnc_productprogram set fisimport=0 where fid='"
+ FPROGRAMFID+"'";
Pbase.ExecuteSql(null,sql,rulebase.SqlResultEnum.No);
sql = "delete from DNC_FLOW_TRANSFERLIST where FTASKFID='"
+ FID + "'";
Pbase.ExecuteSql(null,sql,rulebase.SqlResultEnum.No);
sql = "delete from DNC_FLOW_CREATETASK where fid='"
+FID+"'";
Pbase.ExecuteSql(null,sql,rulebase.SqlResultEnum.No);
SelNode.Remove();
this.SelNode = null;
}
}
}
}
--------------------------------------------------------------------------------------------------------
private void listv1datafill(string Fid)
{
string sql = "select * from DNC_Flow_TransferList where FLISTENERFID ='"
+Fid+"' and FSIGN = 0 order by ftime" ;
DataTable dt= Pbase.GetDatetable(null,sql);
if(dt.Rows.Count > 0)
{
for(int i=0;i<dt.Rows.Count;i++)
{
string FDISPOSETYPE="升级";
if(dt.Rows[i]["FDISPOSETYPE"].ToString()=="0")
FDISPOSETYPE="降级";
if(dt.Rows[i]["FDISPOSETYPE"].ToString()=="2")
FDISPOSETYPE="代理";
if(dt.Rows[i]["FDISPOSETYPE"].ToString()=="8")
{
FDISPOSETYPE="程序归档";
this.listView2.Columns[7].Text = "归档原因";
}
string[] liv1 = new string[13]{
dt.Rows[i]["FNAME"].ToString(),
dt.Rows[i]["FTASKFID"].ToString(),
dt.Rows[i]["FTASKNAME"].ToString(),
dt.Rows[i]["FTEMPFID"].ToString(),
dt.Rows[i]["FSENDERFID"].ToString(),
dt.Rows[i]["FTEMPORDER"].ToString(),
dt.Rows[i]["FTEMPCOUNT"].ToString(),
"未处理业务",
FDISPOSETYPE,
dt.Rows[i]["FPROGRAM"].ToString(),
dt.Rows[i]["FPROGRAMFID"].ToString(),
dt.Rows[i]["FSENDERFID"].ToString(),
dt.Rows[i]["FSTRCTFID"].ToString()
};
ListViewItem li = new ListViewItem(liv1);
li.Tag = dt.Rows[i]["Fid"].ToString();
li.ImageIndex = 0;
li.StateImageIndex=1;
this.listView1.Items.Add(li);
}
}
}
--------------------------------------------------------------------------------------------------------
DialogResult Result = MessageBox.Show("是否需要添加处理说明?",
CGlobe.Gmsg,MessageBoxButtons.OKCancel,MessageBoxIcon.Question,MessageBoxDefaultButton.Button2);
if(Result == DialogResult.OK)
{
CGlobe.Fdesc = "";
sql = "select fcode from DNC_PRODUCTPROGRAM_CODE where fid='"
+ dt.Rows[0]["fid"].ToString()+"'";
Object Obj = Pbase.ExecuteSql(null,sql,rulebase.SqlResultEnum.Have);
if(Obj == System.DBNull.Value || Obj == null)return;
byte[] buffer=(byte[])Obj;
string Source = System.Text.Encoding.Default.GetString(buffer);
if(Source.Length > 0 )
{
richTextBox1.Text = "";
this.richTextBox1.Tag = null;
tabControl1.SelectedIndex = 1;
richTextBox1.Text = Source;
this.richTextBox1.Tag = dt.Rows[0]["fid"].ToString();
this.richTextBox1.ForeColor = Color.Blue;
string FProgramFid = this.SelLi.SubItems[10].Text.Trim();
string sql="select fprogramname,fid from dnc_productprogram where fid='"
+ FProgramFid+"'";
Object Obj = Pbase.ExecuteSql(null,sql,rulebase.SqlResultEnum.Have);
if(Obj.ToString() != "" && Obj != null)
{
FileExt = Obj.ToString();
FileExt = "LGCXDNC"+FileExt;
}
else
return;
PManager Manager = new PManager();
SaveFileDialog SFDlg = new SaveFileDialog();
SFDlg.Title="请选择程序下载路径";
SFDlg.ShowHelp = true;
SFDlg.RestoreDirectory = true;
SFDlg.OverwritePrompt = true;
SFDlg.CreatePrompt = true;
SFDlg.CheckPathExists = true;
SFDlg.FileName= Obj.ToString();
if(SFDlg.ShowDialog() == DialogResult.OK)
{
string TempDir = SFDlg.FileName.Substring(0,SFDlg.FileName.LastIndexOf("\\"))+"\\";
string Fid = this.richTextBox1.Tag.ToString();
string FileOne = Manager.FileDown(Fid,FileExt,TempDir);
}
}
---------------------------------------------------------------------------------------------------
listView1.Items.Clear();
for(int i=0;i<Dt.Rows.Count;i++)
{
string[] strlistview=new string[3]
{
Dt.Rows[i][0].ToString(),
Dt.Rows[i][1].ToString(),
Dt.Rows[i][2].ToString(),
};
ListViewItem li = new ListViewItem(strlistview);
li.ImageIndex=1;
if(Dt.Rows.Count == 1)
li.BackColor = Color.Green;
listView1.Items.Add(li);
}
---------------------------------------------------------------------------------------------------
/// <summary>
/// 创建临时文件存放路径
/// </summary>
/// <param name="AppDir"></param>
/// <returns></returns>
public string GetSaveDir(string AppDir)
{
string Dir = AppDir+"\\Downloads";
DirectoryInfo EntDir = new DirectoryInfo(Dir);
if(!EntDir.Exists)
EntDir.Create();
Dir = EntDir.FullName+"\\";
return Dir;
}
/// 读取二进制数据专用
/// </summary>
/// <param name="sql"></param>
/// <returns></returns>
public string GetObj(string sql)
{
Object ob= Pbase.ExecuteSql(null,sql,SqlResultEnum.Have);
if(ob!=null)
{
byte[] buff=(byte[])ob;
if(buff.Length>0)
{
return System.Text.ASCIIEncoding.Default.GetString(buff);
}
else
return "";
}
else
return "";
}
/// <summary>
/// 数控程序使用CIMOC进行编辑,其他文件使用其进行查看。
/// </summary>
/// <param name="FPROGRAMFID"></param>
/// <param name="BDel"></param>
public void ProgramEdit(ref string FPROGRAMFID,bool BDel)
{
//string dir =@"..\..\TempDownload";
string dir = System.Environment.CurrentDirectory +"\\TempDownload";
string sql="select fid,FPROGRAME from DNC_PRODUCTPROGRAM_view where FPROGRAMFID='"
+FPROGRAMFID+"' and FEDITION is not null order by FEDITION desc";
DataTable Dt = Pbase.GetDatetable(null,sql);
if(Dt.Rows.Count>0)
{
string fid=Dt.Rows[0][0].ToString();
sql="select FCODE from DNC_PRODUCTPROGRAM_CODE where fid='"+fid+"'";
String StrSource = GetObj(sql);
DirectoryInfo tempDir = new DirectoryInfo(dir);
if(!tempDir.Exists)tempDir.Create();
int Iextend = Dt.Rows[0][1].ToString().LastIndexOf(".");
string ExtendName;
if (Iextend>0)
{
FPROGRAMFID = Dt.Rows[0][1].ToString().Substring(Iextend);
ExtendName = Dt.Rows[0][0].ToString()+ FPROGRAMFID;
}
else
{
FPROGRAMFID = Dt.Rows[0][1].ToString();
ExtendName = Dt.Rows[0][0].ToString()+ FPROGRAMFID;
}
// try
// {
// FPROGRAMFID = Dt.Rows[0][1].ToString().Substring(Iextend);
// string ExtendName = Dt.Rows[0][0].ToString()+ FPROGRAMFID;
// }
// catch (Exception)
// {
// }
FPROGRAMFID= ExtendName;
FileInfo tempfile = new FileInfo(dir+'\\'+FPROGRAMFID);
if(tempfile.Exists)
tempfile.Delete();
try
{
string str_fileFullName = dir+'\\'+FPROGRAMFID;
FileStream fs = new FileStream(str_fileFullName, FileMode.Create, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.Write(StrSource);
sw.Close();
fs.Close();
FPROGRAMFID = dir+'\\'+FPROGRAMFID;
}
catch (Exception ex)
{
throw ex;
}
//StreamWriter SW = tempfile.AppendText();
//FPROGRAMFID = dir+'\\'+FPROGRAMFID;
//SW.Write(StrSource);
//SW.Close();
if(BDel)
tempfile.Delete();
}
}
--------------------------------------------------------------------------------------------------------------------
/// <summary>
/// 程序比较、方针、查看(使用CIMCOEdit.ext)
/// </summary>
/// <param name="FileDir"></param>
/// <param name="Judge"></param>
public void CompareFile(string FileDir,bool Judge)
{
string[] FileName=FileDir.Split('|');
if(FileName.Length>1)
{
string file='/'+"c "+FileName[0]+" "+ FileName[1];
System.Diagnostics.Process.Start("CIMCOEdit.exe",file);
}
else
{
if(Judge)
{
string file='/'+"solid " +'"'+FileDir+'"';
System.Diagnostics.Process.Start("CIMCOEdit.exe",file);
}
else
{
string file='"'+ FileDir+'"';
System.Diagnostics.Process.Start("CIMCOEdit.exe",file);
}
}
}
public void ProcessStart(string App)
{
System.Diagnostics.Process.Start(App);
}
------------------------------------------------------------------------------------------------------
public class ServerListen
{
public ServerListen()
{
//
// TODO: 在此处添加构造函数逻辑
//
// clientsocket = socket;
// clients = Clients;
}
// Socket clientsocket;
private Thread clientservice;
string Fid;
public string ServiceClient(ref Socket client,ref ArrayList clients)
{
// Socket client = clientsocket;
bool keepalive = true;
while (keepalive)
{
Byte[] buffer = new Byte[1024];
client.Receive(buffer);//接受数据
string clientcommand = System.Text.Encoding.Unicode.GetString(buffer);//编码转换
string[] tokens = clientcommand.Split(new Char[]{'|'});//根据”|“,进行字符解析,填充到数组里。
tokens[1] = tokens[1].Trim().Substring(0,36);
if (tokens[0] == "CONN") //假如是新用户申请加入
{
EndPoint ep = client.RemoteEndPoint;//该SOKET接口继续保存状态,并继续监听。
RDncManager.Client c = new Client(tokens[1], ep, clientservice, client);
clients.Add(c);
Fid = tokens[1];
string message = "LIST|" + "\r\n";//所有用户列表
SendToClient(c, message);//发送返回到登陆用户。
// clientservice.Abort();
}
try
{
if (tokens[0] == "GONE")
{
//关闭该用户的SOKET连接和线程。
int remove = 0;
bool found = false;
int c = clients.Count;
if(c <= 0) return Fid;
for(int n=0; n<c; n++)
{
RDncManager.Client cl = (Client)clients[n];
SendToClient(cl, clientcommand);
if(cl.Name.CompareTo(tokens[1]) == 0)
{
remove = n;
found = true;
}
}
if(found)
clients.RemoveAt(remove);
client.Close();
keepalive = false;
}
}
catch(Exception ex)
{
throw ex;
}
}
return Fid;
}
private void SendToClient(Client cl, string message)
{
try
{
byte[] buffer = System.Text.Encoding.ASCII.GetBytes(message.ToCharArray());
cl.Sock.Send(buffer,buffer.Length,0);
}
catch(Exception ex)
{
throw ex;
// cl.Sock.Close();
// cl.CLThread.Abort();
// clients.Remove(cl);
}
}
}
public class SockSend:MarshalByRefObject
{
private string serveraddress;
public bool connected = false;
// private bool transstop = false;
private int serverport=11000;//端口定义
private NetworkStream ns;
private StreamReader sr;
private bool keepalive;
private Thread receive = null;
private TcpClient clientsocket;
private string Fid;
public SockSend(string fid,string Tcpip)
{
//
// TODO: 在此处添加构造函数逻辑
//
Fid = fid;
serveraddress = Tcpip;
}
/// <summary>
/// 服务器连接
/// </summary>
public void EstablishConnection()
{
// try
// {
// if(Dns.GetHostByAddress(serveraddress) == null)
// {
// return;
// }
clientsocket = new TcpClient(serveraddress,serverport);//建立和服务器的连接。
// linger.en
if(clientsocket == null)
{
connected = false;
return;
}
ns = clientsocket.GetStream();//得到返回流数据。
sr = new StreamReader(ns);
if(ns != null)
connected = true;
// clientsocket = new TcpClient();
// clientsocket.NoDelay = true;
// if(Dns.GetHostByAddress(serveraddress) == "")
// {
// clientsocket.Close();
// return;
// }
// clientsocket.ReceiveTimeout=10000;
// clientsocket.Connect(serveraddress,serverport);
}
public void ServerConn()
{
if(connected)
{
//向服务器发送登陆陈公消息
RegisterWithServer();
//开始监听端口,如果收到消息进行处理。
// receive = new Thread(new ThreadStart(ReceiveChat));
// receive.Start();
}
}
/// <summary>
/// send fid to server and messager to server to stop listening
/// </summary>
private bool RegisterWithServer()
{
try
{
//连接信息发送到服务器。
string command = "CONN|" + this.Fid;
Byte[] outbytes = System.Text.Encoding.Unicode.GetBytes(command.ToCharArray());
ns.Write(outbytes,0,outbytes.Length);
//获得服务器返回的数据。
string serverresponse = sr.ReadLine();
serverresponse = serverresponse.Trim();
string[] tokens = serverresponse.Split(new Char[]{'|'});
if(tokens[0] == "LIST")
{
//stop this talk
QuitChat();
ns.Close();
clientsocket.Close();
if(receive != null && receive.IsAlive)
receive.Abort();
connected = false;
return true;
}
else
return false;
}
catch (Exception ex)
{
throw ex;
}
}
private void QuitChat()
{
if(connected)
{
try
{
//发送消息去服务器
string command = "GONE|" + this.Fid;
Byte[] outbytes = System.Text.Encoding.Unicode.GetBytes(command.ToCharArray());
ns.Write(outbytes,0,outbytes.Length);
// clientsocket.Close();
}
catch(Exception ex)
{
throw ex;
}
}
//关闭线程
}
private void ReceiveChat()
{
keepalive = true;
while (keepalive)
{
try
{
Byte[] buffer = new Byte[2048];
ns.Read(buffer,0,buffer.Length);
string chatter = System.Text.Encoding.ASCII.GetString(buffer);
string[] tokens = chatter.Split(new Char[]{'|'});
//用户离开
if (tokens[0] == "GONE")
{
ns.Close();
clientsocket.Close();
keepalive = false;
connected= false;
// clientsocket.Close();
}
//服务器出现问题
if (tokens[0] == "QUIT")
{
ns.Close();
clientsocket.Close();
keepalive = false;
connected= false;
}
}
catch(Exception ex)
{
throw ex;
}
}
}
}
------------------------------------------------------------------------------------------------------------------
public bool EndFlowTrans(string Fid,string FtaskFid)
{
string sql = "update DNC_FLOW_TRANSFERLIST set fsign = 1, FDISPOSETYPE=1 where fid='"
+ Fid +"'";
if(Pbase.ExecuteSql(null,sql,SqlResultEnum.Have) != System.DBNull.Value)
{
sql = "update DNC_FLOW_CREATETASK set FSIGN = 1 where fid='" + FtaskFid +"'";
if(Pbase.ExecuteSql(null,sql,rulebase.SqlResultEnum.Have) != System.DBNull.Value)
{
return true;
}
else
return false;
}
else
return false;
}
-------------------------------------------------------------------------------------------------------------------
using System;
using System.Xml;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting;
namespace rulebase
{
/// <summary>
/// CreateTrans 的摘要说明。
/// </summary>
public class CreateTrans
{
CreateDnc Dnc = null;
public CreateTrans()
{
//
// TODO: 在此处添加构造函数逻辑
//
try
{
TcpClientChannel channelClient;
if(ChannelServices.RegisteredChannels.Length > 0)
{
channelClient = (TcpClientChannel)ChannelServices.GetChannel("tcp");
}
else
{
channelClient = new TcpClientChannel();
ChannelServices.RegisterChannel(channelClient);
}
PbaseUpdate Pbase = new PbaseUpdate();
string PublishPort = Pbase.GetConf("PublishPort");
string ServerAdd = Pbase.GetConf("ServerAdd");
ServerAdd = "tcp://"+ServerAdd+':'+PublishPort+"/NCBase";
Dnc = (CreateDnc)Activator.GetObject(typeof(CreateDnc),ServerAdd);
if(Dnc == null)
{
return;
}
}
catch(Exception ex)
{
throw ex;
}
}
public string GetConnStr()
{
return Dnc.GetConf("ConnectionString");
}
}
}
---------------------------------------------------------------------------------------------------------------
private void FormHelp_Load(object sender, System.EventArgs e)
{
this.lname.Text="产品名称: "+Application.ProductName;
this.lvision.Text="当前版本: "+Application.ProductVersion;
this.lcompany.Text="版权单位: "+Application.CompanyName;
static void Main()
{
SecurityKey s_Key=new SecurityKey();
int nResult = s_Key.IsOverDue();
if(nResult == 1)
{
//已经过期
MessageBox.Show("试用版已经过期,请在即将打开的窗口获取计算机MAC地址,以生成正版序列号!","兰光科技");
Application.Run(new security());
return;
}
if(nResult != 0 && nResult != 1)
{
//出现错误
MessageBox.Show("系统出现错误,请与管理员联系!","兰光科技");
Application.Exit();
}
Application.Run(new ServerLogin());
}
----------------------------------------------------------------------------------------------------------------
private void notify_DoubleClick(object sender, System.EventArgs e)
{
this.Show();
if (this.WindowState == FormWindowState.Minimized)
this.WindowState = FormWindowState.Normal;
this.Activate();
}
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true; // 取消关闭窗体
this.Hide();
this.ShowInTaskbar = false;
this.notify.Visible = true;//显示托盘图标
}
private void notify_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(e.Button==MouseButtons.Right)
{
Control control = new Control(null,Control.MousePosition.X,Control.MousePosition.Y,1,1);
control.Visible = true;
control.CreateControl();
Point pos = new Point(0,0);
this.contex.Show(control,pos);
}
}
private void btnStartClient_Click(object sender, System.EventArgs e)
{
RegistryKey pregKey;
pregKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\CIMCO NCbase.exe");
if(pregKey == null)
{
MessageBox.Show("请在开始->程序->CIMCO NCbase.exe打开一次客户端程序,此按钮方可生效!","兰光科技");
return;
}
try
{
System.Diagnostics.Process.Start("CIMCO NCbase.exe");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message.ToString() + "启动客户端失败!","兰光科技");
}
}
DialogResult dResult = MessageBox.Show("你确实要停止服务器吗?","兰光科技",MessageBoxButtons.YesNo);
if(dResult == DialogResult.Yes)
{
Application.Exit();
}
--------------------------------------------------------------------------------------------------------------------
PbaseUpdate Pbase = new PbaseUpdate();
RManage RM = new RManage();
string ReceivePath="";
string FPlantFid =Pbase.GetConf("FPlantFid");
RM.GetSysConfig(FPlantFid,"T_ProgramRevceive",ref ReceivePath);
ReceivePath = ReceivePath + @"Error.log";
FileInfo file = new FileInfo(ReceivePath);
if(file.Exists)
{
System.Diagnostics.Process.Start(ReceivePath);
}
else
MessageBox.Show("系统运行正常没有产生异常日志!","兰光科技!");
}
private void WriteError(string ReceivePath,string ErrFileName)
{
try
{
FileInfo file = new FileInfo(ReceivePath);
FileStream FS = null;
if(file.Exists)
FS = new FileStream(ReceivePath,System.IO.FileMode.Append,System.IO.FileAccess.Write,System.IO.FileShare.Write);
else
FS = new FileStream(ReceivePath,System.IO.FileMode.CreateNew,System.IO.FileAccess.Write,System.IO.FileShare.Write);
StreamWriter SR = new StreamWriter(FS);
SR.WriteLine(DateTime.Now.ToString()+'['+ErrFileName+']');
SR.Close();
FS.Close();
}
catch(Exception ex)
{
throw ex;
}
}
PbaseUpdate Pbase=new PbaseUpdate();;
string TmpDirc = Dirc.ToUpper();
if(TmpDirc.Equals(Dirc))
TmpDirc = Dirc.ToLower();
string TmpFileName = FileName.ToUpper();
if(TmpFileName.Equals(FileName))
TmpFileName = FileName.ToLower();
string sql = "select fid from DNC_Flow_TempHandProg where FProgName in ('"
+ FileName
+ "','"
+ TmpFileName
+ "')"
+ " and FMachine in ('"
+ TmpDirc
+ "','"
+ Dirc
+ "')";
--------------------------------------------------------------------------------------------------------
private void button1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
this.button1.Cursor = System.Windows.Forms.Cursors.Hand;
this.button2.Cursor = System.Windows.Forms.Cursors.Hand;
this.toolTip1.SetToolTip(this.button1,"关闭系统");
this.toolTip1.SetToolTip(this.button2,"进入系统");
// this.button1.BackColor=Color.Red;
}
private void button1_Click(object sender, System.EventArgs e)
{
string Dir=@"TempDownload\";
DirectoryInfo Direc = new DirectoryInfo(Dir);
if(Direc.Exists)
{
foreach(FileInfo file in Direc.GetFiles())
{
file.Delete();
}
}
this.Dispose(true);
Application.ExitThread();
Application.Exit();
}
private int count=0;
private void FKeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
// int i=0;
if(e.KeyValue==13)
{
SystemLogin();
}
}
-------------------------------------------------------------------------------------------------------------------
using System.IO;
using rulebase;
using DNCMANAGER.UserSit;
using WindControl;
using Microsoft.Win32;
/// <summary>
/// 把程序启动路径写入注册表
/// </summary>
private void RegistryAppPath()
{
RegistryKey pregKey;
RegistryKey createdKey;
pregKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\CIMCO NCbase.exe",true);
if(pregKey == null)
{
pregKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths",true);
createdKey = pregKey.CreateSubKey("CIMCO NCbase.exe");
createdKey.SetValue("",Application.ExecutablePath.ToString());
createdKey.SetValue("Path",Application.StartupPath.ToString());
}
else
{
pregKey.SetValue("",Application.ExecutablePath.ToString());
pregKey.SetValue("Path",Application.StartupPath.ToString());
}
}
------------------------------------------------------------------------------------------------------------------
if(treeView1.SelectedNode==null)
MessageBox.Show("请选择节点!!","错误!");
else
{
FSTRCTFID=treeView1.SelectedNode.Tag.ToString();
FNAME=treeView1.SelectedNode.Text;
}
sl.Add("FSTRCTFID",FSTRCTFID);
sl.Add("FNAME",FNAME);
public void ViewTree()
{
treeView1.Nodes.Clear();
GetTree("0",treeView1.Nodes);
}
//获得节点,并插入treeView1 递归实现
private void GetTree(string _id,TreeNodeCollection node)
{
string fid = null;
string part_name = null;
DataTable dt = new DataTable();
string sql= "SELECT FID,PART_NAME FROM DNC_PRODUCTSTRUC_PDM WHERE PARENTID='"+_id+"'";
dt = (DataTable) Pbase.GetDatetable(null,sql);
int i=0;
foreach (DataRow row in dt.Rows)
{
fid = row.ItemArray[0].ToString();
part_name = row.ItemArray[1].ToString();
node.Add(part_name);
node[i].Tag=fid;
GetTree(fid,node[i].Nodes);
i++;
}
}
this.treeView1.Refresh();
private void menuItem1_Click(object sender, System.EventArgs e)
{
if(node==null)
{
MessageBox.Show("没有选中节点,系统无法删除!");
return;
}
else
{
if( node.Nodes.Count>0)
{
MessageBox.Show("此节点下存在子节点,系统不允许删除!请先删除子节点!");
return;
}
string sql="DELETE FROM dnc_productstruc_pdm WHERE FID='"+node.Tag.ToString()+"'";
if(Convert.ToInt32(Pbase.ExecuteSql(null,sql,SqlResultEnum.No))<=0)
this.treeView1.Nodes.Remove(node);
else
{
MessageBox.Show("删除节点失败!请与系统管理员联系!");
return;
}
private void btnFile_Click(object sender, System.EventArgs e)
{
openFileDialog1.ShowDialog();
txbIntroduce.Text=openFileDialog1.FileName;
}
private void btnFolder_Click(object sender, System.EventArgs e)
{
folderBrowserDialog1.ShowDialog();
txbExport.Text=folderBrowserDialog1.SelectedPath;
}
//将归档文件批量导出
public void Export()
{
DataTable dt = new DataTable();
string path ;
int i,n;
i=n=0;
string fprogram, fprogramfid,sql;
string startTime = String.Format("{0:yyyy-MM-dd}",this.dateTimePickerS.Value);
string endTime = String.Format("{0:yyyy-MM-dd}",this.dateTimePickerE.Value);
//根据FIsImport和ftime进行筛选
sql="SELECT FID FROM dnc_productprogram WHERE FIsImport=6 and to_char(ftime,'yyyy-mm-dd')>'"+startTime+"' and to_char(ftime,'yyyy-mm-dd')<'"+endTime+"'";
try
{
dt=pbase.GetDatetable(null,sql);
if (dt.Rows.Count > 0)
{
foreach (DataRow row in dt.Rows)
{
path =txbExport.Text;
fprogramfid = row.ItemArray[0].ToString();
sql="SELECT FCODE,FNAME from dnc_productprogram_code WHERE FID='"+fprogramfid+"'";
DataTable data = (DataTable)pbase.GetDatetable(null,sql);
if (data.Rows.Count > 0)
{
fprogram=data.Rows[0].ItemArray[1].ToString();
path=path+"\\"+fprogram+".txt";
try
{
StreamWriter st = new StreamWriter(path);
byte[] code;
code = (byte[])data.Rows[0].ItemArray[0];
st.Write(System.Text.ASCIIEncoding.Default.GetString(code));
st.Flush();
st.Close();
i++;
}
catch(Exception e)
{
n++;
}
}
}
MessageBox.Show("文件导出成功 "+i+",失败"+n,"消息!");
}
}
catch(Exception e)
{
MessageBox.Show(e.Message,"警告!");
}
}
-----------------------------------------------------------------------------------------------------
public string GetXML()
{
XmlDocument xmlDom=new XmlDocument();
xmlDom.Load("dbconn.config");
XmlNodeList nods=xmlDom.GetElementsByTagName("DataBaseType");
XmlNodeList nods1=xmlDom.GetElementsByTagName("ConnectionString");
if ( nods==null )
{
m_DatabaseType=DatabaseTypeEnum.Oledb;
}
else
{
if ( nods[0].InnerText=="OleDb" )
m_DatabaseType=DatabaseTypeEnum.Oledb;
else if ( nods[0].InnerText=="SQLServer" )
m_DatabaseType=DatabaseTypeEnum.SQLServer;
else if ( nods[0].InnerText=="Oracle" )
m_DatabaseType=DatabaseTypeEnum.Oracle;
else
m_DatabaseType=DatabaseTypeEnum.Oledb;
}
// string strConn="";
if ( nods1!=null) return nods1[0].InnerText ;
else
return "";
---------------------------------------------------------------------------------------------------
using rulebase;
using System.Data;
using System.Management;
using System.Data.OracleClient;
using System.Windows.Forms;
namespace DNCMANAGER
{
/// <summary>
/// DBConnect 的摘要说明。
/// </summary>
public class DBConnect
{
public OracleConnection OraConnection;
public DBConnect()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public void Conn()
{
try
{
Connection Cn = new Connection();
string ConSource = Cn.GetXML();
OraConnection=new OracleConnection(ConSource);
OraConnection.Open();
}
catch(Exception e)
{
MessageBox.Show(e.Message +"数据库连接失败,请检查网络或服务器是否有异常!","错误提示",MessageBoxButtons.OK ,MessageBoxIcon.Information);
}
}
public void Close()
{
try
{
OraConnection.Close();
}
catch(OracleException e)
{
MessageBox.Show(e.Message+"数据库连接失败,请检查网络或服务器是否有异常!","错误提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
public void ExecCmd(string pCmd)
{
Conn();
OracleCommand cmd;
try
{
cmd=OraConnection.CreateCommand();
cmd.CommandText=pCmd;
cmd.ExecuteNonQuery();
}
catch(OracleException e)
{
MessageBox.Show(e.Message,"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
Close();
OraConnection.Dispose();
//cmd.Dispose();
}
public DataSet GetRODS(string pSql)
{
Conn();
OracleCommand cmd;
System.Data.DataSet ds=new DataSet();
try
{
cmd=OraConnection.CreateCommand();
cmd.CommandText=pSql;
OracleDataAdapter da=new OracleDataAdapter(cmd);
da.Fill(ds);
}
catch(OracleException e)
{
MessageBox.Show(e.Message,"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
Close();
return ds;
}
/// <summary>
/// 获取表里某个字段的值
/// </summary>
/// <param name="Str"></param>
/// <returns></returns>
public string GetSqlVal(string str)
{
object ojb=new object();
string Str="";
Connection Cn = new Connection();
string ConSource = Cn.GetXML();
OraConnection =new OracleConnection(ConSource);
try
{
OraConnection.Open();
OracleCommand Cmd=new OracleCommand(str,OraConnection);
ojb=Cmd.ExecuteScalar();
if(ojb!=null)
{
Str=ojb.ToString();
}
}
catch(Exception e1)
{}
finally
{
OraConnection.Close();
}
return Str;
}
/// <summary>
/// 判断是否该机进行了注册
/// </summary>
/// <returns></returns>
public bool IsCpu()
{
string str="select fid from DNC_CPU where cupid='"+GetCpuID()+"'";
PbaseUpdate Pbase = new PbaseUpdate();
DataTable Dt = Pbase.GetDatetable(null,str);
if(Dt.Rows.Count>=1)
return true;
else
return false;
}
/// <summary>
/// 获取本机CPU序列号
/// </summary>
/// <returns>本机的CPU序列号</returns>
public String GetCpuID()
{
try
{
ManagementClass mc = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = mc.GetInstances();
String strCpuID = null ;
foreach( ManagementObject mo in moc )
{
strCpuID = mo.Properties["ProcessorId"].Value.ToString();
break;
}
return strCpuID;
}
catch
{
return "";
}
}
/// <summary>
/// 获取表里某个字段的值
/// </summary>
/// <param name="Str"></param>
/// <returns></returns>
public int GetSqlVal1(string str)
{
object ojb=new object();
string Str="";int i=0;
Connection Cn = new Connection();
string ConSource = Cn.GetXML();
OraConnection =new OracleConnection(ConSource);
try
{
OraConnection.Open();
OracleCommand Cmd=new OracleCommand(str,OraConnection);
ojb=Cmd.ExecuteScalar();
if(ojb!=null)
{
Str=ojb.ToString();
i=Convert.ToInt32(Str);
}
}
catch(Exception e1)
{}
finally
{
OraConnection.Close();
}
return i;
}
-------------------------------------------------------------------------------------------------------------------
private void listView1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
ListViewItem li = this.listView1.GetItemAt(e.X,e.Y);
if(li == null)return;
else
{
this.T_FGConsignerFid.Text = li.SubItems[1].Text.Trim();
dateTimePicker1.Value = Convert.ToDateTime(li.SubItems[3].Text.Trim());
string endtime = li.SubItems[4].Text.Trim();
if(endtime != "" && endtime != null)
this.dateTimePicker2.Value = Convert.ToDateTime(endtime);
this.F_Desc.Text = li.SubItems[5].Text.Trim();
}
}
string[] Consign = new string[6]
{
sl["FConsigner"].ToString(),
sl["FGConsigner"].ToString(),
"使用中",
DateTime.Now.ToString(),
"",
sl["FDesc"].ToString()
};
ListViewItem li = new ListViewItem(Consign,0);
li.StateImageIndex = 1;
li.BackColor = System.Drawing.Color.Yellow;
li.Tag = Fid;
this.listView1.Items.Add(li);
private void ComDatabind()
{
string sql="select fname,fid from DNC_SYS_EMPLOYEE where FROLEFID='"
+ CGlobe.GFrolefID+"'";
DataTable dt = Pbase.GetDatetable(null,sql);
if(dt == null && dt.Rows.Count <= 0)
return;
this.T_FGConsignerFid.ValueMember=dt.Columns[1].ToString();
this.T_FGConsignerFid.DisplayMember = dt.Columns[0].ToString();
this.T_FGConsignerFid.DataSource = dt;
}
private void SysInit()
{
string sql="select FID,FConsigner,FGConsigner,decode(FSign,0,'已停止',1,'使用中') FSign,FTIME,FEndTime,FDesc from DNC_Task_Consign where FConsignerFid='"
+ CGlobe.Gfid+"'";
DataTable dt = Pbase.GetDatetable(null,sql);
if(dt == null || dt.Rows.Count <= 0)
return;
else
{
for(int i=0;i<dt.Rows.Count;i++)
{
string[] Consign = new string[6]
{
dt.Rows[i]["FConsigner"].ToString(),
dt.Rows[i]["FGConsigner"].ToString(),
dt.Rows[i]["FSign"].ToString(),
dt.Rows[i]["FTIME"].ToString(),
dt.Rows[i]["FEndTime"].ToString(),
dt.Rows[i]["FDesc"].ToString()
};
ListViewItem li = new ListViewItem(Consign,0);
li.StateImageIndex=1;
li.Tag = dt.Rows[i]["FID"];
if(dt.Rows[i]["FSign"].ToString() == "使用中")
{
this.btn_new.Enabled = false;
li.BackColor = Color.Yellow;
this.btn_End.Enabled = true;
}
this.listView1.Items.Add(li);
}
}
}
----------------------------------------------------------------------------------------------
private void listView1_Click(object sender, EventArgs e)
{
// this.userControEmp.listView1.BackColor = Color.Silver;
ListViewItem li = this.userControEmp.listView1.SelectedItems[0];
PlantFid = li.Tag.ToString();
// li.BackColor = Color.Green;
this.userControEmp.txtfname.Text=li.SubItems[0].Text;
this.userControEmp.txtFduty.Text=li.SubItems[1].Text;
this.userControEmp.txtFWorkAge.Text= li.SubItems[3].Text;
this.userControEmp.txtFEduLevel.Text= li.SubItems[4].Text;
this.userControEmp.txtFtel.Text= li.SubItems[5].Text;
this.userControEmp.txtFEmail.Text= li.SubItems[6].Text;
this.userControEmp.txtFFax.Text= li.SubItems[7].Text;
this.userControEmp.txtFaddr.Text= li.SubItems[8].Text;
this.userControEmp.txtFdesc.Text= li.SubItems[9].Text;
if(li.SubItems[10].Text=="已禁用")this.userControEmp.checkBox2.Checked = true;
else
this.userControEmp.checkBox1.Checked = false;
if(li.SubItems[11].Text == "可改密码") this.userControEmp.checkBox1.Checked = false;
else this.userControEmp.checkBox2.Checked = true;
}
private void listView1_MouseUp(object sender, MouseEventArgs e)
{
if(e.Button==MouseButtons.Right)
{
this.userControEmp.listView1.ContextMenu=this.contextMenu1;
Point point=new Point(e.X,e.Y);
listitem = this.userControEmp.listView1.GetItemAt(point.X,point.Y);
if(listitem == null)
{
menuItem1.Enabled=false;
MessageBox.Show("您没有选中人员系统无法查看用户权限!",CGlobe.Gmsg);
return;
}
else
menuItem1.Enabled=true;
CGlobe.GParm =listitem.Tag.ToString();
}
}
ListViewItem listitem;
private void menuItem1_Click(object sender, System.EventArgs e)
{
FEmpRoleSel FroleSel = new FEmpRoleSel();
FroleSel.ShowDialog(this);
FroleSel.Dispose();
}
#endregion dnc_sys_employee
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
string sql;
SelNode = this.treeView1.SelectedNode;
if(SelNode == null)return;
int Etype = 0;
if(SelNode.Tag.ToString().Length==1)
Etype = Convert.ToInt32(SelNode.Tag.ToString());
else
{
if(SelNode.Tag.ToString().Length>1)
{
Etype = Convert.ToInt32(SelNode.Parent.Tag.ToString());
}
}
DataTable dt;
switch(Etype)
{
case 0:
#region plant
this.userControRole1.SendToBack();
this.userControEmp.SendToBack();
this.userConPlant.listView1.Items.Clear();
sql="select fid,Fname,Fcorporation,Faccount,Ftel,FEmail,Fsit,Faddr,Fdesc from DNC_Sys_Plant where fid like '"
// +CGlobe.GFplantfid+"%'";
+SelNode.Tag.ToString()+"%'";
dt = Pbase.GetDatetable(null,sql);
if(dt.Rows.Count>0)
{
for(int i=0;i<dt.Rows.Count;i++)
{
string[] str = new string[9]{
dt.Rows[i][1].ToString(),
dt.Rows[i][2].ToString(),
dt.Rows[i][3].ToString(),
dt.Rows[i][4].ToString(),
dt.Rows[i][5].ToString(),
dt.Rows[i][6].ToString(),
dt.Rows[i][7].ToString(),
dt.Rows[i][8].ToString(),
dt.Rows[i][0].ToString()
};
ListViewItem item = new ListViewItem(str,1);
item.Tag=dt.Rows[i][0].ToString();
this.userConPlant.listView1.Items.Add(item);
}
}
break;
#endregion plant
case 1:
#region sys_role
this.userConPlant.SendToBack();
this.userControEmp.SendToBack();
this.userControRole1.listVRole.Items.Clear();
sql = "select fid,Fname,Fdesc,FISDELETE,FTIME,FPLANTFID,fcontent from dnc_sys_role where FPLANTFID like '"
// +CGlobe.GFplantfid+"%'";
+SelNode.Tag.ToString()+"%'";
dt = Pbase.GetDatetable(null,sql);
if(dt.Rows.Count>0)
{
for(int i=0;i<dt.Rows.Count;i++)
{
string[] strrole = new string[6]
{
dt.Rows[i][1].ToString(),
"",
dt.Rows[i][2].ToString(),
dt.Rows[i][4].ToString(),
"",
""
};
if(dt.Rows[i][3].ToString() == "0")
strrole.SetValue("使用当中",4);
else
strrole.SetValue("已禁用",4);
sql="select Fname from dnc_sys_plant where fid='"+dt.Rows[i][5].ToString()+"'";
DataTable Dplant = Pbase.GetDatetable(null,sql);
if(Dplant.Rows.Count>0)
strrole.SetValue(Dplant.Rows[0][0].ToString(),1);
strrole.SetValue(dt.Rows[i][6].ToString(),5);
ListViewItem roleitem = new ListViewItem(strrole,2);
roleitem.Tag = dt.Rows[i][0].ToString();
this.userControRole1.listVRole.Items.Add(roleitem);
}
}
break;
#endregion sys_role
case 2:
#region dnc_sys_employee
this.userConPlant.SendToBack();
this.userControRole1.SendToBack();
this.userControEmp.listView1.Items.Clear();
sql = "select fid,Fname,Fduty,FWorkAge,FEduLevel,Ftel,FEmail,FFax,Faddr,Fdesc,fstop,fchangepwd,fplantfid,Frolefid from dnc_sys_employee where FPLANTFID like '"
+SelNode.Tag.ToString()+"%'";
dt = Pbase.GetDatetable(null,sql);
if(dt.Rows.Count>0)
{
for(int i=0;i<dt.Rows.Count;i++)
{
string[] strrole = new string[12]
{
dt.Rows[i][1].ToString(),
dt.Rows[i][2].ToString(),
"",
dt.Rows[i][3].ToString(),
dt.Rows[i][4].ToString(),
dt.Rows[i][5].ToString(),
dt.Rows[i][6].ToString(),
dt.Rows[i][7].ToString(),
dt.Rows[i][8].ToString(),
dt.Rows[i][9].ToString(),
"",
""
};
if(dt.Rows[i][10].ToString() == "0")
strrole.SetValue("正常使用",10);
else
strrole.SetValue("已禁用",10);
if(dt.Rows[i][11].ToString() == "0")
strrole.SetValue("可改密码",11);
else
strrole.SetValue("不可改密码",11);
//
string[] FroleFid = dt.Rows[i]["Frolefid"].ToString().Split('|');
string RoleFid = "";
for(int j=0;j<FroleFid.Length;j++)
{
if(FroleFid[j].Length<= 0)continue;
if(j> 0 && j< (FroleFid.Length-1))
RoleFid = RoleFid+"'" + FroleFid[j]+"',";
else
RoleFid = RoleFid + "'" + FroleFid[j]+"',";
}
if(RoleFid.LastIndexOf(',')!=-1)
RoleFid = RoleFid.Substring(0,RoleFid.Length - 1);
if(RoleFid.Length > 0)
{
sql="select Fname from DNC_Sys_Role where fid in ("+RoleFid+")";
DataTable DtRole = Pbase.GetDatetable(null,sql);
RoleFid = "";
if(DtRole.Rows.Count>0)
{
for(int g=0;g<DtRole.Rows.Count;g++)
RoleFid = RoleFid + "[" +DtRole.Rows[g][0].ToString()+"]";
}
}
else
RoleFid = "未赋角色";
strrole.SetValue(RoleFid,2);
//
ListViewItem roleitem = new ListViewItem(strrole,2);
roleitem.Tag = dt.Rows[i][0].ToString();
this.userControEmp.listView1.Items.Add(roleitem);
}
}
break;
#endregion dnc_sys_employee
default:
break;
}
}
private void listVPurview_ColumnClick(object sender, ColumnClickEventArgs e)
{
// if(this.userControRole1.listVPurview.Columns[e].Text.ToString() == "功能序号")
if(e.Column==0)
{
for(int ii=0;ii<this.userControRole1.listVPurview.Items.Count;ii++)
{
this.userControRole1.listVPurview.Items[ii].Checked = false;
// this.userControRole1.listVPurview.Items[ii].BackColor = Color.Silver;
}
}
}
private void RolelistViewClick(object sender, EventArgs e)
{
for(int ii=0;ii<this.userControRole1.listVPurview.Items.Count;ii++)
{
this.userControRole1.listVPurview.Items[ii].Checked = false;
this.userControRole1.listVPurview.Items[ii].BackColor = Color.Silver;
}
ListViewItem li = this.userControRole1.listVRole.SelectedItems[0];
PlantFid = li.Tag.ToString();
this.userControRole1.txtFname.Text=li.SubItems[0].Text;
this.userControRole1.txtfdesc.Text = li.SubItems[2].Text;
// this.userControRole1.combFplantfid.Items.in
// PbaseUpdate Pbase = new PbaseUpdate();
// Object Obj = Pbase.ExecuteSql(null,"select Fplantfid from dnc_sys_role where fid='"+li.Tag.ToString()+"'",SqlResultEnum.Have) ;
// if(Obj != null)
//// this.userControRole1.txtFname.Text = Obj.ToString();
//
// this.userControRole1.combFplantfid.SelectedText= Obj.ToString();
string strdispose = li.SubItems[5].Text.ToString();
string[] stritem = strdispose.Split('|');
for(int i=0;i<stritem.Length;i++)
{
for(int ii=0;ii<this.userControRole1.listVPurview.Items.Count;ii++)
{
if(this.userControRole1.listVPurview.Items[ii].Tag.ToString() == stritem[i].ToString())
{
this.userControRole1.listVPurview.Items[ii].Checked = true;
this.userControRole1.listVPurview.Items[ii].BackColor = Color.Snow;
}
}
}
}
#region dnc_sys_employee
NodeText="分厂人员增加管理";
NodeTag = 2;
TreeNode ThirdbRoot;
if(CGlobe.Fduty==0)
{
this.userControEmp.btnAdd.Enabled=false;
this.userControEmp.btnUpdate.Enabled=false;
this.userControEmp.btndel.Enabled=false;
this.userControEmp.btnAdd.Enabled=false;
this.userControEmp.btnUpdate.Enabled=false;
this.userControEmp.btndel.Enabled=false;
}
switch(Dt.Rows.Count)
{
case 0:
ThirdbRoot = new TreeNode(NodeText);
ThirdbRoot.Tag=NodeTag;
ThirdbRoot.SelectedImageIndex=1;
ThirdbRoot.ImageIndex=0;
FRoot.Nodes.Add(ThirdbRoot);
break;
case 1:
NodeText=Dt.Rows[0][1].ToString() + NodeText;
ThirdbRoot = new TreeNode(NodeText);
ThirdbRoot.Tag=NodeTag;
ThirdbRoot.SelectedImageIndex=1;
ThirdbRoot.ImageIndex=0;
FRoot.Nodes.Add(ThirdbRoot);
TreeNode subnode = new TreeNode(Dt.Rows[0][1].ToString());
subnode.Tag=Dt.Rows[0][0].ToString();
ThirdbRoot.Nodes.Add(subnode);
// this.userControRole1.combFplantfid.Items.Add(Dt.Rows[0][1].ToString());
break;
default:
ThirdbRoot = new TreeNode(NodeText);
ThirdbRoot.Tag=NodeTag;
ThirdbRoot.SelectedImageIndex=1;
ThirdbRoot.ImageIndex=0;
FRoot.Nodes.Add(ThirdbRoot);
for(int i=0;i<Dt.Rows.Count;i++)
{
TreeNode node = new TreeNode(Dt.Rows[i][1].ToString());
node.Tag=Dt.Rows[i][0].ToString();
node.SelectedImageIndex=2;
node.ImageIndex=3;
ThirdbRoot.Nodes.Add(node);//Fid,Fname
}
break;
}
this.userControEmp.btnAdd.Click+=new EventHandler(btnClick);
this.userControEmp.btnUpdate.Click+=new EventHandler(btnClick);
this.userControEmp.btndel.Click+=new EventHandler(btndelClick);
this.userControEmp.listView1.Click+=new EventHandler(listView1_Click);
this.userControEmp.listView1.MouseUp += new MouseEventHandler(listView1_MouseUp);
#endregion dnc_sys_employee
}
private void PlantbtnClick(object sender, EventArgs e)
{
Button btn = (Button)sender;
if(btn.Name=="btnAdd")
{
this.userConPlant.tbFname.Text="";
this.userConPlant.tbFsit.Text="";
this.userConPlant.tbFaddr.Text="";
this.userConPlant.tbFEmail.Text="";
this.userConPlant.tbFdesc.Text="";
this.userConPlant.tbFtel.Text="";
this.userConPlant.tbFcorporation.Text="";
PlantFid="";
}
if(btn.Name=="btnUpdate")
{
if(this.userConPlant.tbFname.Text.Trim().Length == 0)
{
MessageBox.Show("没有填写企业名称,系统不允许保存!",CGlobe.Gmsg);
return;
}
SaveOptionEnum SaveType;
if(PlantFid!="")
{
SaveType = SaveOptionEnum.Update;
}
else
{
SaveType = SaveOptionEnum.Insert;
PlantFid = Guid.NewGuid().ToString();
}
SortedList sl = new SortedList();
sl.Add("FID",PlantFid);
sl.Add("Fname",this.userConPlant.tbFname.Text.Trim());
sl.Add("Fcorporation",this.userConPlant.tbFcorporation.Text.Trim());
sl.Add("Faccount",this.userConPlant.tbFaccount.Text.Trim());
sl.Add("Faddr",this.userConPlant.tbFaddr.Text.Trim());
sl.Add("Ftel",this.userConPlant.tbFtel.Text.Trim());
sl.Add("FEmail",this.userConPlant.tbFEmail.Text.Trim());
sl.Add("Fsit",this.userConPlant.tbFsit.Text.Trim());
sl.Add("Fisdelete","0");
sl.Add("Fdesc",this.userConPlant.tbFdesc.Text.Trim());
if(Pbase.Save(null,sl,EntityTypeEnum.DNC_Sys_Plant,"FID",SaveType))
{
if(SaveType == SaveOptionEnum.Insert)
{
if(SelNode != null)
{
TreeNode node = new TreeNode(this.userConPlant.tbFname.Text.Trim()) ;
node.Tag=PlantFid;
if(SelNode.Parent != null && SelNode.Tag.ToString()=="0")
{
SelNode.Nodes.Add(node);
}
if(SelNode.Parent == null)
SelNode.Nodes[0].Nodes.Add(node);
if(SelNode.Nodes.Count == 0 && SelNode.Tag.ToString() != "0")
SelNode.Parent.Nodes.Add(node);
node.ForeColor=Color.Red;
}
}
//
//fid,Fname,Fcorporation,Faccount,Ftel,FEmail,Fsit,Faddr,Fdesc
if(SaveType == SaveOptionEnum.Update)
{
ListViewItem Selitem = userConPlant.listView1.SelectedItems[0];
userConPlant.listView1.Items.Remove(Selitem);
}
string[] str1 = new string[9]{
sl["Fname"].ToString(),
sl["Fcorporation"].ToString(),
sl["Faccount"].ToString(),
sl["Ftel"].ToString(),
sl["FEmail"].ToString(),
sl["Fsit"].ToString(),
sl["Faddr"].ToString(),
sl["Fdesc"].ToString(),
PlantFid
};
ListViewItem item = new ListViewItem(str1,1);
item.Tag=sl["FID"].ToString();
this.userConPlant.listView1.Items.Add(item);
// this.userConPlant.listView1.SelectedItems[0]=item;
//
MessageBox.Show("数据保存成功!",CGlobe.Gmsg);
return;
}
}
}
private void PlantlistView1_Click(object sender, EventArgs e)
{
ListViewItem item = this.userConPlant.listView1.SelectedItems[0];
if(item == null)return;
// item.BackColor= Color.Blue;
this.toolTip1.SetToolTip(this.userConPlant.listView1,item.SubItems[0].Text.Trim());
this.userConPlant.tbFname.Text=item.SubItems[0].Text.Trim();
this.userConPlant.tbFsit.Text=item.SubItems[5].Text.Trim();
this.userConPlant.tbFaddr.Text=item.SubItems[6].Text.Trim();
this.userConPlant.tbFEmail.Text=item.SubItems[4].Text.Trim();
this.userConPlant.tbFdesc.Text=item.SubItems[7].Text.Trim();
this.userConPlant.tbFtel.Text=item.SubItems[3].Text.Trim();
this.userConPlant.tbFcorporation.Text=item.SubItems[1].Text.Trim();
this.userConPlant.tbFaccount.Text=item.SubItems[2].Text.Trim();
PlantFid = item.Tag.ToString();
}
NodeText="角色设置";
NodeTag = 1;
TreeNode SubRoot;
userControRole1.FroleContent = CGlobe.Gfrole;
Nbase nbase = new Nbase();
// if(CGlobe.Gfid.Length>2 && CGlobe.Gfrole!="%")
// {
// if(!nbase.Popedom("Btn_Role",CGlobe.Gfrole))
// {
// this.userControRole1.btnAdd.Visible=false;
// this.userControRole1.btnUpdate.Visible=false;
// this.userControRole1.btndel.Visible=false;
// this.userControRole1.btnAdd.Enabled=false;
// this.userControRole1.btnUpdate.Enabled=false;
// this.userControRole1.btndel.Enabled=false;
// }
// }
if(CGlobe.Fduty==0)
{
this.userControRole1.btnAdd.Enabled=false;
this.userControRole1.btnUpdate.Enabled=false;
this.userControRole1.btndel.Enabled=false;
this.userControRole1.btnAdd.Enabled=false;
this.userControRole1.btnUpdate.Enabled=false;
this.userControRole1.btndel.Enabled=false;
}
switch(Dt.Rows.Count)
{
case 0:
SubRoot = new TreeNode(NodeText);
SubRoot.Tag=NodeTag;
SubRoot.SelectedImageIndex=1;
SubRoot.ImageIndex=0;
FRoot.Nodes.Add(SubRoot);
break;
case 1:
NodeText=Dt.Rows[0][1].ToString() + NodeText;
SubRoot = new TreeNode(NodeText);
SubRoot.Tag=NodeTag;
SubRoot.SelectedImageIndex=1;
SubRoot.ImageIndex=0;
FRoot.Nodes.Add(SubRoot);
TreeNode subnode = new TreeNode(Dt.Rows[0][1].ToString());
subnode.Tag=Dt.Rows[0][0].ToString();
SubRoot.Nodes.Add(subnode);
this.userControRole1.combFplantfid.Items.Add(Dt.Rows[0][1].ToString());
break;
default:
SubRoot = new TreeNode(NodeText);
SubRoot.Tag=NodeTag;
SubRoot.SelectedImageIndex=1;
SubRoot.ImageIndex=0;
FRoot.Nodes.Add(SubRoot);
for(int i=0;i<Dt.Rows.Count;i++)
{
TreeNode node = new TreeNode(Dt.Rows[i][1].ToString());
node.Tag=Dt.Rows[i][0].ToString();
node.SelectedImageIndex=2;
node.ImageIndex=3;
SubRoot.Nodes.Add(node);//Fid,Fname
}
break;
}
//
this.userControRole1.combFplantfid.DataSource=Dt;
this.userControRole1.combFplantfid.ValueMember=Dt.Columns[0].ToString();
this.userControRole1.combFplantfid.DisplayMember=Dt.Columns[1].ToString();
//
sql="select fname,fdesc,fmenu,fremark from dnc_sys_menu";
DataTable dt = Pbase.GetDatetable(null,sql);
this.userControRole1.listVPurview.Items.Clear();
for(int i=0;i<dt.Rows.Count;i++)
{
string[] stritem = new string[4]
{
"(" + (1 + i).ToString() + ")",
dt.Rows[i][0].ToString(),
dt.Rows[i][1].ToString(),
// dt.Rows[i][2].ToString(),
dt.Rows[i][3].ToString()
};
ListViewItem li = new ListViewItem(stritem,0);
li.Checked=true;
li.Tag=dt.Rows[i][2].ToString();
this.userControRole1.listVPurview.Items.Add(li);
this.userControRole1.listVPurview.MultiSelect=true;
}
userControRole1.listVPurview.CheckBoxes=true;
dt.Dispose();
this.userControRole1.btnAdd.Click+=new EventHandler(RolebtnClick);
this.userControRole1.btnUpdate.Click+=new EventHandler(RolebtnClick);
this.userControRole1.btndel.Click +=new EventHandler(btndelClick);
this.userControRole1.listVRole.Click+=new EventHandler(RolelistViewClick);
this.userControRole1.listVPurview.ColumnClick+=new ColumnClickEventHandler(listVPurview_ColumnClick);
#endregion
//////
//人员增加
//////
#region dnc_sys_employee
NodeText="分厂人员增加管理";
NodeTag = 2;
TreeNode ThirdbRoot;
if(CGlobe.Fduty==0)
{
this.userControEmp.btnAdd.Enabled=false;
this.userControEmp.btnUpdate.Enabled=false;
this.userControEmp.btndel.Enabled=false;
this.userControEmp.btnAdd.Enabled=false;
this.userControEmp.btnUpdate.Enabled=false;
this.userControEmp.btndel.Enabled=false;
}
switch(Dt.Rows.Count)
{
case 0:
ThirdbRoot = new TreeNode(NodeText);
ThirdbRoot.Tag=NodeTag;
ThirdbRoot.SelectedImageIndex=1;
ThirdbRoot.ImageIndex=0;
FRoot.Nodes.Add(ThirdbRoot);
break;
case 1:
NodeText=Dt.Rows[0][1].ToString() + NodeText;
ThirdbRoot = new TreeNode(NodeText);
ThirdbRoot.Tag=NodeTag;
ThirdbRoot.SelectedImageIndex=1;
ThirdbRoot.ImageIndex=0;
FRoot.Nodes.Add(ThirdbRoot);
TreeNode subnode = new TreeNode(Dt.Rows[0][1].ToString());
subnode.Tag=Dt.Rows[0][0].ToString();
ThirdbRoot.Nodes.Add(subnode);
// this.userControRole1.combFplantfid.Items.Add(Dt.Rows[0][1].ToString());
break;
default:
ThirdbRoot = new TreeNode(NodeText);
ThirdbRoot.Tag=NodeTag;
ThirdbRoot.SelectedImageIndex=1;
ThirdbRoot.ImageIndex=0;
FRoot.Nodes.Add(ThirdbRoot);
for(int i=0;i<Dt.Rows.Count;i++)
{
TreeNode node = new TreeNode(Dt.Rows[i][1].ToString());
node.Tag=Dt.Rows[i][0].ToString();
node.SelectedImageIndex=2;
node.ImageIndex=3;
ThirdbRoot.Nodes.Add(node);//Fid,Fname
}
break;
}
this.userControEmp.btnAdd.Click+=new EventHandler(btnClick);
this.userControEmp.btnUpdate.Click+=new EventHandler(btnClick);
this.userControEmp.btndel.Click+=new EventHandler(btndelClick);
this.userControEmp.listView1.Click+=new EventHandler(listView1_Click);
this.userControEmp.listView1.MouseUp += new MouseEventHandler(listView1_MouseUp);
#endregion dnc_sys_employee
}
----------------------------------------------------------------------------------------------------