Browse Source

调用ERP接口认证登录

章政 6 years ago
parent
commit
3f396cb301

+ 6 - 5
PLCDataReader/DataOperate/DataHelper.cs

@@ -9,10 +9,13 @@ namespace UAS_PLCDataReader.DataOperate
 {
     class DataHelper
     {
-        //系统默认的的连接字符串
-        private string ConnectionStrings = Properties.Settings.Default.Properties["MES"].DefaultValue.ToString();
+
+        //泽天外网地址
+        private readonly string ConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=GOLDEN_TEST;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=183.238.39.179)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+        //泽天ERP地址
+        public static readonly string ERPAddesss = "http://183.238.39.179:8099/ERP/";
         //用户选择的数据库的连接字符串
-        public static string DBConnectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=UAS_DEV;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.253.6)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+        public static string DBConnectionString ;
         public static OracleConnection connection = null;
         OracleCommand command = null;
         /// <summary>
@@ -526,7 +529,6 @@ namespace UAS_PLCDataReader.DataOperate
                 for (int i = 0; i < addpar.Length; i++)
                     command.Parameters.Add(new OracleParameter(addpar[i].ToString(), OracleDbType.Varchar2, names[i], ParameterDirection.Input));
             }
-            Console.WriteLine(SQL);
             switch (Type.ToUpper())
             {
                 case "SELECT":
@@ -989,7 +991,6 @@ namespace UAS_PLCDataReader.DataOperate
             {
                 foreach (string sql in SQL)
                 {
-                    Console.WriteLine(sql);
                     if (!String.IsNullOrEmpty(sql))
                     {
                         command.CommandText = sql;

+ 33 - 5
PLCDataReader/Login.Designer.cs

@@ -33,13 +33,16 @@
             this.UserName_label = new DevExpress.XtraEditors.LabelControl();
             this.PassWord_label = new DevExpress.XtraEditors.LabelControl();
             this.LoginButton = new DevExpress.XtraEditors.SimpleButton();
+            this.Master = new DevExpress.XtraEditors.ComboBoxEdit();
+            this.Master_label = new DevExpress.XtraEditors.LabelControl();
             ((System.ComponentModel.ISupportInitialize)(this.UserName.Properties)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.PassWord.Properties)).BeginInit();
+            ((System.ComponentModel.ISupportInitialize)(this.Master.Properties)).BeginInit();
             this.SuspendLayout();
             // 
             // UserName
             // 
-            this.UserName.Location = new System.Drawing.Point(144, 66);
+            this.UserName.Location = new System.Drawing.Point(144, 57);
             this.UserName.Name = "UserName";
             this.UserName.Properties.Appearance.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
             this.UserName.Properties.Appearance.Options.UseFont = true;
@@ -48,7 +51,7 @@
             // 
             // PassWord
             // 
-            this.PassWord.Location = new System.Drawing.Point(144, 114);
+            this.PassWord.Location = new System.Drawing.Point(144, 105);
             this.PassWord.Name = "PassWord";
             this.PassWord.Properties.Appearance.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
             this.PassWord.Properties.Appearance.Options.UseFont = true;
@@ -60,7 +63,7 @@
             // UserName_label
             // 
             this.UserName_label.Appearance.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
-            this.UserName_label.Location = new System.Drawing.Point(71, 69);
+            this.UserName_label.Location = new System.Drawing.Point(71, 60);
             this.UserName_label.Name = "UserName_label";
             this.UserName_label.Size = new System.Drawing.Size(48, 21);
             this.UserName_label.TabIndex = 2;
@@ -69,7 +72,7 @@
             // PassWord_label
             // 
             this.PassWord_label.Appearance.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
-            this.PassWord_label.Location = new System.Drawing.Point(87, 117);
+            this.PassWord_label.Location = new System.Drawing.Point(87, 108);
             this.PassWord_label.Name = "PassWord_label";
             this.PassWord_label.Size = new System.Drawing.Size(32, 21);
             this.PassWord_label.TabIndex = 3;
@@ -77,18 +80,40 @@
             // 
             // LoginButton
             // 
-            this.LoginButton.Location = new System.Drawing.Point(171, 184);
+            this.LoginButton.Location = new System.Drawing.Point(171, 202);
             this.LoginButton.Name = "LoginButton";
             this.LoginButton.Size = new System.Drawing.Size(75, 23);
             this.LoginButton.TabIndex = 4;
             this.LoginButton.Text = "登录";
             this.LoginButton.Click += new System.EventHandler(this.LoginButton_Click);
             // 
+            // Master
+            // 
+            this.Master.Location = new System.Drawing.Point(144, 149);
+            this.Master.Name = "Master";
+            this.Master.Properties.Appearance.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+            this.Master.Properties.Appearance.Options.UseFont = true;
+            this.Master.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
+            new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)});
+            this.Master.Size = new System.Drawing.Size(145, 28);
+            this.Master.TabIndex = 5;
+            // 
+            // Master_label
+            // 
+            this.Master_label.Appearance.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+            this.Master_label.Location = new System.Drawing.Point(87, 152);
+            this.Master_label.Name = "Master_label";
+            this.Master_label.Size = new System.Drawing.Size(32, 21);
+            this.Master_label.TabIndex = 6;
+            this.Master_label.Text = "账套";
+            // 
             // Login
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 14F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.ClientSize = new System.Drawing.Size(414, 245);
+            this.Controls.Add(this.Master_label);
+            this.Controls.Add(this.Master);
             this.Controls.Add(this.LoginButton);
             this.Controls.Add(this.PassWord_label);
             this.Controls.Add(this.UserName_label);
