Exemplo n.º 1
0
        private void FMain_Load(object sender, EventArgs e)
        {
            // load com
            string[] arr = File.ReadAllLines(Path.Combine(Application.StartupPath, "comport.txt"));
            _com = arr[1].Split('|');
            LoadSylvacCOM();
            StartPLCThread();

            if (!bitManual)
            {
                Thread.Sleep(500);
                RecheckPlcConnection();
                StartThreadToCollectionData();
            }
            else
            {
                btnStart.BackColor = Color.MidnightBlue;
                btnStart.ForeColor = Color.White;
                bitManual          = false;
            }


            //load hệ số rung động
            string strFactor = File.ReadAllText(Path.Combine(Application.StartupPath, "factorVibration.txt"));

            _factorVibration = TextUtils.ToDouble(strFactor);
            // Khởi tạo lại hiển thị nút nhấn Manual
            btnManual.BackColor = Color.White;
            btnManual.ForeColor = Color.Black;
            // Tắt trạng thái Manual
            bitManual = false;
            // Load form Tester
        }
Exemplo n.º 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            ProcessTransaction pt = new ProcessTransaction();

            pt.OpenConnection();
            pt.BeginTransaction();

            try
            {
                if (!ValidateForm())
                {
                    return;
                }

                Model.Code         = txtCode.Text.Trim();
                Model.Name         = txtName.Text.Trim();
                Model.TotalTime    = (double)txtTotalTime.Value;
                Model.ProductID    = TextUtils.ToInt(leProducts.EditValue);
                Model.WorkStatusID = cboStatus.SelectedIndex;
                Model.WorkTypeID   = cboWorkType.SelectedIndex;
                Model.Type         = cboType.SelectedIndex;
                Model.TotalScore   = TextUtils.ToDouble(txtTotalScore.Value);
                Model.Priority     = TextUtils.ToInt(txtPriority.Value);
                Model.Description  = txtDescription.Text.Trim();

                if (Model.ID == 0)
                {
                    Model.CreatedDate = TextUtils.GetSystemDate();
                    Model.CreatedBy   = Global.AppUserName;
                    Model.UpdatedDate = Model.CreatedDate;
                    Model.UpdatedBy   = Global.AppUserName;
                    Model.ID          = (int)pt.Insert(Model);
                }
                else
                {
                    Model.UpdatedDate = TextUtils.GetSystemDate();
                    Model.UpdatedBy   = Global.AppUserName;
                    pt.Update(Model);
                }

                pt.CommitTransaction();

                MessageBox.Show("Lưu trữ thành công!", "Thông báo");
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            { pt.CloseConnection(); }
        }
        private void cboSheet_SelectionChangeCommitted(object sender, EventArgs e)
        {
            grvData.Columns.Clear();
            if (chkAutoCheck.Checked)
            {
                try
                {
                    DataTable dtt = ds.Tables[cboSheet.SelectedIndex];

                    dtt.Columns.Add("DATEF2", typeof(DateTime));
                    for (int i = 0; i < dtt.Rows.Count; i++)
                    {
                        if (i < 1
                            )
                        {
                            continue;
                        }
                        if (string.IsNullOrEmpty(Lib.ToString(dtt.Rows[i]["F1"])))
                        {
                            continue;
                        }
                        if (Lib.ToString(dtt.Rows[i]["F2"]).Trim() != "")
                        {
                            dtt.Rows[i]["DATEF2"] = DateTime.FromOADate(TextUtils.ToDouble(dtt.Rows[i]["F2"]));
                        }
                    }

                    dtt.Columns.Add("DATEF3", typeof(DateTime));
                    for (int i = 0; i < dtt.Rows.Count; i++)
                    {
                        if (i < 1
                            )
                        {
                            continue;
                        }
                        if (string.IsNullOrEmpty(Lib.ToString(dtt.Rows[i]["F1"])))
                        {
                            continue;
                        }
                        if (Lib.ToString(dtt.Rows[i]["F3"]).Trim() != "")
                        {
                            dtt.Rows[i]["DATEF3"] = DateTime.FromOADate(TextUtils.ToDouble(dtt.Rows[i]["F3"]));
                        }
                    }
                    grdData.DataSource = dtt;
                    grvData.PopulateColumns();
                    grvData.BestFitColumns();
                    grdData.Focus();
                }
                catch (Exception ex)
                {
                    TextUtils.ShowError(ex);
                    grdData.DataSource = null;
                }
            }
            else
            {
                try
                {
                    DataTable dt = TextUtils.ExcelToDatatableNoHeader(btnBrowse.Text, cboSheet.SelectedValue.ToString());
                    // thêm 1 cột date mới
                    dt.Columns.Add("DATEF2", typeof(DateTime));
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        if (i < 1
                            )
                        {
                            continue;
                        }
                        if (string.IsNullOrEmpty(Lib.ToString(dt.Rows[i]["F1"])))
                        {
                            continue;
                        }
                        if (Lib.ToString(dt.Rows[i]["F2"]).Trim() != "")
                        {
                            dt.Rows[i]["DATEF2"] = DateTime.FromOADate(TextUtils.ToDouble(dt.Rows[i]["F2"]));
                        }
                    }

                    dt.Columns.Add("DATEF3", typeof(DateTime));
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        if (i < 1
                            )
                        {
                            continue;
                        }
                        if (string.IsNullOrEmpty(Lib.ToString(dt.Rows[i]["F1"])))
                        {
                            continue;
                        }
                        if (Lib.ToString(dt.Rows[i]["F3"]).Trim() != "")
                        {
                            dt.Rows[i]["DATEF3"] = DateTime.FromOADate(TextUtils.ToDouble(dt.Rows[i]["F3"]));
                        }
                    }



                    grdData.DataSource = dt;
                    grvData.PopulateColumns();
                    grvData.BestFitColumns();
                    grdData.Focus();

                    //grvData.Columns[3].DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
                    //grvData.Columns[3].DisplayFormat.FormatString = "dd/MM/yyyy";
                }
                catch (Exception ex)
                {
                    TextUtils.ShowError(ex);
                    grdData.DataSource = null;
                }
            }
        }
