private void btnOK_Click(object sender, EventArgs e) { LoadingScreen ls = new LoadingScreen(); ls.ShowCenterParent(this); SRV_RegisterData srv_regdata = new SRV_RegisterData(); srv_regdata._conn_success = false; srv_regdata._failed_reason = SRV_RegisterData.FAILED_REASON.NONE; LOC_RegisterData loc_regdata = new LOC_RegisterData(); BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += delegate { DriveInformation drive = Licensing.GetDriveInfo(); //loc_regdata.token_key = Licensing.CalcMD5(drive.hddSerialNumber); //loc_regdata.machine_code = drive.hddSerialNumber; loc_regdata.token_key = Licensing.CalcMD5(Licensing.GetHDDSerialNumber(Licensing.GetSystemDriveLetter())); loc_regdata.machine_code = Licensing.GetHDDSerialNumber(Licensing.GetSystemDriveLetter()); loc_regdata.comp_name = Licensing.GetServerCompName(); loc_regdata.reg_type = (Licensing.IsLAN() ? "LAN" : "LOCAL"); loc_regdata.sernum = this.sernum; loc_regdata.contact = this.contact; loc_regdata.telnum = this.telnum; loc_regdata.email = this.email; loc_regdata.remark = this.remark; loc_regdata.slip_filename = Path.GetFileName(this.slip_file_path); loc_regdata.tax_filename = Path.GetFileName(this.tax_file_path); NameValueCollection nvc = new NameValueCollection(); nvc.Add("token_key", loc_regdata.token_key); nvc.Add("machine_code", loc_regdata.machine_code); nvc.Add("comp_name", loc_regdata.comp_name); nvc.Add("reg_type", loc_regdata.reg_type); nvc.Add("sernum", loc_regdata.sernum); nvc.Add("contact", loc_regdata.contact); nvc.Add("telnum", loc_regdata.telnum); nvc.Add("email", loc_regdata.email); nvc.Add("remark", loc_regdata.remark); nvc.Add("slip_filename", loc_regdata.slip_filename); try { string upload_tax_result = WebComm.UploadMultipart("http://www.esg.co.th/XML-Exporter/upload_tax_file.php", this.tax_file_path, "file1", "image/jpg", nvc); ServerResult sr = JsonConvert.DeserializeObject <ServerResult>(upload_tax_result); nvc.Add("tax_filename", sr.message); string web_result = WebComm.UploadMultipart("http://www.esg.co.th/XML-Exporter/upload_register.php", this.slip_file_path, "file1", "image/jpg", nvc); //WebResult web_result = WebComm.UploadMultipart("http://www.weetee.com:3636/XML-Exporter/upload.php", this.file_path, "file1", "image/jpg", nvc); srv_regdata = JsonConvert.DeserializeObject <SRV_RegisterData>(web_result); //loc_regdata.status_code = srv_regdata.status_code; //loc_regdata.status = srv_regdata.status; loc_regdata.reg_date = DateTime.Parse(srv_regdata.reg_date, CultureInfo.GetCultureInfo("en-US").DateTimeFormat); loc_regdata.reg_time = srv_regdata.reg_time; loc_regdata.reg_unixtime = srv_regdata.reg_unixtime; } catch (Exception ex) { srv_regdata._conn_success = false; } }; worker.RunWorkerCompleted += delegate { ls.Close(); if (srv_regdata._conn_success) { if ((int)srv_regdata._failed_reason == (int)SRV_RegisterData.FAILED_REASON.NONE) { //if (Licensing.WriteTokenKey(loc_regdata.token_key, loc_regdata.machine_code, loc_regdata.comp_name, loc_regdata.reg_type, loc_regdata.sernum, loc_regdata.contact, loc_regdata.telnum, loc_regdata.email, loc_regdata.remark, loc_regdata.slip_filename, loc_regdata.status_code, loc_regdata.status, loc_regdata.reg_date.ToString("yyyy-MM-dd", CultureInfo.GetCultureInfo("en-US")), loc_regdata.reg_time, loc_regdata.reg_unixtime)) if (Licensing.WriteTokenKey(loc_regdata.token_key, loc_regdata.machine_code, loc_regdata.comp_name, loc_regdata.reg_type, loc_regdata.sernum, loc_regdata.contact, loc_regdata.telnum, loc_regdata.email, loc_regdata.remark, loc_regdata.slip_filename, loc_regdata.reg_date.ToString("yyyy-MM-dd", CultureInfo.GetCultureInfo("en-US")), loc_regdata.reg_time, loc_regdata.reg_unixtime)) { MessageBox.Show("ส่งข้อมูลการลงทะเบียนโปรแกรมเรียบร้อย, เมื่อข้อมูลดังกล่าวได้รับการตรวจสอบจากทางบริษัทฯ แล้ว ท่านจะสามารถใช้งานความสามารถทั้งหมดของโปรแกรมได้ในทันที\n(โดยปกติใช้เวลาไม่เกิน 1 วันทำการ)"); this.DialogResult = DialogResult.OK; this.Close(); } return; } if ((int)srv_regdata._failed_reason == (int)SRV_RegisterData.FAILED_REASON.DUPLICATE_SN) { MessageBox.Show(srv_regdata._failed_reason.ToReasonString()); return; } } if (!srv_regdata._conn_success && srv_regdata._failed_reason == SRV_RegisterData.FAILED_REASON.NONE) { MessageBox.Show("ไม่สามารถส่งข้อมูลการลงทะเบียนได้, กรุณาตรวจสอบการเชื่อมต่ออินเทอร์เน็ต", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }; worker.RunWorkerAsync(); }