期望#endregion指令,但}匹配

以下代码给出了文件末尾预期的错误#endregion指令。 我已经进行了物理检查,但所有}都匹配。

namespace Labour { public partial class frm_GP_ProjectLPO : Form { #region PublicVariables // int inNarrationCount = 0; // string strCashOrParty = string.Empty; // string strPrefix = string.Empty; // string strSuffix = string.Empty; // string strVoucherNo = string.Empty; // string strOrderNo = string.Empty; // string strBarcode = string.Empty; // string strStatus = string.Empty; // //ArrayList lstArrOfRemove = new ArrayList(); // string tableName = "PurchaseOrderMaster"; // string strProductCode = string.Empty; // public static bool isEdit = false; decimal decPurchaseOrderMasterId = 0; decimal decPurchaseOrderDetailId = 0; decimal decPurchaseOrderMasterIdentity = 0; decimal decPurchaseSuffixPrefixId = 0; decimal decPurchaseOrderTypeId = 0; decimal decPurchaseVoucherId = 0; decimal decCurrentRate = 0; decimal decCurrentConversionRate = 0; // bool isValueChange = true; bool isAutomatic = false; // bool isValueChanged = false; // bool isDoAfterGridFill = true; // bool isAmountcalc = true; // bool isCheck = false; // frmLedgerPopup frmLedgerPopupObj; // frmProductSearchPopup frmProductSearchPopupObj; // DataGridViewTextBoxEditingControl TextBoxControl; // frmPurchaseOrderRegister frmPurchaseOrderRegisterObj; // frmPurchaseOrderReport frmPurchaseOrderReportObj; // frmVoucherSearch objVoucherSearch = null; // frmDayBook frmDayBookObj = null; // frmVoucherWiseProductSearch objfrmVoucherproduct = null; // TransactionsGeneralFill TransactionGeneralFillObj = new TransactionsGeneralFill(); // AutoCompleteStringCollection ProductNames = new AutoCompleteStringCollection(); // AutoCompleteStringCollection ProductCodes = new AutoCompleteStringCollection(); // DataTable dtblunitconversionViewAll = new DataTable(); // DataTable dtbl = new DataTable(); // #endregion // #region Functions string fileName = "", fileSaveDir = @"C:\Docs"; ProjectSP OProjectSP = new ProjectSP(); CommonFunctions OCommonFunctions = new CommonFunctions(); bool ISLoadComplete = false, ErrorExist = false, ISEdit = false; decimal ProjectLPOID = 0; public frm_GP_ProjectLPO() { InitializeComponent(); } public frm_GP_ProjectLPO(decimal projectLPOID) { InitializeComponent(); ProjectLPOID = projectLPOID; } private void frm_GP_ProjectLPO_Load(object sender, EventArgs e) { LaodCombos(); cmbLpoType.SelectedItem = "Customer"; cmbSupplier.Visible = false; lblSupplier.Visible = false; if (ProjectLPOID > 0) { LoadSelectedQoutation(); LoadSeletcedQuotationDetail(); } } private void LoadSeletcedQuotationDetail() { dgvEmployeeDetail.DataSource = OCommonFunctions.SelectData("sp_GP_tbl_GP_ProjectLPODetailSelectForGrid", "@projetlpomasterid", ProjectLPOID.ToString()); } private void LaodCombos() { OCommonFunctions.FillCombo("ledgerName", "ledgerId", "tbl_AccountLedger where accountGroupId=26", cmbClient); OCommonFunctions.FillCombo("name", "projectid", "tbl_GP_ProjectMaster where clientid = " + cmbClient.SelectedValue, cmbProject); //LoadProject OCommonFunctions.FillCombo("name", "categoryid", "tbl_GP_Category ", category); OCommonFunctions.FillCombo("ledgerName", "ledgerId", "tbl_AccountLedger where accountGroupId=22", cmbSupplier); LoadSites(); // OCommonFunctions.FillCombo("name", "siteid", "tbl_GP_SiteMaster s inner join tbl_GP_ProjectLPOMaster l on S.siteid = l.siteid and l.projectid = " + cmbProject.SelectedValue, cmbSite); //Site } public void LoadSites() { DataTable dt = OCommonFunctions.SelectData("[sp_GP_LoadSiteByProject]", "@ProjectID", Convert.ToString(cmbProject.SelectedValue)); if (dt.Rows.Count > 0) { cmbSite.DataSource = dt; cmbSite.DisplayMember = "name"; cmbSite.ValueMember = "siteid"; } } private void LoadSelectedQoutation() { if (ProjectLPOID > 0) { ProjectLPOMasterInfo oProjectLPOMasterInfo = OProjectSP.ProjectLPOMasterView(ProjectLPOID); ProjectLPOID = oProjectLPOMasterInfo.projetlpomasterid; try { cmbProject.SelectedValue = oProjectLPOMasterInfo.projectid; } catch (Exception ex) { } try { dtpDate.Value = oProjectLPOMasterInfo.date; } catch (Exception ex) { } try { dtpFromDate.Value = oProjectLPOMasterInfo.fromdate; } catch (Exception es) { } try { dtpTODate.Value = oProjectLPOMasterInfo.todate; } catch (Exception ed) { } try { cmbSite.SelectedValue = oProjectLPOMasterInfo.siteid; } catch (Exception ex) { } try { txtLPONumber.Text = oProjectLPOMasterInfo.lponumber; } catch (Exception ex) { } try { cmbSupplier.SelectedValue = oProjectLPOMasterInfo.supplierid; } catch (Exception ex) { } try { if (oProjectLPOMasterInfo.Lpotype == 1) { cmbLpoType.SelectedItem = "Customer"; } else { cmbLpoType.SelectedItem = "Supplier"; } } catch (Exception ex) { } } } private void btnSave_Click(object sender, EventArgs e) { try { SaveFunction(); if (CheckUserPrivilege.PrivilegeCheck(PublicVariables._decCurrentUserId, this.Name, btnSave.Text)) { if (!ValidateData()) { if (!DataExist()) { if (Messages.SaveMessage()) { if (SaveProjectLPO() > 0) { Clear(); // LoadFullEmployee(); RefreshList(); Messages.SavedMessage(); } } } else { MessageBox.Show("LPO already exist"); } } } else { Messages.NoPrivillageMessage(); } } catch (Exception ex) { MessageBox.Show("Cus20:" + ex.Message, "EasyERP", MessageBoxButtons.OK, MessageBoxIcon.Information); } } private void Clear() { //txtName.Text = ""; //txtPhone.Text = ""; } private void RefreshList() { frm_GP_ProjectLPOList frm = Application.OpenForms["frm_GP_ProjectLPOList"] as frm_GP_ProjectLPOList; frm.LaodFullProjectLPO(); } ///  /// Print function ///  ///  public void Print(decimal decMasterId) { try { PurchaseOrderMasterSP spPurchaseOrderMaster = new PurchaseOrderMasterSP(); DataSet dsPurchaseOrder = spPurchaseOrderMaster.PurchaseOrderPrinting(decMasterId); frmReport frmReport = new frmReport(); frmReport.MdiParent = formMDI.MDIObj; frmReport.PurchaseOrderPrinting(dsPurchaseOrder); } catch (Exception ex) { MessageBox.Show("PO14:" + ex.Message, "EasyERP", MessageBoxButtons.OK, MessageBoxIcon.Information); } } ///  /// Print function for dotmatrix printer ///  ///  public void PrintForDotMatrix(decimal decMasterId) { try { DataTable dtblOtherDetails = new DataTable(); CompanySP spComapany = new CompanySP(); dtblOtherDetails = spComapany.CompanyViewForDotMatrix(); DataTable dtblGridDetails = new DataTable(); dtblGridDetails.Columns.Add("SlNo"); dtblGridDetails.Columns.Add("BarCode"); dtblGridDetails.Columns.Add("ProductCode"); dtblGridDetails.Columns.Add("ProductName"); dtblGridDetails.Columns.Add("Qty"); dtblGridDetails.Columns.Add("Unit"); dtblGridDetails.Columns.Add("Rate"); dtblGridDetails.Columns.Add("Amount"); int inRowCount = 0; foreach (DataGridViewRow dRow in dgvPurchaseOrder.Rows) { if (!dRow.IsNewRow) { DataRow dr = dtblGridDetails.NewRow(); dr["SlNo"] = ++inRowCount; if (dRow.Cells["dgvtxtBarcode"].Value != null) { dr["BarCode"] = Convert.ToString(dRow.Cells["dgvtxtBarcode"].Value); } if (dRow.Cells["dgvtxtProductCode"].Value != null) { dr["ProductCode"] = Convert.ToString(dRow.Cells["dgvtxtProductCode"].Value); } if (dRow.Cells["dgvtxtProductName"].Value != null) { dr["ProductName"] = Convert.ToString(dRow.Cells["dgvtxtProductName"].Value); } if (dRow.Cells["dgvtxtQty"].Value != null) { dr["Qty"] = Convert.ToString(dRow.Cells["dgvtxtQty"].Value); } if (dRow.Cells["dgvcmbUnit"].Value != null) { dr["Unit"] = Convert.ToString(dRow.Cells["dgvcmbUnit"].FormattedValue); } if (dRow.Cells["dgvtxtRate"].Value != null) { dr["Rate"] = Convert.ToString(dRow.Cells["dgvtxtRate"].Value); } if (dRow.Cells["dgvtxtAmount"].Value != null) { dr["Amount"] = Convert.ToString(dRow.Cells["dgvtxtAmount"].Value); } dtblGridDetails.Rows.Add(dr); } } dtblOtherDetails.Columns.Add("voucherNo"); dtblOtherDetails.Columns.Add("date"); dtblOtherDetails.Columns.Add("ledgerName"); dtblOtherDetails.Columns.Add("Narration"); dtblOtherDetails.Columns.Add("Currency"); dtblOtherDetails.Columns.Add("TotalAmount"); dtblOtherDetails.Columns.Add("DueDays"); dtblOtherDetails.Columns.Add("DueDate"); dtblOtherDetails.Columns.Add("CustomerAddress"); dtblOtherDetails.Columns.Add("CustomerTIN"); dtblOtherDetails.Columns.Add("CustomerCST"); dtblOtherDetails.Columns.Add("AmountInWords"); dtblOtherDetails.Columns.Add("Declaration"); dtblOtherDetails.Columns.Add("Heading1"); dtblOtherDetails.Columns.Add("Heading2"); dtblOtherDetails.Columns.Add("Heading3"); dtblOtherDetails.Columns.Add("Heading4"); DataRow dRowOther = dtblOtherDetails.Rows[0]; dRowOther["voucherNo"] = txtLPONumber.Text; dRowOther["date"] = dtpDate.Text; dRowOther["ledgerName"] = cmbSupplier.Text; dRowOther["Narration"] = "LPO for a period of one month"; dRowOther["Currency"] = "AED"; dRowOther["TotalAmount"] = "NA"; dRowOther["DueDays"] = "NA"; dRowOther["DueDate"] = "NA"; dRowOther["address"] = (dtblOtherDetails.Rows[0]["address"].ToString().Replace("\n", ", ")).Replace("\r", ""); AccountLedgerSP spAccountLedger = new AccountLedgerSP(); AccountLedgerInfo infoAccountLedger = new AccountLedgerInfo(); infoAccountLedger = spAccountLedger.AccountLedgerView(Convert.ToDecimal(cmbSupplier.SelectedValue)); dRowOther["CustomerAddress"] = (infoAccountLedger.Address.ToString().Replace("\n", ", ")).Replace("\r", ""); dRowOther["CustomerTIN"] = infoAccountLedger.Tin; dRowOther["CustomerCST"] = infoAccountLedger.Cst; // dRowOther["AmountInWords"] = new NumToText().AmountWords(Convert.ToDecimal(txtTotalAmount.Text), PublicVariables._decCurrencyId); VoucherTypeSP spVoucherType = new VoucherTypeSP(); DataTable dtblDeclaration = spVoucherType.DeclarationAndHeadingGetByVoucherTypeId(decPurchaseOrderTypeId); dRowOther["Declaration"] = Convert.ToString(dtblDeclaration.Rows[0]["Declaration"]); dRowOther["Heading1"] = Convert.ToString(dtblDeclaration.Rows[0]["Heading1"]); dRowOther["Heading2"] = Convert.ToString(dtblDeclaration.Rows[0]["Heading2"]); dRowOther["Heading3"] = Convert.ToString(dtblDeclaration.Rows[0]["Heading3"]); dRowOther["Heading4"] = Convert.ToString(dtblDeclaration.Rows[0]["Heading4"]); int inFormId = spVoucherType.FormIdGetForPrinterSettings(Convert.ToInt32(dtblDeclaration.Rows[0]["masterId"].ToString())); PrintWorks.DotMatrixPrint.PrintDesign(inFormId, dtblOtherDetails, dtblGridDetails, dtblOtherDetails); } catch (Exception ex) { MessageBox.Show("PO15:" + ex.Message, "EasyERP", MessageBoxButtons.OK, MessageBoxIcon.Information); } } // save function from purchaseorder.cs public void SaveFunction() { try { PurchaseOrderMasterInfo infoPurchaseOrderMaster = new PurchaseOrderMasterInfo(); PurchaseOrderDetailsSP spPurchaseOrderDetails = new PurchaseOrderDetailsSP(); PurchaseOrderDetailsInfo infoPurchaseOrderDetails = new PurchaseOrderDetailsInfo(); PurchaseOrderMasterSP spPurchaseOrderMaster = new PurchaseOrderMasterSP(); ProductInfo infoProduct = new ProductInfo(); ProductSP spProduct = new ProductSP(); SettingsSP spSettings = new SettingsSP(); infoPurchaseOrderMaster.Date = Convert.ToDateTime(dtpDate.Text); infoPurchaseOrderMaster.DueDate = Convert.ToDateTime(dtpFromDate.Text); infoPurchaseOrderMaster.LedgerId = Convert.ToDecimal(cmbSupplier.SelectedValue.ToString()); //if (isAutomatic == true) //{ // infoPurchaseOrderMaster.SuffixPrefixId = decPurchaseSuffixPrefixId; // infoPurchaseOrderMaster.VoucherNo = strVoucherNo; //} //else //{ // infoPurchaseOrderMaster.SuffixPrefixId = 0; // infoPurchaseOrderMaster.VoucherNo = spPurchaseOrderMaster.VoucherNoMax(decPurchaseOrderTypeId); //} //infoPurchaseOrderMaster.VoucherTypeId = decPurchaseOrderTypeId; // infoPurchaseOrderMaster.InvoiceNo = txtOrderNo.Text; infoPurchaseOrderMaster.UserId = PublicVariables._decCurrentUserId; infoPurchaseOrderMaster.EmployeeId = PublicVariables._decCurrentUserId;//by default current userid used as current employeeid infoPurchaseOrderMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId; infoPurchaseOrderMaster.Narration = "LPO from Time Sheet"; //txtNarration.Text.Trim(); //infoPurchaseOrderMaster.TotalAmount = Convert.ToDecimal(txtTotalAmount.Text); // infoPurchaseOrderMaster.exchangeRateId = Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()); infoPurchaseOrderMaster.Extra1 = string.Empty; infoPurchaseOrderMaster.Extra2 = string.Empty; //infoPurchaseOrderMaster.DeliveryPeriod = txtDelivery.Text; //infoPurchaseOrderMaster.QuotationRef = txtQuotation.Text; // infoPurchaseOrderMaster.ProjectRef = txtProject.Text; // infoPurchaseOrderMaster.PaymentTerms = txtTerms.Text; // infoPurchaseOrderMaster.Warrenty = txtWarrenty.Text; decPurchaseOrderMasterIdentity = Convert.ToDecimal(spPurchaseOrderMaster.PurchaseOrderMasterAdd(infoPurchaseOrderMaster)); int inRowcount = dgvPurchaseOrder.Rows.Count; for (int inI = 0; inI  0) { isEdit = true; } projectLPOID = OProjectSP.ProjectLPOMasterAddOREdit(oProjectLPOMasterInfo, isEdit); if (projectLPOID > 0) { bool isSaved = SaveLPODetail(projectLPOID); } return projectLPOID; } private bool SaveLPODetail(decimal projectLPOID) { decimal projectLPODetailID = 0; bool isEdit = false; foreach (DataGridViewRow dr in dgvEmployeeDetail.Rows) { ProjectLPODetailInfo oProjectLPODetailInfo = new ProjectLPODetailInfo(); oProjectLPODetailInfo.projetlpomasterid = projectLPOID; if (dr.Index != dgvEmployeeDetail.Rows.Count - 1) { try { oProjectLPODetailInfo.projectlpodetailid = Convert.ToDecimal(dr.Cells["projectDetailID"].Value); } catch (Exception ex) { } oProjectLPODetailInfo.categoryid = Convert.ToDecimal(dr.Cells["category"].Value); try { oProjectLPODetailInfo.nooflabour = Convert.ToInt32(dr.Cells["NumberOFEmployee"].Value); } catch (Exception ex) { } try { oProjectLPODetailInfo.rate = Convert.ToDecimal(dr.Cells["reatePerHour"].Value); } catch (Exception ex) { } if (oProjectLPODetailInfo.projectlpodetailid > 0) { isEdit = true; } else { isEdit = false; } projectLPODetailID = OProjectSP.ProjectLPODetailAddOREdit(oProjectLPODetailInfo, isEdit); if (projectLPODetailID  0) { return true; } else { return false; } } private bool DataExist() { return false; } private bool ValidateData() { //if (txtName.Text.Trim() == string.Empty) //{ // Messages.InformationMessage("Enter employee name "); // txtName.Focus(); // return true; //} return false; } private void btnClear_Click(object sender, EventArgs e) { Clear(); } private void btnClose_Click(object sender, EventArgs e) { this.Close(); } private void btnSelect_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.CheckFileExists = true; openFileDialog.AddExtension = true; openFileDialog.Multiselect = false; string fileNewPath = ""; openFileDialog.Filter = "PDF files (*.pdf)|*.pdf|JPEG Files (*.jpeg)|*.jpeg|JPG Files (*.jpg)|*.jpg"; if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { foreach (string fileNamepath in openFileDialog.FileNames) { txtFilename.Text = fileNamepath; } } if (!String.IsNullOrEmpty(txtFilename.Text)) { fileName = Path.GetFileName(txtFilename.Text.Trim()); fileName = txtLPONumber.Text + fileName; fileNewPath = Path.Combine(fileSaveDir, fileName); File.Copy(txtFilename.Text.Trim(), fileNewPath); } } private bool SaveFile() { //if (txtName.Text.Trim() == string.Empty) //{ // Messages.InformationMessage("Enter employee name "); // txtName.Focus(); // return true; //} return false; } private void btnPrint_Click(object sender, EventArgs e) { try { DataSet dsLPODetails = OProjectSP.ProjectLPODetails(ProjectLPOID); frmReport frmReport = new frmReport(); frmReport.MdiParent = formMDI.MDIObj; frmReport.ProjectLPOPrint(dsLPODetails); } catch (Exception ex) { MessageBox.Show("PO14:" + ex.Message, "EasyERP", MessageBoxButtons.OK, MessageBoxIcon.Information); } } private void cmbProject_SelectedIndexChanged(object sender, EventArgs e) { cmbSite.DataSource = null; if (cmbProject.SelectedIndex != -1) { if (cmbProject.SelectedValue.ToString() != "System.Data.DataRowView") { // cmbSite.DataSource = null; LoadSites(); } } } private void cmbSite_SelectedIndexChanged(object sender, EventArgs e) { } private void cmbClient_SelectedIndexChanged(object sender, EventArgs e) { if (cmbClient.SelectedValue.ToString() != "System.Data.DataRowView") { cmbProject.DataSource = null; OCommonFunctions.FillCombo("name", "projectid", "tbl_GP_ProjectMaster where clientid = " + cmbClient.SelectedValue, cmbProject); } } private void groupBox1_Enter(object sender, EventArgs e) { } private void cmbLpoType_SelectedIndexChanged(object sender, EventArgs e) { if (cmbLpoType.SelectedItem.ToString() == "Supplier") { cmbSupplier.Visible = true; lblSupplier.Visible = true; } else { cmbSupplier.Visible = false; lblSupplier.Visible = false; } } } } 

我尝试重新启动IDE,重新打开解决方案等,但它没有成功。

正如消息所说 – 你缺乏一个