@@ -101,6 +126,7 @@
             this.Load += new System.EventHandler(this.Login_Load);
             ((System.ComponentModel.ISupportInitialize)(this.UserName.Properties)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.PassWord.Properties)).EndInit();
+            ((System.ComponentModel.ISupportInitialize)(this.Master.Properties)).EndInit();
             this.ResumeLayout(false);
             this.PerformLayout();
 
@@ -113,5 +139,7 @@
         private DevExpress.XtraEditors.LabelControl UserName_label;
         private DevExpress.XtraEditors.LabelControl PassWord_label;
         private DevExpress.XtraEditors.SimpleButton LoginButton;
+        private DevExpress.XtraEditors.ComboBoxEdit Master;
+        private DevExpress.XtraEditors.LabelControl Master_label;
     }
 }

+ 11 - 5
PLCDataReader/Login.cs

@@ -21,6 +21,8 @@ namespace UAS_PLCDataReader
         private void Login_Load(object sender, EventArgs e)
         {
             SystemInf.dh = dh;
+            DataTable dt = (DataTable)dh.ExecuteSql("select ma_user,ma_function from master", "select");
+            BaseUtil.FillComBoxEditWidthDataTable(Master, "ma_function", "ma_user", dt, false);
         }
 
         private void LoginButton_Click(object sender, EventArgs e)
