public void backup() { string str, str1; SqlConnection MyConn = new SqlConnection(CommonFunctions.ConStr); DBAssemblyInfo dbAss = new DBAssemblyInfo(); str = CommonFunctions.DatabaseName; // GetDatabaseName(CommonFunctions.ConStr); //string strDir = "C:\\" + dbAss.AssemblyTitle; string strDir = ObjFunction.GetAppSettings(AppSettings.O_BackUpPath); //+ dbAss.AssemblyTitle; if (Directory.Exists(strDir) == false) { Directory.CreateDirectory(strDir); } DateTime dtNow = System.DateTime.Now; string fn = strDir + "\\" + str + "_" + dtNow.ToString("dd-MMM-yy") + "_" + dtNow.Hour + "." + dtNow.Minute + ".Bak"; str1 = "BACKUP DATABASE " + str + " TO disk = '" + fn + "'"; try { SqlCommand myCommand1 = new SqlCommand(str1, MyConn); MyConn.Open(); myCommand1.ExecuteNonQuery(); OMMessageBox.Show("Back Up is successfully Completed to " + fn); } catch (Exception ex) { OMMessageBox.Show((ex.ToString())); OMMessageBox.Show("Please Select Valid Path Name"); } MyConn.Close(); MyConn = null; }
private void btnOK_Click(object sender, EventArgs e) { if (txtPath.Text != "") { if (CommonFunctions.ServerName.Replace("\\SQLEXPRESS", "") == System.Net.Dns.GetHostName()) { System.Threading.Thread tr = new System.Threading.Thread(backup); tr.Start(); } else { OMMessageBox.Show("Doesn't allow Data backup from Client side....", CommonFunctions.ErrorTitle, OMMessageBoxButton.OK, OMMessageBoxIcon.Error); } } else { OMMessageBox.Show("Please Select Valid Path Name"); } }
public void backup() { string str, str1; SqlConnection MyConn = new SqlConnection("Data Source=" + CommonFunctions.ServerName + ";Initial Catalog=Master;Integrated Security=True"); str = DBGetVal.DBName;// GetDatabaseName(CommonFunctions.ConStr); string fn = this.txtPath.Text + "\\" + str + "_" + Convert.ToDateTime(System.DateTime.Now).ToString("dd-MMM-yy") + Convert.ToDateTime(System.DateTime.Now).ToString(" hh:mm") + ".Bak"; str1 = "BACKUP DATABASE " + str + " TO disk = '" + fn + "' "; try { SqlCommand myCommand1 = new SqlCommand(str1, MyConn); MyConn.Open(); myCommand1.ExecuteNonQuery(); OMMessageBox.Show("Back Up is successfully Completed to " + fn); } catch (Exception ex) { OMMessageBox.Show((ex.ToString())); OMMessageBox.Show("Please Select Valid Path Name"); } MyConn.Close(); MyConn = null; }
public bool BarCodePrinting(long TemplateNo) { try { long PrintType; dBarCodeSetting = ObjFunction.GetDataView("Select PrinterName,ScriptData,NoOfColumn From MBarcodeTemplate Where PKSRNo=" + TemplateNo + "").Table; string strScript = dBarCodeSetting.Rows[0].ItemArray[1].ToString(); strScript = strScript.Replace("\r", ""); string[] str = new string[1]; str[0] = "\n"; // str[1] = "\""; PrintType = Convert.ToInt64(ObjFunction.GetAppSettings(AppSettings.O_BarCodePrintType)); string[] strLine = strScript.Split(str, StringSplitOptions.None); int HeaderIndex = 0; StringCollection strcollect = new StringCollection(); for (int j = 0; j < strLine.Length; j++) { if (PrintType == BarcodePrinterType.TSC) { if (strLine[j].IndexOf("CLS") >= 0) { HeaderIndex = j; break; } strcollect.Add(strLine[j]); } //else if (PrintType == BarcodePrinterType.Godex) //{ // if (strLine[j].IndexOf("Th:m:s") >= 0) // { // HeaderIndex = j; // break; // } //} //else if (PrintType == BarcodePrinterType.Argox) //{ // if (strLine[j].IndexOf("Th:m:s") >= 0) // { // HeaderIndex = j; // break; // } //} } for (int i = 0; i < barcodeprintcollection.Count; i++) { for (int j = HeaderIndex; j < strLine.Length; j++) { string rdline = strLine[j]; int pos = rdline.IndexOf("Var"); if (pos != -1) { string varName = ""; if (PrintType == BarcodePrinterType.TSC) { varName = rdline.Substring(pos + 3, (rdline.Length - 1) - (pos + 3)).Replace("\\", ""); } else if (PrintType == BarcodePrinterType.Godex) { varName = rdline.Substring(pos + 3, (rdline.Length - 1) - (pos + 2)).Replace("\\", ""); } else if (PrintType == BarcodePrinterType.Argox) { varName = rdline.Substring(pos + 3, (rdline.Length - 1) - (pos + 3)).Replace("\\", ""); } if (varName.ToLower().Equals("barcode")) { rdline = rdline.Replace("VarBarcode", barcodeprintcollection[i].VarBarCode); } else if (varName.ToLower().Equals("barcodeno")) { rdline = rdline.Replace("VarBarcodeno", barcodeprintcollection[i].VarBarCode); } else if (varName.ToLower().Equals("firmname")) { rdline = rdline.Replace("VarFirmName", barcodeprintcollection[i].VarFirmName); } else if (varName.ToLower().Equals("mrp")) { rdline = rdline.Replace("VarMRP", barcodeprintcollection[i].VarMRP); } else if (varName.ToLower().Equals("rate")) { rdline = rdline.Replace("VarRate", barcodeprintcollection[i].VarRate); } else if (varName.ToLower().Equals("weight")) { rdline = rdline.Replace("VarWeight", barcodeprintcollection[i].VarWeight); } else if (varName.ToLower().Equals("brand")) { rdline = rdline.Replace("VarBrand", barcodeprintcollection[i].VarBrand); } else if (varName.ToLower().Equals("shortdesc")) { rdline = rdline.Replace("VarShortDesc", barcodeprintcollection[i].VarBrand + " " + barcodeprintcollection[i].VarShortDesc); } else if (varName.ToLower().Equals("packeddate")) { rdline = rdline.Replace("VarPackedDate", barcodeprintcollection[i].VarPackedDate); } else if (varName.ToLower().Equals("bestbefore")) { rdline = rdline.Replace("VarBestBefore", barcodeprintcollection[i].VarBestBefore); } else if (varName.ToLower().Equals("freetext1")) { rdline = rdline.Replace("VarFreeText1", barcodeprintcollection[i].VarFreeText1); } else if (varName.ToLower().Equals("freetext2")) { rdline = rdline.Replace("VarFreeText2", barcodeprintcollection[i].VarFreeText2); } else if (varName.ToLower().Equals("freetext3")) { rdline = rdline.Replace("VarFreeText3", barcodeprintcollection[i].VarFreeText3); } else if (varName.ToLower().Equals("freetext4")) { rdline = rdline.Replace("VarFreeText4", barcodeprintcollection[i].VarFreeText4); } else if (varName.ToLower().Equals("code")) { rdline = rdline.Replace("VarCode", barcodeprintcollection[i].VarCode); } else if (rdline.ToLower().IndexOf("varprint") > -1) { double tmp = Math.Ceiling(Convert.ToDouble(Convert.ToDouble(barcodeprintcollection[i].VarQuantity) / Convert.ToInt64(dBarCodeSetting.Rows[0].ItemArray[2].ToString()))); //tmp = Math.Floor(tmp); //rdline = rdline.Replace("varPrint", barcodeprintcollection[i].VarQuantity.ToString()); rdline = rdline.Replace("VarPrint", tmp.ToString()); } } strcollect.Add(rdline); } } if (PrintType == BarcodePrinterType.TSC) { strcollect.Add(strLine[strLine.Length - 1]); } string strTemp = ""; if (PrintType == BarcodePrinterType.TSC) { TSCLIB_DLL.openport(dBarCodeSetting.Rows[0].ItemArray[0].ToString()); for (int i = 0; i < strcollect.Count; i++) { strTemp += strcollect[i].ToString() + Environment.NewLine; TSCLIB_DLL.sendcommand(strcollect[i].ToString()); } TSCLIB_DLL.closeport(); } else if (PrintType == BarcodePrinterType.Godex) { Godex_DLL.openport(dBarCodeSetting.Rows[0].ItemArray[0].ToString()); Godex_DLL.beginjob(100, 12, 4, 0, 3, 0); for (int i = 0; i < strcollect.Count; i++) { strTemp += strcollect[i].ToString() + Environment.NewLine; Godex_DLL.sendcommand(strcollect[i].ToString()); } Godex_DLL.endjob(); Godex_DLL.closeport(); } else if (PrintType == BarcodePrinterType.Argox) { int nLen, ret = 0, sw; byte[] pbuf = new byte[128]; IntPtr ver; System.Text.Encoding encAscII = System.Text.Encoding.ASCII; System.Text.Encoding encUnicode = System.Text.Encoding.Unicode; // dll version. ver = ArgoxDLL.A_Get_DLL_Version(0); // search port. nLen = ArgoxDLL.A_GetUSBBufferLen() + 1; if (nLen > 1) { byte[] buf1, buf2; int len1 = 128, len2 = 128; buf1 = new byte[len1]; buf2 = new byte[len2]; ArgoxDLL.A_EnumUSB(pbuf); ArgoxDLL.A_GetUSBDeviceInfo(1, buf1, out len1, buf2, out len2); sw = 1; if (1 == sw) { ret = ArgoxDLL.A_CreatePrn(12, encAscII.GetString(buf2, 0, len2));// open usb. } else { ret = ArgoxDLL.A_CreateUSBPort(1);// must call A_GetUSBBufferLen() function fisrt. } if (0 != ret) { } else { if (2 == sw) { //get printer status. pbuf[0] = 0x01; pbuf[1] = 0x46; pbuf[2] = 0x0D; pbuf[3] = 0x0A; ArgoxDLL.A_WriteData(1, pbuf, 4); ret = ArgoxDLL.A_ReadData(pbuf, 2, 1000); } } } if (0 != ret) { return(false); } // sample setting. ArgoxDLL.A_Set_DebugDialog(1); ArgoxDLL.A_Set_Unit('n'); ArgoxDLL.A_Set_Syssetting(1, 0, 0, 0, 0); ArgoxDLL.A_Set_Darkness(8); ArgoxDLL.A_Del_Graphic(1, "*"); // delete all picture. ArgoxDLL.A_Clear_Memory(); // clear memory. strTemp = ""; for (int i = 0; i < strcollect.Count; i++) { strTemp += strcollect[i].ToString() + Environment.NewLine; } //ArgoxDLL.A_WriteData(0, encAscII.GetBytes(strcollect[i].ToString()), strcollect[i].ToString().Length); ArgoxDLL.A_WriteData(0, encAscII.GetBytes(strTemp), strTemp.Length); // output. ArgoxDLL.A_Print_Out(1, 1, 1, 1);// copy 2. // close port. ArgoxDLL.A_ClosePrn(); } return(true); } catch (Exception e) { OMMessageBox.Show(e.Message, CommonFunctions.ErrorTitle); return(false); } }