public void GetToolImage(ToolAdminModel toolAdm) { int offset = 0; TOOL_FAMILY toolfamily = new TOOL_FAMILY(); toolfamily = null; FileStream fileStream = null; byte[] photosource = null; System.IO.MemoryStream strm; try { toolfamily = (from c in DB.TOOL_FAMILY where c.FAMILY_CD == toolAdm.FAMILY_CD select c).SingleOrDefault <TOOL_FAMILY>(); if (toolfamily.IsNotNullOrEmpty()) { if (toolfamily.PICTURE != null) { photosource = toolfamily.PICTURE.ToArray(); offset = GetImageBytesFromOLEField(photosource, toolAdm); strm = new System.IO.MemoryStream(); strm.Write(photosource, offset, photosource.Length - offset); toolAdm.MimeType = getMimeFromFile(photosource); toolAdm.File_Name = System.AppDomain.CurrentDomain.BaseDirectory + "File" + toolfamily.FAMILY_CD + "." + toolAdm.FileType; if (toolAdm.FileType == "vsd") { toolAdm.DisplayFile_Name = System.AppDomain.CurrentDomain.BaseDirectory + "File" + toolfamily.FAMILY_CD + ".bmp"; } else { toolAdm.DisplayFile_Name = System.AppDomain.CurrentDomain.BaseDirectory + "File" + toolfamily.FAMILY_CD + "." + toolAdm.FileType; } //ToolAdm.File_Name = "E:\\File1.vsd"; fileStream = File.Create(toolAdm.File_Name); toolAdm.picture = strm; strm.Seek(0, SeekOrigin.Begin); strm.CopyTo(fileStream); fileStream.Close(); fileStream.Dispose(); strm.Close(); strm.Dispose(); } } } catch (System.Data.Linq.ChangeConflictException) { DB.ChangeConflicts.ResolveAll(System.Data.Linq.RefreshMode.KeepChanges); } catch (Exception ex) { throw ex.LogException(); } }
public bool UpdateToolAdmin(ToolAdminModel tooladm) { bool _status = false; tooladm.Status = ""; try { if (tooladm.Mode == OperationMode.AddNew) { TOOL_FAMILY toolf = (from o in DB.TOOL_FAMILY where o.FAMILY_CD == tooladm.FAMILY_CD select o).FirstOrDefault <TOOL_FAMILY>(); if (toolf == null) { try { toolf = new TOOL_FAMILY(); toolf.FAMILY_CD = tooladm.FAMILY_CD; toolf.FAMILY_NAME = tooladm.FAMILY_NAME; toolf.TOOL_PATH = tooladm.File_Name; if (tooladm.picture != null) { toolf.PICTURE = tooladm.picture.ToArray(); } //toolf.ENTERED_BY = userInformation.UserName; //toolf.ENTERED_DATE = userInformation.Dal.ServerDateTime; //toolf.ROWID = Guid.NewGuid(); DB.TOOL_FAMILY.InsertOnSubmit(toolf); DB.SubmitChanges(); toolf = null; tooladm.Status = PDMsg.SavedSuccessfully; } catch (System.Data.Linq.ChangeConflictException) { DB.ChangeConflicts.ResolveAll(System.Data.Linq.RefreshMode.KeepChanges); tooladm.Status = PDMsg.SavedSuccessfully; } catch (Exception ex) { ex.LogException(); DB.TOOL_FAMILY.DeleteOnSubmit(toolf); } } else if (toolf != null) { try { toolf.FAMILY_CD = tooladm.FAMILY_CD; toolf.FAMILY_NAME = tooladm.FAMILY_NAME; if (tooladm.ImageChanged == true) { toolf.TOOL_PATH = tooladm.File_Name; if (tooladm.picture != null) { toolf.PICTURE = tooladm.picture.ToArray(); } } //toolf.ENTERED_BY = userInformation.UserName; //toolf.ENTERED_DATE = userInformation.Dal.ServerDateTime; //toolf.UPDATED_BY = null; //toolf.UPDATED_DATE = null; DB.SubmitChanges(); toolf = null; tooladm.Status = PDMsg.SavedSuccessfully; } catch (System.Data.Linq.ChangeConflictException) { DB.ChangeConflicts.ResolveAll(System.Data.Linq.RefreshMode.KeepChanges); tooladm.Status = PDMsg.SavedSuccessfully; } catch (Exception ex) { ex.LogException(); DB.TOOL_FAMILY.Context.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, toolf); } } toolf = null; } else if (tooladm.Mode == OperationMode.Edit) { TOOL_FAMILY toolf = (from o in DB.TOOL_FAMILY where o.FAMILY_CD == tooladm.FAMILY_CD select o).FirstOrDefault <TOOL_FAMILY>(); if (toolf != null) { try { if (tooladm.ImageChanged == true) { toolf.FAMILY_CD = tooladm.FAMILY_CD; toolf.FAMILY_NAME = tooladm.FAMILY_NAME; toolf.TOOL_PATH = tooladm.File_Name; if (tooladm.picture != null) { toolf.PICTURE = tooladm.picture.ToArray(); } DB.SubmitChanges(); tooladm.Status = PDMsg.SavedSuccessfully; } //toolf.ENTERED_BY = userInformation.UserName; //toolf.ENTERED_DATE = userInformation.Dal.ServerDateTime; //toolf.UPDATED_BY = null; //toolf.UPDATED_DATE = null; } catch (System.Data.Linq.ChangeConflictException) { DB.ChangeConflicts.ResolveAll(System.Data.Linq.RefreshMode.KeepChanges); tooladm.Status = PDMsg.SavedSuccessfully; } catch (Exception ex) { ex.LogException(); DB.TOOL_FAMILY.Context.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, toolf); } } } foreach (DataRowView dr in tooladm.DVToolParameter) { if (dr["PARAMETER_CD"].ToString() != "") { TOOL_PARAMETER toolp = (from o in DB.TOOL_PARAMETER where o.FAMILY_CD == tooladm.FAMILY_CD && o.PARAMETER_CD == dr["PARAMETER_CD"].ToString() select o).SingleOrDefault <TOOL_PARAMETER>(); if (toolp == null) { try { toolp = new TOOL_PARAMETER(); toolp.FAMILY_CD = tooladm.FAMILY_CD; toolp.PARAMETER_CD = dr["PARAMETER_CD"].ToString(); toolp.PARAMETER_NAME = dr["PARAMETER_NAME"].ToString(); toolp.X_COORDINATE = dr["X_COORDINATE"].ToValueAsString().ToIntValue(); toolp.Y_COORDINATE = dr["Y_COORDINATE"].ToValueAsString().ToIntValue(); toolp.DATATYPE = dr["DATATYPE"].ToValueAsString().ToIntValue(); toolp.DEFAULT_VALUE = dr["DEFAULT_VALUE"].ToString(); toolp.DEFAULT_VISIBLE = dr["DEFAULT_VISIBLE"].ToValueAsString().ToIntValue(); //toolp.ENTERED_BY = userInformation.UserName; //toolp.ENTERED_DATE = userInformation.Dal.ServerDateTime; toolp.ROWID = Guid.NewGuid(); DB.TOOL_PARAMETER.InsertOnSubmit(toolp); DB.SubmitChanges(); toolp = null; //ToolAdm.Status = "Record inserted successfully."; } catch (System.Data.Linq.ChangeConflictException) { DB.ChangeConflicts.ResolveAll(System.Data.Linq.RefreshMode.KeepChanges); } catch (Exception ex) { ex.LogException(); DB.TOOL_PARAMETER.DeleteOnSubmit(toolp); } } else if (toolp != null) { try { toolp.FAMILY_CD = tooladm.FAMILY_CD; toolp.PARAMETER_CD = dr["PARAMETER_CD"].ToString(); toolp.PARAMETER_NAME = dr["PARAMETER_NAME"].ToString(); toolp.X_COORDINATE = dr["X_COORDINATE"].ToValueAsString().ToIntValue(); toolp.Y_COORDINATE = dr["Y_COORDINATE"].ToValueAsString().ToIntValue(); toolp.DATATYPE = dr["DATATYPE"].ToValueAsString().ToIntValue(); toolp.DEFAULT_VALUE = dr["DEFAULT_VALUE"].ToString(); toolp.DEFAULT_VISIBLE = dr["DEFAULT_VISIBLE"].ToValueAsString().ToIntValue(); //toolp.ENTERED_BY = userInformation.UserName; //toolp.ENTERED_DATE = userInformation.Dal.ServerDateTime; //toolp.UPDATED_BY = null; //toolp.UPDATED_DATE = null; DB.SubmitChanges(); toolp = null; //ToolAdm.Status = "Record inserted successfully."; } catch (System.Data.Linq.ChangeConflictException) { DB.ChangeConflicts.ResolveAll(System.Data.Linq.RefreshMode.KeepChanges); } catch (Exception ex) { DB.TOOL_PARAMETER.Context.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, toolp); ex.LogException(); } } toolp = null; } } DeleteParameters(tooladm.DTDeletedRecords, tooladm.FAMILY_CD); _status = true; } catch (System.Data.Linq.ChangeConflictException) { DB.ChangeConflicts.ResolveAll(System.Data.Linq.RefreshMode.KeepChanges); } catch (Exception ex) { throw ex.LogException(); } return(_status); }