private void subLoadOnlineSettings() { string strSQL = ""; using (wsXferEventInfo.XferEventInfo wsDLDiscount = new global::CTWebMgmt.wsXferEventInfo.XferEventInfo()) { strSQL = "SELECT blnShowUsers, " + "lngDiscountID " + "FROM tblDiscountDefs " + "WHERE lngCTUserID = " + clsAppSettings.GetAppSettings().lngCTUserID.ToString(); string strWebXML = ""; try { strWebXML = wsDLDiscount.fcnGetRecords(strSQL, "tblDiscountDefs", clsWebTalk.strWebConn); } catch (Exception ex) { } DataSet dsXML = new DataSet("tblDiscountDefs"); dsXML.ReadXml(new System.IO.StringReader(strWebXML), XmlReadMode.ReadSchema); foreach (DataTable tbl in dsXML.Tables) { foreach (DataRow row in tbl.Rows) { bool blnShowUsers = false; long lngDiscountID = 0; foreach (DataColumn col in tbl.Columns) { string strColName = col.ColumnName; string strColVal = Convert.ToString(row[col]); if (strColName == "blnShowUsers") { try { blnShowUsers = Convert.ToBoolean(strColVal); } catch { blnShowUsers = false; } } else if (strColName == "lngDiscountID") { try { lngDiscountID = Convert.ToInt32(strColVal); } catch { lngDiscountID = 0; } } } ((CheckBox)Controls["chkDisplayOnline" + lngDiscountID.ToString()]).Checked = blnShowUsers; } } } }
private void subLoadCustomFieldDefRegs(long _lngProgramID) { //loop through custom field defs and add controls //first clear any existing panels bool blnContinueClearing = true; while (blnContinueClearing) { for (int intI = 0; intI < pagRegCustom.Controls.Count; intI++) { blnContinueClearing = false; if (pagRegCustom.Controls[intI].Name.Contains("panCustomReg_")) { blnContinueClearing = true; pagRegCustom.Controls.RemoveAt(intI); break; } } } string strSQL = ""; //get web defs from web service, get local defs from db //local defs using (OleDbConnection conDB = new OleDbConnection(clsAppSettings.GetAppSettings().strCTConn)) { conDB.Open(); strSQL = "SELECT tblCustomFieldDefReg.blnUseLocal, " + "tblCustomFieldDefReg.lngCustomFieldDefRegID, tblCustomFieldDefReg.lngSortOrder, " + "tblCustomFieldDefReg.decCharge, " + "tblCustomFieldDefReg.strLocalCaption, tblCustomFieldDefReg.strFieldType " + "FROM tblCustomFieldDefReg " + "ORDER BY tblCustomFieldDefReg.lngSortOrder"; using (OleDbCommand cmdDB = new OleDbCommand(strSQL, conDB)) { using (OleDbDataReader drCust = cmdDB.ExecuteReader()) { intNextRegTop = 55; while (drCust.Read()) { //local defs bool blnUseLocal = false; long lngCustomFieldDefRegID = 0; long lngSortOrder = 0; decimal decCharge = 0; string strLocalCaption = ""; string strFieldType = ""; try { blnUseLocal = Convert.ToBoolean(drCust["blnUseLocal"]); } catch { blnUseLocal = false; } try { lngCustomFieldDefRegID = Convert.ToInt32(drCust["lngCustomFieldDefRegID"]); } catch { lngCustomFieldDefRegID = 0; } try { lngSortOrder = Convert.ToInt32(drCust["lngSortOrder"]); } catch { lngSortOrder = 0; } try { decCharge = Convert.ToDecimal(drCust["decCharge"]); } catch { decCharge = 0; } try { strLocalCaption = Convert.ToString(drCust["strLocalCaption"]); } catch { strLocalCaption = ""; } try { strFieldType = Convert.ToString(drCust["strFieldType"]); } catch { strFieldType = ""; } CheckBox chkUseLocalReg = new CheckBox(); chkUseLocalReg.Name = "chkUseLocalReg_" +lngCustomFieldDefRegID.ToString(); chkUseLocalReg.Checked = blnUseLocal; chkUseLocalReg.Top = 9; chkUseLocalReg.Left =lblUseLocalRegHead.Left; chkUseLocalReg.Width = 15; CheckBox chkUseOnlineReg = new CheckBox(); chkUseOnlineReg.Name = "chkUseOnlineReg_" +lngCustomFieldDefRegID.ToString(); chkUseOnlineReg.Top = 9; chkUseOnlineReg.Left = lblUseOnlineRegHead.Left; chkUseOnlineReg.Width = 15; chkUseOnlineReg.CheckedChanged += new EventHandler(chkUseOnlineReg_CheckedChanged); CheckBox chkRequiredReg = new CheckBox(); chkRequiredReg.Name = "chkRequiredReg_" +lngCustomFieldDefRegID.ToString(); chkRequiredReg.Top = 9; chkRequiredReg.Left = lblRequiredRegHead.Left; chkRequiredReg.Width = 15; chkRequiredReg.Visible = false; TextBox txtChargeReg = new TextBox(); txtChargeReg.Name = "txtChargeReg_" + lngCustomFieldDefRegID.ToString(); txtChargeReg.Top = 9; txtChargeReg.Left = lblChargeRegHead.Left; txtChargeReg.Width = 55; txtChargeReg.Visible = false; TextBox txtSortOrderReg = new TextBox(); txtSortOrderReg.Name = "txtSortOrderReg_" +lngCustomFieldDefRegID.ToString(); txtSortOrderReg.Text = lngSortOrder.ToString(); txtSortOrderReg.Top = 9; txtSortOrderReg.Left = lblSortOrderRegHead.Left; txtSortOrderReg.Width = 55; TextBox txtLocalCaptionReg = new TextBox(); txtLocalCaptionReg.Name = "txtLocalCaptionReg_" +lngCustomFieldDefRegID.ToString(); txtLocalCaptionReg.Text = strLocalCaption; txtLocalCaptionReg.Top = 9; txtLocalCaptionReg.Left =lblLocalCaptionRegHead.Left; txtLocalCaptionReg.Width = 165; txtLocalCaptionReg.Enabled = false; txtLocalCaptionReg.ReadOnly = true; TextBox txtWebCaptionReg = new TextBox(); txtWebCaptionReg.Name = "txtWebCaptionReg_" +lngCustomFieldDefRegID.ToString(); txtWebCaptionReg.Top = 9; txtWebCaptionReg.Left =lblWebCaptionRegHead.Left; txtWebCaptionReg.Width = 165; txtWebCaptionReg.Visible = false; Label lblFieldTypeReg = new Label(); lblFieldTypeReg.Name = "lblFieldTypeReg_" +lngCustomFieldDefRegID.ToString(); lblFieldTypeReg.Top = 9; lblFieldTypeReg.Text = strFieldType; lblFieldTypeReg.Left = lblFieldTypeRegHead.Left; Button btnDetailsReg = new Button(); btnDetailsReg.Name = "btnDetailsReg_" +lngCustomFieldDefRegID.ToString(); btnDetailsReg.Click += new EventHandler(btnDetailsReg_Click); btnDetailsReg.Top = 9; btnDetailsReg.Text = "Details"; btnDetailsReg.Width = 57; btnDetailsReg.Left = txtSortOrderReg.Left + txtSortOrderReg.Width + 6; Button btnDeleteReg = new Button(); btnDeleteReg.Name = "btnDeleteReg_" +lngCustomFieldDefRegID.ToString(); btnDeleteReg.Click += new EventHandler(btnDeleteReg_Click); btnDeleteReg.Top = 9; btnDeleteReg.Text = "Delete"; btnDeleteReg.Width = 55; btnDeleteReg.Left = btnDetailsReg.Left + btnDetailsReg.Width + 6; //holders for header/footer TextBox txtHeader = new TextBox(); txtHeader.Name = "txtHeaderReg_" +lngCustomFieldDefRegID.ToString(); txtHeader.Top = 24; txtHeader.Width = 55; txtHeader.Left = 0; txtHeader.Visible = false; TextBox txtFooter = new TextBox(); txtFooter.Name = "txtFooterReg_" +lngCustomFieldDefRegID.ToString(); txtFooter.Top = 24; txtFooter.Width = 55; txtFooter.Left = 61; txtFooter.Visible = false; TextBox txtDropdownOptions = new TextBox(); txtDropdownOptions.Name = "txtDropdownOptionsReg_" +lngCustomFieldDefRegID.ToString(); txtDropdownOptions.Top = 24; txtDropdownOptions.Width = 55; txtDropdownOptions.Left = 122; if (strFieldType == "DROPDOWN") subLoadDropdownOptionsReg(txtDropdownOptions, lngCustomFieldDefRegID, strLocalCaption); txtDropdownOptions.Visible = false; Panel panCustomReg = new Panel(); panCustomReg.Name = "panCustomReg_" +lngCustomFieldDefRegID.ToString(); panCustomReg.BackColor = ColorTranslator.FromHtml("#E0E0E0"); panCustomReg.Width = btnDeleteReg.Left + btnDeleteReg.Width + 6; panCustomReg.Height = 38; panCustomReg.Left = 3; panCustomReg.Top = intNextRegTop; panCustomReg.Controls.Add(chkUseLocalReg); panCustomReg.Controls.Add(chkUseOnlineReg); panCustomReg.Controls.Add(chkRequiredReg); panCustomReg.Controls.Add(txtChargeReg); panCustomReg.Controls.Add(txtSortOrderReg); panCustomReg.Controls.Add(txtLocalCaptionReg); panCustomReg.Controls.Add(lblFieldTypeReg); panCustomReg.Controls.Add(txtWebCaptionReg); panCustomReg.Controls.Add(btnDetailsReg); panCustomReg.Controls.Add(btnDeleteReg); panCustomReg.Controls.Add(txtHeader); panCustomReg.Controls.Add(txtFooter); panCustomReg.Controls.Add(txtDropdownOptions); pagRegCustom.Controls.Add(panCustomReg); intNextRegTop += 44; } drCust.Close(); } } conDB.Close(); } //web defs //load web reg definitions using (wsXferEventInfo.XferEventInfo wsDLFlags = new global::CTWebMgmt.wsXferEventInfo.XferEventInfo()) { strSQL = "SELECT blnRequired, " + "lngCustomFieldDefRegID, " + "decCharge, " + "strLocalCaption, strWebCaption, strHeader, strFooter " + "FROM tblCustomFieldDefReg " + "WHERE lngCTUserID = " + clsAppSettings.GetAppSettings().lngCTUserID.ToString() + " AND " + "lngProgramID = " + _lngProgramID.ToString(); string strWebXML = ""; try { strWebXML = wsDLFlags.fcnGetRecords(strSQL, "tblCustomVals", clsWebTalk.strWebConn); } catch (Exception ex) { } DataSet dsXML = new DataSet("tblCustomVals"); dsXML.ReadXml(new System.IO.StringReader(strWebXML), XmlReadMode.ReadSchema); foreach (DataTable tbl in dsXML.Tables) { foreach (DataRow row in tbl.Rows) { string strNameOnWS = ""; long lngIDOnWS = 0; bool blnRequired = false; decimal decCharge = 0; string strWebCaption = ""; string strHeader = ""; string strFooter = ""; try { strNameOnWS = Convert.ToString(row["strLocalCaption"]); } catch { strNameOnWS = ""; } try { lngIDOnWS = Convert.ToInt32(row["lngCustomFieldDefRegID"]); } catch { lngIDOnWS = 0; } try { strWebCaption = Convert.ToString(row["strWebCaption"]); } catch { strWebCaption = ""; } if (lngIDOnWS == 0) { //field/flag hasn't been matched with a local id: look up caption from old table to match it to web data using (OleDbConnection conDB = new OleDbConnection(clsAppSettings.GetAppSettings().strCTConn)) { conDB.Open(); strSQL = "SELECT tblCustomFieldDefReg.lngCustomFieldDefRegID " + "FROM tblCustomFieldDefReg " + "INNER JOIN tblCustomRegFlagDesc ON tblCustomFieldDefReg.strLocalCaption = tblCustomRegFlagDesc." + strNameOnWS; using (OleDbCommand cmdDB = new OleDbCommand(strSQL, conDB)) { try { lngIDOnWS = Convert.ToInt32(cmdDB.ExecuteScalar()); } catch { lngIDOnWS = 0; } } conDB.Close(); } } if (lngIDOnWS > 0) { try { try { blnRequired = Convert.ToBoolean(row["blnRequired"]); } catch { blnRequired = false; } try { decCharge = Convert.ToDecimal(row["decCharge"]); } catch { decCharge = 0; } try { strHeader = Convert.ToString(row["strHeader"]); } catch { strHeader = ""; } try { strFooter = Convert.ToString(row["strFooter"]); } catch { strFooter = ""; } Panel panCustomReg = (Panel)pagRegCustom.Controls["panCustomReg_" + lngIDOnWS.ToString()]; ((CheckBox)panCustomReg.Controls["chkUseOnlineReg_" + lngIDOnWS.ToString()]).Checked = true; if (blnRequired) ((CheckBox)panCustomReg.Controls["chkRequiredReg_" + lngIDOnWS.ToString()]).Checked = true; ((TextBox)panCustomReg.Controls["txtWebCaptionReg_" + lngIDOnWS.ToString()]).Text = strWebCaption; ((TextBox)panCustomReg.Controls["txtChargeReg_" + lngIDOnWS.ToString()]).Text = decCharge.ToString("C"); ((TextBox)panCustomReg.Controls["txtHeaderReg_" + lngIDOnWS.ToString()]).Text = strHeader; ((TextBox)panCustomReg.Controls["txtFooterReg_" + lngIDOnWS.ToString()]).Text = strFooter; } catch (Exception ex) { MessageBox.Show("Error retrieving custom field definitions: " + ex.Message); } } } } } }
private static bool fcnGetWebCustomRegFieldDefs(clsCustomFieldRegDef[] _cstRegWebFlags,clsCustomFieldRegDef[] _cstRegWebFields) { string strSQL = ""; bool blnRes = false; //init for (int intI = 0; intI <_cstRegWebFlags.Length; intI++) { _cstRegWebFlags[intI] = new clsCustomFieldRegDef(); _cstRegWebFields[intI] = new clsCustomFieldRegDef(); } try { using (wsXferEventInfo.XferEventInfo wsDLFlags = new global::CTWebMgmt.wsXferEventInfo.XferEventInfo()) { strSQL = "SELECT strFieldName, strValue " + "FROM tblCustomVals " + "WHERE lngProgramID = 0 AND " + "lngCTUserID = " + clsAppSettings.GetAppSettings().lngCTUserID.ToString() + " AND " + "(strFieldName LIKE 'blnUse%Field%' OR " + "strFieldName LIKE 'blnUse%Flag%' OR " + "strFieldName LIKE 'strRegFlag%' OR " + "strFieldName LIKE 'curChargeFlag%' OR " + "strFieldName LIKE 'strRegField%') " + "ORDER BY strFieldName"; string strWebXML = ""; try { strWebXML = wsDLFlags.fcnGetRecords(strSQL, "tblCustomVals", clsWebTalk.strWebConn); } catch (Exception ex) { MessageBox.Show("There was an error retrieving custom field definitions from the web: " + ex.Message); } DataSet dsXML = new DataSet("tblCustomVals"); dsXML.ReadXml(new System.IO.StringReader(strWebXML), XmlReadMode.ReadSchema); foreach (DataTable tbl in dsXML.Tables) { foreach (DataRow row in tbl.Rows) { string strFieldName = ""; string strFieldVal = ""; foreach (DataColumn col in tbl.Columns) { string strColName = col.ColumnName; string strColVal = Convert.ToString(row[col]); if (strColName == "strFieldName") strFieldName = strColVal; else if (strColName == "strValue") strFieldVal = strColVal; } //evaluate field, val, set control value if (strFieldName.IndexOf("blnUseRegField") >= 0) _cstRegWebFields[Convert.ToInt32(strFieldName.Substring(14, strFieldName.Length - 14)) - 1].blnUseOnline = Convert.ToBoolean(strFieldVal); else if (strFieldName.IndexOf("blnUseRegFlag") >= 0) _cstRegWebFlags[Convert.ToInt32(strFieldName.Substring(13, strFieldName.Length - 13)) - 1].blnUseOnline = Convert.ToBoolean(strFieldVal); else if (strFieldName.IndexOf("strRegField") >= 0) _cstRegWebFields[Convert.ToInt32(strFieldName.Substring(11, strFieldName.Length - 11)) - 1].mmoWebCaption = strFieldVal; else if (strFieldName.IndexOf("strRegFlag") >= 0) _cstRegWebFlags[Convert.ToInt32(strFieldName.Substring(10, strFieldName.Length - 10)) - 1].mmoWebCaption = strFieldVal; else if (strFieldName.IndexOf("curChargeFlag") >= 0) _cstRegWebFlags[Convert.ToInt32(strFieldName.Substring(13, strFieldName.Length - 13)) - 1].decCharge = Convert.ToDecimal(strFieldVal); } } } blnRes = true; } catch (Exception ex) { blnRes = false; } return blnRes; }