protected void btnAdd_Click(object sender, EventArgs e)
 {
     DepartmentOrderDocTableAdapters.DocumentTableAdapter docTA = new DepartmentOrderDocTableAdapters.DocumentTableAdapter();
     docTA.Insert1(loggedInUserCoId, int.Parse(ddlDepartment.SelectedValue), int.Parse(ddlDocTypes.SelectedValue), tbName.Text, tbName.Text, tbCode.Text,
         int.Parse(ddlCategories.SelectedValue), int.Parse(tbIndex.Text), fileUpload.FileBytes,cbDefault.Checked);
     gvDocs.DataBind();
 }
    //TODO: The transfer should be in one transaction.
    protected void btnTransfer_Click(object sender, EventArgs e)
    {
        if (ddlTransferDeparment.SelectedValue == ddlDepartment.SelectedValue)
        {
            SetErrorMessage("Source and Target Departments are the same");
            return;
        }
        int targetCoId = int.Parse(ddlTransferCompany.SelectedValue);
        int targetDeptId = int.Parse(ddlTransferDeparment.SelectedValue);
        foreach (GridViewRow gr in gvDocs.Rows)
        {
            CheckBox cb = (CheckBox)gr.FindControl("cbSelect");
            HiddenField hfDocId = (HiddenField)gr.FindControl("hfDocId");
            if (cb.Checked)
            {
                DepartmentOrderDoc.DocumentEntityRow document = DatabaseUtility.GetDocument(int.Parse(hfDocId.Value));
                DepartmentOrderDoc.DocumentTypeEntityRow documentType = DatabaseUtility.GetDocumentType(document.co_id, document.dept_id, document.doc_type_id);

                //see if the document type exists in the target co and dept. If not then create it
                DepartmentOrderDoc.DocumentTypeEntityRow targetDocumentType = DatabaseUtility.GetDocumentType(targetCoId,targetDeptId, documentType.doc_data_type_desc);
                if (targetDocumentType == null)
                {
                    DepartmentOrderDocTableAdapters.DocumentTypeTableAdapter docTypeTA = new DepartmentOrderDocTableAdapters.DocumentTypeTableAdapter();
                    docTypeTA.Insert1(documentType.doc_data_type_desc, false, targetCoId, targetDeptId, documentType.sort_order, documentType.field_type, documentType.generator_class,
                        documentType.required, documentType.style, documentType.flg_landscape, documentType.num_of_sections, documentType.flg_checked);
                    targetDocumentType = DatabaseUtility.GetDocumentType(targetCoId, targetDeptId, documentType.doc_data_type_desc);
                }

                //see if the category exists in the target co and dept. If not then create it
                Categories.CategoryEntityRow targetCategory = DatabaseUtility.GetCategory(targetCoId, targetDeptId, "D", document.category_name);
                if (targetCategory == null)
                {
                    CategoriesTableAdapters.CategoryTableAdapter catTA = new CategoriesTableAdapters.CategoryTableAdapter();
                    catTA.Insert(targetCoId, targetDeptId, document.category_name, "D");
                    targetCategory = DatabaseUtility.GetCategory(targetCoId, targetDeptId, "D", document.category_name);
                }
                byte[] fileContents = null;

                //get fille contents if they are present
                DepartmentOrderDocTableAdapters.DocumentContentTableAdapter docContentTA = new DepartmentOrderDocTableAdapters.DocumentContentTableAdapter();
                IEnumerator iEDocContents = docContentTA.GetDocumentContentById(document.doc_id, document.co_id, document.dept_id).GetEnumerator();
                if (iEDocContents.MoveNext())
                {
                    fileContents = ((DepartmentOrderDoc.DocumentContentEntityRow)iEDocContents.Current).file_contents;
                }

                DepartmentOrderDocTableAdapters.DocumentTableAdapter docTA = new DepartmentOrderDocTableAdapters.DocumentTableAdapter();
                docTA.Insert1(targetCoId, targetDeptId, targetDocumentType.doc_data_type_id, document.doc_name, document.doc_desc, document.doc_code,
                    targetCategory.category_id, document.doc_index, fileContents,document.flg_default);

            }
        }
        SetInfoMessage(WebConstants.Messages.Information.RECORD_SAVED);
    }
