示例#1
0
        private void button2_Click(object sender, EventArgs e)
        {
            DataAcquisitionResult           result = new DataAcquisitionResult();
            List <DataAcquisitionDetailDTO> dtos   = new List <DataAcquisitionDetailDTO>();
            DataAcquisitionDetailDTO        dto    = new DataAcquisitionDetailDTO();

            dto.devicename   = "CNC1发那科";
            dto.spindlespeed = 1100;
            dto.feedspeed    = 8000;
            dto.runtime      = DateTime.Now.ToString();
            dtos.Add(dto);
            dto              = new DataAcquisitionDetailDTO();
            dto.devicename   = "CNC2发那科";
            dto.spindlespeed = 1100;
            dto.feedspeed    = 8000;
            dto.runtime      = DateTime.Now.ToString();
            dtos.Add(dto);
            string server = "http://localhost:15988/api/AutomationLine/SaveDataAcquisitionDetail";
            DataAcquisitionDetailAPIParameter param = new DataAcquisitionDetailAPIParameter();

            param.operator_name = "WebApi";
            param.operator_time = GenerateTimeStamp(DateTime.Now);
            param.sign          = GenSign(param.operator_name, param.operator_time);
            param.data          = dtos;
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("operator_name", param.operator_name);
            dic.Add("operator_time", param.operator_time);
            dic.Add("sign", param.sign);
            dic.Add("strdata", Serialize(param.data));

            try
            {
                HttpWebResponse        response = CreatePostHttpResponse(server, dic, null, null, Encoding.UTF8, null);
                System.IO.StreamReader sr       = new System.IO.StreamReader(response.GetResponseStream());
                string responseContent          = sr.ReadToEnd();
                sr.Close();

                DataAcquisitionResult rtn = Deserialize <DataAcquisitionResult>(responseContent);
                if (rtn.code != "1000")
                {
                    return;
                }
            }
            catch (Exception ex)
            {
                return;
            }
        }
示例#2
0
        public bool InsertDataAcquisitionDetail(DataAcquisitionDetailDTO dto)
        {
            bool fla = false;

            try
            {
                int       re   = 0;
                DbService ds   = new DbService(dbnfin, "MySQL");
                string    srt  = string.Format(@"INSERT INTO Sys_DataAcquisitionDetail(DeviceName,SpindleSpeed,FeedSpeed,RunTime,CreationTime)
                VALUES  ( '{0}',{1},{2},'{3}',NOW())", dto.devicename, dto.spindlespeed, dto.feedspeed, dto.runtime);
                int       sult = ds.InsertSql(srt, out re);
                if (sult > 0)
                {
                    //ds.DeleteSql(string.Format("DELETE from Sys_DataAcquisitionDetail where CreationTime<{0}", DateTime.Now.AddHours(-1).ToShortDateString()));
                    fla = true;
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
            }
            return(fla);
        }