Ejemplo n.º 1
0
        public Form3()
        {
            InitializeComponent();
            String    userid = ClientSession.iduser;
            DB        db     = new DB();
            DataTable table  = new DataTable();

            SqlDataAdapter adapter = new SqlDataAdapter();
            SqlCommand     command = new SqlCommand("Select * from Letters where id_Recipient=@UID AND isSigned = @isSigned AND IsinTrash = @isInTrash  AND IsInDrafts = @isInDrafts", db.GetConnection());

            command.Parameters.Add("@UID", SqlDbType.VarChar).Value    = userid;
            command.Parameters.Add("@isSigned", SqlDbType.Bit).Value   = 0;
            command.Parameters.Add("@isInTrash", SqlDbType.Bit).Value  = 1;
            command.Parameters.Add("@isInDrafts", SqlDbType.Bit).Value = 0;
            adapter.SelectCommand = command;
            adapter.Fill(table);
            int Rowscount = table.Rows.Count;

            tableLayoutPanel1.RowCount = Rowscount;

            if (Rowscount != 0)
            {
                for (int i = 0; i < Rowscount; i++)
                {
                    string theme           = table.Rows[i][8].ToString();
                    string themenospaces   = theme.Replace(" ", "");
                    string comment         = table.Rows[i][9].ToString();
                    string commentnospaces = comment.Replace(" ", "");
                    string id_Sender       = table.Rows[i][1].ToString();
                    string id_status       = table.Rows[i][10].ToString();
                    string statusSigned    = table.Rows[i][7].ToString();
                    string id       = table.Rows[i][0].ToString();
                    string SendDate = table.Rows[i][3].ToString();
                    string SendTime = table.Rows[i][4].ToString();



                    SqlCommand newcommand = new SqlCommand("Select * from Workers where id = @UIDU", db.GetConnection());
                    newcommand.Parameters.Add("@UIDU", SqlDbType.VarChar).Value = id_Sender;
                    DataTable table2 = new DataTable();
                    adapter.SelectCommand = newcommand;
                    adapter.Fill(table2);

                    string ShortUserName = table2.Rows[0][2].ToString();

                    tableLayoutPanel1.Controls.Add(new Label {
                        Text = themenospaces + "\r\n" + ShortUserName + "\r\n" + commentnospaces + "\r\n" + SendDate + " " + SendTime, Name = "LinkClick" + id, Tag = i, Size = new Size(353, 78), BorderStyle = BorderStyle.FixedSingle
                    });
                    tableLayoutPanel1.Controls.Add(new Button {
                        Name = "buttonclick" + id, BackgroundImage = WindowsFormsApp1.Properties.Resources.z00SzkeG89Q, Size = new Size(16, 20)
                    });
                    (tableLayoutPanel1.Controls["LinkClick" + id] as Label).Click    += OpenMy;
                    (tableLayoutPanel1.Controls["buttonclick" + id] as Button).Click += DeleteMy;

                    if (statusSigned == "2")
                    {
                        bool Signed = true;
                        tableLayoutPanel1.Controls.Add(new CheckBox {
                            Checked = Signed
                        });
                    }
                    else
                    {
                        bool Signed = false;
                        tableLayoutPanel1.Controls.Add(new CheckBox {
                            Checked = Signed
                        });
                    }
                }
            }
        }