শনিবার, ১ ফেব্রুয়ারী, ২০১৪

Gridview Code in asp.net with update And link url

  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
                        Width="100%" AllowPaging="True" DataKeyNames="VoucherNo"
                        OnPageIndexChanging="GridView1_PageIndexChanging"
                        OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating"
                        OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowDeleting="GridView1_RowDeleting" OnRowDataBound="GridView1_RowDataBound" PageSize="7" OnRowCommand="GridView1_RowCommand">
                        <Columns>
                            <asp:CommandField ShowEditButton="True" HeaderText="Edit">
                                <HeaderStyle BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Center" />
                                <ItemStyle BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" />

                            </asp:CommandField>

                            <asp:ButtonField HeaderText="View" Text="View" CommandName="VoucherNo" SortExpression="VoucherNo">
                                <HeaderStyle BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Center" Width="40px" />
                                <ItemStyle BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" />
                            </asp:ButtonField>

                            <asp:BoundField DataField="EntryDate" HeaderText="Date" ReadOnly="True" DataFormatString="{0:d}">
                                <HeaderStyle BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Center" />
                                <ItemStyle BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" Width="120px" />
                            </asp:BoundField>
                            <asp:BoundField DataField="AccountName" HeaderText="Account Name" DataFormatString="{0:0.00}" ReadOnly="True">
                                <HeaderStyle BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CssClass="HeaderStylCenter" />
                                <ItemStyle BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Left" />
                            </asp:BoundField>
                            <%--  <asp:BoundField DataField="ToAcc" HeaderText="To Account" ReadOnly="True">
                                                    <HeaderStyle BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CssClass="HeaderStylCenter"  />
                                                    <ItemStyle BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Right" />
                                                </asp:BoundField>--%>
                            <asp:BoundField DataField="DAmount" HeaderText="Debit" ReadOnly="True" DataFormatString="{0:0.00}">
                                <HeaderStyle BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CssClass="HeaderStylRight" Width="100px" />
                                <ItemStyle BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CssClass="HeaderStylRight" />
                            </asp:BoundField>
                            <asp:BoundField DataField="CAmount" HeaderText="Credit" ReadOnly="True" DataFormatString="{0:0.00}">
                                <HeaderStyle BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CssClass="HeaderStylRight" Width="100px" />
                                <ItemStyle BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CssClass="HeaderStylRight" />
                            </asp:BoundField>
                            <asp:BoundField DataField="Balance" HeaderText="Balance" ReadOnly="True" DataFormatString="{0:0.00}">
                                <HeaderStyle BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CssClass="HeaderStylRight" Width="100px" />
                                <ItemStyle BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CssClass="HeaderStylRight" />
                            </asp:BoundField>
                            <asp:BoundField DataField="Descrp" HeaderText="Comments">
                                <HeaderStyle BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Center" />
                                <ItemStyle BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" />
                            </asp:BoundField>

                        </Columns>
                    </asp:GridView>

C# code:

 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "VoucherNo")
            {
                string nov = ((GridView) e.CommandSource).DataKeys[1].Value.ToString();
                Session["nov"] = nov;
                Response.Write("<script> window.open('ViewJournalDetailsUI.aspx','_blank')</script>");
            }

        }

    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            try
            {
                GridViewRow rowIndex = GridView1.Rows[e.RowIndex];
                string vno = GridView1.DataKeys[e.RowIndex].Values["VoucherNo"].ToString();
                string comment = ((TextBox)(rowIndex.Cells[7].Controls[0])).Text;
                comment = comment.Replace("'", "''");
                if (UpdateData(vno, comment))
                {
                    Show("Updated");
                    GridView1.EditIndex = -1;
                }
                else
                {
                    Show("Error Updating");
                }
                FillGrid();

            }
            catch (Exception ex)
            {
                Show(ex.Message.ToString());
            }
        }




বুধবার, ৫ সেপ্টেম্বর, ২০১২

python parallel port on Windows


python parallel port on Windows

Tried different ways of controlling parallel port with Python on Windows. The easiest way is with Inpout32.dll.

Just download the dll, put it in system32 folder. Then from python:
from ctypes import windll
p = windll.inpout32
p.Inp32(0x378) #default 255(all high) on my pc
p.Out32(0x378, 0) #put all low on port 2-9


The address 0x378 might be different on your machine, open System->Hardware->Device Manager->Ports->ECP Printer Port->Properties->Resources, use the first number as your address. 

বুধবার, ৩০ নভেম্বর, ২০১১

Get MAC Address using C#

Add the reference System.Management and Import System.Management namespace.
Get the Mac address of all network cards in the machine 