Exemplo n.º 4
0
        private void btnExportFormBank_Click(object sender, EventArgs e)
        {
            bool         isTrongNuoc = true;
            DialogResult result      = MessageBox.Show("Bạn muốn xuất các biểu mẫu loại trong nước?", TextUtils.Caption, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                isTrongNuoc = true;
            }
            else if (result == DialogResult.No)
            {
                isTrongNuoc = false;
            }
            else
            {
                return;
            }

            string         filePath = "";
            OpenFileDialog ofd      = new OpenFileDialog();

            ofd.Multiselect = false;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                filePath = ofd.FileName;
            }
            else
            {
                return;
            }

            DataTable dtItem = TextUtils.ExcelToDatatableNoHeader(filePath, "Sheet1");

            for (int i = 0; i < 3; i++)
            {
                dtItem.Rows.RemoveAt(0);
            }

            DataTable dtDistinctItem = TextUtils.GetDistinctDatatable(dtItem, "F4");

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

            if (fbd.ShowDialog() == DialogResult.OK)
            {
                path = fbd.SelectedPath;
            }
            else
            {
                return;
            }

            using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang tạo mẫu lệnh chi..."))
            {
                #region Mẫu lệnh chi
                for (int i = 0; i < dtDistinctItem.Rows.Count; i++)
                //for (int i = 0; i < 1; i++)
                {
                    string stt = TextUtils.ToString(dtDistinctItem.Rows[i]["F1"]);
                    if (stt == "")
                    {
                        continue;
                    }

                    string filePathS   = Application.StartupPath + "\\Templates\\PhongKeToan\\NganHang\\Mau lenh chi.xls";
                    string currentPath = path + "\\Mau lenh chi-" + TextUtils.ToString(dtDistinctItem.Rows[i]["F2"]) + ".xls";

                    try
                    {
                        File.Copy(filePathS, currentPath, true);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Có lỗi khi tạo biểu mẫu lệnh chi!" + Environment.NewLine + ex.Message,
                                        TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        continue;
                    }

                    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(currentPath);
                        workBoook = app.Workbooks[1];
                        workSheet = (Excel.Worksheet)workBoook.Worksheets[1];

                        string loaiTienTe       = TextUtils.ToString(dtDistinctItem.Rows[i]["F13"]);
                        string percentThanhToan = TextUtils.ToString(dtDistinctItem.Rows[i]["F14"]);
                        string soTaiKhoan       = TextUtils.ToString(dtDistinctItem.Rows[i]["F4"]);

                        string    soHoaDonHopDong = "";
                        double    tienNhanNo      = 0;
                        DataRow[] drs             = dtItem.Select("F4 = '" + soTaiKhoan + "'");
                        foreach (DataRow item in drs)
                        {
                            tienNhanNo      += TextUtils.ToDouble(item["F9"]);
                            soHoaDonHopDong += TextUtils.ToString(item["F5"]) + ",";
                        }

                        workSheet.Cells[7, 1] = "                                                                                            Số No………Ngày Date ……/"
                                                + string.Format("{0:00}", DateTime.Now.Month) + "/" + DateTime.Now.Year;
                        workSheet.Cells[12, 3] = TextUtils.ToString(dtDistinctItem.Rows[i]["F2"]);  //Bên thụ hưởng
                        workSheet.Cells[15, 4] = TextUtils.ToString(dtDistinctItem.Rows[i]["F12"]); //địa chỉ bên thụ hưởng
                        if (isTrongNuoc)
                        {
                            workSheet.Cells[13, 3] = "'" + soTaiKhoan;
                            workSheet.Cells[16, 4] = tienNhanNo.ToString("n2") + " " + loaiTienTe;      //Số tiền nhận nợ
                            workSheet.Cells[17, 4] = TextUtils.NumericToString(tienNhanNo, loaiTienTe); //tiền nhận nợ bẳng chữ
                        }

                        workSheet.Cells[21, 3] = "Công ty cp tự động hóa Tân phát thanh toán " + tienNhanNo + " " + (loaiTienTe == "" ? "VNĐ" : loaiTienTe)
                                                 + " tiền hợp đồng " + soHoaDonHopDong.Substring(0, soHoaDonHopDong.Length - 1);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    finally
                    {
                        if (app != null)
                        {
                            app.ActiveWorkbook.Save();
                            app.Workbooks.Close();
                            app.Quit();
                        }
                    }
                }
                #endregion Mẫu lệnh chi
            }

            using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang tạo Giấy nhận nợ..."))
            {
                #region Giấy nhận nợ
                Word.Application word = new Word.Application();
                Word.Document    doc  = new Word.Document();
                try
                {
                    string localFilePath = "";
                    if (isTrongNuoc)
                    {
                        localFilePath = Application.StartupPath + "\\Templates\\PhongKeToan\\NganHang\\GiayNhanNo_VND.docx";
                    }
                    else
                    {
                        localFilePath = Application.StartupPath + "\\Templates\\PhongKeToan\\NganHang\\GiayNhanNo_USD.docx";
                    }

                    string currentFilePath = path + "\\GiayNhanNo-" + DateTime.Now.ToString("ddMMyyyy") + ".docx";
                    try
                    {
                        File.Copy(localFilePath, currentFilePath, true);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Có lỗi khi tạo biểu Giấy nhận nợ!" + Environment.NewLine + ex.Message,
                                        TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        return;
                    }

                    doc = word.Documents.Open(currentFilePath);
                    doc.Activate();

                    decimal tong1 = 0;
                    decimal tong2 = 0;

                    for (int i = 0; i < dtItem.Rows.Count; i++)
                    {
                        int stt = TextUtils.ToInt(dtItem.Rows[i]["F1"]);

                        decimal tienHoaDon = TextUtils.ToDecimal(dtItem.Rows[i]["F8"]);
                        decimal tienNhanNo = TextUtils.ToDecimal(dtItem.Rows[i]["F9"]);

                        string loaiTienTe = TextUtils.ToString(dtItem.Rows[i]["F13"]);

                        tong1 += tienHoaDon;
                        tong2 += tienNhanNo;

                        TextUtils.RepalaceText(doc, "<thuHuong" + stt + ">", TextUtils.ToString(dtItem.Rows[i]["F2"]));
                        TextUtils.RepalaceText(doc, "<nganHang" + stt + ">", TextUtils.ToString(dtItem.Rows[i]["F3"]));
                        TextUtils.RepalaceText(doc, "<soTaiKhoan" + stt + ">", TextUtils.ToString(dtItem.Rows[i]["F4"]));
                        TextUtils.RepalaceText(doc, "<soHoaDon" + stt + ">", TextUtils.ToString(dtItem.Rows[i]["F5"]));
                        //TextUtils.RepalaceText(doc, "<ngay" + stt + ">", TextUtils.ToDate3(dtItem.Rows[i]["F6"]).ToString("dd/MM/yyyy"));
                        TextUtils.RepalaceText(doc, "<ngay" + stt + ">", TextUtils.ToString(dtItem.Rows[i]["F6"]));
                        TextUtils.RepalaceText(doc, "<matHang" + stt + ">", TextUtils.ToString(dtItem.Rows[i]["F7"]));
                        TextUtils.RepalaceText(doc, "<tienHoaDon" + stt + ">", tienHoaDon.ToString("n2"));
                        TextUtils.RepalaceText(doc, "<tienNhanNo" + stt + ">", tienNhanNo.ToString("n2"));
                    }

                    TextUtils.RepalaceText(doc, "<tong1>", tong1.ToString("n2"));
                    TextUtils.RepalaceText(doc, "<tong2>", tong2.ToString("n2"));

                    TextUtils.RepalaceText(doc, "<bangchu>", TextUtils.NumericToString((double)tong2, isTrongNuoc ? "" : "USD"));

                    TextUtils.RepalaceText(doc, "<month>", string.Format("{0:00}", DateTime.Now.Month));
                    TextUtils.RepalaceText(doc, "<year>", DateTime.Now.Year.ToString());

                    doc.Save();
                    doc.Close();
                    word.Quit();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Tân Phát", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    TextUtils.ReleaseComObject(doc);
                    TextUtils.ReleaseComObject(word);
                }
                #endregion Giấy nhận nợ
            }

            if (isTrongNuoc)
            {
                return;
            }
            using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang tạo Hợp đồng ngoại tệ..."))
            {
                #region Hợp đồng ngoại tệ
                Word.Application word = new Word.Application();
                Word.Document    doc  = new Word.Document();
                try
                {
                    string localFilePath = Application.StartupPath + "\\Templates\\PhongKeToan\\NganHang\\HopDongMuaBanNgoaiTe.docx";

                    string currentFilePath = path + "\\HopDongMuaBanNgoaiTe-" + DateTime.Now.ToString("ddMMyyyy") + ".docx";
                    try
                    {
                        File.Copy(localFilePath, currentFilePath, true);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Có lỗi khi tạo biểu Hợp đồng mua bán ngoại tệ!" + Environment.NewLine + ex.Message,
                                        TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        return;
                    }

                    doc = word.Documents.Open(currentFilePath);
                    doc.Activate();

                    for (int i = 0; i < dtDistinctItem.Rows.Count; i++)
                    {
                        int f1 = TextUtils.ToInt(dtDistinctItem.Rows[i]["F1"]);
                        if (f1 == 0)
                        {
                            continue;
                        }

                        int stt = f1; //i + 1;

                        string loaiTienTe = TextUtils.ToString(dtDistinctItem.Rows[i]["F13"]);
                        string soTaiKhoan = TextUtils.ToString(dtDistinctItem.Rows[i]["F4"]);

                        double    tienNhanNo = 0;
                        string    noiDung    = "";
                        DataRow[] drs        = dtItem.Select("F4 = '" + soTaiKhoan + "'");
                        if (drs.Length > 1)
                        {
                            foreach (DataRow item in drs)
                            {
                                tienNhanNo += TextUtils.ToDouble(item["F9"]);
                                string soHoaDonHopDong  = TextUtils.ToString(item["F5"]);
                                string ngay             = TextUtils.ToDate3(item["F6"]).ToString("dd/MM/yyyy");
                                string percentThanhToan = TextUtils.ToString(item["F14"]);
                                if (percentThanhToan != "")
                                {
                                    noiDung += "Thanh toán trả trước nốt " + percentThanhToan + "% hợp đồng số " + soHoaDonHopDong + " ngày " + ngay + Environment.NewLine;
                                }
                                else
                                {
                                    noiDung += "Thanh toán tiền hàng hợp đồng số " + soHoaDonHopDong + " ngày " + ngay + Environment.NewLine;
                                }
                            }
                        }
                        else
                        {
                            tienNhanNo = TextUtils.ToDouble(drs[0]["F9"]);
                            string soHoaDonHopDong  = TextUtils.ToString(drs[0]["F5"]);
                            string ngay             = TextUtils.ToDate3(drs[0]["F6"]).ToString("dd/MM/yyyy");
                            string percentThanhToan = TextUtils.ToString(drs[0]["F14"]);
                            if (percentThanhToan != "")
                            {
                                noiDung = "Thanh toán trả trước  nốt " + percentThanhToan + "% hợp đồng số " + soHoaDonHopDong + " ngày " + ngay;
                            }
                            else
                            {
                                noiDung = "Thanh toán tiền hàng  hợp đồng số " + soHoaDonHopDong + " ngày " + ngay;
                            }
                        }

                        int length = noiDung.Length;
                        if (length <= 200)
                        {
                            TextUtils.RepalaceText(doc, "<noiDung" + stt + ">", noiDung);
                        }

                        TextUtils.RepalaceText(doc, "<benThuHuong" + stt + ">", TextUtils.ToString(dtDistinctItem.Rows[i]["F2"]));
                        TextUtils.RepalaceText(doc, "<NganHang" + stt + ">", TextUtils.ToString(dtDistinctItem.Rows[i]["F3"]));
                        TextUtils.RepalaceText(doc, "<soTaiKhoan" + stt + ">", TextUtils.ToString(dtDistinctItem.Rows[i]["F4"]));
                        TextUtils.RepalaceText(doc, "<tienNhanNo" + stt + ">", tienNhanNo.ToString("n2"));
                        TextUtils.RepalaceText(doc, "<bangChu" + stt + ">", TextUtils.NumericToString(tienNhanNo, "USD"));
                        TextUtils.RepalaceText(doc, "<swiftCode" + stt + ">", TextUtils.ToString(dtDistinctItem.Rows[i]["F10"]));

                        TextUtils.RepalaceText(doc, "<diaChiNganHang" + stt + ">", TextUtils.ToString(dtDistinctItem.Rows[i]["F11"]));
                        TextUtils.RepalaceText(doc, "<diaChiBenThuHuong" + stt + ">", TextUtils.ToString(dtDistinctItem.Rows[i]["F12"]));
                    }

                    TextUtils.RepalaceText(doc, "<month>", string.Format("{0:00}", DateTime.Now.Month));
                    TextUtils.RepalaceText(doc, "<year>", DateTime.Now.Year.ToString());

                    doc.Save();
                    doc.Close();
                    word.Quit();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Tân Phát", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    TextUtils.ReleaseComObject(doc);
                    TextUtils.ReleaseComObject(word);
                }
                #endregion Hợp đồng ngoại tệ
            }
        }