public void OnCreatedTSVH(object source, FileSystemEventArgs e)
        {
            Common.MoveFile(e, conf);
            /*ShowNotificationMessage(500, "Create", $"{e.Name}", ToolTipIcon.None);*/
            for (int count = 0; count <= 2000; count++)
            {
                try
                {
                    DbContextService db = new DbContextService();

                    //Console.WriteLine("Try to access file !!!");
                    reader = new StreamReader(e.FullPath);
                    //Console.WriteLine("Access file successfully !!!");
                    string fileName = e.Name.Split('.')[0];
                    string serial   = fileName.Split('_')[0];
                    // check Serial Cong To
                    if (!CongToDAO.CheckSerialCongTo(serial))
                    {
                        //ShowNotificationMessage(50, "Error", "Công to serial không tồn tại", ToolTipIcon.Error);
                        reader.Close();
                        return;
                    }
                    // read file
                    string        line;
                    List <string> data = new List <string>();
                    while ((line = reader.ReadLine()) != null)
                    {
                        data.Add(line);
                    }
                    DateTime dt     = new DateTime();
                    var      dt_Str = data[1].Split(',')[2];
                    var      rs_Dt  = DateTime.TryParseExact(dt_Str, "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt);
                    if (!rs_Dt)
                    {
                        //ShowNotificationMessage(50, "Error", "Định dạng thời gian không đúng", ToolTipIcon.Error);
                        reader.Close();
                        return;
                    }

                    if (!ThongSoVanHanhDAO.checkExistTSVH(serial, dt))
                    {
                        ThongSoVanHanh tsvh = new ThongSoVanHanh();
                        tsvh.Serial         = serial;
                        tsvh.ThoiGianCongTo = dt;

                        var bool_rs = true;
                        //var he_so_nhan = 0.001;//from W to kW

                        tsvh.P_Nhan = Common.ParseDouble(data[6 - 1].Split(',')[1], ref bool_rs);
                        tsvh.P_Giao = Common.ParseDouble(data[7 - 1].Split(',')[1], ref bool_rs);

                        tsvh.Q_Nhan = Common.ParseDouble(data[13 - 1].Split(',')[1], ref bool_rs);
                        tsvh.Q_Giao = Common.ParseDouble(data[14 - 1].Split(',')[1], ref bool_rs);

                        tsvh.P_Nhan_BT = Common.ParseDouble(data[19 - 1].Split(',')[1], ref bool_rs);
                        tsvh.P_Nhan_CD = Common.ParseDouble(data[20 - 1].Split(',')[1], ref bool_rs);
                        tsvh.P_Nhan_TD = Common.ParseDouble(data[21 - 1].Split(',')[1], ref bool_rs);

                        tsvh.P_Giao_BT = Common.ParseDouble(data[22 - 1].Split(',')[1], ref bool_rs);
                        tsvh.P_Giao_CD = Common.ParseDouble(data[23 - 1].Split(',')[1], ref bool_rs);
                        tsvh.P_Giao_TD = Common.ParseDouble(data[24 - 1].Split(',')[1], ref bool_rs);

                        tsvh.PhaseA_Amps        = Common.ParseDouble(data[72 - 1].Split(',')[1], ref bool_rs);
                        tsvh.PhaseA_Volts       = Common.ParseDouble(data[73 - 1].Split(',')[1], ref bool_rs);
                        tsvh.PhaseA_PowerFactor = Common.ParseDouble(data[77 - 1].Split(',')[1], ref bool_rs);
                        tsvh.PhaseA_Frequency   = Common.ParseDouble(data[78 - 1].Split(',')[1], ref bool_rs);
                        tsvh.PhaseA_Angle       = Common.ParseDouble(data[79 - 1].Split(',')[1], ref bool_rs);

                        tsvh.PhaseB_Amps        = Common.ParseDouble(data[72 - 1].Split(',')[2], ref bool_rs);
                        tsvh.PhaseB_Volts       = Common.ParseDouble(data[73 - 1].Split(',')[2], ref bool_rs);
                        tsvh.PhaseB_PowerFactor = Common.ParseDouble(data[77 - 1].Split(',')[2], ref bool_rs);
                        tsvh.PhaseB_Frequency   = Common.ParseDouble(data[78 - 1].Split(',')[2], ref bool_rs);
                        tsvh.PhaseB_Angle       = Common.ParseDouble(data[79 - 1].Split(',')[2], ref bool_rs);

                        tsvh.PhaseC_Amps        = Common.ParseDouble(data[72 - 1].Split(',')[3], ref bool_rs);
                        tsvh.PhaseC_Volts       = Common.ParseDouble(data[73 - 1].Split(',')[3], ref bool_rs);
                        tsvh.PhaseC_PowerFactor = Common.ParseDouble(data[77 - 1].Split(',')[3], ref bool_rs);
                        tsvh.PhaseC_Frequency   = Common.ParseDouble(data[78 - 1].Split(',')[3], ref bool_rs);
                        tsvh.PhaseC_Angle       = Common.ParseDouble(data[79 - 1].Split(',')[3], ref bool_rs);

                        tsvh.Phase_Rotation = data[80 - 1].Split(',')[4];

                        if (!bool_rs)
                        {
                            //ShowNotificationMessage(50, "Error", "Lỗi format number in file", ToolTipIcon.Error);
                            reader.Close();
                            return;
                        }

                        var rs = ThongSoVanHanhDAO.Create(tsvh);

                        if (!rs.Equals("success"))
                        {
                            //ShowNotificationMessage(50, "Error", rs, ToolTipIcon.Error);
                            reader.Close();
                            return;
                        }
                    }

                    //ShowNotificationMessage(50, "Success", "Reading file 'Thông số vận hành' finished!!!!", ToolTipIcon.Info);
                    //reader.Close();
                    break;
                }
                catch (IOException)
                {
                    //Console.WriteLine("Wait to access file !!!");
                    //ShowNotificationMessage(50, "Error", "Wait to access file !!!", ToolTipIcon.Error);
                    Thread.Sleep(100);
                }
                catch
                {
                    //Console.WriteLine(ex.Message);
                    //ShowNotificationMessage(50, "Error", ex.Message, ToolTipIcon.Error);
                    break;
                }
                finally
                {
                    try
                    {
                        reader.Close();
                    }
                    catch
                    {
                    }
                }
            }
        }
        public void OnCreatedCSC(object source, FileSystemEventArgs e)
        {
            /*ShowNotificationMessage(500, "Create", $"{e.Name}", ToolTipIcon.None);*/
            while (true)
            {
                try
                {
                    DbContextService db = new DbContextService();

                    //Console.WriteLine("Try to access file !!!");
                    StreamReader reader = new StreamReader(e.FullPath);
                    //Console.WriteLine("Access file successfully !!!");
                    string fileName = e.Name.Split('.')[0];
                    string serial   = fileName.Split('_')[0];
                    // check Serial Cong To
                    if (!CongToDAO.CheckSerialCongTo(serial))
                    {
                        ShowNotificationMessage(50, "Error", "Công to serial không tồn tại", ToolTipIcon.Error);
                        reader.Close();
                        return;
                    }
                    // read file
                    string        line;
                    List <string> data = new List <string>();
                    while ((line = reader.ReadLine()) != null)
                    {
                        data.Add(line);
                    }
                    int numberRecord = int.Parse(Math.Floor((Decimal)data.Count / 58).ToString());

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

                    for (int i = 0; i < numberRecord; i++)
                    {
                        DateTime dt = DateTime.Parse(data[i * 58 + 56 - 1].Split(',')[1]);
                        if (!ChiSoChotDAO.checkExistCSC(serial, dt))
                        {
                            ChiSoChot csc = new ChiSoChot();
                            csc.CongToSerial = serial;
                            csc.thang        = dt;

                            csc.TongGiao       = double.Parse(data[i * 58 + 7 - 1].Split(',')[1]);
                            csc.PhanKhangGiao  = double.Parse(data[i * 58 + 14 - 1].Split(',')[1]);
                            csc.BinhThuongGiao = double.Parse(data[i * 58 + 22 - 1].Split(',')[1]);
                            csc.CaoDiemGiao    = double.Parse(data[i * 58 + 23 - 1].Split(',')[1]);
                            csc.ThapDiemGiao   = double.Parse(data[i * 58 + 24 - 1].Split(',')[1]);

                            csc.TongNhan       = double.Parse(data[i * 58 + 6 - 1].Split(',')[1]);
                            csc.PhangKhangNhan = double.Parse(data[i * 58 + 13 - 1].Split(',')[1]);
                            csc.BinhThuongNhan = double.Parse(data[i * 58 + 19 - 1].Split(',')[1]);
                            csc.CaoDiemNhan    = double.Parse(data[i * 58 + 20 - 1].Split(',')[1]);
                            csc.ThapDiemNhan   = double.Parse(data[i * 58 + 21 - 1].Split(',')[1]);

                            var rs = ChiSoChotDAO.Create(csc);
                            if (!rs.Equals("success"))
                            {
                                ShowNotificationMessage(50, "Error", rs, ToolTipIcon.Info);
                                reader.Close();
                                return;
                            }
                        }
                    }

                    ShowNotificationMessage(50, "Success", "Reading file 'Chỉ Số Chốt' finished!!!!", ToolTipIcon.Info);
                    reader.Close();
                    break;
                }
                catch (IOException)
                {
                    //Console.WriteLine("Wait to access file !!!");
                    ShowNotificationMessage(50, "Error", "Wait to access file !!!", ToolTipIcon.Error);
                    Thread.Sleep(100);
                }
                catch (Exception ex)
                {
                    //Console.WriteLine(ex.Message);
                    ShowNotificationMessage(50, "Error", ex.Message, ToolTipIcon.Error);
                    break;
                }
                finally
                {
                    try
                    {
                        string fileName   = e.Name;
                        string sourcePath = conf.ThuMucQuet;
                        string targetPath = conf.ThuMucChuyen;
                        //Combine file và đường dẫn
                        string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
                        string destFile   = System.IO.Path.Combine(targetPath, fileName);
                        //Copy file từ file nguồn đến file đích
                        System.IO.File.Copy(sourceFile, destFile, true);
                        ShowNotificationMessage(50, "Di chuyển file !!!", "Thành công", ToolTipIcon.None);
                    }
                    catch (Exception ex)
                    {
                        ShowNotificationMessage(50, "Error !!!", ex.Message, ToolTipIcon.Error);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void OnCreatedCSC(object source, FileSystemEventArgs e)
        {
            Common.MoveFile(e, conf);
            /*ShowNotificationMessage(500, "Create", $"{e.Name}", ToolTipIcon.None);*/
            for (var count = 0; count < 20000; count++)
            {
                try
                {
                    DbContextService db = new DbContextService();

                    //Console.WriteLine("Try to access file !!!");
                    reader = new StreamReader(e.FullPath);
                    //Console.WriteLine("Access file successfully !!!");
                    string fileName = e.Name.Split('.')[0];
                    string serial   = fileName.Split('_')[0];
                    // check Serial Cong To
                    if (!CongToDAO.CheckSerialCongTo(serial))
                    {
                        //ShowNotificationMessage(50, "Error", "Công to serial không tồn tại", ToolTipIcon.Error);
                        reader.Close();
                        return;
                    }
                    // read file
                    string        line;
                    List <string> data = new List <string>();
                    while ((line = reader.ReadLine()) != null)
                    {
                        data.Add(line);
                    }
                    int numberRecord = int.Parse(Math.Floor((Decimal)data.Count / 74).ToString());

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

                    for (int i = 0; i < numberRecord; i++)
                    {
                        DateTime dt = DateTime.Parse(data[i * 74 + 72 - 1].Split(',')[1]);
                        if (!ChiSoChotDAO.checkExistCSC(serial, dt))
                        {
                            ChiSoChot csc = new ChiSoChot();
                            csc.CongToSerial = serial;
                            csc.thang        = dt;

                            var bool_check = true;

                            csc.TongGiao       = Common.ParseDouble(data[i * 74 + 7 - 1].Split(',')[1], ref bool_check);
                            csc.PhanKhangGiao  = Common.ParseDouble(data[i * 74 + 14 - 1].Split(',')[1], ref bool_check);
                            csc.BinhThuongGiao = Common.ParseDouble(data[i * 74 + 22 - 1].Split(',')[1], ref bool_check);
                            csc.CaoDiemGiao    = Common.ParseDouble(data[i * 74 + 23 - 1].Split(',')[1], ref bool_check);
                            csc.ThapDiemGiao   = Common.ParseDouble(data[i * 74 + 24 - 1].Split(',')[1], ref bool_check);

                            csc.TongNhan       = Common.ParseDouble(data[i * 74 + 6 - 1].Split(',')[1], ref bool_check);
                            csc.PhangKhangNhan = Common.ParseDouble(data[i * 74 + 13 - 1].Split(',')[1], ref bool_check);
                            csc.BinhThuongNhan = Common.ParseDouble(data[i * 74 + 19 - 1].Split(',')[1], ref bool_check);
                            csc.CaoDiemNhan    = Common.ParseDouble(data[i * 74 + 20 - 1].Split(',')[1], ref bool_check);
                            csc.ThapDiemNhan   = Common.ParseDouble(data[i * 74 + 21 - 1].Split(',')[1], ref bool_check);

                            var rs = ChiSoChotDAO.Create(csc);
                            if (!rs.Equals("success"))
                            {
                                //ShowNotificationMessage(50, "Error", rs, ToolTipIcon.Info);
                                reader.Close();
                                return;
                            }
                        }
                    }

                    //ShowNotificationMessage(50, "Success", "Reading file 'Chỉ Số Chốt' finished!!!!", ToolTipIcon.Info);
                    //reader.Close();
                    break;
                }
                catch (IOException)
                {
                    //Console.WriteLine("Wait to access file !!!");
                    //ShowNotificationMessage(50, "Error", "Wait to access file !!!", ToolTipIcon.Error);
                    Thread.Sleep(100);
                }
                catch
                {
                    //Console.WriteLine(ex.Message);
                    //ShowNotificationMessage(50, "Error", ex.Message, ToolTipIcon.Error);
                    break;
                }
                finally
                {
                    try
                    {
                        reader.Close();
                    }
                    catch
                    {
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public void OnCreatedTSVH(object source, FileSystemEventArgs e)
        {
            /*ShowNotificationMessage(500, "Create", $"{e.Name}", ToolTipIcon.None);*/
            while (true)
            {
                try
                {
                    DbContextService db = new DbContextService();

                    //Console.WriteLine("Try to access file !!!");
                    StreamReader reader = new StreamReader(e.FullPath);
                    //Console.WriteLine("Access file successfully !!!");
                    string fileName = e.Name.Split('.')[0];
                    string serial   = fileName.Split('_')[0];
                    // check Serial Cong To
                    if (!CongToDAO.CheckSerialCongTo(serial))
                    {
                        ShowNotificationMessage(50, "Error", "Công to serial không tồn tại", ToolTipIcon.Error);
                        reader.Close();
                        return;
                    }
                    // read file
                    string        line;
                    List <string> data = new List <string>();
                    while ((line = reader.ReadLine()) != null)
                    {
                        data.Add(line);
                    }
                    DateTime dt     = new DateTime();
                    var      dt_Str = data[1].Split(',')[2];
                    var      rs_Dt  = DateTime.TryParseExact(dt_Str, "M/dd/yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt);
                    if (!rs_Dt)
                    {
                        ShowNotificationMessage(50, "Error", "Định dạng thời gian không đúng", ToolTipIcon.Error);
                        reader.Close();
                        return;
                    }

                    if (!ThongSoVanHanhDAO.checkExistTSVH(serial, dt))
                    {
                        ThongSoVanHanh tsvh = new ThongSoVanHanh();
                        tsvh.Serial         = serial;
                        tsvh.ThoiGianCongTo = dt;

                        tsvh.P_Nhan = double.Parse(data[6 - 1].Split(',')[1]);
                        tsvh.P_Giao = double.Parse(data[7 - 1].Split(',')[1]);

                        tsvh.Q_Nhan = double.Parse(data[13 - 1].Split(',')[1]);
                        tsvh.Q_Giao = double.Parse(data[14 - 1].Split(',')[1]);

                        tsvh.P_Nhan_BT = double.Parse(data[19 - 1].Split(',')[1]);
                        tsvh.P_Nhan_CD = double.Parse(data[20 - 1].Split(',')[1]);
                        tsvh.P_Nhan_TD = double.Parse(data[21 - 1].Split(',')[1]);

                        tsvh.P_Giao_BT = double.Parse(data[22 - 1].Split(',')[1]);
                        tsvh.P_Giao_CD = double.Parse(data[23 - 1].Split(',')[1]);
                        tsvh.P_Giao_TD = double.Parse(data[24 - 1].Split(',')[1]);

                        tsvh.PhaseA_Amps        = double.Parse(data[56 - 1].Split(',')[1]);
                        tsvh.PhaseA_Volts       = double.Parse(data[57 - 1].Split(',')[1]);
                        tsvh.PhaseA_PowerFactor = double.Parse(data[61 - 1].Split(',')[1]);
                        tsvh.PhaseA_Frequency   = double.Parse(data[62 - 1].Split(',')[1]);
                        tsvh.PhaseA_Angle       = double.Parse(data[63 - 1].Split(',')[1]);

                        tsvh.PhaseB_Amps        = double.Parse(data[56 - 1].Split(',')[2]);
                        tsvh.PhaseB_Volts       = double.Parse(data[57 - 1].Split(',')[2]);
                        tsvh.PhaseB_PowerFactor = double.Parse(data[61 - 1].Split(',')[2]);
                        tsvh.PhaseB_Frequency   = double.Parse(data[62 - 1].Split(',')[2]);
                        tsvh.PhaseB_Angle       = double.Parse(data[63 - 1].Split(',')[2]);

                        tsvh.PhaseC_Amps        = double.Parse(data[56 - 1].Split(',')[3]);
                        tsvh.PhaseC_Volts       = double.Parse(data[57 - 1].Split(',')[3]);
                        tsvh.PhaseC_PowerFactor = double.Parse(data[61 - 1].Split(',')[3]);
                        tsvh.PhaseC_Frequency   = double.Parse(data[62 - 1].Split(',')[3]);
                        tsvh.PhaseC_Angle       = double.Parse(data[63 - 1].Split(',')[3]);

                        tsvh.Phase_Rotation = data[64 - 1].Split(',')[4];

                        var rs = ThongSoVanHanhDAO.Create(tsvh);

                        if (!rs.Equals("success"))
                        {
                            ShowNotificationMessage(50, "Error", rs, ToolTipIcon.Error);
                            reader.Close();
                            return;
                        }
                    }

                    ShowNotificationMessage(50, "Success", "Reading file 'Thông số vận hành' finished!!!!", ToolTipIcon.Info);
                    reader.Close();
                    break;
                }
                catch (IOException)
                {
                    //Console.WriteLine("Wait to access file !!!");
                    ShowNotificationMessage(50, "Error", "Wait to access file !!!", ToolTipIcon.Error);
                    Thread.Sleep(100);
                }
                catch (Exception ex)
                {
                    //Console.WriteLine(ex.Message);
                    ShowNotificationMessage(50, "Error", ex.Message, ToolTipIcon.Error);
                    break;
                }
                finally
                {
                    try
                    {
                        string fileName   = e.Name;
                        string sourcePath = conf.ThuMucQuet;
                        string targetPath = conf.ThuMucChuyen;
                        //Combine file và đường dẫn
                        string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
                        string destFile   = System.IO.Path.Combine(targetPath, fileName);
                        //Copy file từ file nguồn đến file đích
                        System.IO.File.Copy(sourceFile, destFile, true);
                        ShowNotificationMessage(50, "Di chuyển file !!!", "Thành công", ToolTipIcon.None);
                    }
                    catch (Exception ex)
                    {
                        ShowNotificationMessage(50, "Error !!!", ex.Message, ToolTipIcon.Error);
                    }
                }
            }
        }