Пример #1
0
        private bool CheckInfo()
        {
            if (cboCongTyLienHe.Text.Trim() == string.Empty)
            {
                MsgBox.Show(this.Text, "Vui lòng nhập công ty liên hệ.", IconType.Information);
                cboCongTyLienHe.Focus();
                return(false);
            }

            //if (txtNguoiLienHe.Text.Trim() == string.Empty)
            //{
            //    MsgBox.Show(this.Text, "Vui lòng nhập tên người liên hệ.", IconType.Information);
            //    txtNguoiLienHe.Focus();
            //    return false;
            //}

            if (txtSoDienThoaiLienHe.Text.Trim() == string.Empty && txtEmail.Text.Trim() == string.Empty)
            {
                MsgBox.Show(this.Text, "Vui lòng nhập số điện thoại hoặc email liên hệ.", IconType.Information);
                txtSoDienThoaiLienHe.Focus();
                return(false);
            }

            //if (txtThangKham.Text.Trim() == string.Empty)
            //{
            //    MsgBox.Show(this.Text, "Vui lòng nhập tháng khám.", IconType.Information);
            //    txtThangKham.Focus();
            //    return false;
            //}

            string nhatKyLienHeCongTyGUID = string.Empty;

            if (!_isNew)
            {
                nhatKyLienHeCongTyGUID = _nhatKyLienHeCongTy.NhatKyLienHeCongTyGUID.ToString();
            }

            Result result = NhatKyLienHeCongTyBus.CheckCongTyLienHeExist(cboCongTyLienHe.Text, nhatKyLienHeCongTyGUID);

            if (result.Error.Code == ErrorCode.EXIST || result.Error.Code == ErrorCode.NOT_EXIST)
            {
                if (result.Error.Code == ErrorCode.EXIST)
                {
                    MsgBox.Show(this.Text, string.Format("Công ty: '{0}' đã liên hệ rồi. Vui lòng xem lại thông tin.", cboCongTyLienHe.Text),
                                IconType.Information);

                    _isView = true;
                    return(false);
                }
            }
            else
            {
                MsgBox.Show(this.Text, result.GetErrorAsString("NhatKyLienHeCongTyBus.CheckCongTyLienHeExist"), IconType.Error);
                return(false);
            }

            nhatKyLienHeCongTyGUID = string.Empty;
            if (!_isNew)
            {
                nhatKyLienHeCongTyGUID = _nhatKyLienHeCongTy.NhatKyLienHeCongTyGUID.ToString();
            }

            result = NhatKyLienHeCongTyBus.CheckCongTyLienHeExist2(cboCongTyLienHe.Text, nhatKyLienHeCongTyGUID);
            if (result.Error.Code == ErrorCode.EXIST || result.Error.Code == ErrorCode.NOT_EXIST)
            {
                if (result.Error.Code == ErrorCode.EXIST)
                {
                    string sChoice = string.Format("Công ty: '{0}' đã liên hệ rồi. Bạn có muốn tạo liên hệ với công ty này nữa không?", cboCongTyLienHe.Text);
                    if (MsgBox.Question(this.Text, sChoice) == DialogResult.Yes)
                    {
                        return(true);
                    }

                    _isView = true;
                    return(false);
                }
            }
            else
            {
                MsgBox.Show(this.Text, result.GetErrorAsString("NhatKyLienHeCongTyBus.CheckCongTyLienHeExist2"), IconType.Error);
                return(false);
            }


            return(true);
        }
Пример #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);
            }
        }