Example #1
0
        private void save_data()
        {
            if (check_data_is_ok() == false)
            {
                return;
            }

            try
            {
                m_us.BeginTransaction();

                #region Xử lý file đính kèm
                switch (m_e_file_mode)
                {
                case DataEntryFileMode.UploadFile:
                    // Kiểm tra file đã tồn tại trên server hay chưa
                    if (FileExplorer.IsExistedFile(m_str_directory_to + FileExplorer.fileName))
                    {
                        BaseMessages.MsgBox_Infor("Tên file đã tồn tại. Vui lòng đổi tên khác");
                        return;
                    }

                    // Nếu đã chọn file
                    if (m_lbl_file_name.Text != "")
                    {
                        // Upload server có sử dụng user và pass
                        if (m_str_user_name != "")
                        {
                            FileExplorer.UploadFile(m_str_domain, m_str_directory_to, m_str_user_name, m_str_password);
                        }
                        // Upload không sử dụng user và pass
                        else
                        {
                            FileExplorer.UploadFile(m_str_domain, m_str_directory_to);
                        }
                    }
                    break;

                case DataEntryFileMode.EditFile:
                    // Nếu ko up lên file mới sẽ bỏ qua bước này
                    if (m_str_link_old != m_lbl_file_name.Text)
                    {
                        // Kiểm tra file vừa upload đã tồn tại hay chưa
                        if (FileExplorer.IsExistedFile(m_str_directory_to + FileExplorer.fileName))
                        {
                            BaseMessages.MsgBox_Infor("Tên file đã tồn tại. Vui lòng đổi tên khác");
                            return;
                        }

                        // Xóa file cũ
                        if (FileExplorer.IsExistedFile(m_str_directory_to + m_str_link_old))
                        {
                            FileExplorer.DeleteFile(m_str_directory_to + m_str_link_old);
                        }

                        // Upload file mới lên
                        if (m_str_user_name != "")
                        {
                            FileExplorer.UploadFile(m_str_domain, m_str_directory_to, m_str_user_name, m_str_password);
                        }
                        else
                        {
                            FileExplorer.UploadFile(m_str_domain, m_str_directory_to);
                        }
                    }
                    break;

                case DataEntryFileMode.DeleteFile:
                    // Kiểm tra file có tồn tại hay không
                    if (FileExplorer.IsExistedFile(m_str_directory_to + m_str_link_old) == false)
                    {
                        BaseMessages.MsgBox_Infor("File không tồn tại!");
                        return;
                    }
                    FileExplorer.DeleteFile(m_str_directory_to + m_str_link_old);
                    break;
                }
                #endregion

                #region Xử lý quyết định
                form_to_us_quyet_dinh();
                switch (m_e_quyet_dinh_mode)
                {
                case DataEntryFormMode.InsertDataState:
                    if (is_exist_quyet_dinh(m_txt_ma_quyet_dinh.Text))
                    {
                        BaseMessages.MsgBox_Error("Mã quyết định đã tồn tại.");
                        m_txt_ma_quyet_dinh.Focus();
                        return;
                    }
                    m_us.Insert();
                    break;

                case DataEntryFormMode.UpdateDataState:
                    if (!m_txt_ma_quyet_dinh.Text.Equals(m_str_ma_quyet_dinh_old))
                    {
                        if (is_exist_quyet_dinh(m_txt_ma_quyet_dinh.Text))
                        {
                            BaseMessages.MsgBox_Error("Mã quyết định đã tồn tại hoặc đang được dùng cho dự án khác.");
                            m_txt_ma_quyet_dinh.Focus();
                            return;
                        }
                    }
                    m_us.Update();
                    break;
                }
                #endregion

                m_us.CommitTransaction();
            }
            catch (Exception)
            {
                if (m_us.is_having_transaction())
                {
                    m_us.Rollback();
                }
            }



            form_2_us_nhan_vien();

            US_DM_QUYET_DINH v_us_qd = new US_DM_QUYET_DINH();
            DS_DM_QUYET_DINH v_ds_qd = new DS_DM_QUYET_DINH();
            switch (m_e_form_mode)
            {
            case DataEntryFormMode.InsertDataState:
                // Insert nhân sự
                chuyen_trang_thai_ve_no(m_us.dcID_NHAN_SU);
                m_us.strTRANG_THAI_HIEN_TAI = "Y";


                // Quyết định
                if (m_b_check_quyet_dinh_save)
                {
                    form_to_us_quyet_dinh();
                    if (m_b_check_quyet_dinh_null)
                    {
                        m_us_quyet_dinh.Insert();

                        US_DM_QUYET_DINH v_us = new US_DM_QUYET_DINH();
                        DS_DM_QUYET_DINH v_ds = new DS_DM_QUYET_DINH();
                        v_us.FillDataset_By_Ma_qd(v_ds, m_us_quyet_dinh.strMA_QUYET_DINH);
                        if (v_ds.DM_QUYET_DINH.Rows.Count != 0)
                        {
                            US_GD_QUYET_DINH_PHAP_NHAN v_us_qd_pn = new US_GD_QUYET_DINH_PHAP_NHAN();
                            v_us_qd_pn.dcID_PHAP_NHAN  = CAppContext_201.getCurrentIDPhapnhan();
                            v_us_qd_pn.dcID_QUYET_DINH = CIPConvert.ToDecimal(v_ds_qd.Tables[0].Rows[0]["ID"]);
                            v_us_qd_pn.Insert();
                        }
                    }
                    else
                    {
                        m_us_quyet_dinh.Update();
                    }

                    v_us_qd.FillDataset_By_Ma_qd(v_ds_qd, m_us_quyet_dinh.strMA_QUYET_DINH);
                    if (v_ds_qd.Tables[0].Rows.Count != 0)
                    {
                        m_us.dcID_QUYET_DINH = CIPConvert.ToDecimal(v_ds_qd.Tables[0].Rows[0]["ID"]);
                    }
                }
                m_us.Insert();
                break;

            case DataEntryFormMode.UpdateDataState:
                if (m_txt_ma_quyet_dinh.Text != "")
                {
                    form_to_us_quyet_dinh();
                    if (m_b_check_quyet_dinh_save)
                    {
                        m_us_quyet_dinh.Insert();
                    }
                    else
                    {
                        m_us_quyet_dinh.Update();
                    }

                    v_us_qd.FillDataset_By_Ma_qd(v_ds_qd, m_us_quyet_dinh.strMA_QUYET_DINH);
                    if (v_ds_qd.Tables[0].Rows.Count != 0)
                    {
                        m_us.dcID_QUYET_DINH = CIPConvert.ToDecimal(v_ds_qd.Tables[0].Rows[0]["ID"]);
                    }
                }
                m_us.Update();
                break;
            }
            BaseMessages.MsgBox_Infor("Dữ liệu đã được cập nhật");
            this.Close();
        }