@@ -28,8 +30,12 @@ namespace UAS_PLCDataReader
             if (UserName.Text != "" && PassWord.Text != "")
             {
                 string oErrMessage = "";
-                if (LogicHandler.CheckUserLogin(UserName.Text, PassWord.Text, out oErrMessage))
+                string master = BaseUtil.GetComboxEditValue(Master);
+                if (LogicHandler.CheckUserLogin(UserName.Text, PassWord.Text, master, out oErrMessage))
                 {
+                    DataHelper.DBConnectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=" + master + ";Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=183.238.39.179)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+                    dh = new DataHelper();
+                    SystemInf.dh = dh;
                     SetInf();
                     Main main = new Main();
                     Hide();
@@ -47,8 +53,8 @@ namespace UAS_PLCDataReader
         private void SetInf()
         {
             //设置全局用户信息
-            string[] field = { "em_code,em_depart,em_type,em_name,em_position,em_professname,em_type,ug_code,ug_name" };
-            UserInf = dh.getFieldsDataByCondition("Employee left join cs$userresource on ur_emcode=em_code left join cs$usergroup on ug_code=ur_groupcode", field, "upper(em_code)='" + UserName.Text.ToUpper() + "'");
+            string[] field = { "em_code,em_depart,em_type,em_name,em_position,em_professname,em_type" };
+            UserInf = dh.getFieldsDataByCondition("Employee ", field, "upper(em_code)='" + UserName.Text.ToUpper() + "'");
             //通过Source表关联岗位资源编号查询出当前的执行工序
             User.UserCode = UserInf.Rows[0]["em_code"].ToString();
             User.UserDepartment = UserInf.Rows[0]["em_depart"].ToString();
@@ -56,8 +62,8 @@ namespace UAS_PLCDataReader
             User.UserPosition = UserInf.Rows[0]["em_position"].ToString();
             User.UserProfessName = UserInf.Rows[0]["em_professname"].ToString();
             User.UserAccountType = UserInf.Rows[0]["em_type"].ToString();
-            User.UserGroupCode = UserInf.Rows[0]["ug_code"].ToString();
-            User.UserGroup = UserInf.Rows[0]["ug_name"].ToString();
+            //User.UserGroupCode = UserInf.Rows[0]["ug_code"].ToString();
+            //User.UserGroup = UserInf.Rows[0]["ug_name"].ToString();
         }
 
         private void PassWord_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)

+ 6 - 6
PLCDataReader/Main.cs

@@ -614,7 +614,7 @@ namespace UAS_PLCDataReader
             if (ButtonSaveCommandSet.LastSaveID != null && ButtonSaveCommandSet.LastSaveID.Length > 0)
             {
                 dh.BatchInsert(sql.ToString(), new string[] { "dpc_id" }, ButtonSaveCommandSet.LastSaveID);
-            }
+            }   
             GridPollingSetting.RefreshData();
         }
         /// <summary>
@@ -661,10 +661,9 @@ namespace UAS_PLCDataReader
             if (PageDeviceStatus.PageVisible)
             {
                 DeviceStatusQuerySQL.Clear();
-                DeviceStatusQuerySQL.Append("select distinct de_code,de_name,dr_runstatus from device left join devicerunstatus on dr_decode=de_code order by de_code");
-                PaintDeviceStatusControl(DeviceStatusQuerySQL.ToString());
-                //填充筛选条件,车间和线体
-                DataTable dt = (DataTable)dh.ExecuteSql("select wc_code,wc_name from workcenter", "select");
+                CheckEditDeviceStatusEnable_CheckedChanged(sender, e);
+                  //填充筛选条件,车间和线体
+                  DataTable dt = (DataTable)dh.ExecuteSql("select wc_code,wc_name from workcenter", "select");
                 BaseUtil.FillComBoxEditWidthDataTable(ComboxDeviceStatusWC, "wc_name", "wc_code", dt, true);
             }
         }
@@ -691,7 +690,7 @@ namespace UAS_PLCDataReader
             string WC = BaseUtil.GetComboxEditValue(ComboxDeviceStatusWC);
             if (CheckEditDeviceStatusEnable.Checked)
             {
-                DeviceStatusQuerySQL.Append("select distinct de_code,de_name,dr_runstatus from device left join devicerunstatus left join  ");
+                DeviceStatusQuerySQL.Append("select distinct de_code,de_name,dr_runstatus from device left join devicerunstatus ");
                 DeviceStatusQuerySQL.Append("on dr_decode=de_code left join DEVICEPOLLINGCONFIG on de_code=dpc_decode where nvl(dpc_enable,0)<>0 and de_wccode='" + WC + "' order by de_code");
             }
             else
