public void btnSave_click(object sender, System.EventArgs e) { bool bRes = false; //Start transaction - we need update all records or none DBase.BeginTransaction("admWebSaveLoyalityPoints"); DataTable oDT = DBase.GetDataTableBatch(Config.DbUpdateLoyalityPoints); if (oDT != null) { DataView oDV = new DataView(oDT); int nID = 0; foreach (string sKey in Request.Form.AllKeys) { nID = GetID(sKey, "MinValueForPoint_"); if (nID > 0) { SetValue(oDV, nID, "MinValueForPoint", sKey); } nID = GetID(sKey, "PointsValue_"); if (nID > 0) { SetValue(oDV, nID, "PointsValue", sKey); } nID = GetID(sKey, "NameSQLProcedure_"); if (nID > 0) { SetValue(oDV, nID, "NameSQLProcedure", sKey); } } bRes = DBase.Update(oDT); } if (bRes) { //Commit successful transaction DBase.CommitTransaction("admWebSaveLoyalityPoints"); BindData(); lblError.Text = "Data has been saved"; lblError.ForeColor = Color.Green; } else { //Rollback transaction in error ocurred DBase.RollbackTransaction("admWebSaveLoyalityPoints"); lblError.Text = "DataBase error occured"; lblError.ForeColor = Color.Red; } }
protected void RemoveItemsSql() { DataTable oDT = DBase.GetDataTableBatch("select ip from AllowedIP"); foreach (DataRow oDR in oDT.Rows) { ListItem oLI = chkIpList.Items.FindByText(oDR["IP"].ToString()); if (oLI != null && oLI.Selected) { oDR.Delete(); } } DBase.Update(oDT); }
protected void btnSave_click(object sender, System.EventArgs e) { bool bRes = false; //Start transaction - we need update all records or none DBase.BeginTransaction("admWebSaveOptions"); DataTable oDT = DBase.GetDataTableBatch(Config.DbUpdateConfig); if (oDT != null) { DataView oDV = new DataView(oDT); foreach (string sKey in Request.Form.AllKeys) { if (sKey.StartsWith("edtVal_")) { int nID = Utils.GetInt(sKey.Substring(7)); if (nID > 0) // Must be positive integer { oDV.RowFilter = string.Format("[id]={0}", nID); if (oDV.Count == 1) { // Update exists row oDV[0]["PropertyValue"] = Request[sKey]; } } } } bRes = DBase.Update(oDT); } if (bRes) { //Commit successful transaction DBase.CommitTransaction("admWebSaveOptions"); BindGrid(); lblError.Text = "Data has been saved"; lblError.ForeColor = Color.Green; Response.Redirect(GetGoBackUrl()); } else { //Rollback transaction in error ocurred DBase.RollbackTransaction("admWebSaveOptions"); lblError.Text = "DataBase error occured"; lblError.ForeColor = Color.Red; } }
protected void btnSave_Click(object sender, EventArgs e) { int fileID = -1; int originalFileID = -1; string sKey = ""; string sError = ""; string sErrorVersion = ""; string sErrorContentType = ""; int iVersion = -1; bool bRes = false; string tranName = ""; int iContentType = -1; int executableCount = 0; string fileList = ""; DataRow oRow = null; if (AffID <= 0) { return; } oPostedFile = new PostedFile(AffID); //1. Content type and version changes tranName = "updateClientApplication"; DBase.BeginTransaction(tranName); DataTable oDT = DBase.GetDataTableBatch(String.Format(Config.ClientFilesBatchSQL, AffID)); DataColumn[] PrimaryKeyArrayVersion = new DataColumn[1]; PrimaryKeyArrayVersion[0] = oDT.Columns["ID"]; oDT.PrimaryKey = PrimaryKeyArrayVersion; for (int i = 0; i < Request.Form.AllKeys.Length; i++) { string sFormKey = Request.Form.AllKeys[i]; string [] tags = sFormKey.TrimStart('_').Split('_'); if (tags.Length < 2) { continue; } //a. content Type if (tags[0] == chkComboName.TrimEnd('_')) { fileID = Convert.ToInt32(sFormKey.Substring(chkComboName.Length)); iContentType = Convert.ToInt32(Request[sFormKey]); if ((fileID > 0) && (iContentType == ContentTypeExecutable)) { executableCount++; } oRow = oDT.Rows.Find(fileID); if ((oRow != null) && (oRow["contentTypeID"] != DBNull.Value) && (Convert.ToInt32(oRow["contentTypeID"]) != iContentType)) { if (executableCount > 1) { sErrorContentType += "You can not have more than one executable file. Content type of file " + oRow["name"] + " remains the same.<br>"; } else { oRow["contentTypeID"] = iContentType; } } } else if (tags[0] == edtName.TrimEnd('_')) //b. File Version { fileID = Convert.ToInt32(tags[1]); oRow = oDT.Rows.Find(fileID); if (oRow != null) { if (tags[2] == "version") { iVersion = Utils.GetInt(Request[sFormKey]); if (oRow[tags[2]] != DBNull.Value) { if (Convert.ToInt32(oRow[tags[2]]) > iVersion) { sErrorVersion += "Version you specified for file: " + oRow["name"] + " is not correct or lower than existing one. File version was not changed.<br>"; } else if (Convert.ToInt32(oRow[tags[2]]) < iVersion) { oRow[tags[2]] = iVersion; } } else { oRow[tags[2]] = iVersion; } } else { oRow[tags[2]] = Utils.GetInt(Request[sFormKey]); } } } } bRes = DBase.Update(oDT); if (bRes) { DBase.CommitTransaction(tranName); } else { DBase.RollbackTransaction(tranName); lblInfo.Text = "DataBase error occured during updating table"; lblInfo.ForeColor = Color.Red; return; } sError += sErrorContentType + sErrorVersion; //2. file upload for (int i = 0; i < Request.Files.Count; i++) { sKey = Request.Files.AllKeys[i]; fileID = -1; if ((sKey != null) && (sKey != "")) { fileID = Convert.ToInt32(sKey); } originalFileID = fileID; iContentType = -1; if (Request[chkComboName + sKey] != null) { iContentType = Convert.ToInt32(Request[chkComboName + sKey]); } if ((iContentType == ContentTypeExecutable) && (originalFileID <= 0)) { executableCount++; } if ((executableCount > 1) && (originalFileID <= 0)) { sError += "You can not upload one more executable file. New file wasn't upload"; } else { HttpPostedFile postFile = Request.Files[i]; if ((postFile.FileName != "") && (postFile.FileName != null)) { string sErrorUpload = ""; string fileExtension = Path.GetExtension(postFile.FileName); if (fileExtension == zipExtension) { sErrorUpload = oPostedFile.SaveZipFile(Page, postFile, iContentType, ref fileList); } else { sErrorUpload = oPostedFile.SaveFile(Page, postFile, iContentType, ref fileID); } if (sErrorUpload != "") { sError += sErrorUpload + "<br>"; } } } } //File Upload result if (sError == "") { lblInfo.Text = "File upload succeeded"; lblInfo.ForeColor = Color.Green; } else { lblInfo.Text = "There were errors during file upload. Some files could not be uploaded. See details below:<br>" + sError; lblInfo.ForeColor = Color.Red; } RunBat(); BindDataGrid(); }
private bool SaveData(int stateID) { string tranName = "SaveEvent"; DBase.BeginTransaction(tranName); //1. Save/Update Event object StartDate = Utils.GetDbDate(Request["comboDate"] + " " + Request["comboTime"] + ":00"); int nRes = DBase.ExecuteReturnInt(Config.DbSaveEvent, "@EventID", nEventID, "@StateID", stateID, "@StartSchedule", sGuid, "@SubCategoryID", Request["comboSubCategory"], "@AwayTeamID", Request["comboAway"], "@HomeTeamID", Request["comboHome"], "@StartDate", StartDate); if (nRes <= 0) { ShowError("Database error occured"); DBase.RollbackTransaction(tranName); return(false); } //2. Update Outcomes decimal Rate = 0; decimal Point = 0; bool isSave = false; string sPoint = ""; DataTable oDT = DBase.GetDataTableBatch(string.Format(Config.DbUpdateOutcome, nRes)); DataColumn[] PrimaryKeyArray = new DataColumn[4]; PrimaryKeyArray[0] = oDT.Columns["EventID"]; PrimaryKeyArray[1] = oDT.Columns["BetTypeID"]; PrimaryKeyArray[2] = oDT.Columns["isHome"]; PrimaryKeyArray[3] = oDT.Columns["PeriodID"]; oDT.PrimaryKey = PrimaryKeyArray; //Home Spread Rate = Utils.GetDecimal(txtHomeSpread.Text); sPoint = Request["comboHomeSpread"]; Point = Utils.GetDecimal(sPoint); isSave = isNumber(sPoint); UpdateRow(oDT, nRes, typeSpread, againstHome, periodFull, Rate, Point, isSave); UpdateRow(oDT, nRes, typeSpread, againstAway, periodFull, -Rate, -Point, isSave); Rate = Utils.GetDecimal(txtHomeSpreadHalf.Text); sPoint = Request["comboHomeSpreadHalf"]; Point = Utils.GetDecimal(sPoint); isSave = isNumber(sPoint); UpdateRow(oDT, nRes, typeSpread, againstHome, periodHalf, Rate, Point, isSave); UpdateRow(oDT, nRes, typeSpread, againstAway, periodHalf, -Rate, -Point, isSave); //Over Under Rate = Utils.GetDecimal(txtTotalOU.Text); sPoint = Request["comboTotalOU"]; Point = Utils.GetDecimal(sPoint); isSave = isNumber(sPoint); UpdateRow(oDT, nRes, typeOu, againstHome, periodFull, Rate, Point, isSave); UpdateRow(oDT, nRes, typeOu, againstAway, periodFull, -Rate, -Point, isSave); Rate = Utils.GetDecimal(txtTotalOUHalf.Text); sPoint = Request["comboTotalOUHalf"]; Point = Utils.GetDecimal(sPoint); isSave = isNumber(sPoint); UpdateRow(oDT, nRes, typeOu, againstHome, periodHalf, Rate, Point, isSave); UpdateRow(oDT, nRes, typeOu, againstAway, periodHalf, -Rate, -Point, isSave); //ML Rate = Utils.GetDecimal(txtHomeTeam.Text); sPoint = Request["comboHomeTeam"]; Point = Utils.GetDecimal(sPoint); isSave = isNumber(sPoint); UpdateRow(oDT, nRes, typeML, againstHome, periodFull, Rate, Point, isSave); UpdateRow(oDT, nRes, typeML, againstAway, periodFull, -Rate, -Point, isSave); bool bRes = DBase.Update(oDT); if (!bRes) { ShowError("DataBase error occured during saving Outcomes"); DBase.RollbackTransaction(tranName); return(false); } // Everything is Ok DBase.CommitTransaction(tranName); nEventID = nRes; StoreBackID(nRes); hdnEventID.Value = nRes.ToString(); return(true); }
protected void btnProcess_Click(object sender, System.EventArgs e) { string tranName = "ProcessEvent"; DBase.BeginTransaction(tranName); //1. Save Event Score int nRes = DBase.ExecuteNonQuery(Config.DbSaveEventScore, "@EventID", nEventID, "@HomeScore", txtHomeScore.Text, "@AwayScore", txtAwayScore.Text, "@HomeScoreHalf", txtHomeScoreHalf.Text, "@AwayScoreHalf", txtAwayScoreHalf.Text, "@StateID", stateProcessing); if (nRes < 0) { ShowError("DataBase error occured"); DBase.RollbackTransaction(tranName); return; } //2. Update Outcomes DataTable oDT = DBase.GetDataTableBatch(string.Format(Config.DbUpdateOutcome, nEventID)); DataColumn[] PrimaryKeyArray = new DataColumn[1]; PrimaryKeyArray[0] = oDT.Columns["ID"]; oDT.PrimaryKey = PrimaryKeyArray; int HomeScore = Utils.GetInt(txtHomeScore.Text); int HomeScoreHalf = Utils.GetInt(txtHomeScoreHalf.Text); int AwayScore = Utils.GetInt(txtAwayScore.Text); int AwayScoreHalf = Utils.GetInt(txtAwayScoreHalf.Text); foreach (DataRow oRow in oDT.Rows) { int BetTypeID = Utils.GetInt(oRow["BetTypeID"]); int IsHome = Utils.GetInt(oRow["IsHome"]); int PeriodID = Utils.GetInt(oRow["PeriodID"]); switch (BetTypeID) { case typeSpread: if (IsHome == againstHome) { oRow["WonValue"] = HomeScore - AwayScore; } else { oRow["WonValue"] = AwayScore - HomeScore; } if (PeriodID == periodFull) { oRow["OutcomeResultID"] = hdnResultHomeSpread.Value; } else { oRow["OutcomeResultID"] = hdnResultHomeSpreadHalf.Value; } break; case typeOu: oRow["WonValue"] = HomeScore + AwayScore; if (PeriodID == periodFull) { oRow["OutcomeResultID"] = hdnResultTotalOU.Value; } else { oRow["OutcomeResultID"] = hdnResultTotalOUHalf.Value; } break; case typeML: if (IsHome == againstHome) { oRow["OutcomeResultID"] = hdnResultHomeML.Value; } else { oRow["OutcomeResultID"] = hdnResultAwayML.Value; } break; } } bool bRes = DBase.Update(oDT); if (!bRes) { ShowError("DataBase error occured during puting results"); DBase.RollbackTransaction(tranName); return; } //3. Processing Bets int nRes2 = DBase.ExecuteNonQuery(Config.DbProcessBetsOnEventFinish, "@EventID", nEventID); if (nRes2 < 0) { ShowError("DataBase error occured in nprocessing Bets"); DBase.RollbackTransaction(tranName); return; } //Commit transaction DBase.CommitTransaction(tranName); //4. Invoke Com object StartDate = DateTime.Now; string sRet = InvokeCom(StartDate, sGuid, stateProcessing); if (sRet == null) { return; } sGuid = sRet; // Everything is Ok nStateID = stateProcessing; hdnStateID.Value = nStateID.ToString(); hdnGuid.Value = sGuid; lblInfo.ForeColor = Color.Green; lblInfo.Text = "Event was processed successfully"; //Response.Redirect(GetGoBackUrl()); GetPageData(); InitJS(); DisplayControls(); }
/// <summary> /// Save event handler. /// </summary> protected void btnSave_Click(object sender, System.EventArgs e) { //1. Get XML sXML = hdnXML.Value; oPrize.FillTable(ref sXML, ref table, true, false); //fill table from xml //2. Save category in DB string tranNameTotal = "admSaveSBCategoryDetails"; DBase.BeginTransaction(tranNameTotal); int nRes = DBase.ExecuteReturnInt(Config.DbSaveSBCategoryDetails, new object[] { "@id", nCategoryID, "@Name", txtName.Text }); if (nRes <= 0) { DBase.RollbackTransaction(tranNameTotal); lblInfo.ForeColor = Color.Red; switch (nRes) { case -1: lblInfo.Text = "Typed category name already exists"; break; case 0: lblInfo.Text = "Database error occured"; break; default: lblInfo.Text = "Unknown error occured"; break; } return; } //3. Batch upload of Teaser Table try { DataTable xmlDT = oPrize.getDataTable(sXML); //DataTable from xml DataColumn[] PrimaryKeyArray = new DataColumn[3]; PrimaryKeyArray[0] = xmlDT.Columns[PrizeTable.tblColName]; PrimaryKeyArray[1] = xmlDT.Columns[PrizeTable.tblRowName]; PrimaryKeyArray[2] = xmlDT.Columns[PrizeTable.tblValueName]; xmlDT.PrimaryKey = PrimaryKeyArray; //using primary key we can update only recods that were changed DataTable oDT = DBase.GetDataTableBatch("select id, Points, BetCount, Rate, CategoryID from Teaser where categoryID = " + nRes.ToString() + " order by Points, BetCount"); //dataTable from SQL //clear all old data foreach (DataRow oDR in oDT.Rows) { DataRow oRow = xmlDT.Rows.Find(new object[3] { oDR["Points"].ToString(), oDR["BetCount"].ToString(), oDR["Rate"].ToString() }); if (oRow != null) { oRow.Delete(); } else { oDR.Delete(); } } //do we have any records to add bool hasRecords = true; if (xmlDT.Rows.Count < 1) { hasRecords = false; } if ((xmlDT.Rows.Count == 1) && (xmlDT.Rows[0][PrizeTable.tblValueName].ToString() == "")) { hasRecords = false; //one record, but value is empty } if (hasRecords) { //add new data foreach (DataRow oDR in xmlDT.Rows) { DataRow row = oDT.NewRow(); row["Points"] = oDR[PrizeTable.tblColName]; row["BetCount"] = oDR[PrizeTable.tblRowName]; row["Rate"] = Utils.GetDecimal(oDR[PrizeTable.tblValueName]); row["CategoryID"] = nRes; oDT.Rows.Add(row); } } bool bRes = DBase.Update(oDT); if (!bRes) { DBase.RollbackTransaction(tranNameTotal); ShowError("DB error occured during Teaser data update."); return; } } catch (Exception oEx) { DBase.RollbackTransaction(tranNameTotal); ShowError("DB error occured during Teaser data update block."); Log.Write(this, oEx); return; } //End of Batch upload of Teaser Table //4. Sucess message DBase.CommitTransaction(tranNameTotal); nCategoryID = nRes; StoreBackID(nRes); hdnID.Value = nRes.ToString(); lblInfo.ForeColor = Color.Green; lblInfo.Text = "Category details have been saved"; Response.Redirect(GetGoBackUrl()); }
protected void btnSave_Click(object sender, System.EventArgs e) { string tranName = "UpdateSubCategoryStats"; DBase.BeginTransaction(tranName); //1. Save/update Subcategory details SqlCommand oCmd = DBase.GetCommand(Config.DbSaveSubCategoryDetails); SqlParameterCollection oParams = oCmd.Parameters; oParams.Add("@ID", nSubCategoryID); oParams.Add("@Name", txtName.Text); oParams.Add("@StatusID", Core.GetSelectedValueInt(comboStatus)); oParams.Add("@CategoryID", Core.GetSelectedValueInt(comboCategory)); int nRes = DBase.ExecuteReturnInt(oCmd); if (nRes <= 0) { lblInfo.ForeColor = Color.Red; switch (nRes) { case -1: lblInfo.Text = "Typed category name already exists"; break; default: lblInfo.Text = "Database error occured"; break; } DBase.RollbackTransaction(tranName); return; } //2. update SubCategoryStats table DataTable oDT = DBase.GetDataTableBatch(string.Format(Config.DbUpdateSubCategoryStats, nRes)); DataColumn[] PrimaryKeyArray = new DataColumn[2]; PrimaryKeyArray[0] = oDT.Columns["SubCategoryID"]; PrimaryKeyArray[1] = oDT.Columns["StatsTypeID"]; oDT.PrimaryKey = PrimaryKeyArray; try { //a. Delete rows that are not any more in the list string[] statsList = hdnStatsList.Value.Split(','); int statsLen = statsList.Length; if (hdnStatsList.Value == "") { statsLen = 0; } int k = 0; while (k < oDT.Rows.Count) { DataRow oRow = oDT.Rows[k]; bool bFind = false; for (int i = 0; i < statsLen; i++) { if (oRow["StatsTypeID"].ToString() == statsList[i]) { bFind = true; } } if (!bFind) { oRow.Delete(); } k++; } //b. Add/update order for the list for (int i = 0; i < statsLen; i++) { DataRow oRow = oDT.Rows.Find(new object[] { nRes, statsList[i] }); if (oRow == null) { oDT.Rows.Add(new object[] { nSubCategoryID, statsList[i], i + 1 }); } else { if (Convert.ToInt32(oRow["Order"]) != i + 1) { oRow["Order"] = i + 1; } } } } catch (Exception oEx) { Log.Write(this, "DataTable operations Error: " + oEx.Message); DBase.RollbackTransaction(tranName); lblInfo.Text = "DataBase error occured during updating table"; lblInfo.ForeColor = Color.Red; return; } bool bRes = DBase.Update(oDT); if (bRes) { DBase.CommitTransaction(tranName); hdnSubCategoryID.Value = nRes.ToString(); StoreBackID(nRes); lblInfo.Text = "Category details have been saved"; lblInfo.ForeColor = Color.Green; Response.Redirect(GetGoBackUrl()); nSubCategoryID = nRes; BindStatsList(); rowRelatedProcesses.Visible = true; BindRelatedProcessList(); } else { DBase.RollbackTransaction(tranName); lblInfo.Text = "DataBase error occured during updating table"; lblInfo.ForeColor = Color.Red; } }