예제 #1
0
        private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
        {
            DataGridView da = new DataGridView();

            if (CMND.ToString().Trim().Length <= 0)
            {
                MessageBox.Show("Chứng minh nhân dân đã tồn tại!", "Khach Hang", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (DienThoai.ToString().Trim().Length <= 0)
            {
                MessageBox.Show("Điện thoại đã tồn tại!", "Khach Hang", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                DataRow row = ctrl.NewRow();

                row["MaKhachHang"]  = "";
                row["TenKhachHang"] = "";
                row["CMND"]         = "";
                row["GioiTinh"]     = "";
                row["DiaChi"]       = "";
                row["DienThoai"]    = 0;
                row["QuocTich"]     = "";

                ctrl.Add(row);
                bindingNavigator1.BindingSource.MoveLast();
                //MaKhachHang.Focus();
            }
        }
예제 #2
0
        public CMND getInfo(string SOCMND)
        {
            CMND cmnd = null;

            try
            {
                SqlDataReader read = Reader("select NGAY_CAP,NOI_CAP from SO_CMND where CMND='" + SOCMND + "'");

                while (read.Read())
                {
                    cmnd         = new CMND();
                    cmnd.NgayCap = read.GetDateTime(0);
                    cmnd.NoiCap  = read.GetString(1);
                    break;
                }
                read.Close();
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }

            con.Close();

            return(cmnd);
        }
        private void Add_DoanVien_Click(object sender, RoutedEventArgs e)
        {
            Add = true;

            Add_DoanVien.IsEnabled = false;
            Mod_DoanVien.IsEnabled = false;

            SQLiteConnection sqlite_conn = new SQLiteConnection("Data source = QuanLyDoanVien.db");
            SQLiteCommand    sqlite_com  = new SQLiteCommand();

            sqlite_conn.Open();
            sqlite_com = sqlite_conn.CreateCommand();

            sqlite_com.CommandText = "SELECT Max(ID) FROM DoanVien";
            MaDoanVien.Text        = (Convert.ToInt32(sqlite_com.ExecuteScalar()) + 1).ToString();



            HoVaTen.IsEnabled                   = NgaySinh.IsEnabled = QueQuan.IsEnabled =
                GioiTinh.IsEnabled              = ChiDoan.IsEnabled = ChucVu.IsEnabled = ToDanPho.IsEnabled =
                    PhuongXa.IsEnabled          = QuanHuyen.IsEnabled = TinhThanh.IsEnabled = NgayVaoDang.IsEnabled =
                        NgayVaoDoan.IsEnabled   = TinhTrang.IsEnabled = CMND.IsEnabled = Email.IsEnabled =
                            DienThoai.IsEnabled = DanToc.IsEnabled = TonGiao.IsEnabled = HoanCanh.IsEnabled = TrinhDo.IsEnabled
                                                                                                                  = true;

            HoVaTen.Clear();
            NgaySinh.Clear(); QueQuan.Clear();
            GioiTinh.Clear(); ChiDoan.Clear(); ChucVu.Clear(); ToDanPho.Clear();
            PhuongXa.Clear(); QuanHuyen.Clear(); TinhThanh.Clear(); NgayVaoDang.Clear();
            NgayVaoDoan.Clear(); TinhTrang.Clear(); CMND.Clear(); Email.Clear();
            DienThoai.Clear(); DanToc.Clear(); TonGiao.Clear(); HoanCanh.Clear(); TrinhDo.Clear();
        }
예제 #4
0
 public bool create(CMND entity)
 {
     try
     {
         string sqlString = "INSERT INTO CMNDs VALUES ('" + entity.MaSo + "','" + entity.NgayCap.ToShortDateString() + "',N'" + entity.NoiCap + "')";
         return(db.MyExecuteNonQuery(sqlString, CommandType.Text));
     }
     catch (Exception e)
     {
         MessageBox.Show("Lỗi create CMND + " + e.Message);
         return(false);
     }
 }
예제 #5
0
 public bool edit(CMND enitity)
 {
     try
     {
         string sqlString = " UPDATE CMNDs " +
                            " SET MaSo = '" + enitity.MaSo + "'" +
                            ",NgayCap = '" + enitity.NgayCap.ToShortDateString() + "'" +
                            ",NoiCap = N'" + enitity.NoiCap + "' " +
                            "WHERE MaCD = '" + enitity.MaSo + "'";
         return(db.MyExecuteNonQuery(sqlString, CommandType.Text));
     }
     catch (Exception e)
     {
         MessageBox.Show("Lỗi edit CMND + " + e.Message);
         return(false);
     }
 }
예제 #6
0
 public CMND findById(string id)
 {
     try
     {
         string  sqlString = "select * from CMNDs where MaSo = " + id + "";
         DataSet ds        = db.ExecuteQueryDataSet(sqlString, CommandType.Text);
         CMND    cmnd      = new CMND()
         {
             MaSo    = (string)ds.Tables[0].Rows[0].ItemArray[0],
             NgayCap = (DateTime)ds.Tables[0].Rows[0].ItemArray[1],
             NoiCap  = (string)ds.Tables[0].Rows[0].ItemArray[2],
         };
         return(cmnd);
     }
     catch (Exception e)
     {
         MessageBox.Show("Lỗi findById CMND + " + e.Message);
         return(null);
     }
 }
예제 #7
0
 public CMND getLast()
 {
     try
     {
         string      sqlString = "select * from CMNDs ";
         DataSet     ds        = db.ExecuteQueryDataSet(sqlString, CommandType.Text);
         DataTable   dt        = ds.Tables[0];
         List <CMND> CMNDs     = new List <CMND>();
         foreach (DataRow dr in dt.Rows)
         {
             CMND cmnd = findById((string)dr.ItemArray[0]);
             CMNDs.Add(cmnd);
         }
         return(CMNDs.LastOrDefault());
     }
     catch (Exception e)
     {
         MessageBox.Show("Lỗi getLast CMND + " + e.Message);
         return(null);
     }
 }
예제 #8
0
        public bool taoCMND(string maCD, string tonGiao, string hinhAnh, string so, DateTime ngayCap, string noiCap)
        {
            CMND cmnd = new CMND(so, ngayCap, noiCap);

            if (cmndDAO.create(cmnd))
            {
                CongDan congDan = congDanController.layCongDanBangMaCD(maCD);
                if (congDan != null)
                {
                    congDan.HinhAnh = hinhAnh;
                    congDan.soCMND  = so;
                    congDan.TonGiao = tonGiao;
                    if (congDanController.chinhSuaCongDan(congDan))
                    {
                        MessageBox.Show("Sửa CMND công dân thành công");
                        return(true);
                    }
                }
                MessageBox.Show("Lỗi sửa CMND công dân");
                xoaCMND(cmnd);
            }
            return(false);
        }
예제 #9
0
 public int Insert(CMND cmnd)
 {
     return(ExecuteUpdate("insert into SO_CMND values('" + cmnd.SOCMND + "','" + cmnd.NgayCap.ToString() + "',N'" + cmnd.NoiCap + "')"));
 }
예제 #10
0
 public int Edit(CMND cmnd, string CMNDCU, string MaHS)
 {
     return(ExecuteUpdate("EditCMND", System.Data.CommandType.StoredProcedure, new SqlParameter("@CMNDCU", CMNDCU),
                          new SqlParameter("@CMND", cmnd.SOCMND), new SqlParameter("@NGAY_CAP", cmnd.NgayCap),
                          new SqlParameter("@NOI_CAP", cmnd.NoiCap), new SqlParameter("@MaHS", MaHS)));
 }
예제 #11
0
        /// <summary>
        /// Write value in DM
        /// </summary>
        /// <param name="S_ip">Source IP: Ip of the PC</param>
        /// <param name="S_port">Source Port: Port of the PC (9600)</param>
        /// <param name="D_ip">Destination IP: IP of the PLC</param>
        /// <param name="D_port">Destination Port: Port of the PLC (UDP Port default: 9600)</param>
        /// <param name="dmnum">DM Position: (DM100)</param>
        /// <param name="value">Value of the DM</param>
        /// <returns>True if there aren't error </returns>
        public bool WriteDM(string S_ip, int S_port, string D_ip, int D_port, int dmnum, int value)
        {
            int X, CmdLength, Cnt = 0, retval;

            byte[]     ByteArray = new byte[17];
            byte[]     myByte = new byte[1024];
            string     Header, tmp1, CMND;
            IPAddress  Remote_IP, Local_IP;
            IPEndPoint Remote_IPEndPoint, Local_IPEndPoint;
            EndPoint   Remote_EndPoint;
            Socket     Ethernet_Socket;

            Random rnd = new Random();
            string SID = rnd.Next(1, 99).ToString("00");

            string[] D_parts = D_ip.Split('.');
            int      D_fin   = Convert.ToInt16(D_parts[3]);

            string DA1 = D_fin.ToString("x2").ToUpper();

            if (Global.settings.DA1 != DA1)
            {
                throw new Exception("configurazione di comunicazione errata (DNA) " + Global.settings.DNA + " <> " + DA1);
            }

            string[] S_parts = S_ip.Split('.');
            int      S_fin   = Convert.ToInt16(S_parts[3]);

            string SA1 = S_fin.ToString("x2").ToUpper();

            if (Global.settings.SA1 != SA1)
            {
                throw new Exception("configurazione di comunicazione errata (SNA) " + Global.settings.SNA + " <> " + SA1);
            }


            Header = Global.settings.ICF + Global.settings.RSV + Global.settings.GCT + Global.settings.DNA + Global.settings.DA1 + Global.settings.DA2 + Global.settings.SNA + Global.settings.SA1 + Global.settings.SA2 + SID;

            if (DEBUGMODE)
            {
                Console.WriteLine("Header : " + Header);
            }

            string cmd_write = "0102";
            string cmd_DM    = "82";
            //string cmd_startaddress = "0064";
            string cmd_byteempty  = "00";
            string cmd_wordnumber = "0001";
            //string cmd_value = "0003";

            string cmd_startaddress = dmnum.ToString("x4");
            string cmd_value        = value.ToString("x4");

            CMND = Header + cmd_write + cmd_DM + cmd_startaddress + cmd_byteempty + cmd_wordnumber + cmd_value;

            if (DEBUGMODE)
            {
                Console.WriteLine("CMD : " + CMND);
            }

            //'txtSend.Text = ""
            CmdLength = CMND.Length;
            ByteArray = new byte[CmdLength / 2];

            for (X = 0; X < CmdLength; X += 2)
            {
                tmp1           = CMND.Substring(X, 2);
                ByteArray[Cnt] = Convert.ToByte(tmp1, 16);
                Cnt           += 1;
            }

            if (DEBUGMODE)
            {
                Console.WriteLine("txtSend : " + ToHex(ByteArray));
            }

            try
            {
                Local_IP = IPAddress.Parse(S_ip);
            }
            catch (Exception e)
            {
                throw new Exception("invalid local IP address \r\n" + e);
            }

            try
            {
                Remote_IP = IPAddress.Parse(D_ip);
            }
            catch (Exception e)
            {
                throw new Exception("invalid PLC IP address \r\n" + e);
            }

            Remote_IPEndPoint = new IPEndPoint(Remote_IP, D_port);
            Remote_EndPoint   = (EndPoint)Remote_IPEndPoint;
            Local_IPEndPoint  = new IPEndPoint(Local_IP, S_port);

            Ethernet_Socket = new Socket(Local_IPEndPoint.AddressFamily, SocketType.Dgram, ProtocolType.Udp);

            if (Ethernet_Socket != null)
            {
                Ethernet_Socket.SendTo(ByteArray, Remote_EndPoint); //send FINS cmd
                Ethernet_Socket.ReceiveTimeout = 200;

                try
                {
                    retval = Ethernet_Socket.ReceiveFrom(myByte, ref Remote_EndPoint); //recv from socket
                    return(WriteDM_Received_Data(myByte, retval, SID));                //call sub to process byte array
                }
                catch (Exception e)
                {
                    throw new Exception("No response from PLC \r\n\r\n" + e);
                }
            }
            return(false);
        }
예제 #12
0
 public bool xoaCMND(CMND cmnd)
 {
     return(cmndDAO.delete(cmnd.MaSo));
 }