Ejemplo n.º 3
0
 public static DepartmentOrderDoc.DocumentEntityRow GetDocument(int docId)
 {
     DepartmentOrderDoc.DocumentEntityRow dataRow = null;
     DepartmentOrderDocTableAdapters.DocumentTableAdapter da = new DepartmentOrderDocTableAdapters.DocumentTableAdapter();
     IEnumerator iEnumerator = da.GetDocById(docId).GetEnumerator();
     if (iEnumerator.MoveNext())
     {
         dataRow = (DepartmentOrderDoc.DocumentEntityRow)iEnumerator.Current;
     }
     return dataRow;
 }
 protected void rptDocDetails_ItemDataBound(object sender, RepeaterItemEventArgs e)
 {
     try
     {
         DepartmentOrderDoc.DocumentTypeEntityRow dataRow = (DepartmentOrderDoc.DocumentTypeEntityRow)((System.Data.DataRowView)e.Item.DataItem).Row;
         if (AreEqual(dataRow.field_type, "detail"))
         {
             CheckBoxList cbList = ((CheckBoxList)e.Item.FindControl("cbList"));
             DepartmentOrderDocTableAdapters.DocumentTableAdapter ta = new DepartmentOrderDocTableAdapters.DocumentTableAdapter();
             cbList.DataSource = ta.GetDocsByTypeId(loggedInUserCoId, (int)Session[WebConstants.Session.DEPT_ID], dataRow.doc_data_type_id);
             cbList.DataTextField = "doc_name";
             cbList.DataValueField = "doc_id";
             cbList.DataBind();
         }
     }
     catch (StrongTypingException ex)
     {
         //do mothing
     }
 }
    protected void btnTransfer_Click(object sender, EventArgs e)
    {
        if (ddlTransferDeparment.SelectedValue == ddlDepartment.SelectedValue)
        {
            SetErrorMessage("Source and Target Departments are the same");
            return;
        }
        int targetCoId = int.Parse(ddlTransferCompany.SelectedValue);
        int targetDeptId = int.Parse(ddlTransferDeparment.SelectedValue);

        int sourceCoId = int.Parse(ddlCompany.SelectedValue);
        int sourceDeptId = int.Parse(ddlDepartment.SelectedValue);
        bool isInserted = false;
        foreach (GridViewRow gr in gvDocTypes.Rows)
        {
            CheckBox cb = (CheckBox)gr.FindControl("cbSelect");
            if (cb.Checked)
            {
                int docTypeId = int.Parse(((HiddenField)gr.FindControl("hfDocTypeId")).Value);
                DepartmentOrderDoc.DocumentTypeEntityRow documentType = DatabaseUtility.GetDocumentType(sourceCoId, sourceDeptId, docTypeId);
                if (documentType != null)
                {
                    DepartmentOrderDocTableAdapters.DocumentTypeTableAdapter docTypeTA = new DepartmentOrderDocTableAdapters.DocumentTypeTableAdapter();
                    IEnumerator ie = docTypeTA.GetDocTypeByDeptId(targetDeptId, targetCoId).GetEnumerator();
                    bool alreadyExists = false;
                    while (ie.MoveNext())
                    {
                        DepartmentOrderDoc.DocumentTypeEntityRow targetDocType = (DepartmentOrderDoc.DocumentTypeEntityRow)ie.Current;
                        if (targetDocType.doc_data_type_desc == documentType.doc_data_type_desc)
                        {
                            SetErrorMessage(WebConstants.Messages.Error.ALREAD_EXISTS);
                            alreadyExists = true;
                            break;
                        }
                    }
                    if (alreadyExists == false)
                    {
                        Nullable<bool> flgLandscape = null;
                        if (documentType.Isflg_landscapeNull() == false) flgLandscape = documentType.flg_landscape;
                        Nullable<int> numOfSections = null;
                        if (documentType.Isnum_of_sectionsNull() == false) numOfSections = documentType.num_of_sections;

                        docTypeTA.DocumentTypeInsert(documentType.doc_data_type_desc, false, targetCoId, targetDeptId, documentType.sort_order,
                            (documentType.Isfield_typeNull()) ? null : documentType.field_type, (documentType.Isgenerator_classNull()) ? null : documentType.generator_class,
                            documentType.required, (documentType.IsstyleNull()) ? null : documentType.style, flgLandscape,
                            numOfSections, documentType.flg_checked, (documentType.IscategoryNull()) ? null : documentType.category);
                        isInserted = true;

                        if (cbTransferDocs.Checked)
                        {
                            DepartmentOrderDoc.DocumentTypeEntityRow targetDocType = DatabaseUtility.GetDocumentType(targetCoId, targetDeptId, documentType.doc_data_type_desc);
                            if (targetDocType != null)
                            {
                                //insert templates section
                                DocumentTemplateTableAdapters.DocumentSectionTableAdapter sectionTA = new DocumentTemplateTableAdapters.DocumentSectionTableAdapter();
                                IEnumerator ieSections = sectionTA.GetByDocType(sourceCoId, sourceDeptId, docTypeId).GetEnumerator();
                                while (ieSections.MoveNext())
                                {
                                    DocumentTemplate.DocumentSectionEntityRow sourceSection = (DocumentTemplate.DocumentSectionEntityRow)ieSections.Current;
                                    DocumentTemplate.DocumentSectionEntityRow targetSection = DatabaseUtility.GetSection(targetCoId, targetDeptId, sourceSection.section_desc);
                                    if (targetSection == null)
                                    {
                                        sectionTA.Insert(false, targetCoId, targetDeptId, sourceSection.section_index, sourceSection.section_desc, sourceSection.section_type,
                                            targetDocType.doc_data_type_id, sourceSection.repeat_columns);
                                        targetSection = DatabaseUtility.GetSection(targetCoId, targetDeptId, sourceSection.section_desc);
                                    }
                                    //insert section details for the sections for which it exists
                                    DocumentTemplateTableAdapters.DocumentSectionDetailsTableAdapter sectionDetailTA = new DocumentTemplateTableAdapters.DocumentSectionDetailsTableAdapter();
                                    IEnumerator ieSectionDetails = sectionDetailTA.GetBySecId(sourceCoId, sourceDeptId, sourceSection.section_id).GetEnumerator();
                                    while (ie.MoveNext())
                                    {
                                        DocumentTemplate.DocumentSectionDetailsEntityRow sourceSectionDetail = (DocumentTemplate.DocumentSectionDetailsEntityRow)ieSectionDetails.Current;
                                        DocumentTemplate.DocumentSectionDetailsEntityRow targetSectionDetail = DatabaseUtility.GetSectionDetail(targetCoId, targetDeptId, targetSection.section_id, sourceSectionDetail.section_detail_desc);
                                        if (targetSectionDetail == null)
                                        {
                                            sectionDetailTA.Insert(targetSection.section_id, targetCoId, targetDeptId, sourceSectionDetail.section_detail_index, sourceSectionDetail.section_detail_desc);
                                        }
                                    }
                                }
                                //insert docs
                                DepartmentOrderDocTableAdapters.DocumentTableAdapter docTA = new DepartmentOrderDocTableAdapters.DocumentTableAdapter();
                                IEnumerator ieDocs = docTA.GetDocsByTypeId(sourceCoId, sourceDeptId, docTypeId).GetEnumerator();
                                {
                                    DepartmentOrderDoc.DocumentEntityRow sourceDocument = (DepartmentOrderDoc.DocumentEntityRow)ieDocs.Current;
                                    DepartmentOrderDoc.DocumentEntityRow targetDocument = DatabaseUtility.GetDocument(targetCoId, targetDeptId, targetDocType.doc_data_type_id, sourceDocument.doc_name);
                                    if (targetDocument == null)
                                    {
                                        Categories.CategoryEntityRow targetCategory = DatabaseUtility.GetCategory(targetCoId, targetDeptId, "D", sourceDocument.category_name);
                                        if (targetCategory == null)
                                        {
                                            CategoriesTableAdapters.CategoryTableAdapter catTA = new CategoriesTableAdapters.CategoryTableAdapter();
                                            catTA.Insert(targetCoId, targetDeptId, sourceDocument.category_name, "D");
                                            targetCategory = DatabaseUtility.GetCategory(targetCoId, targetDeptId, "D", sourceDocument.category_name);
                                        }
                                        byte[] fileContents = null;

                                        //get fille contents if they are present
                                        DepartmentOrderDocTableAdapters.DocumentContentTableAdapter docContentTA = new DepartmentOrderDocTableAdapters.DocumentContentTableAdapter();
                                        IEnumerator iEDocContents = docContentTA.GetDocumentContentById(sourceDocument.doc_id, sourceCoId, sourceDeptId).GetEnumerator();
                                        if (iEDocContents.MoveNext())
                                        {
                                            fileContents = ((DepartmentOrderDoc.DocumentContentEntityRow)iEDocContents.Current).file_contents;
                                        }

                                        docTA.Insert1(targetCoId, targetDeptId, targetDocType.doc_data_type_id, sourceDocument.doc_name, sourceDocument.doc_desc, sourceDocument.doc_code,
                                            targetCategory.category_id, sourceDocument.doc_index, fileContents,sourceDocument.flg_default);

                                    }
                                }

                                //insert template items
                            }
                        }
                    }
                }
            }
        }
        if (isInserted)
        {
            ddlCompany.SelectedValue = ddlTransferCompany.SelectedValue;
            ddlDepartment.DataBind();
            ddlDepartment.SelectedValue = ddlTransferDeparment.SelectedValue;
            gvDocTypes.DataBind();
            SetInfoMessage(WebConstants.Messages.Information.RECORD_SAVED);
        }
    }
    private void BindRepeater()
    {
        if (Session[WebConstants.Session.USER_CO_ID] != null && Session[WebConstants.Session.DEPT_ID] != null)
        {
            int loggedInUserCoId = (int)Session[WebConstants.Session.USER_CO_ID];
            int deptId = (int)Session[WebConstants.Session.DEPT_ID];

            DepartmentOrderDocTableAdapters.DocumentTableAdapter ta = new DepartmentOrderDocTableAdapters.DocumentTableAdapter();
            IEnumerator iEnum = ta.GetRemainingDocsByTypeName(loggedInUserCoId, deptId, DocTypeName, int.Parse(Request[WebConstants.Request.DEPT_ORDER_ID])).GetEnumerator();
            while (iEnum.MoveNext())
            {
                DepartmentOrderDoc.DocumentEntityRow dataRow = (DepartmentOrderDoc.DocumentEntityRow)iEnum.Current;
                if (categories.ContainsKey(dataRow.category_name) == false)
                {
                    categories.Add(dataRow.category_name, new List<KeyValuePair<int, string>>());
                }
                List<KeyValuePair<int, string>> docs = categories[dataRow.category_name];
                docs.Add(new KeyValuePair<int, string>(dataRow.doc_id, dataRow.doc_name));
            }
            rptDocs.DataSource = categories.Keys;
            rptDocs.DataBind();
        }
    }
