3 Temmuz 2013 Çarşamba

Download Picture as .zip file on asp.net mvc

you must download this dll -- Ionic.Zip.dll

////////////////////////////// Then we have create or picture class //////////////////////////

public class cPicture
    {
        public int CID { get; set; }
        public int AlbumID { get; set; }
        public int DosyaID { get; set; }
        public string name { get; set; }
        public double size { get; set; }
        public string type { get; set; }
        public string url { get; set; }
        public string delete_url { get; set; }
        public string thumbnail_url { get; set; }
        public string delete_type { get; set; }
        public string Tag { get; set; }
    }

///////////////// then we are creating new class ///////////////////////////////////

public class ZipResult : ActionResult
    {
        private IEnumerable<string> _files;
        private string _fileName;

        public string FileName
        {
            get
            {
                return _fileName ?? "file.zip";
            }
            set { _fileName = value; }
        }

        public ZipResult(params string[] files)
        {
            this._files = files;
        }

        public ZipResult(IEnumerable<string> files)
        {
            this._files = files;
        }

        public override void ExecuteResult(ControllerContext context)
        {
            using (ZipFile zf = new ZipFile())
            {
                zf.AddFiles(_files, false, "");
                context.HttpContext
                    .Response.ContentType = "application/zip";
                context.HttpContext
                    .Response.AppendHeader("content-disposition", "attachment; filename=" + FileName);
                zf.Save(context.HttpContext.Response.OutputStream);
            }
        }
    }

/// Now we are creating or ActionResult for download/////////////////////
public ActionResult DownloadPicture()
        {
            
                IEnumerable<cPicture> pictures = // our cPictureList
                string basePath = Server.MapPath("~/UserFiles/");
                IEnumerable<string> pp = pictures.Select(a => Path.Combine(basePath, a.name)).ToArray();

                return new ZipResult(pp);
        }


<a href="/Home/DownloadPicture/" target="_blank">Download File</a>

Yeah That's it.

27 Haziran 2013 Perşembe

Android Socket programming connection failed

if there  is connection failed on your app you must run this command from console

                    adb forward tcp:8080 tcp:8080

each of this tcp:8080 is your server port and client port number.



1 Haziran 2013 Cumartesi

DEVEXPRESS Use Cascade Combobox in İnline Edit Mode

<dx:GridViewDataComboBoxColumn FieldName="Category1ID" VisibleIndex="4">
                    <PropertiesComboBox DataSourceID="dsCategory1" TextField="Name" ValueField="ID" ValueType="System.Int32">
                    </PropertiesComboBox>
                    <EditItemTemplate>
                            <dxe:ASPxComboBox ID="Cat1" runat="server"
                            DataSourceID="dsCategory1"  TextField="Name" ValueField="ID" Value='<%# Bind("Category1ID") %>'
                            AutoPostBack="true" OnSelectedIndexChanged="Cat1_SelectedIndexChanged" ValueType="System.Int32">
                            </dxe:ASPxComboBox>
                    </EditItemTemplate>
                </dx:GridViewDataComboBoxColumn>

------------------------------------------------------------------------------------------------------------

protected void grid_HtmlRowCreated(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewTableRowEventArgs e)
        {
            if ((e.RowType == GridViewRowType.InlineEdit)) {
                ASPxComboBox combo2 = ((ASPxComboBox)grid.FindEditRowCellTemplateControl(
                    grid.Columns["Category2ID"] as GridViewDataComboBoxColumn, "Cat2"));
                if (Request.Params[combo2.UniqueID] != null) return;

                if (!grid.IsNewRowEditing) {
                    object[] vals = (object[])grid.GetRowValues(grid.EditingRowVisibleIndex,
                    new string[] { "Category2ID", "Category3ID", "Category4ID" });
                    ASPxComboBox combo4 = ((ASPxComboBox)grid.FindEditRowCellTemplateControl(
                    grid.Columns["Category4ID"] as GridViewDataComboBoxColumn, "Cat4"));
                    ASPxComboBox combo3 = ((ASPxComboBox)grid.FindEditRowCellTemplateControl(
                    grid.Columns["Category3ID"] as GridViewDataComboBoxColumn, "Cat3"));
                    combo2.Value = vals[0];
                    combo3.Value = vals[1];
                    combo4.Value = vals[2];
                }
            }
        }

31 Mayıs 2013 Cuma

DEVEXPRESS ASPxGridView PropertiesComboBox DataSource On CodeBehind

