private void setListView()
        {
            if (grfView.IsDisposed)
            {
                return;
            }
            if (grfView.Rows == null)
            {
                return;
            }
            grfView.Rows.Count = 0;
            Column colpic1 = grfView.Cols[colUploadImg];

            colpic1.DataType = typeof(Image);

            foreach (String file in lFile)
            {
                try
                {
                    Row row = grfView.Rows.Add();
                    row[colUploadPath] = file;
                    string ext = Path.GetExtension(file);
                    Image  loadedImage, resizedImage;
                    if (ext.ToLower().IndexOf("pdf") < 0)
                    {
                        loadedImage = Image.FromFile(file);
                        int originalWidth = 0;
                        originalWidth = loadedImage.Width;
                        int newWidth = 280;
                        newWidth          = bc.imggridscanwidth;
                        resizedImage      = loadedImage.GetThumbnailImage(newWidth, (newWidth * loadedImage.Height) / originalWidth, null, IntPtr.Zero);
                        row[colUploadImg] = resizedImage;
                        loadedImage.Dispose();
                    }
                    else
                    {
                        row[colUploadImg] = Resources.pdf_symbol_300;
                    }
                }
                catch (Exception ex)
                {
                    new LogWriter("e", file + " " + ex.Message);
                    MessageBox.Show("err " + file + " " + ex.Message, "");
                }
            }
            grfView.AutoSizeCols();
            grfView.AutoSizeRows();
        }
        public void GetData()
        {
            CheckForIllegalCrossThreadCalls = false;
            if (this.ListofModule != null)
            {
                try
                {
                    PaginationModule _pm = this.ListofModule.Where(c => c.ModuleName == _currentModule).SingleOrDefault();
                    if (_pm != null)
                    {
                        if (_pm.PageLocked == true)
                        {
                            cboLimit.Enabled  = false;
                            chkLocked.Checked = true;
                            cboLimit.Text     = _pm.Limit;
                            chkLocked.Enabled = false;
                            chkLocked.Checked = true;
                            chkLocked.Enabled = true;
                            cboLimit.Enabled  = true;
                        }
                        else if (_pm.PageLocked == false)
                        {
                            chkLocked.Enabled = false;
                            chkLocked.Checked = false;
                            chkLocked.Enabled = true;
                        }
                    }
                }
                catch (Exception)
                {
                    chkLocked.Enabled = false;
                    chkLocked.Checked = false;
                    chkLocked.Enabled = true;
                }
            }
            else
            {
                chkLocked.Enabled = false;
                chkLocked.Checked = false;
                chkLocked.Enabled = true;
            }

            string _display   = "Page {0} of {1}";
            string _status    = "Showing {0} to {1} of {2} entries";
            string _cursearch = "";

            if (_search == "" || _search == "''")
            {
                _cursearch = "''";
            }
            else
            {
                _cursearch = "'%" + _search + "%'";
            }

            long _limit = 0;

            if (cboLimit.Text != "ALL")
            {
                _limit = Convert.ToInt64(cboLimit.Text);
            }
            string _query = string.Format(_commandtext, (_cursearch == "''" ? _page : 0), _limit, _cursearch);


            DataTable _tb = new DataTable();

            try
            {
                MySqlConnection  _con = new MySqlConnection(ConnectionString);
                MySqlCommand     _com = new MySqlCommand(_query, _con);
                MySqlDataAdapter _adp = new MySqlDataAdapter(_com);
                _com.CommandTimeout = 500;
                _adp.Fill(_tb);

                _con.Dispose(); _con = null;
                _com.Dispose(); _com = null;
                _adp.Dispose(); _adp = null;
            }
            catch (Exception)
            { }

            if (grid != null)
            {
                try
                {
                    grid.DataSource = _tb;
                }
                catch (Exception) { }
            }

            if (cboLimit.Text != "ALL")
            {
                lblRecord.Text  = "record per page";
                flpPage.Visible = true;

                if (_tb.Columns.Contains("Total") && _tb.Rows.Count > 0)
                {
                    _total = _tb.Rows[0].Field <long>("Total");
                }


                long _recordfrom = (_page * _limit) + 1;
                long _recordto   = (_recordfrom - 1) + _limit;

                decimal _temp = Convert.ToDecimal(_total) / Convert.ToDecimal(_limit);
                lblDisplay.Text = string.Format(_display, _page + 1, Math.Ceiling(_temp));

                if (_page > Math.Ceiling(_temp))
                {
                    _page = _total; GetData();
                    return;
                }

                if (Math.Ceiling(_temp) == 1 || _page == Convert.ToInt32(Math.Ceiling(_temp)) - 1)
                {
                    btnNext.Enabled = false;
                    btnLast.Enabled = false;
                    _recordto       = _total;
                }
                else
                {
                    btnNext.Enabled = true;
                    btnLast.Enabled = true;
                }

                if (_page == 0)
                {
                    btnFirst.Enabled = false;
                    btnPrev.Enabled  = false;
                }
                else
                {
                    btnFirst.Enabled = true;
                    btnPrev.Enabled  = true;
                }


                if (_label != null)
                {
                    _label.Text  = _total == 0 ? "No record to display" : String.Format(_status, _recordfrom, _recordto, _total);
                    _label.Width = 170;
                }

                this.Visible = (_total > 100);
            }
            else
            {
                if (_tb.Columns.Contains("Total") && _tb.Rows.Count > 0)
                {
                    _total = _tb.Rows[0].Field <long>("Total");
                }
                this.Visible = (_total > 100);

                lblRecord.Text  = "record";
                flpPage.Visible = false;
            }

            foreach (Column _col in grid.Cols)
            {
                if (_col.DataType != null)
                {
                    if (_col.DataType.Name == typeof(System.DateTime).Name)
                    {
                        _col.Format    = "yyyy-MM-dd";
                        _col.TextAlign = TextAlignEnum.CenterCenter;
                    }
                }
            }


            if (grid.Cols.Contains("..."))
            {
                grid.Cols["..."].AllowResizing  = false;
                grid.Cols["..."].AllowSorting   = false;
                grid.Cols["..."].Width          = 45;
                grid.Cols["..."].TextAlignFixed = TextAlignEnum.CenterCenter;
            }

            if (grid.Cols.Contains("Total"))
            {
                grid.Cols["Total"].Visible = false;
            }

            grid.Cols[0].Visible = false;
            grid.AllowFreezing   = AllowFreezingEnum.None;
            grid.Cols.Frozen     = 2;
            grid.AllowEditing    = false;
            grid.AllowDelete     = false;
            grid.AutoSizeCols(2, grid.Cols.Count - 1, 0);

            if (AfterDataLoaded != null)
            {
                AfterDataLoaded(this, new EventArgs());
            }
        }
 private void BtnRefresh_Click(object sender, EventArgs e)
 {
     //throw new NotImplementedException();
     grfVs.AutoSizeCols();
     grfVs.AutoSizeRows();
 }
        private void FormatGrid(C1FlexGrid grid)
        {
            if (grid == null)
            {
                return;
            }

            ColumnCollection _cols = grid.Cols;

            if (grid.Name == grdUsers.Name)
            {
                grid.AllowEditing = true;

                for (int i = 0; i <= (_cols.Count - 1); i++)
                {
                    _cols[i].AllowEditing = false;
                }
                _cols["AccountHolder"].AllowEditing = true;

                for (int i = 0; i <= (grid.Rows.Count - 1); i++)
                {
                    CheckEnum _checked = CheckEnum.Unchecked;
                    if (i == (_cols.Fixed - 1))
                    {
                        _checked = CheckEnum.Checked;
                    }
                    else
                    {
                        if (VisualBasic.CBool(grid[i, "Select"]))
                        {
                            _checked = CheckEnum.Checked;
                        }
                    }

                    grid.SetCellCheck(i, _cols["AccountHolder"].Index, _checked);
                }

                _cols["AccountHolder"].Caption = "Account Holder";
                _cols["Username"].Visible      = false;
                _cols["Select"].Visible        = false;
                grid.ExtendLastCol             = true;
                _cols[_cols.Fixed - 1].Visible = false;
            }
            else if (grid == grdActions)
            {
                grid.AllowEditing = true;

                for (int i = 0; i <= (_cols.Count - 1); i++)
                {
                    _cols[i].AllowEditing = false;
                }
                _cols["Action"].AllowEditing = true;

                for (int i = 0; i <= (grid.Rows.Count - 1); i++)
                {
                    CheckEnum _checked = CheckEnum.Unchecked;
                    if (i == (_cols.Fixed - 1))
                    {
                        _checked = CheckEnum.Checked;
                    }
                    else
                    {
                        if (VisualBasic.CBool(grid[i, "Select"]))
                        {
                            _checked = CheckEnum.Checked;
                        }
                    }

                    grid.SetCellCheck(i, _cols["Action"].Index, _checked);
                }

                _cols["Id"].Visible            = false;
                _cols["Select"].Visible        = false;
                grid.ExtendLastCol             = true;
                _cols[_cols.Fixed - 1].Visible = false;
            }
            else if (grid == grdLogs)
            {
                _cols["DateAndTime"].Format    = "dd-MMM-yyyy hh:mm:ss tt";
                _cols["DateAndTime"].Caption   = "Date and Time";
                _cols["AccountHolder"].Caption = "Account Holder";
                _cols["ReferenceNo"].Caption   = "Reference No";
                _cols["ComputerName"].Caption  = "Computer Name";
                _cols["IPAddress"].Caption     = "IP Address";
                _cols["Image"].Caption         = "";

                _cols["DetailId"].Visible = false;
                grid.AutoSizeCols(); grid.ExtendLastCol = true;
                _cols[_cols.Fixed - 1].Visible          = false;
                _cols["Image"].Width = 30;
            }
            else
            {
            }
        }