Ejemplo n.º 7
0
 public static DepartmentOrderDoc.DocumentEntityRow GetDocument(int coId, int deptId, int docTypeId, string docName)
 {
     DepartmentOrderDoc.DocumentEntityRow document = null;
     DepartmentOrderDocTableAdapters.DocumentTableAdapter ta = new DepartmentOrderDocTableAdapters.DocumentTableAdapter();
     IEnumerator ie = ta.GetDocumentByName(coId, deptId, docTypeId, docName).GetEnumerator();
     if (ie.MoveNext())
     {
         document = (DepartmentOrderDoc.DocumentEntityRow)ie.Current;
     }
     return document;
 }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (Request[WebConstants.Request.DOC_ID] != null)
        {
            string docCodes = "";
            foreach (GridViewRow grRow in gvDocs.Rows)
            {
                if (grRow.RowType == DataControlRowType.DataRow)
                {
                    CheckBox cbSelect = (CheckBox)grRow.FindControl("cbSelect");
                    if (cbSelect != null && cbSelect.Checked == true)
                    {
                        Label docCodeLabel = (Label)grRow.FindControl("lblDocCode");
                        if (docCodeLabel != null)
                        {
                            if (docCodes.Length > 0)
                            {
                                docCodes += ",";
                            }
                            docCodes += docCodeLabel.Text;
                        }
                    }

                }
            }
            if (docCodes.Length == 0) docCodes = null;
            DepartmentOrderDocTableAdapters.DocumentTableAdapter docTA = new DepartmentOrderDocTableAdapters.DocumentTableAdapter();
            docTA.UpdateRelatedDocCodes(docCodes, int.Parse(Request[WebConstants.Request.DOC_ID]));
        }
    }