<dx:ASPxGridView ID="GridViewTRY" runat="server"  DataSourceID="SDSGridViewTRY" KeyFieldName="ID" OnInit="GridViewTRY_Init">
        <Columns>                                  
              <dx:GridViewDataComboBoxColumn FieldName="PersonalFK" Caption="Personel Adı" ShowInCustomizationForm="True" >
                      <PropertiesComboBox TextField="PersonelName" ValueField="ID"></PropertiesComboBox>
                       </dx:GridViewDataComboBoxColumn>            
          </Columns>
</dx:ASPxGridView>

                           //                        on CodeBehind             //                          

protected void GridViewTRY_Init(object sender, EventArgs e)
{
   ASPxGridView gridView = (ASPxGridView)sender;
   ((GridViewDataComboBoxColumn)(gridView.Columns["PersonelFK"])).PropertiesComboBox.DataSource = myPersonalList;
}

30 Mayıs 2013 Perşembe

pass null parameter if Selectparameter is null

<asp:SqlDataSource ID="SDStry" runat="server" CancelSelectOnNullParameter="false"
SELECTCommand="SELECT  * FROM tbFirma WHERE KisiFK=ISNULL(@KisiFK,KisiFK)">

<SelectParameters>
        <asp:Parameter Name="KisiFK" ConvertEmptyStringToNull="true" />
</SelectParameters>

</asp:SqlDataSource>

2 Mayıs 2013 Perşembe

create special Sorting with c#



public class SortByNumber : Comparer<object>
{

    public override int Compare(object x, object y)
    {

        var xParts = x.GetType().GetProperty("Code").GetValue(x, null).ToString().Split(new[] { '.' });
        var yParts = y.GetType().GetProperty("Code").GetValue(y, null).ToString().Split(new[] { '.' });

        xParts = xParts.Select((c) => { return (c == "" ? "0" : c); }).ToArray();
        yParts = yParts.Select((c) => { return (c == "" ? "0" : c); }).ToArray();

        int index = 0;
        while (true)
        {
            bool xHasValue = xParts.Length > index;
            bool yHasValue = yParts.Length > index;
            if (xHasValue && !yHasValue)
                return 1;   // x bigger
            if (!xHasValue && yHasValue)
                return -1;  // y bigger
            if (!xHasValue && !yHasValue)
                return 0;   // no more values -- same
           
            var xValue = int.Parse(xParts[index]);
            var yValue = int.Parse(yParts[index]);

            if (xValue > yValue)
                return 1;   // x bigger
            if (xValue < yValue)
                return -1;  // y bigger
            index++;
        }
    }

        }

//*******//

     
        public class ctry { public string Code{ get; set; }}
        public void tryTest()
        {
         
            List<ctry> cList = new List<ctry>();

            cList.Add(new ctry() { Code= "1.1" });
            cList.Add(new ctry() { Code = "5" });
            cList.Add(new ctry() { Code = "1.5" });
            cList.Add(new ctry() { Code = "1.2" });
            cList.Add(new ctry() { Code = "1.1.2" });
            cList.Add(new ctry() { Code = "1" });
            cList.Add(new ctry() { Code = "1.1.1" });
            cList.Add(new ctry() { Code = "1.11" });
            cList.Add(new ctry() { Code = "1.4" });
            cList.Add(new ctry() { Code = "6" });


            cList.Sort(new SortComparer ());
         
        }
         

23 Kasım 2012 Cuma

mvc de $.ajax() ile multi delete


function f_MultiDelete()
{
if ($(".chList").size() > 0) {
            var IDS = [];

            $(".chList").each(function (i) {
                if ($(this).attr('checked') == "checked" && $(this).attr('name') == "checkDelete") {
                    var ID = $(this).attr("vl");
                    IDS.push(ID);
                }
            });
            if (IDS.length > 0) {
                $.ajax({
                    type: "POST",url: Path,

                    traditional:true,
                    dataType:"json",
                    data: { 'IDList': IDS },
                    success: function (data) {
                        alert(data);
                    }
                });
            }
        }
}

<input name="checkDelete" class="chList" vl="4" type="checkbox" />
<input name="checkDelete" class="chList" vl="3" type="checkbox" />
<input name="checkDelete" class="chList" vl="2" type="checkbox" />
<input name="checkDelete" class="chList" vl="5" type="checkbox" />

<div onclick="f_MultiDelete('/Admin/AGaleri/MultiDelete/')" class="btn btn-primary">Seçilileri Sil </div>




public ActionResult MultiDelete(IEnumerable<string> IDList)
{
    //IDList parametresinden seçili ID lere ulaşabilirsiniz.
}