Beispiel #5
0
        private void setImage(String[] file1)
        {
            String err = "";

            txtVN.Hide();
            btnVn.Hide();
            //label3.Hide();
            //txtAN.Hide();
            //txtAnCnt.Hide();
            //chkIPD.Hide();
            label6.Hide();
            txtVisitDate.Hide();
            setVisible(false);
            Application.DoEvents();
            //txtAnDate.Hide();
            //txtPreNo.Hide();
            err = "01";
            //MessageBox.Show("222", "");
            ProgressBar pB1 = new ProgressBar();

            pB1.Location = new System.Drawing.Point(15, 15);
            pB1.Name     = "pB1";
            pB1.Size     = new System.Drawing.Size(862, 23);
            groupBox1.Controls.Add(pB1);
            //pB1.Left = txtVN.Left;
            pB1.Show();
            int i = 1, j = 1, row = grf.Rows.Count;

            grf.Rows.Add();
            row = grf.Rows.Count;
            String re = "";

            array1.Clear();
            try
            {
                err         = "02";
                pB1.Value   = 0;
                pB1.Minimum = 0;
                pB1.Maximum = file1.Length;
                foreach (String file in file1)
                {
                    try
                    {
                        Image    loadedImage, resizedImage;
                        String[] sur = file.Split('.');
                        String   ex  = "";
                        if (sur.Length == 2)
                        {
                            ex = sur[1];
                        }
                        err = "021";
                        if (!ex.Equals("pdf"))
                        {
                            String ext = "";
                            ext = Path.GetExtension(file);
                            if (ext.IndexOf("db") > 0)
                            {
                                continue;
                            }
                            loadedImage = Image.FromFile(file);
                            //byte[] buff = System.IO.File.ReadAllBytes(file);
                            //System.IO.MemoryStream ms = new System.IO.MemoryStream(buff);
                            //MemoryStream stream = new MemoryStream(buff);

                            //loadedImage.Save(stream, ImageFormat.Jpeg);
                            //loadedImage.Dispose();
                            //loadedImage = Image.FromStream(stream);
                            int originalWidth = 0;
                            originalWidth = loadedImage.Width;
                            int newWidth = 280;
                            resizedImage = loadedImage.GetThumbnailImage(newWidth, (newWidth * loadedImage.Height) / originalWidth, null, IntPtr.Zero);
                            arrayImg.Add(file + ",");
                            loadedImage.Dispose();
                        }
                        else
                        {
                            resizedImage = Resources.pdf_symbol_80_2;
                        }
                        if (j > 4)
                        {
                            grf.Rows.Add();
                            row = grf.Rows.Count;
                            j   = 1;
                            i++;
                        }
                        err = "022";
                        //grf.Cols[colPic1].ImageAndText = true;
                        //grf.Cols[colPic2].ImageAndText = true;
                        //grf.Cols[colPic3].ImageAndText = true;
                        //grf.Cols[colPic4].ImageAndText = true;
                        int hei = grf.Rows.DefaultSize;

                        //grf[row - 1, colDay2PathPic] = file;
                        //grfDay2Img[row - 1, colBtn] = "send";
                        array1.Add(i + "," + j + ",*" + file);
                        if (j == 1)
                        {
                            //grf[i, colPic1] = resizedImage;
                            grf.SetCellImage(i, colPic1, resizedImage);
                        }
                        else if (j == 2)
                        {
                            //grf[i, colPic2] = resizedImage;
                            grf.SetCellImage(i, colPic2, resizedImage);
                        }
                        else if (j == 3)
                        {
                            //grf[i, colPic3] = resizedImage;
                            grf.SetCellImage(i, colPic3, resizedImage);
                        }
                        else if (j == 4)
                        {
                            //grf[i, colPic4] = resizedImage;
                            grf.SetCellImage(i, colPic4, resizedImage);
                        }
                        err = "023";
                        j++;
                        pB1.Value++;
                        if (pB1.Value == 47)
                        {
                            String aaa = "";
                        }
                        //resizedImage.Dispose();
                    }
                    catch (Exception ex)
                    {
                        re = ex.Message;
                        MessageBox.Show("Error" + ex.Message + " Lenght " + file1.Length + " row " + pB1.Value, "err " + err);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error" + ex.Message, "");
            }
            setVisible(true);
            //MessageBox.Show("555", "");
            grf.AutoSizeCols();
            grf.AutoSizeRows();
            grf.Rows[0].Visible = false;
            grf.Cols[0].Visible = false;
            pB1.Dispose();
            txtVN.Show();
            btnVn.Show();
            //label3.Show();
            //txtAN.Show();
            //txtAnCnt.Show();
            //chkIPD.Show();
            label6.Show();
            //if (chkIPD.Checked)
            //{
            //    txtVisitDate.Hide();
            //    txtAnDate.Show();
            //}
            //else
            //{
            txtVisitDate.Show();
            //    txtAnDate.Hide();
            //}
            //txtPreNo.Show();
        }