private int populateDb() { Log.UCTechReception.Debug("populateDb()"); int idLoan = 0; // creating a loan associated with product, accessories, doc try { // using elementAt(0) because the list is empty after creating another one VisualisationPret loan = detail.ElementAt(0); LOAN newLoan = new LOAN { LOA_USER_ID_FK = UserManager.currentUser.Id, LOA_PROVIDER = radDropDownListProvider.Text, LOA_COMM_G = tBoxObservation.Text, LOA_DATE = dateTimePicker1.Value, LOA_STATE = 0 }; VpretContext.Instance.vPretContext.LOAN.InsertOnSubmit(newLoan); VpretContext.Instance.vPretContext.SubmitChanges(); idLoan = newLoan.LOA_ID; foreach (string item in loan.l_Photo) { DOCUMENT photo = new DOCUMENT { DOC_LOA_ID_FK = idLoan, DOC_NAME = item.ToString(), }; VpretContext.Instance.vPretContext.DOCUMENT.InsertOnSubmit(photo); VpretContext.Instance.vPretContext.SubmitChanges(); } foreach (VisualisationProduct product in loan.listProducts) { PRODUCT newProduct = new PRODUCT { PRO_LOA_ID_FK = idLoan, PRO_SN = product.Sn, PRO_NAME = product.Name, PRO_COM = product.Com, PRO_STATE = 0 }; VpretContext.Instance.vPretContext.PRODUCT.InsertOnSubmit(newProduct); VpretContext.Instance.vPretContext.SubmitChanges(); foreach (VisualitationAccesories accessorie in product.listAccessories) { ACCESSORIES naccessorie = new ACCESSORIES { ACC_LOA_ID_FK = idLoan, ACC_PRO_ID_FK = newProduct.PRO_ID, ACC_NAME = accessorie.Name, ACC_PN = accessorie.Pn, ACC_COM = accessorie.Com, ACC_STATE = 0 }; VpretContext.Instance.vPretContext.ACCESSORIES.InsertOnSubmit(naccessorie); VpretContext.Instance.vPretContext.SubmitChanges(); } } } catch (Exception e) { Log.UCTechReception.Error("Population failed with exception: " + e.ToString()); } finally { Log.UCTechReception.Debug("Population completed."); } return(idLoan); }
private void radGridViewCustmerReturn_ValueChanged(object sender, EventArgs e) { DataRowView cRow = this.radGridViewCutomerReturn.CurrentRow.DataBoundItem as DataRowView; DataRow currentRow = cRow.Row; GridViewDataRowInfo rrow = this.radGridViewCutomerReturn.CurrentRow as GridViewDataRowInfo; if (radGridViewCutomerReturn.CurrentCell != null) { if (radGridViewCutomerReturn.CurrentCell.Value.Equals(0)) { try { IQueryable <LOAN> loans = (from LOAN in VpretContext.Instance.vPretContext.LOAN where LOAN.LOA_CP.Equals(currentRow["N° CP"].ToString()) select LOAN); if (loans != null) { foreach (LOAN loan in loans) { VpretContext.Instance.vPretContext.LOAN.DeleteOnSubmit(loan); VpretContext.Instance.vPretContext.SubmitChanges(); } } } catch (Exception ex) { Log.UCRP.Error("Exception SQl radGridViewRetourClient_ValueChanged : " + ex.ToString()); } finally { Log.UCRP.Debug("radGridViewRetourClient_ValueChanged - Loans deleted"); } } else if (radGridViewCutomerReturn.CurrentCell.Value.Equals(1)) { CommentDialog dialog = new CommentDialog(); dialog.StartPosition = FormStartPosition.CenterScreen; dialog.ShowDialog(); // DateTime loaDate = Convert.ToDateTime(currentRow["Date LP"].ToString()); DateTime loaDateRetour = Convert.ToDateTime(currentRow["Date retour prévue"].ToString()); try { List <LOAN> loans = (from LOAN in VpretContext.Instance.vPretContext.LOAN where LOAN.LOA_CP == currentRow["N° CP"].ToString() select LOAN).ToList(); if (loans.Count() > 0) { foreach (LOAN loan in loans) { if (loan.LOA_STATE > 1) { loan.LOA_STATE = 1; } } VpretContext.Instance.vPretContext.SubmitChanges(); } else { string commG = " "; if (dialog.Comment != "") { commG = dialog.Comment; } LOAN newLoan = new LOAN { LOA_CLIENT = currentRow["Client"].ToString(), LOA_CP = currentRow["N° CP"].ToString(), // LOA_DATE = loaDate, LOA_DATE_RETOUR = loaDateRetour, LOA_NUM_CLIENT = Int32.Parse(currentRow["N° de Client"].ToString()), LOA_STATE = 1, // 0 en cours 1 à controler 2 terminé LOA_COMM_G = commG }; VpretContext.Instance.vPretContext.LOAN.InsertOnSubmit(newLoan); VpretContext.Instance.vPretContext.SubmitChanges(); int idLoan = newLoan.LOA_ID; GridViewDataRowInfo row = this.radGridViewCutomerReturn.CurrentRow as GridViewDataRowInfo; GridViewHierarchyRowInfo hierarchyRow = row as GridViewHierarchyRowInfo; if (hierarchyRow != null) { IterateChildRowsAndAddProduct(hierarchyRow, idLoan); } } } catch (Exception ex) { Log.UCRP.Error("radGridViewRetourClient_ValueChanged() : " + ex.ToString()); } finally { Log.UCRP.Debug("radGridViewRetourClient_ValueChanged() : STATUT : PASSED"); } } } }