@@ -741,6 +740,7 @@ namespace UAS_PLCDataReader
 
         private void PaintDeviceStatusControl(string SQL)
         {
+            Console.WriteLine(SQL);
             DataTable dt = (DataTable)dh.ExecuteSql(SQL, "select");
             //界面重新展示时如过数量不一致则重新绘制
             if (PanelDeviceStatus.Controls.Count != dt.Rows.Count)

+ 3 - 3
PLCDataReader/Properties/Settings.Designer.cs

@@ -25,9 +25,9 @@ namespace UAS_PLCDataReader.Properties {
         
         [global::System.Configuration.UserScopedSettingAttribute()]
         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
-        [global::System.Configuration.DefaultSettingValueAttribute("Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=UAS_MES_PROD;Pool" +
-            "ing=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=19" +
-            "2.168.253.6)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));")]
+        [global::System.Configuration.DefaultSettingValueAttribute("Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=GOLDEN_TEST;Pooli" +
+            "ng=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=183" +
+            ".238.39.179)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));")]
         public string MES {
             get {
                 return ((string)(this["MES"]));

+ 1 - 1
PLCDataReader/Properties/Settings.settings

@@ -3,7 +3,7 @@
   <Profiles />
   <Settings>
     <Setting Name="MES" Type="System.String" Scope="User">
-      <Value Profile="(Default)">Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=UAS_MES_PROD;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.253.6)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));</Value>
+      <Value Profile="(Default)">Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=GOLDEN_TEST;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=183.238.39.179)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));</Value>
     </Setting>
   </Settings>
 </SettingsFile>

+ 47 - 0
PLCDataReader/PublicMethod/BaseUtil.cs

@@ -11,6 +11,7 @@ using UAS_PLCDataReader.CustomerControl.ValueLabel;
 using System.Collections.Generic;
 using System.Xml;
 using UAS_PLCDataReader.Entity;
+using System.Text.RegularExpressions;
 
 namespace UAS_PLCDataReader.PublicMethod
 {
@@ -81,6 +82,52 @@ namespace UAS_PLCDataReader.PublicMethod
                 return (ComBox.SelectedItem as ComboBoxData).Value;
         }
 
