protected void btnShow4_Click(object sender, EventArgs e) { wizardData wData = readWizardSteps(); using (var dbContext = new OTERTConnStr()) { try { dbContext.Configuration.ProxyCreationEnabled = false; OTERT_Entity.Invoices curInvoice; curInvoice = new OTERT_Entity.Invoices(); curInvoice.CustomerID = wData.CustomerID; curInvoice.DateFrom = wData.DateFrom; curInvoice.DateTo = wData.DateTo; curInvoice.RegNo = wData.Code; curInvoice.IsLocked = wData.locked; curInvoice.DatePaid = wData.DatePayed; curInvoice.DateCreated = wData.DateCreated; TasksController tcont = new TasksController(); List <TaskB> invTasks = tcont.GetTasksForInvoice(curInvoice.CustomerID, wData.DateFrom, wData.DateTo, wData.SelectedJobs, wData.SelectedTasks); decimal totalTasksCost = 0; foreach (TaskB curTask in invTasks) { totalTasksCost += curTask.CostActual.GetValueOrDefault(); } curInvoice.TasksLineAmount = totalTasksCost; /* * foreach (GridDataItem item in gridSales.MasterTableView.Items) { * CheckBox chk = (CheckBox)item.FindControl("chk"); * decimal? tasksValue = decimal.Parse(item["TasksCost"].Text); * decimal? salesValue = decimal.Parse(item["SalesCost"].Text); * curInvoice.TasksLineAmount = tasksValue; * if (chk.Checked) { * curInvoice.DiscountLineAmount = salesValue; * } * dbContext.Invoices.Add(curInvoice); * } */ dbContext.Invoices.Add(curInvoice); dbContext.SaveChanges(); foreach (TaskB curTask in invTasks) { TasksLine newTaskLine = new TasksLine(); newTaskLine.InvoiceID = curInvoice.ID; newTaskLine.TaskID = curTask.ID; newTaskLine.JobID = curTask.JobID.GetValueOrDefault(); dbContext.TasksLine.Add(newTaskLine); } dbContext.SaveChanges(); } catch (Exception) { } Response.Redirect("/Pages/Invoices/InvoiceShow.aspx", false); } //Session["wizardStep"] = wData; //showWizardSteps(wData); }
protected void gridMain_DeleteCommand(object source, GridCommandEventArgs e) { if (e.Item.OwnerTableView.Name == "Master") { var ID = (int)((GridDataItem)e.Item).GetDataKeyValue("ID"); using (var dbContext = new OTERTConnStr()) { var selCustomer = dbContext.Customers.Where(n => n.ID == ID).FirstOrDefault(); if (selCustomer != null) { List <Files> curFiles = dbContext.Files.Where(k => k.CustomerID == ID).ToList(); foreach (Files curFile in curFiles) { string FileToDelete = Server.MapPath(curFile.FilePath); if (System.IO.File.Exists(FileToDelete)) { System.IO.File.Delete(FileToDelete); } dbContext.Files.Remove(curFile); try { dbContext.SaveChanges(); } catch (Exception) { ShowErrorMessage(-1); } } dbContext.Customers.Remove(selCustomer); try { dbContext.SaveChanges(); } catch (Exception ex) { string err = ex.InnerException.InnerException.Message; int errCode = -1; if (err.StartsWith("The DELETE statement conflicted with the REFERENCE constraint")) { errCode = 1; } ShowErrorMessage(errCode); } } } } else if (e.Item.OwnerTableView.Name == "AttachedFiles") { var ID = (int)((GridDataItem)e.Item).GetDataKeyValue("ID"); using (var dbContext = new OTERTConnStr()) { var curFile = dbContext.Files.Where(n => n.ID == ID).FirstOrDefault(); if (curFile != null) { string FileToDelete = Server.MapPath(curFile.FilePath); if (System.IO.File.Exists(FileToDelete)) { System.IO.File.Delete(FileToDelete); } dbContext.Files.Remove(curFile); try { dbContext.SaveChanges(); } catch (Exception) { ShowErrorMessage(-1); } } } } }
protected void gridMain_InsertCommand(object source, GridCommandEventArgs e) { var editableItem = ((GridEditableItem)e.Item); using (var dbContext = new OTERTConnStr()) { var currPricelist = new PTSGRPricelist(); Hashtable values = new Hashtable(); editableItem.ExtractValues(values); try { currPricelist.Name = (string)values["Name"]; currPricelist.InstallationCost = decimal.Parse((string)values["InstallationCost"]); currPricelist.ChargesPerMonth = decimal.Parse((string)values["ChargesPerMonth"]); currPricelist.ChargesPerDay = decimal.Parse((string)values["ChargesPerDay"]); currPricelist.MSNPerMonth = decimal.Parse((string)values["MSNPerMonth"]); currPricelist.MSNPerDay = decimal.Parse((string)values["MSNPerDay"]); if (currPricelist.MSNPerMonth > 0 || currPricelist.MSNPerDay > 0) { currPricelist.SupportsMSN = true; } else { currPricelist.SupportsMSN = false; } currPricelist.HasRouter = (bool)values["HasRouter"]; currPricelist.IsChargePerMonth = (bool)values["IsChargePerMonth"]; dbContext.PTSGRPricelist.Add(currPricelist); dbContext.SaveChanges(); } catch (Exception) { ShowErrorMessage(-1); } } }
protected void gridMain_UpdateCommand(object source, GridCommandEventArgs e) { var editableItem = ((GridEditableItem)e.Item); var ID = (int)editableItem.GetDataKeyValue("ID"); using (var dbContext = new OTERTConnStr()) { var curDistance = dbContext.Distances.Where(n => n.ID == ID).FirstOrDefault(); if (curDistance != null) { editableItem.UpdateValues(curDistance); if (Session["JobsMainID"] != null) { JobsMainID = int.Parse(Session["JobsMainID"].ToString()); } if (JobsMainID > 0 && Session["Position1"] != null && Session["Position1"] != null) { curDistance.Position1 = Session["Position1"].ToString(); curDistance.Position2 = Session["Position2"].ToString(); curDistance.JobsMainID = JobsMainID; JobsMainID = -1; Session.Remove("JobsMainID"); Session.Remove("Position1"); Session.Remove("Position2"); } try { dbContext.SaveChanges(); } catch (Exception) { ShowErrorMessage(-1); } } } }
protected void gridMain_UpdateCommand(object source, GridCommandEventArgs e) { var editableItem = ((GridEditableItem)e.Item); var ID = (int)editableItem.GetDataKeyValue("ID"); using (var dbContext = new OTERTConnStr()) { var docRep = dbContext.DocumentReplacemets.Where(n => n.ID == ID).FirstOrDefault(); if (docRep != null) { editableItem.UpdateValues(docRep); if (Session["textFromSession"] != null) { textFromSession = Session["textFromSession"].ToString().Trim(); } if (!string.IsNullOrEmpty(textFromSession)) { docRep.Text = textFromSession; textFromSession = ""; Session.Remove("textFromSession"); } try { dbContext.SaveChanges(); } catch (Exception) { ShowErrorMessage(); } } } }
protected void gridMain_InsertCommand(object source, GridCommandEventArgs e) { var editableItem = ((GridEditableItem)e.Item); using (var dbContext = new OTERTConnStr()) { var place = new Places(); Hashtable values = new Hashtable(); editableItem.ExtractValues(values); if (Session["CountryID"] != null) { newID = int.Parse(Session["CountryID"].ToString()); } if (newID > 0) { try { place.CountryID = newID; place.NameGR = (string)values["NameGR"]; place.NameEN = (string)values["NameEN"]; dbContext.Places.Add(place); dbContext.SaveChanges(); } catch (Exception) { ShowErrorMessage(-1); } finally { newID = -1; Session.Remove("CountryID"); } } else { ShowErrorMessage(-1); } } }
protected void gridMain_UpdateCommand(object source, GridCommandEventArgs e) { var editableItem = ((GridEditableItem)e.Item); var ID = (int)editableItem.GetDataKeyValue("ID"); using (var dbContext = new OTERTConnStr()) { var place = dbContext.Places.Where(n => n.ID == ID).FirstOrDefault(); if (place != null) { editableItem.UpdateValues(place); if (Session["CountryID"] != null) { newID = int.Parse(Session["CountryID"].ToString()); } if (newID > 0) { place.CountryID = newID; newID = -1; Session.Remove("CountryID"); } try { dbContext.SaveChanges(); } catch (Exception) { ShowErrorMessage(-1); } } } }
protected void gridMain_UpdateCommand(object source, GridCommandEventArgs e) { var editableItem = ((GridEditableItem)e.Item); var ID = (int)editableItem.GetDataKeyValue("ID"); using (var dbContext = new OTERTConnStr()) { var selCustomer = dbContext.Customers.Where(n => n.ID == ID).FirstOrDefault(); if (selCustomer != null) { editableItem.UpdateValues(selCustomer); if (Session["CountryID"] != null) { countryID = int.Parse(Session["CountryID"].ToString()); } if (countryID > 0) { selCustomer.CountryID = countryID; countryID = -1; Session.Remove("CountryID"); } if (Session["CustomerTypeID"] != null) { customerTypeID = int.Parse(Session["CustomerTypeID"].ToString()); } if (customerTypeID > 0) { selCustomer.CustomerTypeID = customerTypeID; customerTypeID = -1; Session.Remove("CustomerTypeID"); } if (Session["LanguageID"] != null) { languageID = int.Parse(Session["LanguageID"].ToString()); } if (languageID > 0) { selCustomer.LanguageID = languageID; languageID = -1; Session.Remove("LanguageID"); } if (Session["UserID"] != null) { userID = int.Parse(Session["UserID"].ToString()); } if (userID > 0) { selCustomer.UserID = userID; userID = -1; Session.Remove("UserID"); } try { dbContext.SaveChanges(); } catch (Exception) { ShowErrorMessage(-1); } } } }
protected void gridMain_InsertCommand(object source, GridCommandEventArgs e) { if (e.Item.OwnerTableView.Name == "Master") { var editableItem = ((GridEditableItem)e.Item); using (var dbContext = new OTERTConnStr()) { var curSale = new Sales(); Hashtable values = new Hashtable(); editableItem.ExtractValues(values); if (Session["SalesType"] != null) { SalesType = int.Parse(Session["SalesType"].ToString()); } if (SalesType > 0) { try { curSale.Name = (string)values["Name"]; curSale.Type = SalesType; dbContext.Sales.Add(curSale); dbContext.SaveChanges(); } catch (Exception) { ShowErrorMessage(-1); } finally { SalesType = -1; Session.Remove("SalesType"); } } else { ShowErrorMessage(-1); } } } else if (e.Item.OwnerTableView.Name == "Details") { GridTableView detailtabl = (GridTableView)e.Item.OwnerTableView; GridDataItem parentItem = (GridDataItem)detailtabl.ParentItem; int salesID = int.Parse(parentItem.GetDataKeyValue("ID").ToString()); var editableItem = ((GridEditableItem)e.Item); using (var dbContext = new OTERTConnStr()) { var curSaleFurmula = new SalesFormulas(); Hashtable values = new Hashtable(); editableItem.ExtractValues(values); curSaleFurmula.SalesID = salesID; curSaleFurmula.Distance = decimal.Parse((string)values["Distance"]); curSaleFurmula.SalePercent = decimal.Parse((string)values["SalePercent"]); dbContext.SalesFormulas.Add(curSaleFurmula); try { dbContext.SaveChanges(); } catch (Exception) { ShowErrorMessage(-1); } } } }
protected void gridMain_InsertCommand(object source, GridCommandEventArgs e) { var editableItem = ((GridEditableItem)e.Item); using (var dbContext = new OTERTConnStr()) { var currPricelist = new CountryPricelist(); Hashtable values = new Hashtable(); editableItem.ExtractValues(values); if (Session["CustomerID"] != null) { CustomerID = int.Parse(Session["CustomerID"].ToString()); } if (Session["LineTypeID"] != null) { LineTypeID = int.Parse(Session["LineTypeID"].ToString()); } if (CustomerID > 0 && LineTypeID > 0) { try { currPricelist.CustomerID = CustomerID; currPricelist.LineTypeID = LineTypeID; currPricelist.InstallationCost = decimal.Parse((string)values["InstallationCost"]); currPricelist.MonthlyCharges = decimal.Parse((string)values["MonthlyCharges"]); currPricelist.Internet = decimal.Parse((string)values["Internet"]); currPricelist.MSN = decimal.Parse((string)values["MSN"]); currPricelist.PaymentIsForWholeMonth = (bool)values["PaymentIsForWholeMonth"]; dbContext.CountryPricelist.Add(currPricelist); dbContext.SaveChanges(); } catch (Exception ex) { string err = ex.InnerException.InnerException.Message; int errCode = -1; if (err.StartsWith("Violation of UNIQUE KEY constraint 'UC_CustomerID_LineTypeID'")) { errCode = 2; } ShowErrorMessage(errCode); } finally { CustomerID = -1; Session.Remove("CustomerID"); LineTypeID = -1; Session.Remove("LineTypeID"); } } else { ShowErrorMessage(-1); } } }
protected void gridMain_InsertCommand(object source, GridCommandEventArgs e) { var editableItem = ((GridEditableItem)e.Item); using (var dbContext = new OTERTConnStr()) { var lineType = new LineTypes(); Hashtable values = new Hashtable(); editableItem.ExtractValues(values); lineType.Name = (string)values["Name"]; dbContext.LineTypes.Add(lineType); try { dbContext.SaveChanges(); } catch (Exception) { ShowErrorMessage(-1); } } }
protected void gridMain_DeleteCommand(object source, GridCommandEventArgs e) { if (e.Item.OwnerTableView.Name == "Master") { var ID = (int)((GridDataItem)e.Item).GetDataKeyValue("ID"); using (var dbContext = new OTERTConnStr()) { var curJob = dbContext.Jobs.Where(n => n.ID == ID).FirstOrDefault(); if (curJob != null) { dbContext.Jobs.Remove(curJob); try { dbContext.SaveChanges(); } catch (Exception ex) { string err = ex.InnerException.InnerException.Message; int errCode = -1; if (err.StartsWith("The DELETE statement conflicted with the REFERENCE constraint")) { errCode = 1; } ShowErrorMessage(errCode); } } } } else if (e.Item.OwnerTableView.Name == "FormulaDetails") { var ID = (int)((GridDataItem)e.Item).GetDataKeyValue("ID"); using (var dbContext = new OTERTConnStr()) { var curJobFurmula = dbContext.JobFormulas.Where(n => n.ID == ID).FirstOrDefault(); if (curJobFurmula != null) { dbContext.JobFormulas.Remove(curJobFurmula); try { dbContext.SaveChanges(); } catch (Exception) { ShowErrorMessage(-1); } } } } else if (e.Item.OwnerTableView.Name == "CancelDetails") { var ID = (int)((GridDataItem)e.Item).GetDataKeyValue("ID"); using (var dbContext = new OTERTConnStr()) { var curCancel = dbContext.JobCancelPrices.Where(n => n.ID == ID).FirstOrDefault(); if (curCancel != null) { dbContext.JobCancelPrices.Remove(curCancel); try { dbContext.SaveChanges(); } catch (Exception) { ShowErrorMessage(-1); } } } } }
protected void gridMain_InsertCommand(object source, GridCommandEventArgs e) { var editableItem = ((GridEditableItem)e.Item); using (var dbContext = new OTERTConnStr()) { var curSat = new Satelites(); Hashtable values = new Hashtable(); editableItem.ExtractValues(values); curSat.Name = (string)values["Name"]; curSat.Frequency = (string)values["Frequency"]; dbContext.Satelites.Add(curSat); try { dbContext.SaveChanges(); } catch (Exception) { ShowErrorMessage(-1); } } }
protected void gridMain_InsertCommand(object source, GridCommandEventArgs e) { var editableItem = ((GridEditableItem)e.Item); using (var dbContext = new OTERTConnStr()) { var reqPosotion = new RequestedPositions(); Hashtable values = new Hashtable(); editableItem.ExtractValues(values); reqPosotion.NameGR = (string)values["NameGR"]; reqPosotion.NameEN = (string)values["NameEN"]; dbContext.RequestedPositions.Add(reqPosotion); try { dbContext.SaveChanges(); } catch (Exception) { ShowErrorMessage(-1); } } }
protected void gridMain_UpdateCommand(object source, GridCommandEventArgs e) { var editableItem = ((GridEditableItem)e.Item); var ID = (int)editableItem.GetDataKeyValue("ID"); using (var dbContext = new OTERTConnStr()) { var custType = dbContext.CustomerTypes.Where(n => n.ID == ID).FirstOrDefault(); if (custType != null) { editableItem.UpdateValues(custType); try { dbContext.SaveChanges(); } catch (Exception) { ShowErrorMessage(-1); } } } }
protected void btnUpdate_Click(object sender, EventArgs e) { wizardData wData = readWData(); using (var dbContext = new OTERTConnStr()) { try { dbContext.Configuration.ProxyCreationEnabled = false; OTERT_Entity.Invoices curInvoice = dbContext.Invoices.Where(o => o.ID == wData.CustomerID).FirstOrDefault(); curInvoice.RegNo = txtAccountNo.Text.Trim(); curInvoice.IsLocked = (chkIsLocked.Checked != null ? (bool)chkIsLocked.Checked : false); curInvoice.DatePaid = (dpDatePay.SelectedDate != null ? (DateTime)dpDatePay.SelectedDate : DateTime.Now); dbContext.SaveChanges(); } catch (Exception ex) { } Response.Redirect("/Pages/Invoices/InvoiceShow.aspx", false); } }
protected void gridMain_UpdateCommand(object source, GridCommandEventArgs e) { var editableItem = ((GridEditableItem)e.Item); var ID = (int)editableItem.GetDataKeyValue("ID"); using (var dbContext = new OTERTConnStr()) { var currPricelist = dbContext.CountryPricelist.Where(n => n.ID == ID).FirstOrDefault(); if (currPricelist != null) { editableItem.UpdateValues(currPricelist); if (Session["CustomerID"] != null) { CustomerID = int.Parse(Session["CustomerID"].ToString()); } if (CustomerID > 0) { currPricelist.CustomerID = CustomerID; CustomerID = -1; Session.Remove("CustomerID"); } if (Session["LineTypeID"] != null) { LineTypeID = int.Parse(Session["LineTypeID"].ToString()); } if (LineTypeID > 0) { currPricelist.LineTypeID = LineTypeID; LineTypeID = -1; Session.Remove("LineTypeID"); } try { dbContext.SaveChanges(); } catch (Exception ex) { string err = ex.InnerException.InnerException.Message; int errCode = -1; if (err.StartsWith("Violation of UNIQUE KEY constraint 'UC_CustomerID_LineTypeID'")) { errCode = 2; } ShowErrorMessage(errCode); } } } }
protected void gridMain_UpdateCommand(object source, GridCommandEventArgs e) { if (e.Item.OwnerTableView.Name == "Master") { var editableItem = ((GridEditableItem)e.Item); var ID = (int)editableItem.GetDataKeyValue("ID"); using (var dbContext = new OTERTConnStr()) { var curSale = dbContext.Sales.Where(n => n.ID == ID).FirstOrDefault(); if (curSale != null) { editableItem.UpdateValues(curSale); if (Session["SalesType"] != null) { SalesType = int.Parse(Session["SalesType"].ToString()); } if (SalesType > 0) { curSale.Type = SalesType; SalesType = -1; Session.Remove("SalesType"); } try { dbContext.SaveChanges(); } catch (Exception) { ShowErrorMessage(-1); } } } } else if (e.Item.OwnerTableView.Name == "Details") { var editableItem = ((GridEditableItem)e.Item); var ID = (int)editableItem.GetDataKeyValue("ID"); using (var dbContext = new OTERTConnStr()) { var curSaleFurmula = dbContext.SalesFormulas.Where(n => n.ID == ID).FirstOrDefault(); if (curSaleFurmula != null) { editableItem.UpdateValues(curSaleFurmula); try { dbContext.SaveChanges(); } catch (Exception) { ShowErrorMessage(-1); } } } } }
protected void gridMain_DeleteCommand(object source, GridCommandEventArgs e) { var ID = (int)((GridDataItem)e.Item).GetDataKeyValue("ID"); using (var dbContext = new OTERTConnStr()) { var custType = dbContext.CustomerTypes.Where(n => n.ID == ID).FirstOrDefault(); if (custType != null) { dbContext.CustomerTypes.Remove(custType); try { dbContext.SaveChanges(); } catch (Exception ex) { string err = ex.InnerException.InnerException.Message; int errCode = -1; if (err.StartsWith("The DELETE statement conflicted with the REFERENCE constraint")) { errCode = 1; } ShowErrorMessage(errCode); } } } }
protected void gridMain_InsertCommand(object source, GridCommandEventArgs e) { var editableItem = ((GridEditableItem)e.Item); using (var dbContext = new OTERTConnStr()) { var user = new Users(); Hashtable values = new Hashtable(); editableItem.ExtractValues(values); if (Session["UserGroupID"] != null) { newID = int.Parse(Session["UserGroupID"].ToString()); } if (newID > 0) { try { user.UserGroupID = newID; user.NameGR = (string)values["NameGR"]; user.NameEN = (string)values["NameEN"]; user.Telephone = (string)values["Telephone"]; user.FAX = (string)values["FAX"]; user.Email = (string)values["Email"]; user.UserName = (string)values["UserName"]; user.Password = (string)values["Password"]; dbContext.Users.Add(user); dbContext.SaveChanges(); } catch (Exception) { ShowErrorMessage(-1); } finally { newID = -1; Session.Remove("UserGroupID"); } } else { ShowErrorMessage(-1); } } }
protected void gridMain_InsertCommand(object source, GridCommandEventArgs e) { var editableItem = ((GridEditableItem)e.Item); using (var dbContext = new OTERTConnStr()) { var newDistance = new Distances(); Hashtable values = new Hashtable(); editableItem.ExtractValues(values); if (Session["JobsMainID"] != null) { JobsMainID = int.Parse(Session["JobsMainID"].ToString()); } if (JobsMainID > 0 && Session["Position1"] != null && Session["Position1"] != null) { try { newDistance.JobsMainID = JobsMainID; newDistance.Position1 = Session["Position1"].ToString(); newDistance.Position2 = Session["Position2"].ToString(); newDistance.KM = int.Parse((string)values["KM"]); dbContext.Distances.Add(newDistance); dbContext.SaveChanges(); } catch (Exception) { ShowErrorMessage(-1); } finally { JobsMainID = -1; Session.Remove("JobsMainID"); Session.Remove("Position1"); Session.Remove("Position2"); } } else { ShowErrorMessage(-1); } } }
protected void gridMain_InsertCommand(object source, GridCommandEventArgs e) { if (e.Item.OwnerTableView.Name == "Master") { var editableItem = ((GridEditableItem)e.Item); using (var dbContext = new OTERTConnStr()) { var curJob = new Jobs(); Hashtable values = new Hashtable(); editableItem.ExtractValues(values); if (Session["SalesID"] != null) { SalesID = int.Parse(Session["SalesID"].ToString()); } if (Session["JobsMainID"] != null) { JobsMainID = int.Parse(Session["JobsMainID"].ToString()); } if (Session["JobTypesID"] != null) { JobTypesID = int.Parse(Session["JobTypesID"].ToString()); } if (SalesID > -1 && JobsMainID > 0 && JobTypesID > 0) { try { curJob.Name = (string)values["Name"]; if (SalesID == 0) { curJob.SalesID = null; } else { curJob.SalesID = SalesID; } curJob.JobsMainID = JobsMainID; curJob.JobTypesID = JobTypesID; if (!string.IsNullOrEmpty((string)values["MinimumTime"])) { curJob.MinimumTime = int.Parse((string)values["MinimumTime"]); } else { curJob.MinimumTime = null; } curJob.InvoiceCode = (string)values["InvoiceCode"]; dbContext.Jobs.Add(curJob); dbContext.SaveChanges(); } catch (Exception) { ShowErrorMessage(-1); } finally { SalesID = -1; Session.Remove("SalesID"); JobsMainID = -1; Session.Remove("JobsMainID"); JobTypesID = -1; Session.Remove("JobTypesID"); } } else { ShowErrorMessage(-1); } } } else if (e.Item.OwnerTableView.Name == "FormulaDetails") { GridTableView detailtabl = (GridTableView)e.Item.OwnerTableView; GridDataItem parentItem = (GridDataItem)detailtabl.ParentItem; int jobsID = int.Parse(parentItem.GetDataKeyValue("ID").ToString()); var editableItem = ((GridEditableItem)e.Item); using (var dbContext = new OTERTConnStr()) { var curJobFurmula = new JobFormulas(); Hashtable values = new Hashtable(); editableItem.ExtractValues(values); curJobFurmula.JobsID = jobsID; curJobFurmula.Formula = (string)values["Formula"]; curJobFurmula.Condition = (string)values["Condition"]; dbContext.JobFormulas.Add(curJobFurmula); try { dbContext.SaveChanges(); } catch (Exception) { ShowErrorMessage(-1); } } } else if (e.Item.OwnerTableView.Name == "CancelDetails") { GridTableView detailtabl = (GridTableView)e.Item.OwnerTableView; GridDataItem parentItem = (GridDataItem)detailtabl.ParentItem; int jobsID = int.Parse(parentItem.GetDataKeyValue("ID").ToString()); var editableItem = ((GridEditableItem)e.Item); using (var dbContext = new OTERTConnStr()) { var curCancel = new JobCancelPrices(); Hashtable values = new Hashtable(); editableItem.ExtractValues(values); curCancel.JobsID = jobsID; curCancel.Name = (string)values["Name"]; curCancel.Price = (string)values["Price"]; dbContext.JobCancelPrices.Add(curCancel); try { dbContext.SaveChanges(); } catch (Exception) { ShowErrorMessage(-1); } } } }
protected void gridMain_UpdateCommand(object source, GridCommandEventArgs e) { if (e.Item.OwnerTableView.Name == "Master") { var editableItem = ((GridEditableItem)e.Item); var ID = (int)editableItem.GetDataKeyValue("ID"); using (var dbContext = new OTERTConnStr()) { var curJob = dbContext.Jobs.Where(n => n.ID == ID).FirstOrDefault(); if (curJob != null) { editableItem.UpdateValues(curJob); if (Session["SalesID"] != null) { SalesID = int.Parse(Session["SalesID"].ToString()); } if (SalesID > -1) { if (SalesID == 0) { curJob.SalesID = null; } else { curJob.SalesID = SalesID; } SalesID = -1; Session.Remove("SalesID"); } if (Session["JobsMainID"] != null) { JobsMainID = int.Parse(Session["JobsMainID"].ToString()); } if (JobsMainID > 0) { curJob.JobsMainID = JobsMainID; JobsMainID = -1; Session.Remove("JobsMainID"); } if (Session["JobTypesID"] != null) { JobTypesID = int.Parse(Session["JobTypesID"].ToString()); } if (JobTypesID > 0) { curJob.JobTypesID = JobTypesID; JobTypesID = -1; Session.Remove("JobTypesID"); } try { dbContext.SaveChanges(); } catch (Exception) { ShowErrorMessage(-1); } } } } else if (e.Item.OwnerTableView.Name == "FormulaDetails") { var editableItem = ((GridEditableItem)e.Item); var ID = (int)editableItem.GetDataKeyValue("ID"); using (var dbContext = new OTERTConnStr()) { var curJobFurmula = dbContext.JobFormulas.Where(n => n.ID == ID).FirstOrDefault(); if (curJobFurmula != null) { editableItem.UpdateValues(curJobFurmula); try { dbContext.SaveChanges(); } catch (Exception) { ShowErrorMessage(-1); } } } } else if (e.Item.OwnerTableView.Name == "CancelDetails") { var editableItem = ((GridEditableItem)e.Item); var ID = (int)editableItem.GetDataKeyValue("ID"); using (var dbContext = new OTERTConnStr()) { var curCancel = dbContext.JobCancelPrices.Where(n => n.ID == ID).FirstOrDefault(); if (curCancel != null) { editableItem.UpdateValues(curCancel); try { dbContext.SaveChanges(); } catch (Exception) { ShowErrorMessage(-1); } } } } }
protected void btnShow3_Click(object sender, EventArgs e) { wizardData wData = readWizardSteps(); wData.Step = 4; wData.SelectedTasks = new List <string>(); foreach (GridDataItem item in gridTasks.MasterTableView.Items) { CheckBox chk = (CheckBox)item.FindControl("chk"); string value = item.GetDataKeyValue("ID").ToString(); if (chk.Checked) { wData.SelectedTasks.Add(value); } } //Session["wizardStep"] = wData; //showWizardSteps(wData); //gridSales.Rebind(); //wizardData wData = readWizardSteps(); using (var dbContext = new OTERTConnStr()) { try { dbContext.Configuration.ProxyCreationEnabled = false; OTERT_Entity.Invoices curInvoice; curInvoice = new OTERT_Entity.Invoices(); curInvoice.CustomerID = wData.CustomerID; curInvoice.DateFrom = wData.DateFrom; curInvoice.DateTo = wData.DateTo; curInvoice.RegNo = wData.Code; curInvoice.IsLocked = wData.locked; curInvoice.DatePaid = wData.DatePayed; curInvoice.DateCreated = wData.DateCreated; TasksController tcont = new TasksController(); List <TaskB> invTasks = tcont.GetTasksForInvoice(curInvoice.CustomerID, wData.DateFrom, wData.DateTo, wData.SelectedJobs, wData.SelectedTasks); decimal totalTasksCost = 0; foreach (TaskB curTask in invTasks) { totalTasksCost += curTask.CostActual.GetValueOrDefault(); } curInvoice.TasksLineAmount = totalTasksCost; dbContext.Invoices.Add(curInvoice); dbContext.SaveChanges(); foreach (TaskB curTask in invTasks) { TasksLine newTaskLine = new TasksLine(); newTaskLine.InvoiceID = curInvoice.ID; newTaskLine.TaskID = curTask.ID; newTaskLine.JobID = curTask.JobID.GetValueOrDefault(); Tasks curTaskEntity = dbContext.Tasks.Where(s => s.ID == curTask.ID).First(); curTaskEntity.IsLocked = true; DateTime dnow = DateTime.Now; //curTaskEntity.PaymentDateActual = dnow; curTaskEntity.PaymentDateCalculated = wData.DatePayed; curTaskEntity.PaymentDateOrder = wData.DateCreated; dbContext.TasksLine.Add(newTaskLine); } dbContext.SaveChanges(); } catch (Exception) { } Response.Redirect("~/Pages/Invoices/InvoiceShow.aspx", false); } }
protected void gridMain_InsertCommand(object source, GridCommandEventArgs e) { if (e.Item.OwnerTableView.Name == "Master") { var editableItem = ((GridEditableItem)e.Item); using (var dbContext = new OTERTConnStr()) { var selCustomer = new Customers(); Hashtable values = new Hashtable(); editableItem.ExtractValues(values); if (Session["CountryID"] != null) { countryID = int.Parse(Session["CountryID"].ToString()); } if (Session["CustomerTypeID"] != null) { customerTypeID = int.Parse(Session["CustomerTypeID"].ToString()); } if (Session["LanguageID"] != null) { languageID = int.Parse(Session["LanguageID"].ToString()); } if (Session["UserID"] != null) { userID = int.Parse(Session["UserID"].ToString()); } if (countryID > 0 && customerTypeID > 0 && languageID > 0 && userID > 0) { try { selCustomer.CountryID = countryID; selCustomer.NameGR = (string)values["NameGR"]; selCustomer.NameEN = (string)values["NameEN"]; selCustomer.NamedInvoiceGR = (string)values["NamedInvoiceGR"]; selCustomer.NamedInvoiceEN = (string)values["NamedInvoiceEN"]; selCustomer.ZIPCode = (string)values["ZIPCode"]; selCustomer.CityGR = (string)values["CityGR"]; selCustomer.CityEN = (string)values["CityEN"]; selCustomer.ChargeTelephone = (string)values["ChargeTelephone"]; selCustomer.Telephone1 = (string)values["Telephone1"]; selCustomer.Telephone2 = (string)values["Telephone2"]; selCustomer.FAX1 = (string)values["FAX1"]; selCustomer.FAX2 = (string)values["FAX2"]; selCustomer.Address1GR = (string)values["Address1GR"]; selCustomer.Address1EN = (string)values["Address1EN"]; selCustomer.Address2GR = (string)values["Address2GR"]; selCustomer.Address2EN = (string)values["Address2EN"]; selCustomer.ContactPersonGR = (string)values["ContactPersonGR"]; selCustomer.ContactPersonEN = (string)values["ContactPersonEN"]; selCustomer.CustomerTypeID = customerTypeID; selCustomer.LanguageID = languageID; selCustomer.Email = (string)values["Email"]; selCustomer.URL = (string)values["URL"]; selCustomer.AFM = (string)values["AFM"]; selCustomer.DOY = (string)values["DOY"]; selCustomer.SAPCode = (string)values["SAPCode"]; selCustomer.UserID = userID; selCustomer.Comments = (string)values["Comments"]; selCustomer.IsProvider = (bool)values["IsProvider"]; selCustomer.IsPTS = (bool)values["IsPTS"]; dbContext.Customers.Add(selCustomer); dbContext.SaveChanges(); } catch (Exception) { ShowErrorMessage(-1); } finally { countryID = -1; Session.Remove("CountryID"); customerTypeID = -1; Session.Remove("CustomerTypeID"); languageID = -1; Session.Remove("LanguageID"); userID = -1; Session.Remove("UserID"); } } else { ShowErrorMessage(-1); } } } else if (e.Item.OwnerTableView.Name == "AttachedFiles") { GridTableView detailtabl = e.Item.OwnerTableView; GridDataItem parentItem = detailtabl.ParentItem; int customerID = int.Parse(parentItem.GetDataKeyValue("ID").ToString()); var editableItem = ((GridEditableItem)e.Item); using (var dbContext = new OTERTConnStr()) { var curFile = new Files(); Hashtable values = new Hashtable(); editableItem.ExtractValues(values); curFile.CustomerID = customerID; curFile.FileName = (string)values["FileName"]; curFile.FilePath = uploadedFilePath; curFile.DateStamp = DateTime.Now; dbContext.Files.Add(curFile); try { dbContext.SaveChanges(); } catch (Exception) { ShowErrorMessage(-1); } } } }