Exemple #1
0
        //--------------------------------------------------------
        //Method to chack Email ther is in DB or not
        public int IsAvailableEmail(String ID_Email)
        {
            int userID = 0;

            try
            {
                UTable = UDA.GetDataByID_Email(ID_Email);

                if (UTable.Rows.Count > 0) // we hava account
                {
                    for (int i = 0; i <= UTable.Rows.Count - 1; i++)
                    {
                        URow = UTable.Rows[0] as DataSet1.UserRow;
                        if (URow.ID_Email == ID_Email)
                        {
                            userID = 1;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                userID = 0;
                //"cannot add your infromation"
            }
            return(userID);
        }
Exemple #2
0
        //------------------------------------------------------------
        //Method to login to the system
        public string Login(String ID_Email, String password)
        {
            bool   isVialed = false;
            String Message  = "";
            int    UserType = 0;

            try
            {
                UTable = UDA.GetDataByID_Email(ID_Email);

                {
                    URow = UTable.Rows[0] as DataSet1.UserRow;
                    if (URow.ID_Email == ID_Email && URow.Password == password)
                    {
                        UserType = URow.ID_UserType;
                        isVialed = true;
                        Message  = "Welcom " + URow.FirstName + " " + URow.LastName;
                    }
                    else
                    {
                        UserType = 0;
                        isVialed = false;
                        Message  = "Email or password Not correct !!!!";
                    }
                }
            }
            catch (Exception ex)
            {
                //"cannot add your infromation"
                UserType = 0;
                isVialed = false;
                Message  = "Email or password Not correct !!!!";
            }

            var jsonData = new
            {
                isVialed = isVialed,
                UserType = UserType,
                Message  = Message
            };

            return(ser.Serialize(jsonData));
        }
Exemple #3
0
        public void Receive()
        {
            string Request;

            while (m_bConnect)
            {
                Request = m_Read.ReadLine();
                if (Request.Equals("View"))
                {
                    try
                    {
                        DataRow[] dataRows = SendClass.getAllRows();
                        int       num      = dataRows.Length;
                        m_Write.WriteLine("View");
                        m_Write.WriteLine(num.ToString());

                        Trade[] trades = new Trade[num];

                        for (int i = 0; i < num; i++)
                        {
                            if (trades[i] == null)
                            {
                                trades[i] = new Trade();
                            }
                            trades[i].category    = dataRows[i][0].ToString();
                            trades[i].transaction = (DateTime)dataRows[i][1];
                            trades[i].deadline    = (DateTime)dataRows[i][2];
                            trades[i].orderer     = dataRows[i][3].ToString();
                            trades[i].demander    = dataRows[i][4].ToString();
                            trades[i].contents    = dataRows[i][5].ToString();
                            trades[i].product     = dataRows[i][6].ToString();
                            trades[i].OS          = dataRows[i][7].ToString();
                            trades[i].quantity    = int.Parse(dataRows[i][8].ToString());
                            trades[i].price       = int.Parse(dataRows[i][9].ToString());
                            trades[i].manager     = dataRows[i][10].ToString();
                            trades[i].inspection  = (DateTime)dataRows[i][11];
                            trades[i].bill        = (DateTime)dataRows[i][12];
                            trades[i].modify      = (DateTime)dataRows[i][13];
                            trades[i].registrar   = dataRows[i][14].ToString();
                            trades[i].number      = (int)dataRows[i][15];
                        }
                        MemoryStream ms = new MemoryStream();
                        bf.Serialize(ms, trades);
                        sendBuffer = ms.ToArray();
                        m_Write.WriteLine(sendBuffer.Length.ToString());
                        m_Write.Flush();
                        Send();
                    }
                    catch (Exception e)
                    {
                        serverForm.Invoke(new System.Action(delegate()
                        {
                            MessageBox.Show(e.ToString(), "Exception occured!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }));
                    }
                }
                if (Request.Equals("Import"))
                {
                    trade = new Trade();
                    int size = int.Parse(m_Read.ReadLine());
                    readBuffer = new byte[size];
                    m_bRead.Read(readBuffer, 0, size);

                    try
                    {
                        MemoryStream ms = new MemoryStream(readBuffer);
                        ms.Position = 0;
                        trade       = (Trade)bf.Deserialize(ms);
                        SendClass.importTrade(this.trade);
                    }
                    catch (Exception e)
                    {
                        serverForm.Invoke(new System.Action(delegate()
                        {
                            MessageBox.Show(e.ToString(), "Exception occured!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }));
                    }
                }
                else if (Request.Equals("Login"))
                {
                    user = new User();
                    try
                    {
                        DataSet1.UserDataTable userRows = new DataSet1.UserDataTable();
                        try
                        {
                            userRows.ReadXml(SendClass.filepath + "user_data.xml");
                        }
                        catch (FileNotFoundException)
                        {
                            userRows.WriteXml(SendClass.filepath + "user_data.xml");
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.ToString(), "Exception occured!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }

                        user.id       = m_Read.ReadLine();
                        user.password = m_Read.ReadLine();

                        string    query   = "id=\'" + user.id + "\' AND password=\'" + user.password + "\'";
                        DataRow[] dataRow = userRows.Select(query);

                        if (dataRow.Length == 0)
                        {
                            m_Write.WriteLine("None");
                            m_Write.Flush();
                        }
                        else
                        {
                            m_Write.WriteLine("Login");
                            m_Write.WriteLine(dataRow[0][0].ToString());
                            m_Write.Flush();
                        }
                    }
                    catch (Exception e)
                    {
                        serverForm.Invoke(new System.Action(delegate()
                        {
                            MessageBox.Show(e.ToString(), "Exception occured!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }));
                    }
                }
                else if (Request.Equals("Modify"))
                {
                    try
                    {
                        int      number       = int.Parse(m_Read.ReadLine());
                        string   inspect      = m_Read.ReadLine();
                        string   bill         = m_Read.ReadLine();
                        DateTime date_inspect = new DateTime(int.Parse(inspect.Substring(0, 4)), int.Parse(inspect.Substring(5, 2))
                                                             , int.Parse(inspect.Substring(8, 2)));
                        DateTime date_bill = new DateTime(int.Parse(bill.Substring(0, 4)), int.Parse(bill.Substring(5, 2))
                                                          , int.Parse(bill.Substring(8, 2)));

                        SendClass.Modify(number, date_inspect, date_bill);
                    }
                    catch (Exception e)
                    {
                        serverForm.Invoke(new System.Action(delegate
                        {
                            MessageBox.Show(e.ToString(), "exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }));
                    }
                }
                else if (Request.Equals("Resource"))
                {
                    int number = int.Parse(m_Read.ReadLine());
                    dir = new DirectoryInfo(SendClass.filepath + '/' + number.ToString());
                    if (!dir.Exists)
                    {
                        dir.Create();
                    }
                    FileInfo[] fileInfos = dir.GetFiles();

                    int filenum = fileInfos.Length;
                    m_Write.WriteLine("Resource");
                    m_Write.WriteLine(filenum.ToString());
                    for (int i = 0; i < fileInfos.Length; i++)
                    {
                        m_Write.WriteLine(fileInfos[i].Name);
                    }
                    m_Write.Flush();
                }
                else if (Request.Equals("Delete"))
                {
                    int number = int.Parse(m_Read.ReadLine());
                    SendClass.Delete(number);
                }
                else if (Request.Equals("DeleteFile"))
                {
                    int    number = int.Parse(m_Read.ReadLine());
                    string name   = m_Read.ReadLine();
                    string path   = SendClass.filepath + number.ToString() + '/' + name;

                    FileInfo file = new FileInfo(path);
                    file.Delete();
                }
                else if (Request.Equals("Upload"))
                {
                    int    number = int.Parse(m_Read.ReadLine());
                    string name   = m_Read.ReadLine();
                    string path   = SendClass.filepath + number.ToString() + '/' + name;
                    int    size   = int.Parse(m_Read.ReadLine());
                    readBuffer = new byte[size];
                    m_bRead.Read(readBuffer, 0, size);

                    FileStream fileStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
                    fileStream.Write(readBuffer, 0, size);
                    fileStream.Close();
                }
                else if (Request.Equals("Download"))
                {
                    string path = m_Read.ReadLine();
                    try
                    {
                        FileInfo   fileInfo   = new FileInfo(SendClass.filepath + path);
                        FileStream fileStream = new FileStream(SendClass.filepath + path, FileMode.Open, FileAccess.Read);

                        BinaryReader br = new BinaryReader(fileStream);
                        sendBuffer = br.ReadBytes((int)fileInfo.Length);

                        m_Write.WriteLine("Download");
                        m_Write.WriteLine(fileInfo.Length.ToString());
                        m_Write.Flush();

                        m_bWrite.Write(sendBuffer);
                        m_bWrite.Flush();
                        fileStream.Close();
                    }
                    catch (Exception e)
                    {
                        serverForm.Invoke(new Action(delegate
                        {
                            MessageBox.Show(e.ToString());
                        }));
                    }
                }
                else if (Request.Equals("Disconnect"))
                {
                    break;
                }
            }
            m_bConnect = false;
        }