+        public static Dictionary<string, object> ToDictionary(string JsonData)
+        {
+            object Data = null;
+            Dictionary<string, object> Dic = new Dictionary<string, object>();
+            if (JsonData.StartsWith("["))
+            {
+                //如果目标直接就为数组类型,则将会直接输出一个Key为List的List<Dictionary<string, object>>集合 
+                //使用示例List<Dictionary<string, object>> ListDic = (List<Dictionary<string, object>>)Dic["List"]; 
+                List<Dictionary<string, object>> List = new List<Dictionary<string, object>>();
+                MatchCollection ListMatch = Regex.Matches(JsonData, @"{[\s\S]+?}");//使用正则表达式匹配出JSON数组 
+                foreach (Match ListItem in ListMatch)
+                {
+                    List.Add(ToDictionary(ListItem.ToString()));//递归调用 
+                }
+                Data = List;
+                Dic.Add("List", Data);
+            }
+            else
+            {
+                MatchCollection Match = Regex.Matches(JsonData, @"""(.+?)"": {0,1}(\[[\s\S]+?\]|null|"".+?""|-{0,1}\d*)");//使用正则表达式匹配出JSON数据中的键与值 
+                foreach (Match item in Match)
+                {
+                    try
+                    {
+                        if (item.Groups[2].ToString().StartsWith("["))
+                        {
+                            //如果目标是数组,将会输出一个Key为当前Json的List<Dictionary<string, object>>集合 
+                            //使用示例List<Dictionary<string, object>> ListDic = (List<Dictionary<string, object>>)Dic["Json中的Key"]; 
+                            List<Dictionary<string, object>> List = new List<Dictionary<string, object>>();
+                            MatchCollection ListMatch = Regex.Matches(item.Groups[2].ToString(), @"{[\s\S]+?}");//使用正则表达式匹配出JSON数组 
+                            foreach (Match ListItem in ListMatch)
+                            {
+                                List.Add(ToDictionary(ListItem.ToString()));//递归调用 
+                            }
+                            Data = List;
+                        }
+                        else if (item.Groups[2].ToString().ToLower() == "null") Data = null;//如果数据为null(字符串类型),直接转换成null
+                        else Data = item.Groups[2].ToString(); //数据为数字、字符串中的一类,直接写入 
+                        Dic.Add(item.Groups[1].ToString(), Data);
+                    }
+                    catch { }
+                }
+            }
+            return Dic;
+        }
+
         /// <summary>
         /// 获取LRC
         /// </summary>

+ 61 - 0
PLCDataReader/PublicMethod/LogicHandler.cs

@@ -1,6 +1,8 @@
 using System;
 using System.Collections.Generic;
 using System.Data;
+using System.IO;
+using System.Net;
 using System.Text;
 using System.Windows.Forms;
 using UAS_PLCDataReader.DataOperate;
@@ -38,6 +40,63 @@ namespace UAS_PLCDataReader.PublicMethod
             }
         }
 
+        public static bool CheckUserLogin(string UserName, string PassWord, string Master, out string oMsg)
+        {
+            oMsg = "";
+            try
+            {
+                string url = DataHelper.ERPAddesss + "mobile/login.action";//html调用的地址              
+                HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(url);
+                if (webrequest == null)
+                {
+                    return false;
+                }
+                webrequest.Method = "POST";
+                webrequest.Timeout = 1000;
+                webrequest.ContentType = "application/x-www-form-urlencoded";
+                System.Collections.Hashtable pars = new System.Collections.Hashtable();
+                pars.Add("username", UserName);
+                pars.Add("password", PassWord);
+                pars.Add("master", Master);
+                string buffer = "";
+                //发送POST数据 
+                if (!(pars == null || pars.Count == 0))
+                {
+                    foreach (string key in pars.Keys)
+                    {
+                        buffer = buffer + "&" + key + "=" + pars[key].ToString();
+                    }
+                    byte[] data = Encoding.UTF8.GetBytes(buffer);
+                    using (Stream stream = webrequest.GetRequestStream())
+                    {
+                        stream.Write(data, 0, data.Length);
+                    }
+                }
+
+                string[] values = webrequest.Headers.GetValues("Content-Type");
+                WebResponse myResponse = webrequest.GetResponse();
+
+                using (Stream resStream = myResponse.GetResponseStream())//得到回写的流
+                {
+                    StreamReader newReader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
+                    string Content = newReader.ReadToEnd();
+                    Dictionary<string, object> dic = new Dictionary<string, object>();
+                    dic = BaseUtil.ToDictionary(Content);
+                    if (!dic.ContainsKey("erpaccount"))
+                    {
+                        oMsg = dic["reason"].ToString();
+                        return false;
+                    }
+                    newReader.Close();
+                }
+            }
+            catch (Exception ex)
+            {
+                LogManager.DoLog(ex.Message.ToString());
+            }
+            return true;
+        }
+
         /// <summary>
         /// 进行差异日志记录
         /// </summary>
@@ -182,6 +241,8 @@ namespace UAS_PLCDataReader.PublicMethod
             string PARAM1 = "";
             string PARAM2 = "";
             string PARAM3 = "";
+            if (ItemData == null)
+                return;
             foreach (var item in ItemData)
             {
                 switch (item.Key)

+ 1 - 1
PLCDataReader/app.config

@@ -8,7 +8,7 @@
     <userSettings>
         <UAS_PLCDataReader.Properties.Settings>
             <setting name="MES" serializeAs="String">
-                <value>Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=UAS_MES_PROD;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.253.6)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));</value>
+                <value>Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=GOLDEN_TEST;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=183.238.39.179)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));</value>
             </setting>
         </UAS_PLCDataReader.Properties.Settings>
     </userSettings>