Пример #1
0
        private void OnSaveInfo()
        {
            try
            {
                _nhatKyLienHeCongTy.Status = (byte)Status.Actived;

                if (_isNew)
                {
                    _nhatKyLienHeCongTy.CreatedDate = DateTime.Now;
                    _nhatKyLienHeCongTy.CreatedBy   = Guid.Parse(Global.UserGUID);
                }
                else
                {
                    _nhatKyLienHeCongTy.UpdatedDate = DateTime.Now;
                    _nhatKyLienHeCongTy.UpdatedBy   = Guid.Parse(Global.UserGUID);
                }

                MethodInvoker method = delegate
                {
                    _nhatKyLienHeCongTy.NgayGioLienHe = dtpkNgayGioLienHe.Value;
                    if (!_isNew)
                    {
                        int soNgay = DateTime.Now.Subtract(dtpkNgayGioLienHe.Value).Days;
                        int thang  = soNgay / 30;
                        int ngay   = soNgay % 30;

                        if (thang > 0)
                        {
                            _nhatKyLienHeCongTy.SoNgay = string.Format("{0} tháng {1} ngày", thang, ngay);
                        }
                        else
                        {
                            _nhatKyLienHeCongTy.SoNgay = string.Format("{0} ngày", ngay);
                        }
                    }

                    if (Global.StaffType != StaffType.Admin)
                    {
                        _nhatKyLienHeCongTy.DocStaffGUID = Guid.Parse(Global.UserGUID);
                    }
                    else
                    {
                        _nhatKyLienHeCongTy.DocStaffGUID = null;
                    }

                    _nhatKyLienHeCongTy.CongTyLienHe      = cboCongTyLienHe.Text;
                    _nhatKyLienHeCongTy.NoiDungLienHe     = txtNoiDungLienHe.Text;
                    _nhatKyLienHeCongTy.Note              = string.Empty;
                    _nhatKyLienHeCongTy.TenNguoiLienHe    = txtNguoiLienHe.Text;
                    _nhatKyLienHeCongTy.SoDienThoaiLienHe = txtSoDienThoaiLienHe.Text;
                    _nhatKyLienHeCongTy.SoNguoiKham       = txtSoNguoiKham.Text;
                    _nhatKyLienHeCongTy.DiaChi            = txtDiaChi.Text;
                    _nhatKyLienHeCongTy.Email             = txtEmail.Text;
                    _nhatKyLienHeCongTy.ThangKham         = txtThangKham.Text;
                    _nhatKyLienHeCongTy.Highlight         = chkHighlight.Checked;

                    Result result = NhatKyLienHeCongTyBus.InsertNhatKyLienHeCongTy(_nhatKyLienHeCongTy);
                    if (!result.IsOK)
                    {
                        MsgBox.Show(this.Text, result.GetErrorAsString("NhatKyLienHeCongTyBus.InsertNhatKyLienHeCongTy"), IconType.Error);
                        Utility.WriteToTraceLog(result.GetErrorAsString("NhatKyLienHeCongTyBus.InsertNhatKyLienHeCongTy"));
                        this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
                    }
                };

                if (InvokeRequired)
                {
                    BeginInvoke(method);
                }
                else
                {
                    method.Invoke();
                }
            }
            catch (Exception e)
            {
                MsgBox.Show(this.Text, e.Message, IconType.Error);
                Utility.WriteToTraceLog(e.Message);
            }
        }