 #endregion 

在你的代码中。

一开始就有一个开口

 #region 

永远不会关闭。

在第3行, #region开始,但在第43行,匹配的#endregion被注释掉。

你的课程以#region开头:

 public partial class frm_GP_ProjectLPO : Form { #region PublicVariables . . . 

所以你需要一个匹配的`#endregion’:

  . . . #endregion . . . } 

您可以根据需要添加区域名称。

对于每个#region标记,您需要一个结束#endregion标记。 您正在使用

 #region PublicVariables 

但是没有用#endregion关闭它(它被关闭但它被注释掉了)

更多信息,请访问MSDN Region C#

首先:

在此处输入图像描述

这意味着您在文件中有一个不匹配的#region行,已经正确提到了。

剩下的问题是如何找到合适的?

这可以是一种先进的眼科训练,没有找到正确的方法:

  • 假设IDE是Visual Studio,我们可以使用Ctrl-M,Ctrl-O将源折叠到定义,因此我们将对文件进行更多概述。 然后通过简单地将文件与缺少的#endregion行分开,给我们一些提示。 如果错误消息消失,则缺失的行位于当前位置上方。 在每个步骤之后,您可以划分剩余部分。 当然,我们必须在每一步中删除#endregion行,直到我们收敛到正确的位置:)

  • 如果我们使用像#region|#endregion这样的正则表达式并列出给定文件中的所有实例,那就更简单了。 结果列表甚至包含行号。