Пример #1
0
        private void UpLoadMulti_5Folder()
        {
            List <string> lStrBath1 = new List <string>();
            List <string> lStrBath2 = new List <string>();
            List <string> lStrBath3 = new List <string>();
            List <string> lStrBath4 = new List <string>();

            lStrBath1.AddRange(Directory.GetDirectories(txt_PathFolder.Text));
            int    k          = 0;
            int    total      = lStrBath1.Count;
            string pathserver = @"\" + new DirectoryInfo(txt_PathFolder.Text).Name;
            string pathexcel  = @"X:";
            string s          = new DirectoryInfo(txt_PathFolder.Text).Name;

            createFolder(s);
            int       n  = 0;
            DataTable dt = new DataTable();

            dt.Columns.AddRange(new[] { new DataColumn("ImageID", typeof(string)) });
            foreach (string item1 in lStrBath1)
            {
                string pathserver1 = pathserver + @"\" + new DirectoryInfo(item1).Name;
                string litem1      = s + @"\" + new DirectoryInfo(item1).Name;
                createFolder(litem1);
                lStrBath2.Clear();
                lStrBath2.AddRange(Directory.GetDirectories(item1));
                if (lStrBath2.Count > 0)
                {
                    foreach (string item2 in lStrBath2)
                    {
                        string litem2 = litem1 + @"\" + new DirectoryInfo(item2).Name;
                        createFolder(litem2);
                        lStrBath3.Clear();
                        lStrBath3.AddRange(Directory.GetDirectories(item2));
                        if (lStrBath3.Count > 0)
                        {
                            foreach (string item3 in lStrBath3)
                            {
                                string pathserver2 = pathserver1 + @"\" + new DirectoryInfo(item3).Name;
                                string litem3      = litem2 + @"\" + new DirectoryInfo(item3).Name;
                                createFolder(litem3);
                                lStrBath4.Clear();
                                lStrBath4.AddRange(Directory.GetDirectories(item3));
                                if (lStrBath4.Count > 0)
                                {
                                    for (int i = 0; i < lStrBath4.Count; i++)
                                    {
                                        string FolderNameTemp = new DirectoryInfo(lStrBath4[i]).Name;
                                        if (true /*FolderNameTemp.Substring(0, 7) == "2225000"*/)
                                        {
                                            string batchID     = (new DirectoryInfo(lStrBath4[i]).Name + txt_DateCreate.Text).Replace("/", "").Replace(@"\", "").Replace(@":", "").Replace(@"-", "");
                                            string pathserver3 = pathserver2 + @"\" + new DirectoryInfo(lStrBath4[i]).Name + @"\";
                                            string litem4      = litem3 + @"\" + batchID;
                                            dt.Clear();
                                            int m = 0;
                                            n += 1;
                                            lb_SobatchHoanThanh.Text = n + @" :";
                                            var      filters           = new String[] { "jpg", "jpeg", "tif" };
                                            string[] pathImageLocation = GetFilesFrom(lStrBath4[i], filters, true);

                                            var fBatch = new tbl_Batch
                                            {
                                                BatchID       = batchID,
                                                BatchName     = new DirectoryInfo(lStrBath4[i]).Name,
                                                UserCreate    = txt_UserCreate.Text,
                                                DateCreate    = DateTime.Now,
                                                PathServer    = pathserver1 + @"\" + new DirectoryInfo(item2).Name + @"\" + new DirectoryInfo(item3).Name + @"\",
                                                PathPicture   = pathexcel + pathserver3,
                                                Location      = txt_PathFolder.Text,
                                                NumberImage   = pathImageLocation.Length + "",
                                                ChiaUser      = chk_ChiaUser.Checked ? true : false,
                                                CongKhaiBatch = false,
                                            };
                                            Global.Db.tbl_Batches.InsertOnSubmit(fBatch);
                                            Global.Db.SubmitChanges();

                                            progressBar1.Step    = 1;
                                            progressBar1.Value   = 1;
                                            progressBar1.Maximum = pathImageLocation.Count();
                                            progressBar1.Minimum = 0;
                                            ModifyProgressBarColor.SetState(progressBar1, 1);
                                            for (int j = 0; j < pathImageLocation.Count(); j++)
                                            {
                                                FileInfo fi = new FileInfo(pathImageLocation[j]);
                                                dt.Rows.Add(fi.Name);
                                            }
                                            string        ConnectionString = Global.Db.Connection.ConnectionString;
                                            SqlConnection con = new SqlConnection(ConnectionString);
                                            con.Open();
                                            SqlCommand cmd = new SqlCommand("Insert_Image", con);
                                            cmd.CommandTimeout = 10 * 60;
                                            cmd.CommandType    = CommandType.StoredProcedure;
                                            cmd.Parameters.AddWithValue("@BatchID", batchID);
                                            cmd.Parameters.AddWithValue("@ListIdImage", dt);
                                            cmd.Parameters.AddWithValue("@ChiaUser", chk_ChiaUser.Checked ? 1 : 0);
                                            cmd.ExecuteNonQuery();
                                            con.Close();
                                            string temp = Global.StrPath + "\\" + litem4;
                                            if (!Directory.Exists(temp))
                                            {
                                                Directory.CreateDirectory(temp);
                                            }
                                            else
                                            {
                                                MessageBox.Show("Bị trùng tên batch!");
                                                return;
                                            }
                                            for (int j = 0; j < pathImageLocation.Count(); j++)
                                            {
                                                File.Copy(pathImageLocation[j], temp + @"\" + new FileInfo(pathImageLocation[j]).Name);
                                                lb_SoImageDaHoanThanh.Text = (j + 1) + @"\" + pathImageLocation.Count();
                                                m += 1;
                                                progressBar1.PerformStep();
                                            }
                                            lb_SoImageDaHoanThanh.Text = m + @"/" + pathImageLocation.Length;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                k++;
            }
            MessageBox.Show(@"Tạo batch mới thành công!");
            txt_BatchName.Text     = "";
            txt_ImagePath.Text     = "";
            lb_SoLuongHinh.Text    = "";
            txt_PathFolder.Text    = "";
            txt_Path.Text          = @"X:\N\13";
            btn_Browser.Enabled    = true;
            txt_PathFolder.Enabled = true;
            txt_Path.Enabled       = true;
        }
Пример #2
0
        private void UpLoadSingle()
        {
            if (txt_Path.Text == @"X:\N\13")
            {
                MessageBox.Show("Bạn đang để đường dẫn path mặc định. Vui lòng kiểm tra lại.");
                return;
            }
            progressBar1.Step    = 1;
            progressBar1.Value   = 1;
            progressBar1.Maximum = _lFileNames.Length;
            progressBar1.Minimum = 0;
            ModifyProgressBarColor.SetState(progressBar1, 1);

            string sBatchID = (txt_BatchName.Text + txt_DateCreate.Text).Replace("/", "").Replace(@"\", "").Replace(@":", "").Replace(@"-", "");
            var    batch    = (from w in Global.Db.tbl_Batches.Where(w => w.BatchID == sBatchID) select w.BatchID).FirstOrDefault();

            if (!string.IsNullOrEmpty(txt_ImagePath.Text))
            {
                if (string.IsNullOrEmpty(batch))
                {
                    var fBatch = new tbl_Batch
                    {
                        BatchID       = sBatchID,
                        BatchName     = txt_BatchName.Text,
                        UserCreate    = txt_UserCreate.Text,
                        DateCreate    = DateTime.Now,
                        PathServer    = "",
                        PathPicture   = txt_Path.Text,
                        Location      = txt_ImagePath.Text,
                        NumberImage   = soluonghinh.ToString(),
                        ChiaUser      = chk_ChiaUser.Checked ? true : false,
                        CongKhaiBatch = false,
                    };
                    Global.Db.tbl_Batches.InsertOnSubmit(fBatch);
                    Global.Db.SubmitChanges();
                }
                else
                {
                    MessageBox.Show("Batch đã tồn tại vui lòng điền tên batch khác!");
                    return;
                }
            }
            else
            {
                MessageBox.Show("Bạn chưa chọn hình ảnh!");
                return;
            }

            string temp = Global.StrPath + "\\" + sBatchID;

            if (!Directory.Exists(temp))
            {
                Directory.CreateDirectory(temp);
            }
            else
            {
                MessageBox.Show("Bị trùng tên batch!");
                return;
            }
            DataTable dt = new DataTable();

            dt.Columns.AddRange(new[] { new DataColumn("ImageID", typeof(string)) });
            for (int i = 0; i < _lFileNames.Count(); i++)
            {
                FileInfo fi = new FileInfo(_lFileNames[i]);
                dt.Rows.Add(fi.Name);
            }
            string        ConnectionString = Global.Db.Connection.ConnectionString;
            SqlConnection con = new SqlConnection(ConnectionString);
            SqlCommand    cmd = new SqlCommand("Insert_Image", con);

            cmd.CommandTimeout = 10 * 60;
            cmd.CommandType    = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@BatchID", sBatchID);
            cmd.Parameters.AddWithValue("@ListIdImage", dt);
            cmd.Parameters.AddWithValue("@ChiaUser", chk_ChiaUser.Checked ? 1 : 0);
            con.Open();
            cmd.ExecuteNonQuery();

            for (int i = 0; i < _lFileNames.Count(); i++)
            {
                File.Copy(_lFileNames[i], temp + @"\" + new FileInfo(_lFileNames[i]).Name);
                progressBar1.PerformStep();
                lb_SoImageDaHoanThanh.Text = (i + 1) + @"\" + _lFileNames.Count();
            }
            txt_DateCreate.Text = DateTime.Now.ToShortDateString() + "-" + DateTime.Now.ToShortTimeString();
            MessageBox.Show("Tạo batch mới thành công!");
            txt_BatchName.Text  = "";
            txt_ImagePath.Text  = "";
            txt_Path.Text       = @"X:\N\13";
            lb_SoLuongHinh.Text = "";
        }
Пример #3
0
        private void UpLoadMulti()
        {
            try
            {
                btn_Browser.Enabled    = false;
                txt_PathFolder.Enabled = false;
                txt_Path.Enabled       = false;
                List <string> lStrBath = new List <string>();
                lStrBath.AddRange(Directory.GetDirectories(txt_PathFolder.Text));
                int    countBatchExists = 0;
                string listBatchExxists = "";
                for (int i = 0; i < lStrBath.Count; i++)
                {
                    sBatchID = (new DirectoryInfo(lStrBath[i]).Name + txt_DateCreate.Text).Replace("/", "").Replace(@"\", "").Replace(@":", "").Replace(@"-", "");
                    batch    = (from w in Global.Db.tbl_Batches.Where(w => w.BatchID == sBatchID) select w.BatchID).FirstOrDefault();
                    if (!string.IsNullOrEmpty(batch))
                    {
                        countBatchExists += 1;
                        listBatchExxists += lStrBath[i] + "\r\n";
                    }
                }
                if (countBatchExists > 0)
                {
                    MessageBox.Show("Batch đã tồn tại :\r\n" + listBatchExxists);
                    btn_Browser.Enabled    = true;
                    txt_PathFolder.Enabled = true;
                    txt_Path.Enabled       = true;
                    return;
                }
                int       n  = 0;
                DataTable dt = new DataTable();
                dt.Columns.AddRange(new[] { new DataColumn("ImageID", typeof(string)) });
                foreach (string itemBatch in lStrBath)
                {
                    dt.Clear();
                    string batchName = "";
                    int    m         = 0;
                    batchName = (new DirectoryInfo(itemBatch).Name + txt_DateCreate.Text).Replace("/", "").Replace(@"\", "").Replace(@":", "").Replace(@"-", "");
                    n        += 1;
                    lb_SobatchHoanThanh.Text = n + @" :";
                    var      filters           = new String[] { "jpg", "jpeg", "tif" };
                    string[] pathImageLocation = GetFilesFrom(itemBatch, filters, true);

                    var fBatch = new tbl_Batch
                    {
                        BatchID       = batchName,
                        BatchName     = new DirectoryInfo(itemBatch).Name,
                        UserCreate    = txt_UserCreate.Text,
                        DateCreate    = DateTime.Now,
                        PathServer    = "",
                        PathPicture   = txt_Path.Text,
                        Location      = txt_PathFolder.Text,
                        NumberImage   = pathImageLocation.Length + "",
                        ChiaUser      = chk_ChiaUser.Checked ? true : false,
                        CongKhaiBatch = false,
                    };
                    Global.Db.tbl_Batches.InsertOnSubmit(fBatch);
                    Global.Db.SubmitChanges();

                    progressBar1.Step    = 1;
                    progressBar1.Value   = 1;
                    progressBar1.Maximum = pathImageLocation.Count();
                    progressBar1.Minimum = 0;
                    ModifyProgressBarColor.SetState(progressBar1, 1);

                    for (int i = 0; i < pathImageLocation.Count(); i++)
                    {
                        FileInfo fi = new FileInfo(pathImageLocation[i]);
                        dt.Rows.Add(fi.Name);
                    }
                    string        ConnectionString = Global.Db.Connection.ConnectionString;
                    SqlConnection con = new SqlConnection(ConnectionString);
                    con.Open();
                    SqlCommand cmd = new SqlCommand("Insert_Image", con);
                    cmd.CommandTimeout = 10 * 60;
                    cmd.CommandType    = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@BatchID", batchName);
                    cmd.Parameters.AddWithValue("@ListIdImage", dt);
                    cmd.Parameters.AddWithValue("@ChiaUser", chk_ChiaUser.Checked ? 1 : 0);
                    cmd.ExecuteNonQuery();
                    con.Close();
                    string temp = Global.StrPath + "\\" + batchName;
                    if (!Directory.Exists(temp))
                    {
                        Directory.CreateDirectory(temp);
                    }
                    else
                    {
                        MessageBox.Show("Bị trùng tên batch!");
                        return;
                    }
                    for (int i = 0; i < pathImageLocation.Count(); i++)
                    {
                        File.Copy(pathImageLocation[i], temp + @"\" + new FileInfo(pathImageLocation[i]).Name);
                        lb_SoImageDaHoanThanh.Text = (i + 1) + @"\" + pathImageLocation.Count();
                        m += 1;
                        progressBar1.PerformStep();
                    }
                    lb_SoImageDaHoanThanh.Text = m + @"/" + pathImageLocation.Length;
                }
                MessageBox.Show(@"Tạo batch mới thành công!");
                txt_BatchName.Text  = "";
                txt_ImagePath.Text  = "";
                lb_SoLuongHinh.Text = "";
                txt_PathFolder.Text = "";
                txt_Path.Text       = @"X:\N\13";
                //btn_CreateBatch.Enabled = true;
                btn_Browser.Enabled    = true;
                txt_PathFolder.Enabled = true;
                txt_Path.Enabled       = true;
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }
Пример #4
0
        public void TableToExcel_Check(string strfilename)
        {
            try
            {
                lb_SoLuong.Text      = "";
                progressBar1.Step    = 1;
                progressBar1.Value   = 0;
                progressBar1.Maximum = dataGridView1.RowCount;
                progressBar1.Minimum = 0;
                progressBar1.Visible = true;
                ModifyProgressBarColor.SetState(progressBar1, 1);
                app  = new Microsoft.Office.Interop.Excel.Application();
                book = app.Workbooks.Open(strfilename, 0, true, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);

                wrksheet = (Microsoft.Office.Interop.Excel.Worksheet)book.Sheets["NATSU"];
                int h = 1, n = 0;
                wrksheet.Cells[2, 7] = "Thời gian:" + timeFisrt.Text + "/" + dtp_FirstDay.Value.Day + "/" + dtp_FirstDay.Value.Month + "/" + dtp_FirstDay.Value.Year + " đến " + timeEnd.Text + "/" + dtp_EndDay.Value.Day + "/" + dtp_EndDay.Value.Month + "/" + dtp_EndDay.Value.Year;
                for (int i = 0; i < dataGridView1.RowCount; i++)
                {
                    wrksheet.Cells[h + 2, 1] = h;
                    wrksheet.Cells[h + 2, 2] = dataGridView1.Rows[i].Cells[0].Value + ""; //username
                    wrksheet.Cells[h + 2, 3] = dataGridView1.Rows[i].Cells[1].Value + ""; //fullname
                    wrksheet.Cells[h + 2, 4] = dataGridView1.Rows[i].Cells[2].Value + ""; //tong
                    wrksheet.Cells[h + 2, 5] = dataGridView1.Rows[i].Cells[3].Value + ""; //thoigian
                    h++;
                    progressBar1.PerformStep();
                    lb_SoLuong.Text = ++n + @"\" + progressBar1.Maximum;
                }
                string savePath;

                saveFileDialog1                  = new SaveFileDialog();
                saveFileDialog1.Title            = @"Save Excel Files";
                saveFileDialog1.Filter           = @"Excel files (*.xlsx)|*.xlsx";
                saveFileDialog1.FileName         = "NangSuatCheckerNatSu_" + dtp_FirstDay.Value.Day + "-" + dtp_EndDay.Value.Day;
                saveFileDialog1.RestoreDirectory = true;
                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    book.SaveCopyAs(saveFileDialog1.FileName);
                    book.Saved = true;
                    savePath   = Path.GetDirectoryName(saveFileDialog1.FileName);
                }
                else
                {
                    MessageBox.Show(@"Error exporting excel!");
                    return;
                }
                if (savePath != null)
                {
                    Process.Start(savePath);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
            finally
            {
                progressBar1.Visible = false;
                lb_SoLuong.Text      = "";
                if (book != null)
                {
                    book.Close(false);
                }
                if (app != null)
                {
                    app.Quit();
                }
                if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Productivity_Check.xlsx"))
                {
                    File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Productivity_Check.xlsx");
                }
                if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + saveFileDialog1.FileName))
                {
                    File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + saveFileDialog1.FileName);
                }
            }
        }