using Ease.Core.Model; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; using System.Reflection; using System.Text; using System.Xml; namespace HRM.BO { #region Menu Tree public class KeyStack:CollectionBase { public KeyStack() { InnerList.Clear(); } public void Add(object oItem) { InnerList.Add(oItem); } public void Remove(object oItem) { InnerList.Remove(oItem); } public object this[int i] { get{return (object)InnerList[i];} set{InnerList[i]=value;} } } public class EaseMenuItem { #region Constructor for menu item public EaseMenuItem() { _sKey=""; _sCaption=""; _sParentKey=""; _bVisible=false; } #endregion #region Key for menu item private string _sKey; public string Key { get{return _sKey;} set{_sKey=value;} } #endregion #region ParenKey for menu item private string _sParentKey; public string ParentKey { get{return _sParentKey;} set{_sParentKey=value;} } #endregion #region Visible for menu item private bool _bVisible; public bool Visible { get{return _bVisible;} set{_bVisible=value;} } #endregion #region Caption for menu item private string _sCaption; public string Caption { get{return _sCaption;} set{_sCaption=value;} } #endregion } public class EaseMenuTree:CollectionBase { private KeyStack _oKeyStack; public EaseMenuTree() { _oKeyStack=new KeyStack(); } public void Add(EaseMenuTree oMenuTree) { foreach(EaseMenuItem oMenuItem in oMenuTree) { InnerList.Add(oMenuItem); } } private string GetCurrentParent() { if(_oKeyStack.Count>0) {return (string)_oKeyStack[_oKeyStack.Count-1];} else {return null;} } private void PushParent(string sKey) { _oKeyStack.Add(sKey); } private void PopParent() { _oKeyStack.RemoveAt(_oKeyStack.Count-1); } public EaseMenuItem this[int i] { get{return (EaseMenuItem)InnerList[i];} set{InnerList[i]=value;} } private int GetIndex(string sKey) { int i; for(i=0;i 10 ) { _sPow =_sPow + " " + sPows.GetValue (_nCommaCount % 3) + " Crore "; } else _sPow =_sPow + " " + sPows.GetValue (_nCommaCount % 3) ; } if (_sTaka != "") { if (_sPow != "" ) _sPow=_sPow + " " ; } _sTaka= _sPow + _sTaka ; if (_NumStr.Length <= _nDigitCount) _NumStr=""; else _NumStr=Left(_NumStr,_NumStr.Length -_nDigitCount) ; _nCommaCount=_nCommaCount + 1 ; } //EndDo while(_NumStr != ""); } if (_sTaka != "" ) { _sTaka=" Taka " + _sTaka ; } _TakaWords=_sTaka ; if (_TakaWords != "" ) { if (_sPaisa != "" ) _TakaWords=_TakaWords + " And " ; } _TakaWords=_TakaWords + _sPaisa ; if (_TakaWords == "" ) _TakaWords="Taka Zero" ; _TakaWords = _Sign + _TakaWords + " Only" ; return _TakaWords ; } //EndofTakaWords #endregion #region Encrypt with XMLFile and Dycrypt public static void DecryptFile(string FilePath, DataSet oDataSet) { try { string line=null; string fullstring=""; StreamReader strReader=new StreamReader(FilePath); while(((line=strReader.ReadLine()) != null)) { fullstring=fullstring+line; } strReader.Close(); AES oAES=new AES(); byte [] bytIn=oAES.StringToByte(fullstring); byte [] bytPassword=oAES.StringToByte("celadmin"); //Decrypt the data byte [] bytOut=oAES.DecryptData (bytIn, bytPassword); StreamWriter oWriter=new StreamWriter(FilePath); oWriter.Write(oAES.ByteToString( bytOut)); oWriter.Flush(); oWriter.Close(); //TextReader txtReader=new StringReader(oAES.ByteToString(bytOut)); oDataSet.ReadXml(FilePath); //txtReader.Close(); } catch(Exception eh) { throw new Exception(eh.Message); } } public static void CreateCSVFile(string FilePath, System.Data.DataSet DataSet, System.Data.DataTable oTable, string GPDCName) { try { string sText=""; string sDelimiter=","; int nCount=0; long nQty=0; DateTime dTranDate=DateTime.Today; string StartKitNo=""; string EndKitNo=""; StreamWriter oWriter=new StreamWriter(FilePath); foreach(DataRow oRow in oTable.Rows) { string sKitNo=""; long nCode=0; nCount++; dTranDate=Convert.ToDateTime(oRow["TranDate"].ToString()); nQty=Convert.ToInt64( oRow["TotalQty"].ToString()); if(oRow["TranType"].ToString()=="3") { nQty=(-1)*nQty; } sKitNo=oRow["StartKitNo"].ToString(); StartKitNo=sKitNo.Substring(0,8) + oRow["KitPrefix"].ToString() + sKitNo.Substring(8,12); //+ oRow["KitSuffix"].ToString(); sKitNo=oRow["EndKitNo"].ToString(); EndKitNo=sKitNo.Substring(0,8) + oRow["KitPrefix"].ToString() + sKitNo.Substring(8,12);// + oRow["KitSuffix"].ToString(); //ERP requires only number, no padding nCode=Convert.ToInt64(oRow["Code"]); sText= oRow["TranNo"].ToString() + sDelimiter + dTranDate.ToString("dd/MM/yyyy") + sDelimiter; sText= sText + nCode.ToString() + sDelimiter + GPDCName + sDelimiter + nCount.ToString()+ sDelimiter + oRow[3].ToString()+ sDelimiter ; sText= sText + oRow["Price"].ToString() + sDelimiter + nQty.ToString() + sDelimiter + sDelimiter ; sText= sText + StartKitNo + sDelimiter + EndKitNo ; oWriter.WriteLine(sText); } oWriter.Close(); } catch(Exception err) { throw new Exception(err.Message); } } public static void CreateSCCSVFile(string FilePath, DataSet oDataSet, string GPDCName) { try { string sText=""; string sDelimiter=","; int nCount=0; long nQty=0; DateTime dTranDate=DateTime.Today; string StartKitNo=""; string EndKitNo=""; string sBatchCode=""; StreamWriter oWriter=new StreamWriter(FilePath); foreach(DataRow oRow in oDataSet.Tables[0].Rows) { long nCode=0; nCount++; dTranDate=Convert.ToDateTime(oRow["TranDate"].ToString()); nQty=Convert.ToInt64( oRow["TotalQty"].ToString()); if(oRow["TranType"].ToString()=="3") { nQty=(-1)*nQty; } sBatchCode=oRow["BatchNo"].ToString() ; StartKitNo=oRow["StartNo"].ToString() ; EndKitNo=oRow["EndNo"].ToString(); //ERP requires only number, no padding nCode=Convert.ToInt64(oRow["Code"]); sText= "SC-" + oRow["TranNo"].ToString() + sDelimiter + dTranDate.ToString("dd/MM/yyyy") + sDelimiter; sText= sText + nCode.ToString() + sDelimiter + GPDCName + sDelimiter + nCount.ToString()+ sDelimiter + oRow[3].ToString()+ sDelimiter ; sText= sText + oRow["UnitPrice"].ToString() + sDelimiter + nQty.ToString() + sDelimiter + sBatchCode + sDelimiter ; sText= sText + StartKitNo + sDelimiter + EndKitNo ; oWriter.WriteLine(sText); } oWriter.Close(); } catch(Exception err) { throw new Exception(err.Message); } } public static void CreateXMLFile(string FilePath, System.Data.DataSet Dataset, bool encrypt) { try { // Create the FileStream to write with. System.IO.FileStream myFileStream = new System.IO.FileStream (FilePath, System.IO.FileMode.Create); // Create an XmlTextWriter with the fileStream. System.Xml.XmlTextWriter myXmlWriter = new System.Xml.XmlTextWriter(myFileStream, System.Text.Encoding.Unicode); // Write to the file with the WriteXml method. Dataset.WriteXml(myXmlWriter); myXmlWriter.Close(); // if(encrypt) // { // string line=null; // string fullstring=""; // StreamReader strReader=new StreamReader(FilePath); // while(((line=strReader.ReadLine()) != null)) // { // fullstring=fullstring+line; // } // strReader.Close(); // // AES oAES=new AES(); // byte [] bytIn=oAES.StringToByte(fullstring); // byte [] bytPassword=oAES.StringToByte("celadmin"); // // //Encrypt the data // // byte [] bytOut=oAES.EncryptData(bytIn, bytPassword); // //oAES.EncryptData(bytIn, bytPassword); // //StreamWriter oWriter=new StreamWriter(FilePath); // StreamWriter oWriter=new StreamWriter("C:\\STS\\x.md"); // oWriter.Write(oAES.ByteToString( bytOut)); // oWriter.Flush(); // oWriter.Close(); // } myFileStream.Close(); } catch(Exception err) { throw new Exception(err.Message); } } #endregion #region XML File Format public static void ChangeDateFormat(DataSet oSet,string sFilePath,string sFormat,params string[] values) { string sFieldName=""; DateTime dDate; bool bInsert=false; NameTable nt = new NameTable(); XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt); //nsmgr.AddNamespace("bk", "urn:sample"); XmlParserContext context = new XmlParserContext(null, nsmgr,null, XmlSpace.None); XmlTextReader oXMLReader = new XmlTextReader(oSet.GetXml(), XmlNodeType.Element, context); XmlTextWriter oXMLWriter=new XmlTextWriter(sFilePath,Encoding.Unicode); oXMLWriter.WriteStartDocument(); try { while(oXMLReader.Read()) { switch(oXMLReader.NodeType) { case XmlNodeType.Element: oXMLWriter.WriteStartElement(oXMLReader.Name); if(oXMLReader.IsEmptyElement) oXMLWriter.WriteEndElement(); sFieldName=oXMLReader.Name; break; case XmlNodeType.Text: bInsert=false; foreach(string sField in values) { if(sFieldName.ToUpper()==sField.ToUpper()) { if(oXMLReader.Value.ToString() != "0") dDate=DateTime.Parse(oXMLReader.Value.ToString()); else dDate=DateTime.MinValue; oXMLWriter.WriteString(dDate.ToString(sFormat)); bInsert=true; break; } } if(!bInsert) { oXMLWriter.WriteString(oXMLReader.Value); } break; case XmlNodeType.EndElement: oXMLWriter.WriteEndElement(); break; } } oXMLWriter.Close(); } catch(XmlException e) { throw new Exception(e.Message); } } #endregion } #endregion #region Clone class public sealed class CloneObject { private CloneObject() { } public static void Clone(object srcObject, object destObject) { PropertyInfo[] props = (srcObject.GetType()).GetProperties(); foreach(PropertyInfo prop in props) { if(prop.CanRead) { object val = prop.GetValue(srcObject, null); if(prop.CanWrite) { prop.SetValue(destObject, val, null); } } } } } #endregion }