コード例 #1
0
ファイル: Licensing.cs プロジェクト: wee2tee/XML-Exporter
        public static SRV_RegisterData GetSrvRegisterData(LOC_RegisterData local_regdata)
        {
            if (local_regdata == null)
            {
                return(null);
            }

            SRV_RegisterData srv_regdata = new SRV_RegisterData();

            srv_regdata._conn_success  = false;
            srv_regdata._failed_reason = SRV_RegisterData.FAILED_REASON.NONE;

            try
            {
                string json_data = "{\"token_key\":\"" + local_regdata.token_key + "\"}";
                string result    = WebComm.PostData("http://www.esg.co.th/XML-Exporter/get_registered_data.php", json_data);
                srv_regdata = JsonConvert.DeserializeObject <SRV_RegisterData>(result);
            }
            catch (Exception)
            {
                return(null);
            }

            return(srv_regdata);
        }
コード例 #2
0
ファイル: Licensing.cs プロジェクト: wee2tee/XML-Exporter
        public static LOC_RegisterData GetLocalRegData()
        {
            LOC_RegisterData local_reg = null;

            if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + "CL.DLL"))
            {
                return(local_reg);
            }

            try
            {
                string conn_str = "Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "CL.DLL;Version=3;";
                using (SQLiteConnection conn = new SQLiteConnection(conn_str, true))
                {
                    conn.SetPassword("weetee.dev");
                    conn.Open();

                    using (SQLiteCommand cmd = conn.CreateCommand())
                    {
                        // Reading data
                        cmd.CommandText = @"Select * From config";
                        using (SQLiteDataReader reader = cmd.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                local_reg               = new LOC_RegisterData();
                                local_reg.token_key     = reader.IsDBNull(1) ? "" : reader.GetString(1).Trim();
                                local_reg.machine_code  = reader.IsDBNull(2) ? "" : reader.GetString(2).Trim();
                                local_reg.comp_name     = reader.IsDBNull(3) ? "" : reader.GetString(3).Trim();
                                local_reg.reg_type      = reader.IsDBNull(4) ? "" : reader.GetString(4).Trim();
                                local_reg.sernum        = reader.IsDBNull(5) ? "" : reader.GetString(5).Trim();
                                local_reg.contact       = reader.IsDBNull(6) ? "" : reader.GetString(6).Trim();
                                local_reg.telnum        = reader.IsDBNull(7) ? "" : reader.GetString(7).Trim();
                                local_reg.email         = reader.IsDBNull(8) ? "" : reader.GetString(8).Trim();
                                local_reg.remark        = reader.IsDBNull(9) ? "" : reader.GetString(9).Trim();
                                local_reg.slip_filename = reader.IsDBNull(10) ? "" : reader.GetString(10).Trim();
                                //local_reg.status_code = reader.IsDBNull(11) ? "" : reader.GetString(11).Trim();
                                //local_reg.status = reader.IsDBNull(12) ? "" : reader.GetString(12).Trim();
                                local_reg.reg_date     = reader.IsDBNull(13) ? DateTime.Now.AddYears(50) : reader.GetDateTime(13);
                                local_reg.reg_time     = reader.IsDBNull(14) ? "" : reader.GetString(14).Trim();
                                local_reg.reg_unixtime = reader.IsDBNull(15) ? "" : reader.GetString(15).Trim();
                            }
                        }
                    }
                    conn.Close();
                }
            }
            catch (SQLiteException ex)
            {
                // do nothing.
            }
            return(local_reg);
        }
コード例 #3
0
        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();
        }