示例#1
0
        void sendEmail()
        {
            ModulesModel product     = (ModulesModel)ModulesBO.Instance.FindByPK(ErrorModel.ModuleID);
            string       productCode = product.Code;

            string nguoiGayLoi = "";
            string userMails   = "";

            foreach (DataGridViewRow item in grvData.Rows)
            {
                nguoiGayLoi += item.Cells[colFullName.Index].Value.ToString() + ",";
                userMails   += item.Cells[colLoginName.Index].Value.ToString() + ";";
            }

            frmSendEmailAttach frm = new frmSendEmailAttach();

            frm.To = "*****@*****.**";
            frm.CC = //"*****@*****.**";
                     "[email protected];[email protected];[email protected];[email protected];";
            frm.Subject = string.Format("ERROR REPORT - {0} - {1}", ErrorModel.Code, productCode);
            DataTable dtConfig = TextUtils.Select("select KeyValue from [ConfigSystem] where [KeyName]='TKToKCS_Email'");
            string    content  = dtConfig.Rows[0][0].ToString();

            frm.Content = content.Replace("<ErrorCode>", "<b>" + ErrorModel.Code + "</b>")
                          .Replace("<ProjectCode>", "<b>" + ErrorModel.ProjectCode + "</b>")
                          .Replace("<ProductCode>", "<b>" + productCode + "</b>")
                          .Replace("<ProductName>", product.Name)
                          .Replace("<ErrorStatus>", "<b>" + cboStatus.Text + "</b>")
                          .Replace("<ErrorUser>", nguoiGayLoi)
                          .Replace("<TamThoi>", ErrorModel.HuongKhacPhucTamThoi)
                          .Replace("<LauDai>", ErrorModel.HuongKhacPhuc == "" ? "Chưa có" : ErrorModel.HuongKhacPhuc);
            frm.Show();
        }
示例#2
0
        private void btnExcel_Click(object sender, EventArgs e)
        {
            if (grvData.RowCount == 0)
            {
                return;
            }

            string localPath        = "";
            FolderBrowserDialog fbd = new FolderBrowserDialog();

            if (fbd.ShowDialog() == DialogResult.OK)
            {
                localPath = fbd.SelectedPath + "\\ProjectReport_ " + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + ".xlsx";
            }
            else
            {
                return;
            }

            string filePath = Application.StartupPath + "\\Templates\\PhongSXLR\\ProjectReport.xlsx";

            try
            {
                File.Copy(filePath, localPath, true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi: File excel đang được mở." + Environment.NewLine + ex.Message);
                return;
            }

            using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang tạo FCM..."))
            {
                System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
                Excel.Application app       = default(Excel.Application);
                Excel.Workbook    workBoook = default(Excel.Workbook);
                Excel.Worksheet   workSheet = default(Excel.Worksheet);
                try
                {
                    app = new Excel.Application();
                    app.Workbooks.Open(localPath);
                    workBoook = app.Workbooks[1];
                    workSheet = (Excel.Worksheet)workBoook.Worksheets[1];

                    for (int i = grvData.RowCount - 1; i >= 0; i--)
                    {
                        workSheet.Cells[3, 1] = i + 1;
                        workSheet.Cells[3, 2] = TextUtils.ToString(grvData.GetRowCellValue(i, colName));
                        workSheet.Cells[3, 3] = TextUtils.ToString(grvData.GetRowCellValue(i, colCode));
                        workSheet.Cells[3, 4] = TextUtils.ToDecimal(grvData.GetRowCellDisplayText(i, colCompletePercent));
                        workSheet.Cells[3, 5] = TextUtils.ToDecimal(grvData.GetRowCellDisplayText(i, colCNC));
                        workSheet.Cells[3, 6] = TextUtils.ToDecimal(grvData.GetRowCellDisplayText(i, colIN));
                        workSheet.Cells[3, 7] = TextUtils.ToDecimal(grvData.GetRowCellDisplayText(i, colGCAL));
                        workSheet.Cells[3, 8] = TextUtils.ToDecimal(grvData.GetRowCellDisplayText(i, colPCB));
                        workSheet.Cells[3, 9] = TextUtils.ToDecimal(grvData.GetRowCellDisplayText(i, colLR));
                        ((Excel.Range)workSheet.Rows[3]).Insert();
                    }

                    ((Excel.Range)workSheet.Rows[2]).Delete();
                    ((Excel.Range)workSheet.Rows[2]).Delete();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    if (app != null)
                    {
                        app.ActiveWorkbook.Save();
                        app.Workbooks.Close();
                        app.Quit();
                    }
                }

                //Process.Start(localPath);
                DataTable dtFile = new DataTable();

                dtFile.Columns.Add("ID");
                dtFile.Columns.Add("FileName");
                dtFile.Columns.Add("Path");

                dtFile.Rows.Add(0, Path.GetFileName(localPath), localPath);

                frmSendEmailAttach frm = new frmSendEmailAttach();
                frm.dtFile  = dtFile;
                frm.Content = "Hi all!<br>SXLR gửi báo cáo tiến độ sản xuất ngày " + DateTime.Now.ToString("dd-MM-yyyy")
                              + ".<br>Vui lòng xem trong attach file.<br>Để rõ chi tiết từng dự án, vui lòng xem trên phần mềm QLTK: PHÒNG SXLR/Báo cáo tiến độ/Báo cáo tiến độ theo thiết bị.";
                frm.To      = "[email protected];[email protected];[email protected];[email protected];[email protected]";
                frm.Subject = "Báo cáo tiến độ sản xuất đến ngày: " + DateTime.Now.ToString("dd-MM-yyyy");
                frm.Show();
            }
        }