protected void GetMACAddress()
{
    ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
    ManagementObjectCollection moc = mc.GetInstances();
    string MACAddress = "";
    foreach (ManagementObject mo in moc)
    {                
        if (mo["MacAddress"] != null)
        {                    
            MACAddress = mo["MacAddress"].ToString();
            MessageBox.Show(MACAddress);
        }                                
    } 
}
 
Get the Mac address of network card is being used in the machine
 
protected void GetMACAddress()
{ ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"); ManagementObjectCollection moc = mc.GetInstances(); string MACAddress = ""; foreach (ManagementObject mo in moc) { if (mo["MacAddress"] != null) { if ((bool)mo["IPEnabled"] == true) { MACAddress = mo["MacAddress"].ToString(); MessageBox.Show(MACAddress); } } } }

  
 Output:


Barcode Print in Crystal report WPF

Code:

  private void printBarcodebutton_Click(object sender, RoutedEventArgs e)
       {
           BarCodeCrpt pbarcode = new BarCodeCrpt();
           pbarcode.SetDataSource(SetbarcodeData());
           ReportViewer Viewer = new ReportViewer();
           Viewer.setReportSource(pbarcode);
           // frmViewer.MdiParent = mdiParent;
           Viewer.ShowDialog();
       }

  private List<Barcode> SetbarcodeData()
       {
           List<Barcode> code = new List<Barcode>();
           Barcode acode = new Barcode();
           Product secProduct = productobj;
           acode.ProductName = secProduct.ProductName;
           acode.ProductPrice = secProduct.SalesPrice;
           FileStream fs1 = new FileStream("hhhh.bmp", FileMode.Open, FileAccess.Read);
           fs1.Flush();
           BinaryReader br = new BinaryReader(fs1);
           byte[] imgbyte = new byte[fs1.Length + 1];
           imgbyte = br.ReadBytes(Convert.ToInt32((fs1.Length)));
           acode.BarcodeSt = imgbyte;
           for (int i = 0; i <9; i++)
           {
               code.Add(acode);
           }
           fs1.Close();
           return code;
       }

Create "hhhh.bmp" Code:
( Add " Neodynamic.WPF.Barcode.dll" in refarence)

private void UpdateBarcodeOnHeader()
        {
            try
            {
                if (productobj.Barcode.Length != 12)
                {
                    Microsoft.Windows.Controls.MessageBox.Show("Please enter a value to encode, thanks!");
                    return;
                }

                barcodeimage.SetValue(System.Windows.Controls.Image.SourceProperty, null);
                //Create an instance of Barcode Professional
                BarcodeProfessional bcp = new BarcodeProfessional();
                 //Barcode settings
                bcp.Symbology = Symbology.Code128;

                bcp.BarcodeUnit = BarcodeUnit.Inch;
                bcp.BarWidth = 1f / 96f;
                bcp.BarHeight = 0.5f;

                //Set the value to encode
                bcp.Code = productobj.Barcode;
                imgGet = bcp.GetBarcodeImageBinary();

                if (imgGet.Length > 0)
                {
                    FileStream fs1 = new FileStream("hhhh.bmp", FileMode.Create, FileAccess.Write);
                    fs1.Write(imgGet, 0, imgGet.Length);
                    fs1.Flush();
                    fs1.Close();
                    Bitmap bmp = new Bitmap("hhhh.bmp");
                    BitmapImage bi = new BitmapImage();
                    MemoryStream ms = new MemoryStream();
                    bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
                    bi.BeginInit();
                    ms.Seek(0, SeekOrigin.Begin);
                    bi.CacheOption = BitmapCacheOption.OnLoad;
                    bi.StreamSource = ms;
                    bi.EndInit();
                    bi.StreamSource.Dispose();
                    bmp.Dispose();
                    bmp = null;
                    ms.Dispose();
                    ms = null;
                    this.barcodeimage.Source = bi;
                }
            }
            catch (Exception ex)
            {
                log.Error(ex.ToString());
            }           
        }    

Autosuggest Textbox for WPF

In this post i will share to everyone how to make an auto suggest TextBox in wpf like GOOGLE Textbox.
For this i create a grid whose first row contains a textbox and the second row contains a Listbox. Now, when the textbox gets the focus and its text changes due to the user’s input then fill up the listbox.
Here is the XAML code

1<Grid>
2        <TextBox Height="23" HorizontalAlignment="Left" Margin="111,46,0,0" Name="txtAutoSuggestName" VerticalAlignment="Top" Width="161" PreviewKeyDown="txtAutoSuggestName_PreviewKeyDown" TextChanged="txtAutoSuggestName_TextChanged" />
3        <ListBox Height="Auto" HorizontalAlignment="Left" Margin="111,69,0,0" Name="listBoxSuggestion" VerticalAlignment="Top" Width="161" Visibility="Hidden" PreviewKeyDown="listBoxSuggestion_PreviewKeyDown" KeyDown="listBoxSuggestion_KeyDown" />
4    </Grid>

Now this is CS code for glorious effect in textbox
01private void txtAutoSuggestName_TextChanged(object sender, TextChangedEventArgs e)
02       {
03           listBoxSuggestion.Items.Clear();
04           if (txtAutoSuggestName.Text != "")
05           {
06               List<Customer> namelist = CustomerGatewayObj.listShow(txtAutoSuggestName.Text);
07               if (namelist.Count > 0)
08               {
09                   listBoxSuggestion.Visibility = Visibility.Visible;
10                   foreach (var obj in namelist)
11                   {
12                       listBoxSuggestion.Items.Add(obj.id);
13                   }
14               }
15           }
16           else
17           {
18               listBoxSuggestion.Visibility = Visibility.Hidden;
19           }
20       }
21 
22       private void txtAutoSuggestName_PreviewKeyDown(object sender, KeyEventArgs e)
23       {
24           if (e.Key == Key.Down)
25           {
26               listBoxSuggestion.Focus();
27           }
28       }
29 
30 
31       private void listBoxSuggestion_PreviewKeyDown(object sender, KeyEventArgs e)
32       {
33           if (listBoxSuggestion.SelectedIndex == 0 && e.Key == Key.Up)
34           {
35               txtAutoSuggestName.Focus();
36           }
37       }
38 
39       private void listBoxSuggestion_KeyDown(object sender, KeyEventArgs e)
40       {
41           if (listBoxSuggestion.SelectedIndex > -1)
42           {
43               if (e.Key == Key.Enter)
44               {
45                   txtAutoSuggestName.Text = listBoxSuggestion.SelectedItem.ToString();
46               }
47           }
48       }

Multi Column ComboBox in C# WPF

For my working purpose I wanna try to make a multiple column Combox Box.So i prepare myself to make this.But i fetched too many problem for this and Finally i have gotten this solution.
At first write this code in XAML file to create MultiColumn ComboBox.


<ComboBox Grid.Column="1" Height="23" HorizontalAlignment="Left" Margin="1,0,0,232" Name="cmbWHTypeId" Width="175" TabIndex="0" VerticalAlignment="Bottom">

    <ComboBox.ItemTemplate>

        <DataTemplate>

            <StackPanel Orientation="Horizontal">

                <TextBlock Text="{Binding WhtID}" Width="60"/>

                <TextBlock Text="|" Width="10"/>

                <TextBlock Text="{Binding WhtName}" Width="100" />

            </StackPanel>

        </DataTemplate>

    </ComboBox.ItemTemplate>

</ComboBox>

Then Write the following Code in CS file of  UI


cmbWHTypeId.ItemsSource = objBWhTypes.GetAllWhTypes();

Here GetAllWhTypes() is a method which returns a list collection.

public List<EWareHouseTypes>GetAllWhTypes()

{

List<EWareHouseTypes> liWhTypes = new List<EWareHouseTypes>();

 

try

{

IEBSDataContext objDataContext = new IEBSDataContext();

 

var b = from WAREHOUSE_TYPES in objDataContext.SP_WarehouseType_GetAll() select WAREHOUSE_TYPES;

foreach (var item in b)

{

EWareHouseTypes objEWhTypes = new EWareHouseTypes();

objEWhTypes.WhtID = item.WT_ID;

objEWhTypes.WhtName = item.WT_NAME;

liWhTypes.Add(objEWhTypes);

}

}

catch (Exception e)

{

 

throw e;

}

return liWhTypes;

}

EWareHouseTypes is a class and it contains two property id and name.

GET VALUE FROM COMBO BOX


EWareHouseTypes aWHType = (EWareHouseTypes)cmbWHTypeId.SelectedItem;

MessageBox.Show(aWHType.WhtID);
Manually SET INDEX for a Particular ID


string typeID="WHT01"

 

for (int i = 0; i < cmbWHTypeId.Items.Count; i++)

{

EWareHouseTypes aWHType = (EWareHouseTypes)cmbWHTypeId.Items[i];

if (aWHType.WhtID == typeID)

{

cmbWHTypeId.SelectedIndex = i;

break;
}
}

If you have any query about this topic please leave a comment.

Run Multiprogram in one click by bat file

Code:
@echo off
rem IE
cd C:\Program Files\Internet Explorer
start iexplore.exe
timeout 5
rem Notepad
cd C:\Windows
start notepad.exe
exit
...........
and save it "file_name.bat"