Пример #2
0
        private void ImportNhatKyFromExcel(string filename)
        {
            string LogFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Log");

            LogFile = Path.Combine(LogFile, "Import_" + DateTime.Now.ToString("dd-MM-yyyy-") + System.Environment.MachineName + ".txt");
            if (File.Exists(LogFile))
            {
                File.Delete(LogFile);
            }
            string message = "Nhập dữ liệu từ Excel hoàn tất." + System.Environment.NewLine;

            Cursor.Current = Cursors.WaitCursor;
            try
            {
                if (File.Exists(filename))
                {
                    IWorkbook book = SpreadsheetGear.Factory.GetWorkbook(filename);

                    foreach (IWorksheet sheet in book.Worksheets)
                    {
                        if (CheckNhatKyTemplate(sheet, ref message))
                        {
                            int RowCount    = sheet.UsedRange.RowCount + 1;
                            int ColumnCount = sheet.UsedRange.ColumnCount + 1;
                            for (int i = 1; i < RowCount; i++)
                            {
                                NhatKyLienHeCongTy diary = new NhatKyLienHeCongTy();
                                for (int j = 0; j < ColumnCount; j++)
                                {
                                    string curCellValue = string.Empty;
                                    if (sheet.Cells[i, j] != null && sheet.Cells[i, j].Value != null && sheet.Cells[i, j].Text != null)
                                    {
                                        curCellValue = sheet.Cells[i, j].Text.Trim();
                                    }
                                    //process NULL text in excel
                                    if (curCellValue.ToUpper() == "NULL")
                                    {
                                        curCellValue = "";
                                    }

                                    string sType = sheet.Cells[i, j].NumberFormat.Trim();
                                    if (sType.Contains("yy"))
                                    {
                                        curCellValue = ReFormatDate(sType, curCellValue);
                                    }
                                    //process "'" character
                                    curCellValue = curCellValue.Replace("'", "''");
                                    if (sheet.Cells[i, j].Font.Name.ToLower().IndexOf("vni") == 0)
                                    {
                                        curCellValue = Utility.ConvertVNI2Unicode(curCellValue);
                                    }
                                    if (sheet.Cells[0, j].Value != null && sheet.Cells[0, j].Value.ToString().Trim() != null)
                                    {
                                        switch (sheet.Cells[0, j].Value.ToString().Trim().ToLower())
                                        {
                                        case "district":
                                            diary.DiaChi = curCellValue;
                                            break;

                                        case "company name":
                                            diary.CongTyLienHe = curCellValue;
                                            break;

                                        case "person contact":
                                            diary.TenNguoiLienHe = curCellValue;
                                            break;

                                        case "tel":
                                            diary.SoDienThoaiLienHe = curCellValue;
                                            break;

                                        case "quantity":
                                            diary.SoNguoiKham = curCellValue;
                                            break;

                                        case "check-up month":
                                            diary.ThangKham = curCellValue;
                                            break;

                                        //
                                        case "feedback":
                                            diary.NoiDungLienHe = curCellValue;
                                            break;

                                        case "email":
                                            diary.Email = curCellValue;
                                            break;

                                        case "contact date":
                                            DateTime dt = new DateTime();
                                            if (DateTime.TryParse(curCellValue, out dt))
                                            {
                                                diary.CreatedDate   = dt;
                                                diary.NgayGioLienHe = dt;
                                            }
                                            else
                                            {
                                                diary.CreatedDate   = DateTime.Now;
                                                diary.NgayGioLienHe = DateTime.Now;
                                            }
                                            break;

                                        default:
                                            break;
                                        }
                                    }
                                }

                                //add to db
                                //if (diary.CongTyLienHe != null && diary.CongTyLienHe != "" && diary.TenNguoiLienHe != null && diary.TenNguoiLienHe != "")
                                if (diary.CongTyLienHe != null && diary.CongTyLienHe != "")
                                {
                                    Result rs = NhatKyLienHeCongTyBus.CheckCongTyLienHeExist(diary.CongTyLienHe, string.Empty);
                                    if (rs.Error.Code == ErrorCode.EXIST)
                                    {
                                        string sLog = string.Format("Line {0}: Company:{1}", (i + 1).ToString(), diary.CongTyLienHe);
                                        WriteToLogFile(LogFile, sLog);
                                        continue;
                                    }
                                    else
                                    {
                                        if (Global.StaffType != StaffType.Admin)
                                        {
                                            diary.DocStaffGUID = Guid.Parse(Global.UserGUID);
                                        }
                                        else
                                        {
                                            diary.DocStaffGUID = null;
                                        }

                                        diary.CreatedBy = Guid.Parse(Global.UserGUID);
                                        diary.Note      = "Import from Excel on " + DateTime.Now.ToString("dd/MM/yyyy");
                                        Result result = NhatKyLienHeCongTyBus.InsertNhatKyLienHeCongTy(diary);
                                        if (!result.IsOK)
                                        {
                                            MsgBox.Show(this.Text, result.GetErrorAsString("NhatKyLienHeCongTyBus.InsertNhatKyLienHeCongTy"), IconType.Error);
                                            Utility.WriteToTraceLog(result.GetErrorAsString("NhatKyLienHeCongTyBus.InsertNhatKyLienHeCongTy"));
                                        }
                                    }
                                }
                                else
                                {
                                    string sLog = string.Format("Line {0}: Company:{1}", (i + 1).ToString(), diary.CongTyLienHe);
                                    WriteToLogFile(LogFile, sLog);
                                }
                            }
                        }
                    }
                }

                MsgBox.Show(Application.ProductName, message, IconType.Information);
                DisplayAsThread();
            }
            catch (Exception ex)
            {
                MsgBox.Show(Application.ProductName, ex.Message, IconType.Error);
                Utility.WriteToTraceLog(ex.Message);
            }
        }