private void SaleOrderWarehouseListForm_Load(object sender, EventArgs e)
        {
            using (SSLsEntities db = new SSLsEntities())
            {
                this._pc = PhysicalAddressPOS.ShowNetworkInterfaces();
                var b = SingletonAuthen.Instance().MyBranch.Id;
                var pcs = db.PosMachine.Where(w => w.Enable == true && w.FKBranch == b).ToList();
                //var checkPC = pcs.FirstOrDefault(w => w.EthernetPhysicalAddress == pc.EthernetAddress || w.WirelessPhysicalAddress == pc.WirelessAddress && w.Enable == true && w.FKBranch == b);
                var checkPC = pcs.FirstOrDefault(w => w.ComputerName == _pc.ComputerName && w.Enable == true && w.FKBranch == b);
                if (checkPC != null)
                {
                    // แสดงว่า เครื่อง เคยบันทึกการตั้งค่าแล้ว
                    _posMachine = checkPC;
                }
                else
                {
                    MessageBox.Show("ไม่พบการตั้งค่าหมายเลขเครื่อง กรุณาติดต่อ Admin");
                }
            }

            DataGridViewCheckBoxColumn ColumnCheckBox = new DataGridViewCheckBoxColumn();
            ColumnCheckBox.Width = width_columcheckbox;
            ColumnCheckBox.DataPropertyName = "Select";
            //dataGridView1.Columns.Add(ColumnCheckBox);
            Rectangle rect = dataGridView1.GetCellDisplayRectangle(colCheckAll, -1, true);
            ckBox.Size = new Size(14, 14);
            rect.X = rect.Location.X + (rect.Width / 2) - (ckBox.Width / 2);
            rect.Y += 3;
            ckBox.Location = rect.Location;
            this.ckBox.CheckedChanged += new EventHandler(this.ckBox_CheckedChanged);
            dataGridView1.Controls.Add(ckBox);
            dataGridView1.Columns[colCheckAll].Frozen = false;

            LoadGrid();
        }
Example #2
0
        public static PhysicalAddressPC ShowNetworkInterfaces()
        {
            try
            {
                IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties();
                NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
                //Console.WriteLine("Interface information for {0}.{1}     ",
                //        computerProperties.HostName, computerProperties.DomainName);
                PhysicalAddressPC pc = new PhysicalAddressPC();
                pc.ComputerName = computerProperties.HostName;
                if (nics == null || nics.Length < 1)
                {
                    //Console.WriteLine("  No network interfaces found.");
                    pc.ComputerName    = computerProperties.HostName;
                    pc.EthernetAddress = computerProperties.HostName;
                    pc.WirelessAddress = computerProperties.HostName;
                    return(pc);
                }

                //Console.WriteLine("  Number of interfaces .................... : {0}", nics.Length);

                foreach (NetworkInterface adapter in nics)
                {
                    IPInterfaceProperties properties = adapter.GetIPProperties(); //  .GetIPInterfaceProperties();
                    Console.WriteLine();
                    //Console.WriteLine(adapter.Description);
                    //Console.WriteLine(String.Empty.PadLeft(adapter.Description.Length, '='));
                    //Console.WriteLine("  Interface type .......................... : {0}", adapter.NetworkInterfaceType);
                    if (adapter.NetworkInterfaceType.ToString().Contains("Ethernet"))
                    {
                        //Console.Write("  Physical address ........................ : ");
                        PhysicalAddress address = adapter.GetPhysicalAddress();
                        byte[]          bytes   = address.GetAddressBytes();
                        string          no      = "";
                        for (int i = 0; i < bytes.Length; i++)
                        {
                            // Display the physical address in hexadecimal.
                            //Console.Write("{0}", bytes[i].ToString("X2"));
                            no = no + bytes[i].ToString("X2").ToString();
                            // Insert a hyphen after each byte, unless we are at the end of the
                            // address.
                            if (i != bytes.Length - 1)
                            {
                                //Console.Write("-");
                                no = no + "-";
                            }
                        }
                        pc.EthernetAddress = no;
                    }
                    else if (adapter.NetworkInterfaceType.ToString().Contains("Wireless"))
                    {
                        //Console.Write("  Physical address ........................ : ");
                        PhysicalAddress address = adapter.GetPhysicalAddress();
                        byte[]          bytes   = address.GetAddressBytes();
                        string          no      = "";
                        for (int i = 0; i < bytes.Length; i++)
                        {
                            // Display the physical address in hexadecimal.
                            //Console.Write("{0}", bytes[i].ToString("X2"));
                            no = no + bytes[i].ToString("X2").ToString();
                            // Insert a hyphen after each byte, unless we are at the end of the
                            // address.
                            if (i != bytes.Length - 1)
                            {
                                //Console.Write("-");
                                no = no + "-";
                            }
                        }
                        pc.WirelessAddress = no;
                    }
                    if (pc.EthernetAddress != null && pc.WirelessAddress != null)
                    {
                        return(pc);
                    }
                    else if (pc.EthernetAddress == null)
                    {
                        pc.EthernetAddress = "Undefine";
                    }
                    else if (pc.WirelessAddress == null)
                    {
                        pc.WirelessAddress = "Undefine";
                    }

                    Console.WriteLine();
                }
                return(pc);
            }
            catch (Exception ex)
            {
                IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties();
                PhysicalAddressPC  pc = new PhysicalAddressPC();
                pc.ComputerName    = computerProperties.HostName;
                pc.EthernetAddress = computerProperties.HostName;
                pc.WirelessAddress = computerProperties.HostName;
                return(pc);
            }
        }