public bool CheckEmptyApp(string App) { string sqlString = string.Format(@"select ApplicationName from [" + Config._DBNameFrontEnd + "].dbo.SGC_ApplicationItem where len(ltrim(Item)) = 0 or Item is null and ApplicationName = '{0}'", App); object kq = ConnectDb.ExcuteScalar(sqlString); if (kq == null || kq is DBNull) { return(false); } return(true); }
public int GetMaxNumber() { string sqlString = string.Format(@"SELECT TOP 1 CONVERT(INT, sa.ID) AS ID FROM [" + Config._DBNameFrontEnd + @"].dbo.SGC_Attachment sa ORDER BY CONVERT(INT, sa.ID) DESC "); object kq = ConnectDb.ExcuteScalar(sqlString); if (kq == null || kq is DBNull) { return(0); } return(int.Parse(Convert.ToString(kq))); }
public string GetMaxdatemodify(string appname) { string sqlString = string.Format(@"SELECT IsNull(max(dateModify),MAX(sdi.datecreated)) AS Ngay FROM [" + Config._DBNameFrontEnd + @"].dbo.SGC_DocumentIssue sdi where sdi.AppName=N'{0}' ", appname); object kq = ConnectDb.ExcuteScalar(sqlString); if (kq.ToString() == string.Empty) { return(""); } return(Convert.ToDateTime(kq).ToString("dd-MM-yy HH:mm:ss")); }
bool DeleteinDB(string AttName, string DocumentID) { string sql = string.Format(@"select Title from [" + Config._DBNameFrontEnd + "].dbo.SGC_DocumentDetail where ID = '{0}'", DocumentID); object a = ConnectDb.ExcuteScalar(sql); if (a == null || a is DBNull) { return(false); } List <string> lstString = new List <string>(); List <string> lstSql = new List <string>(); string[] lst_db = a.ToString().Split(';'); foreach (string s in lst_db) { if (s.Length > 0) { int index = s.IndexOf('-') + 1; int length = s.Length - index; if (s.Substring(index, length) == AttName) { string id = s.Substring(0, index - 1); string sqlDelete = string.Format(@"delete from [" + Config._DBNameFrontEnd + "].dbo.SGC_Attachment where ID = '{0}'", id); lstSql.Add(sqlDelete); } else { lstString.Add(s); } } } string newTitle = MakeTitle(lstString); string sqlUpdate = string.Format(@"update [" + Config._DBNameFrontEnd + "].dbo.SGC_DocumentDetail set Title = N'{0}' where ID='{1}'", newTitle, DocumentID); lstSql.Add(sqlUpdate); try { ConnectDb.ExcuteNonQuery_WithTransaction(lstSql); } catch (Exception ex) { return(false); } return(true); }
/// <summary> /// Thêm attachment /// </summary> /// <param name="s"></param> /// <param name="DocumentID"></param> /// <param name="detail"></param> /// <param name="fileName"></param> /// <param name="version"></param> /// <param name="reference"></param> /// <param name="title_Att"></param> /// <returns></returns> public bool AddNewAtt(string s, string DocumentID, string detail, string fileName, string version, string reference, string title_Att) { string sqlString_Title = string.Format(@"select Title from [" + Config._DBNameFrontEnd + "].dbo.SGC_DocumentDetail where ID= '{0}'", DocumentID); object tt = ConnectDb.ExcuteScalar(sqlString_Title); string title = ""; if (tt is DBNull || tt == null) { title_Att = ""; } else { title_Att = tt.ToString(); } int nextID = GetMaxNumber(); FileInfo fi = new FileInfo(s); byte[] b = ConvertFileToByte(fi); string attName = "@Att" + (nextID + 1).ToString(); string sqlAtt = string.Format(@"INSERT INTO [" + Config._DBNameFrontEnd + @"].dbo.SGC_Attachment ( ID, Attachment, DocumentID ) VALUES ( '{0}', " + attName + @", '{1}' )", (nextID + 1), DocumentID); SqlParameter param_Byte = new SqlParameter(attName, SqlDbType.Binary, b.Length, ParameterDirection.Input, true, 0, 0, "Attachment", DataRowVersion.Current, b); int num = GetMaxNumber(); title += (num + 1) + "-" + fileName + ";"; detail = detail.Replace("'", "''"); string sqlString = string.Format(@"UPDATE [" + Config._DBNameFrontEnd + @"].dbo.SGC_DocumentDetail SET IssueContent = N'{0}', [Version] = N'{2}', Reference = N'{3}', Title = N'{4}' WHERE ID = '{1}'", detail, DocumentID, version, reference, title_Att + title); List <string> sqlStrings = new List <string>(); sqlStrings.Add(sqlAtt); sqlStrings.Add(sqlString); List <SqlParameter> lstParam = new List <SqlParameter>(); lstParam.Add(param_Byte); try { if (ConnectDb.ExcuteNonQuery_WithTransaction(sqlStrings, lstParam) > 0) { return(true); } } catch (Exception ex) { return(false); } return(true); }