Quantcast
Channel: Visual C# forum
Viewing all 31927 articles
Browse latest View live

Data organizing in Settings OR Resource?

$
0
0

Data organizing in Settings OR Resource?

Hi All!

First I want to mention that I'mnew in C# language and Development world.

Second,

My little project is getting experience inCoded UI field, build an automation project.

So, I start to think about all my constant data in the tested system. I want to organize my data in a way the functions will access to Data sources. If something goes wrong, or somebody decide to change the data (like IP address), I'll just go to the Data source and change the relevant value there.

Currently, after a little research I found to type of files: App.Config and *.resx

It was made me confused aboutWHAT datato put WHERE?

My Data list includes:

1. Servers IP's.

2. Usernames and Passwords.

3. List of License files.

4. List of video files.

Is there any direction?

Thanks for the help

 

Hiddai


Reading XML Elements from behind code

$
0
0

How do I get the FirstName, LastName and OtherName on the below sample xml file? I need to assign them to a variable from behind code using C#.

<PatientRecord><Demographics><Names><cdsd:LegalName namePurpose="L"><cdsd:FirstName><cdsd:Part>SARAH</cdsd:Part><cdsd:PartType>GIV</cdsd:PartType></cdsd:FirstName><cdsd:LastName><cdsd:Part>GOMEZ</cdsd:Part><cdsd:PartType>FAMC</cdsd:PartType></cdsd:LastName><cdsd:OtherName><cdsd:Part>GABRIELA</cdsd:Part><cdsd:PartType>GIV</cdsd:PartType><cdsd:PartQualifier>BR</PartQualifier>            

C# How to stop executing the current method, break? return? or some other?

$
0
0

My English level is really...bad...If there's something make you confused, plz tell me and I will give much more details.

First of all, this is my code(s)

protected void btnPeopleCount_Click(object sender, EventArgs e)
        {
            SetBookingInfoTable(GetPeopleCount());
        }


private int GetPeopleCount()
        {
            int intPeopleCount = 0;
            try
            {
                intPeopleCount = Int32.Parse(txtPeopleCount.Text);
            }
            catch (Exception)
            {
                lblPeopleCountTip.BackColor = System.Drawing.Color.Red;
                lblPeopleCountTip.ForeColor = System.Drawing.Color.White;
                txtPeopleCount.Text = "";
                return 0;
            }

            return intPeopleCount;
        }

I need that when GetPeopleCount() catches any error, the program would finish the catch (exception) code(s)

and then

stop running any code(stop from running SetBookingInfoTable()).

like the below image, when i input an integer number in that box and press the button near to it, the GetPeopleCount start to execute. If the input value is not an integer, GetPeopleCount stops running and SetBookingInfoTable won't run, neither.

For now, I use return 0 and then use IF to make a choice whether intPeopleCount is bigger than 0 or not.

It did could reach my goal, but I just want to learn

HOW TO STOP EXECUTING THE CODE......

Thanks for help.


C# code snippet to write string Index of functionality

$
0
0

Hi Team,

I have below code snippet using which i can find number of occurances of a given substring in a string.
I used IndexOf built in method which returns position of substring or else -1 taking two arguments substring and starting position.
Can you help me sharing code snippet, which exactly does the same thing as IndexOf.

            string text = "My kumar name is kumar and kumar";
            string value = "ar";

            int count = 0, minIndex = text.IndexOf(value, 0);
            while (minIndex != -1)
            {
               
                minIndex = text.IndexOf(value, minIndex + value.Length);
                count++;
            }
            Console.WriteLine(count);

Thanks,

How remove xsi:nil="true" from List Item & Add Attributes to list item ( SOAP Webservice )

$
0
0
using System;
using System.Data;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Web.Services.Description;
using System.Web.Services.Protocols;
using System.Xml.Serialization;
using System.Collections;

/// <summary>
/// Summary description for tbs_service
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class abc : System.Web.Services.WebService
{
[WebMethod]
    [SoapDocumentMethod("xxx", RequestNamespace = "xxx", ResponseNamespace = "xxx", Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
    public querySeat_Main querySeat([XmlAttribute] string signature, string operator_code, string route_id, string trip_no, string depart_date, string counter_from, string counter_to, string bus_type)
    {
        querySeat_Main main = new querySeat_Main();
        querySeat_status status = new querySeat_status();
        querySeat_status.detail detail = new querySeat_status.detail();
        status.code = 0;
        status.msg = "success";
        main.querySeat_status = status;
        return main;
    }
}

[Serializable]
[GeneratedCode("System.Xml", "4.0.30319.33440")]
[XmlType(Namespace = "https://www.busonlineticket.com/tbs")]
[DebuggerStepThrough]
[DesignerCategory("code")]
public class querySeat_Main
{
    querySeat_status status;
    public querySeat_Main()
    {

    }
    public querySeat_status querySeat_status { get { return status; } set { status = value; } }
}

[Serializable]
[GeneratedCode("System.Xml", "xxx")]
[XmlType(Namespace = "xxx")]
[DebuggerStepThrough]
[DesignerCategory("code")]
[XmlRoot("querySeat_status", Namespace = "xxx")]
public class querySeat_status
{
    int Code;
    string Msg;

    public querySeat_status() { }

    [XmlAttribute]
    public int code { get { return Code; } set { Code = value; } }
    [XmlAttribute]
    public string msg { get { return Msg; } set { Msg = value; } }



    [XmlArray("details")]
    [XmlArrayItem("detail")]
    public List<detail> details = new List<detail>();

    [Serializable]
    [GeneratedCode("System.Xml", "xxx")]
    [DebuggerStepThrough]
    [DesignerCategory("code")]
    [XmlRoot("querySeat_status", Namespace = "xxx")]
    public class detail
    {
        string seat;
        string avail;
        public detail() { }

        [XmlAttribute]
        public string seat_no { get { return seat; } set { seat = value; } }
        [XmlAttribute]
        public string available { get { return avail; } set { avail = value; } }
    }
}

I am getting following Output :

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><querySeatResponse xmlns="xxx"><querySeatResult><querySeat_status code="int" msg="string"><details><detail xsi:nil="true" /><detail xsi:nil="true" /></details></querySeat_status></querySeatResult></querySeatResponse></soap:Body></soap:Envelope>

But I need in the following output

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><querySeatResponse xmlns="xxx"><querySeatResult><querySeat_status code="int" msg="string"><details><detail seat_no=”string” available=”string” /><detail seat_no=”string” available=”string” /></details></querySeat_status></querySeatResult></querySeatResponse></soap:Body></soap:Envelope>

How to write this fake program and make it actually work?

$
0
0
var lining = File.ReadAllLines(@"C:\file.txt");    // file.txt = 1024 lines long
for (int i = 0; i < 1025; i++) {
lining[i] = "Array: " + i * 2;
}
File.WriteAllLines(@"C:\file.txt", lining);
The code speaks for itself of what I'm trying to achieve, but I don't know how, could you help me?

Program freezes after exception -- how to continue program execution

$
0
0

In the following sample program (running in winform vs2012) I am retrieving data from an httpclient and using IAsynResult - asyncronous operation.  I need to loop through a list of parameters that I pass to the Demo procedure (below) for creating the url.  Some parameters are valid and some parameters are invalid.  The invalid params cause an exception, and the program freezes.  The error message is

The remote server returned an error: (404) Not Found.

The error occurs at the HttpWebResponse line.  When the code execution is in the Demo Procedure -- when the code reaches allDone.WaitOne(); the code goes to the procedure

private static void RespCallback(IAsyncResult asynchronousResult)

The line where the code bombs out is

myRequestState.response = (HttpWebResponse)myHttpWebRequest2.EndGetResponse(asynchronousResult);

I want to know if there is a way I can continue program execution -- prevent the program from freezing on invalid parameters.  Maybe I should use different coding altogether?  How can I check for this exception and bypass the call to HttpWebResponse if there is evidence of an exception?

using System;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows;
using System.Net;
using System.IO;
using System.Threading;

namespace mySampleProject
{
    public partial class Form6 : Form
    {
        private void button1_Click(object sender, EventArgs e)
        {
            StartDemo();
        }

        public static ManualResetEvent allDone = new ManualResetEvent(false);
        const int BUFFER_SIZE = 1024;

        public static string strContent;

        public void StartDemo()
        {
            string myStringContent;
            DateTime dStart = new DateTime(2014, 1, 1);
            DateTime d1;

            EF1_DBContext db1 = new EF1_DBContext();

            string s1, s2, s3, s4;

            int daysCount = 10;
            d1 = dStart.AddDays(daysCount);
            string format = "yyyy-MM-dd";

            var query = from b in db1.MasterParameterCodes
                        select b;

            foreach (var item in query.ToList())
            {
                strContent = "";
                myStringContent = "";
                s1 = "ca";
                s2 = dStart.ToString(format);
                s3 = d1.ToString(format);
                s4 = item.ParameterCode.ToString();

                try
                {
                    Demo(s1, s2, s3, s4);
                    myStringContent = strContent;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }

        public static void Demo(string s1, string s2, string s3, string s4)
        {
            try
            {
                string s_url = "http://" + s1 + "&startDT=" + s2 + "&endDT=" + s3 + "&parameterCd=" + s4;
                System.Uri uri = new Uri(s_url);

                // Create a HttpWebrequest object to the desired URL.
                HttpWebRequest myHttpWebRequest1 = (HttpWebRequest)WebRequest.Create(uri);

                // Create an instance of the RequestState and assign the previous myHttpWebRequest1
                // object to it's request field.
                RequestState myRequestState = new RequestState();
                myRequestState.request = myHttpWebRequest1;

                // Start the asynchronous request.
                IAsyncResult result = (IAsyncResult)myHttpWebRequest1.BeginGetResponse(new AsyncCallback(RespCallback), myRequestState);

                allDone.WaitOne();

                // Release the HttpWebResponse resource.
                myRequestState.response.Close();
            }
            catch (WebException e)
            {
                Console.WriteLine("Problem at Demo");
                Console.WriteLine(e.Message);
            }
        }

        private static void RespCallback(IAsyncResult asynchronousResult)
        {
            try
            {
                // State of request is asynchronous.
                RequestState myRequestState = (RequestState)asynchronousResult.AsyncState;
                HttpWebRequest myHttpWebRequest2 = myRequestState.request;

		//--code execution bombs out at this line here
                myRequestState.response = (HttpWebResponse)myHttpWebRequest2.EndGetResponse(asynchronousResult);

                // Read the response into a Stream object.
                Stream responseStream = myRequestState.response.GetResponseStream();
                myRequestState.streamResponse = responseStream;

                // Begin the Reading of the contents of the HTML page and print it to the console.
                IAsyncResult asynchronousInputRead = responseStream.BeginRead(myRequestState.BufferRead, 0, BUFFER_SIZE, new AsyncCallback(ReadCallBack), myRequestState);
            }
            catch (WebException e)
            {
                Console.WriteLine("Problem at RespCallback");
                Console.WriteLine(e.Message);
            }
        }

        private static void ReadCallBack(IAsyncResult asyncResult)
        {
            try
            {
                RequestState myRequestState = (RequestState)asyncResult.AsyncState;
                Stream responseStream = myRequestState.streamResponse;
                int read = responseStream.EndRead(asyncResult);

                // Read the HTML page and then do something with it
                if (read > 0)
                {
                    myRequestState.requestData.Append(Encoding.UTF8.GetString(myRequestState.BufferRead, 0, read));
                    IAsyncResult asynchronousResult = responseStream.BeginRead(myRequestState.BufferRead, 0, BUFFER_SIZE, new AsyncCallback(ReadCallBack), myRequestState);
                }
                else
                {
                    if (myRequestState.requestData.Length > 1)
                    {
                        //string stringContent;
                        //stringContent = myRequestState.requestData.ToString();
                        strContent = myRequestState.requestData.ToString();
                        // do something with the response stream here
                        //Console.WriteLine(stringContent);
                    }

                    responseStream.Close();
                    allDone.Set();
                }
            }
            catch (WebException e)
            {
                Console.WriteLine("problem at ReadCallBack");
                Console.WriteLine(e.Message);
            }
        }
    }

    public class RequestState
    {
        // This class stores the State of the request.
        const int BUFFER_SIZE = 1024;
        public StringBuilder requestData;
        public byte[] BufferRead;
        public HttpWebRequest request;
        public HttpWebResponse response;
        public Stream streamResponse;

        public RequestState()
        {
            BufferRead = new byte[BUFFER_SIZE];
            requestData = new StringBuilder("");
            request = null;
            streamResponse = null;
        }
    }
}


Rich P


The Performance of ReportViewer

$
0
0

Hi,

My application seems to have a critical loss of the performance of reportviewer depends on the device the application is executed.

While I debugged the application on my computer which had installed visual studio, there weren't any problems with reportviewer. However, if the application is executed on the computer that has not installed any visual studio, it obviously slows down while it loads data.

on the computer that has installed visual studio, it just takes few seconds to load about 100 data.

On the other hand, it took more than 10 seconds to load the same data when I attempted on the computer which had not installed visual studio.

I dont  even know if  I am right or not, but I assume dlls are the cause of this problem, so I'll list up the dlls I copied on local to operate the reportviewer functions below.

・Microsoft.ReportViewer.Common.dll

・Microsoft.ReportViewer.ProcessingObjectModel.DLL

・Microsoft.ReportViewer.WinForms.dll

・Microsoft.SqlServer.Types.dll

I have no idea if the loss of the persformance is related to dll that I should have put in the same directory as the exe file. 

If you know any ways to solve this, please let me know.

any help appreciated.

thanks.



Changing fields to properties

$
0
0

I want to change 3 private fields to properties.

How could I change?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TiodSensorManagement
{
    class SensorFile : ISensorType
    {
        private int sensortype;
        private string LocalFolder;
        private string SensorFileName;
        void ISensorType.WriteSensorType(int sensortype, string LocalFolder, string SensorFileName)
        {
            this.sensortype = sensortype;
            this.LocalFolder = LocalFolder;
            this.SensorFileName = SensorFileName;

            TiodConfig.WriteIniString("Sensor Type", "Type", this.sensortype.ToString(), this.LocalFolder + "\\" + this.SensorFileName + "\\" + this.SensorFileName + ".bin");
        }
    }
}


How to make file excel file as downloadable in ASP.NET?

$
0
0

Hello Friends...
i have created excel file using C# at server side using following code.

 protected void btnexport_Click(object sender, EventArgs e)
        {

            Excel.Application excelApp = new Excel.Application();
            excelApp.Workbooks.Add();
            Excel._Worksheet workSheet = excelApp.ActiveSheet;
            //string FilePath = @"C:\Mori-2014\Report\DailyReport.xls";
            string FilePath = @"C:\Mori-2014\Mori-2014\Reports\DailyReport.xls";
            Excel.Range rng1, rng2, range3,rng4,rng5,rng6,rng7;

            SqlConnection ObjConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ToString());
            SqlCommand ObjCommand = new SqlCommand("spgetproduction", ObjConnection);
            ObjConnection.Open();
            ObjCommand.CommandType = CommandType.StoredProcedure;
            ObjCommand.Parameters.AddWithValue("@date", Convert.ToDateTime(txtdate1.Text));
            DataSet ds = new DataSet();
            SqlDataAdapter adt = new SqlDataAdapter();
            adt.SelectCommand = ObjCommand;
            adt.Fill(ds);
            workSheet.get_Range("A1", "H1").Merge(true);
            workSheet.get_Range("A1:L1").RowHeight = 39;
            workSheet.get_Range("A1:L1").EntireRow.VerticalAlignment = 2;
            workSheet.get_Range("A1:L1").EntireRow.HorizontalAlignment = 3;
            workSheet.get_Range("A1:L1").EntireRow.Font.Size = 26;
            workSheet.get_Range("A2:L51").EntireRow.Font.Size = 16;
            //workSheet.get_Range("I13:J17").EntireRow.Font.Size = 14;
            //workSheet.get_Range("K29:K32").EntireRow.Font.Size = 14;
            rng1 = workSheet.get_Range("B1", "D1").EntireColumn;
            rng1.HorizontalAlignment = 3;

            workSheet.Cells[1, 1] = "DAILY OPERATING REPORT - HINDALCO MURI";
            //workSheet.get_Range("A1", "D1").Font.Bold = true;
            //workSheet.get_Range("A2", "D2").Font.Bold = true;

            //-------- Logo Image ------------

            workSheet.Shapes.AddPicture(@"C:\Mori-2014\Mori-2014\Image\muri.png", Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, 0, 0, 57, 38);
            rng2 = workSheet.get_Range("F1", "H1").EntireColumn;
            rng2.HorizontalAlignment = 3;


            //--------- Date Part --------------------
            workSheet.Cells[1, 9] = String.Format("{0:dd-MMM-yyyy}", Convert.ToDateTime(txtdate1.Text));
            workSheet.get_Range("I1", "L1").Merge(true);

            // ---------Production ------------
            workSheet.Cells[2, 1] = "Production (MT)";
            workSheet.Cells[2, 2] = "Today";
            workSheet.Cells[2, 3] = "Avg.";
            workSheet.Cells[2, 4] = "Todate";

            for (int r = 0; r < ds.Tables[0].Rows.Count; r++)
            {
                for (int c = 0; c < ds.Tables[0].Columns.Count; c++)
                {
                    workSheet.Cells[r+3, c+1] = ds.Tables[0].Rows[r][c].ToString();
                }
            }

            //--------------- Efficiencies -----------
            ds = null; adt = null;
            ObjCommand = new SqlCommand();
            ObjCommand.CommandText = "spgetefficiencies";
            ObjCommand.CommandType = CommandType.StoredProcedure;
            ObjCommand.Connection = ObjConnection;
            ObjCommand.Parameters.AddWithValue("@date", Convert.ToDateTime(txtdate1.Text));
            ds = new DataSet();
            adt = new SqlDataAdapter();
            adt.SelectCommand = ObjCommand;
            adt.Fill(ds);

            workSheet.get_Range("A6", "D6").Merge(true);
            workSheet.get_Range("A7", "D7").Font.Bold = true;
            workSheet.Cells[7, 1] = "Efficiencies";
            workSheet.Cells[7, 2] = "Target";
            workSheet.Cells[7, 3] = "Today";
            workSheet.Cells[7, 4] = "Avg.(Todate)";

            for (int r = 0; r < ds.Tables[0].Rows.Count; r++)
            {
                for (int c = 0; c < ds.Tables[0].Columns.Count; c++)
                {
                    workSheet.Cells[r + 8, c + 1] = ds.Tables[0].Rows[r][c].ToString();
                }
            }


            // -------- Consumption Factors --------------
            ds = null; adt = null;
            ObjCommand = new SqlCommand();
            ObjCommand.CommandText = "spgetconsumptionfactors";
            ObjCommand.CommandType = CommandType.StoredProcedure;
            ObjCommand.Connection = ObjConnection;
            ObjCommand.Parameters.AddWithValue("@date", Convert.ToDateTime(txtdate1.Text));
            ds = new DataSet();
            adt = new SqlDataAdapter();
            adt.SelectCommand = ObjCommand;
            adt.Fill(ds);
            workSheet.get_Range("A20", "D20").Merge(true);
            workSheet.get_Range("A21", "D21").Font.Bold = true;
            workSheet.Cells[21, 1] = "Consumption Factors";
            workSheet.Cells[21, 2] = "Target";
            workSheet.Cells[21, 3] = "Today";
            workSheet.Cells[21, 4] = "Avg.(Todate)";

            for (int r = 0; r < ds.Tables[0].Rows.Count; r++)
            {
                for (int c = 0; c < ds.Tables[0].Columns.Count; c++)
                {
                    workSheet.Cells[r + 22, c + 1] = ds.Tables[0].Rows[r][c].ToString();
                }
            }

            // ---------- Stock ----------------
            workSheet.get_Range("A30", "D30").Merge(true);
            ds = null; adt = null;
            ObjCommand = new SqlCommand();
            ObjCommand.CommandText = "spgetstock";
            ObjCommand.CommandType = CommandType.StoredProcedure;
            ObjCommand.Connection = ObjConnection;
            ObjCommand.Parameters.AddWithValue("@date", Convert.ToDateTime(txtdate1.Text));
            ds = new DataSet();
            adt = new SqlDataAdapter();
            adt.SelectCommand = ObjCommand;
            adt.Fill(ds);

            workSheet.Cells[31, 1] = "Stock";
            workSheet.Cells[31, 3] = "Todate";
            workSheet.get_Range("A31", "B31").Merge(true);
            workSheet.get_Range("C31", "D31").Merge(true);
            for (int r = 0; r < ds.Tables[0].Rows.Count; r++)
            {
                for (int c = 0; c < ds.Tables[0].Columns.Count; c++)
                {
                    workSheet.Cells[r + 32, c + 1] = ds.Tables[0].Rows[r][0].ToString();
                }
            }
            workSheet.get_Range("B32", "B41").Clear();
            for (int r = 0; r < ds.Tables[0].Rows.Count; r++)
            {
                for (int c = 0; c < ds.Tables[0].Columns.Count; c++)
                {
                    workSheet.Cells[r + 32, c + 3] = ds.Tables[0].Rows[r][1].ToString();
                }
            }
            workSheet.get_Range("D32", "D41").Clear();
            workSheet.get_Range("A32", "B41").Merge(true);
            workSheet.get_Range("C32", "D41").Merge(true);
            workSheet.get_Range("A31", "D31").Font.Bold = true;

            // ---------- PDS Slurry ----------------
            workSheet.get_Range("A42", "D42").Merge(true);
            ds = null; adt = null;
            ObjCommand = new SqlCommand();
            ObjCommand.CommandText = "spgetpdsslurry";
            ObjCommand.CommandType = CommandType.StoredProcedure;
            ObjCommand.Connection = ObjConnection;
            ObjCommand.Parameters.AddWithValue("@date", Convert.ToDateTime(txtdate1.Text));
            ds = new DataSet();
            adt = new SqlDataAdapter();
            adt.SelectCommand = ObjCommand;
            adt.Fill(ds);
            workSheet.Cells[43, 1] = "Reasons(s) for Flow Cut:";
            workSheet.Cells[43, 2] = "Normal Flow";
            workSheet.get_Range("B43", "C43").Merge(true);
            workSheet.Cells[43, 4] = "Today's Flow";
            workSheet.get_Range("A43", "D43").Font.Bold = true;
            if (ds.Tables[0].Rows.Count > 0)
            {
                workSheet.Cells[44, 1] = ds.Tables[0].Rows[0][0].ToString();
                workSheet.Cells[44, 2] = ds.Tables[0].Rows[0][1].ToString();
                workSheet.get_Range("B44", "C44").Merge(true);
                workSheet.Cells[44, 4] = ds.Tables[0].Rows[0][2].ToString();
            }
            workSheet.Cells[45, 1] = "Reasons(s) for Flow Cut:";
            workSheet.get_Range("A45", "D47").Font.Bold = true;
            workSheet.get_Range("A45:D47").VerticalAlignment = 1;
            workSheet.get_Range("A45:D47").Merge();


            workSheet.Cells[48, 1] = "Note: Daily basis declared production,efficiencies,receipt and dispatch numbers are only tentative. It can be verified with month-end physical inventory.";
            workSheet.get_Range("A48:D49").Merge();
            workSheet.get_Range("A48:D49").VerticalAlignment = 1;
            workSheet.get_Range("A48:D49").WrapText = true;
            workSheet.get_Range("A48:D49").Font.Bold = true;
            workSheet.get_Range("A48:D49").Font.Size = 14;

            //-------------Rain Fall------------------
            ds = null; adt = null;
            ObjCommand = new SqlCommand();
            ObjCommand.CommandText = "spgetrainfall";
            ObjCommand.CommandType = CommandType.StoredProcedure;
            ObjCommand.Connection = ObjConnection;
            ObjCommand.Parameters.AddWithValue("@date", Convert.ToDateTime(txtdate1.Text));
            ds = new DataSet();
            adt = new SqlDataAdapter();
            adt.SelectCommand = ObjCommand;
            adt.Fill(ds);

            workSheet.Cells[50, 1] = "Rain Fall (mm)";
            workSheet.get_Range("A50:B51").Merge();
            workSheet.get_Range("A50:B51").VerticalAlignment = 2;
            workSheet.get_Range("A50:B51").HorizontalAlignment = 3;
            workSheet.get_Range("A50:B51").Font.Bold = true;
            workSheet.Cells[50, 3] = "Today";
            workSheet.Cells[50, 4] = "Todate";
            workSheet.Cells[51, 3] = ds.Tables[0].Rows[0][1].ToString();
            workSheet.Cells[51, 4] = ds.Tables[0].Rows[0][2].ToString();
            workSheet.get_Range("C50", "D50").Font.Bold = true;



            //-------P & B Target for Hydrate--------
            workSheet.Cells[2, 5] = "P & B Target for Hydrate(MT)";
            workSheet.get_Range("E2", "G2").Merge();
            workSheet.get_Range("E2", "G2").HorizontalAlignment = 3;
            workSheet.get_Range("E2", "G2").VerticalAlignment = 2;
            workSheet.get_Range("E2", "H2").Font.Bold = true;
            workSheet.Cells[2, 8] = "29000";

            workSheet.Cells[3, 5] = "Revised target for Hydrate(MT)";
            workSheet.get_Range("E3","G3").Merge();
            workSheet.get_Range("E3", "G3").HorizontalAlignment = 3;
            workSheet.get_Range("E3", "G3").VerticalAlignment = 2;
            workSheet.Cells[3, 8] = "29000";
            //---------- Bauxite Quality ------------
            workSheet.get_Range("E4", "H4").Merge(true);
            workSheet.Cells[5, 5] = "Bauxite Quality (%)";
            workSheet.Cells[5, 6] = "Target";
            workSheet.Cells[5, 7] = "Today";
            workSheet.Cells[5, 8] = "Avg.(todate)";
            workSheet.get_Range("E5", "H5").Font.Bold = true;

            ds = null; adt = null;
            ObjCommand = new SqlCommand();
            ObjCommand.CommandText = "spgetbauxitequality";
            ObjCommand.CommandType = CommandType.StoredProcedure;
            ObjCommand.Connection = ObjConnection;
            ObjCommand.Parameters.AddWithValue("@date", Convert.ToDateTime(txtdate1.Text));
            ds = new DataSet();
            adt = new SqlDataAdapter();
            adt.SelectCommand = ObjCommand;
            adt.Fill(ds);

            for (int r = 0; r < ds.Tables[0].Rows.Count; r++)
            {
                for (int c = 0; c < ds.Tables[0].Columns.Count; c++)
                {
                    workSheet.Cells[r + 6, c + 5] = ds.Tables[0].Rows[r][c].ToString();
                }
            }

            //-------------- Loss Times ------------
            workSheet.get_Range("E11", "H11").Merge(true);
            workSheet.Cells[12, 5] = "Loss Times(Hrs)";
            workSheet.get_Range("E12", "F12").Merge();
            workSheet.Cells[12, 7] = "Today";
            workSheet.Cells[12, 8] = "ToDate";
            workSheet.get_Range("E12", "H12").Font.Bold = true;

            ds = null; adt = null;
            ObjCommand = new SqlCommand();
            ObjCommand.CommandText = "spgetlosstimes";
            ObjCommand.CommandType = CommandType.StoredProcedure;
            ObjCommand.Connection = ObjConnection;
            ObjCommand.Parameters.AddWithValue("@date", Convert.ToDateTime(txtdate1.Text));
            ds = new DataSet();
            adt = new SqlDataAdapter();
            adt.SelectCommand = ObjCommand;
            adt.Fill(ds);

            for (int r = 0; r < ds.Tables[0].Rows.Count; r++)
            {
                for (int c = 0; c < ds.Tables[0].Columns.Count; c++)
                {
                    workSheet.Cells[r + 13, c + 5] = ds.Tables[0].Rows[r][0].ToString();
                }
            }

            workSheet.get_Range("F13", "F17").Clear();
            workSheet.get_Range("E13","F17").Merge(true);
            for (int r = 0; r < ds.Tables[0].Rows.Count; r++)
            {
                for (int c = 0; c < ds.Tables[0].Columns.Count; c++)
                {
                    workSheet.Cells[r + 13, c + 7] = ds.Tables[0].Rows[r][1].ToString();
                }
            }

            for (int r = 0; r < ds.Tables[0].Rows.Count; r++)
            {
                for (int c = 0; c < ds.Tables[0].Columns.Count; c++)
                {
                    workSheet.Cells[r + 13, c + 8] = ds.Tables[0].Rows[r][2].ToString();
                }
            }
            workSheet.get_Range("I13:I17").Clear();
            workSheet.get_Range("J13:J17").Clear();

            //----------Operating Flows -----------
            workSheet.get_Range("E18", "H18").Merge(true);
            ds = null; adt = null;
            ObjCommand = new SqlCommand();
            ObjCommand.CommandText = "spgetoperatingflows";
            ObjCommand.CommandType = CommandType.StoredProcedure;
            ObjCommand.Connection = ObjConnection;
            ObjCommand.Parameters.AddWithValue("@date", Convert.ToDateTime(txtdate1.Text));
            ds = new DataSet();
            adt = new SqlDataAdapter();
            adt.SelectCommand = ObjCommand;
            adt.Fill(ds);

            workSheet.Cells[19, 5] = "Operating Flows";
            workSheet.Cells[19, 6] = "Target";
            workSheet.Cells[19, 7] = "Today";
            workSheet.Cells[19, 8] = "Avg.(Todate)";

            for (int r = 0; r < ds.Tables[0].Rows.Count; r++)
            {
                for (int c = 0; c < ds.Tables[0].Columns.Count; c++)
                {
                    workSheet.Cells[r + 20, c + 5] = ds.Tables[0].Rows[r][c].ToString();
                }
            }

           workSheet.get_Range("E19", "H19").Font.Bold = true;
           workSheet.get_Range("E27").Clear();

            //-------------CGPP Report -----------
            workSheet.get_Range("E27", "H27").Merge(true);
            workSheet.Cells[28, 5] = "CGPP Report";
            workSheet.Cells[28, 6] = "Target";
            workSheet.Cells[28, 7] = "Today";
            workSheet.Cells[28, 8] = "Avg.(Todate)";
            workSheet.get_Range("E28", "H28").Font.Bold = true;
            workSheet.get_Range("F28", "H28").HorizontalAlignment = 3;

            ds = null; adt = null;
            ObjCommand = new SqlCommand();
            ObjCommand.CommandText = "spgetcgpp";
            ObjCommand.CommandType = CommandType.StoredProcedure;
            ObjCommand.Connection = ObjConnection;
            ObjCommand.Parameters.AddWithValue("@date", Convert.ToDateTime(txtdate1.Text));
            ds = new DataSet();
            adt = new SqlDataAdapter();
            adt.SelectCommand = ObjCommand;
            adt.Fill(ds);

            for (int r = 0; r < ds.Tables[0].Rows.Count; r++)
            {
                for (int c = 0; c < ds.Tables[0].Columns.Count; c++)
                {
                    workSheet.Cells[r + 29, c + 5] = ds.Tables[0].Rows[r][c].ToString();
                }
            }

            ////----------Process Steam Consumption---------
            //workSheet.get_Range("E33", "H33").Merge(true);
            workSheet.Cells[33, 5] = "Process Steam Consumption (TPH)";
            workSheet.get_Range("E33", "F33").Merge();
            workSheet.get_Range("E33", "H33").Font.Bold = true;
            workSheet.Cells[33, 7] = "Today";
            workSheet.Cells[33, 8] = "Avg.(Todate)";

            ds = null; adt = null;
            ObjCommand = new SqlCommand();
            ObjCommand.CommandText = "spgetprocesssteamconsumption";
            ObjCommand.CommandType = CommandType.StoredProcedure;
            ObjCommand.Connection = ObjConnection;
            ObjCommand.Parameters.AddWithValue("@date", Convert.ToDateTime(txtdate1.Text));
            ds = new DataSet();
            adt = new SqlDataAdapter();
            adt.SelectCommand = ObjCommand;
            adt.Fill(ds);

            for (int r = 0; r < ds.Tables[0].Rows.Count; r++)
            {
                for (int c = 0; c < ds.Tables[0].Columns.Count; c++)
                {
                    if (c == 1)
                        break;
                    workSheet.Cells[r + 34, c + 5] = ds.Tables[0].Rows[r][0].ToString();
                }
            }

            workSheet.get_Range("E34", "F37").Merge(true);
            for (int r = 0; r < ds.Tables[0].Rows.Count; r++)
            {
                for (int c = 0; c < ds.Tables[0].Columns.Count; c++)
                {
                    workSheet.Cells[r + 34, c + 7] = ds.Tables[0].Rows[r][1].ToString();
                }
            }

            for (int r = 0; r < ds.Tables[0].Rows.Count; r++)
            {
                for (int c = 0; c < ds.Tables[0].Columns.Count; c++)
                {
                    workSheet.Cells[r + 34, c + 8] = ds.Tables[0].Rows[r][2].ToString();
                }
            }
            //workSheet.get_Range("I35:K32").Clear();
            workSheet.Cells[38, 5] = "Total Process Steam (TPH)";
            workSheet.Cells[38, 7] = "=SUM(G34:G37)";
            workSheet.Cells[38, 8] = "=SUM(H34:H37)";
            workSheet.get_Range("E38", "F38").Merge();
            workSheet.get_Range("E38", "H38").Font.Bold = true;

            ////-------------- Receipts ----------
           // workSheet.get_Range("E40", "H40").Merge(true);
            workSheet.Cells[39, 5] = "Receipts";
            workSheet.get_Range("E39", "F39").Merge();
            workSheet.get_Range("E39", "H39").Font.Bold = true;
            workSheet.Cells[39, 7] = "Today";
            workSheet.Cells[39, 8] = "Todate";


            ds = null; adt = null;
            ObjCommand = new SqlCommand();
            ObjCommand.CommandText = "spgetreciept";
            ObjCommand.CommandType = CommandType.StoredProcedure;
            ObjCommand.Connection = ObjConnection;
            ObjCommand.Parameters.AddWithValue("@date", Convert.ToDateTime(txtdate1.Text));
            ds = new DataSet();
            adt = new SqlDataAdapter();
            adt.SelectCommand = ObjCommand;
            adt.Fill(ds);

            for (int r = 0; r < ds.Tables[0].Rows.Count; r++)
            {
                for (int c = 0; c < ds.Tables[0].Columns.Count; c++)
                {
                    if (c == 1)
                        break;
                    workSheet.Cells[r + 40, c + 5] = ds.Tables[0].Rows[r][0].ToString();
                }
            }

            //workSheet.get_Range("F35", "F41").Clear();
            workSheet.get_Range("E40", "F46").Merge(true);
            for (int r = 0; r < ds.Tables[0].Rows.Count; r++)
            {
                for (int c = 0; c < ds.Tables[0].Columns.Count; c++)
                {
                    if (c == 2)
                        break;
                    workSheet.Cells[r + 40, c + 7] = ds.Tables[0].Rows[r][c+1].ToString();
                }
            }

            //------------- Reason(s) For Loss Time
            workSheet.Cells[47, 5] = "Reasons for Loss Times";
            workSheet.get_Range("E47", "L47").Merge(true);
            workSheet.get_Range("E47", "L47").Font.Bold = true;
            workSheet.Cells[48, 5] = "LT";
            workSheet.Cells[49, 5] = "HT";
            workSheet.Cells[50, 5] = "CFBC";
            workSheet.Cells[51, 5] = "Microfiner";
            workSheet.get_Range("F48", "L51").Merge(true);
            workSheet.Cells[51, 6] = "Feed Material Shortage.";
            workSheet.get_Range("F48", "L51").HorizontalAlignment = 1;



            //---------P & B Target---------
            workSheet.Cells[2, 9] = "P & B Target for Std.Caln. (MT)";
            workSheet.get_Range("I2", "K2").Merge(true);
            workSheet.get_Range("I2", "K2").HorizontalAlignment = 3;
            workSheet.get_Range("I2", "K2").VerticalAlignment = 2;
            workSheet.get_Range("I2", "L2").Font.Bold = true;

            workSheet.Cells[2, 12] = "27600";

            workSheet.Cells[3, 9] = "Reviseed target for Std. Caln. (MT)";
            workSheet.get_Range("I3", "K3").Merge(true);
            workSheet.get_Range("I3", "K3").HorizontalAlignment = 3;
            workSheet.get_Range("I3", "K3").VerticalAlignment = 2;
            workSheet.get_Range("I3", "L3").Font.Bold = true;

            workSheet.Cells[3, 12] = "27600";

            //--------------- Operating Parameters -------------

            workSheet.Cells[4, 9] = "Operating Parameters";
            workSheet.Cells[4, 11] = "Today";
            workSheet.get_Range("I4", "J4").Merge(true);
            workSheet.get_Range("I4", "L4").Font.Bold = true;
            workSheet.get_Range("I4", "L4").HorizontalAlignment = 3;
            workSheet.get_Range("K4", "L4").Merge(true);

            //--------------- Red Area 1--------------
            ds = null; adt = null;
            ObjCommand = new SqlCommand();
            ObjCommand.CommandText = "sp_getoperatingparameters1";
            ObjCommand.CommandType = CommandType.StoredProcedure;
            ObjCommand.Connection = ObjConnection;
            ObjCommand.Parameters.AddWithValue("@date", Convert.ToDateTime(txtdate1.Text));
            ds = new DataSet();
            adt = new SqlDataAdapter();
            adt.SelectCommand = ObjCommand;
            adt.Fill(ds);

            workSheet.Cells[5, 9] = "Red Area";
            workSheet.Cells[5, 10] = "Target";
            workSheet.Cells[5, 11] = "Conc.";
            workSheet.Cells[5, 12] = "Ratio";
            workSheet.get_Range("I5", "L5").Font.Bold = true;
            workSheet.get_Range("J5", "L5").HorizontalAlignment = 3;

            for (int r = 0; r < ds.Tables[0].Rows.Count; r++)
            {
                for (int c = 0; c < ds.Tables[0].Columns.Count; c++)
                {
                    workSheet.Cells[r + 6, c + 9] = ds.Tables[0].Rows[r][c].ToString();
                }
            }
            workSheet.get_Range("J5", "L27").HorizontalAlignment = 3;

            //-------------Red Area 2 --------------
            ds = null; adt = null;
            ObjCommand = new SqlCommand();
            ObjCommand.CommandText = "spgetoperatingparameters2";
            ObjCommand.CommandType = CommandType.StoredProcedure;
            ObjCommand.Connection = ObjConnection;
            ObjCommand.Parameters.AddWithValue("@date", Convert.ToDateTime(txtdate1.Text));
            ds = new DataSet();
            adt = new SqlDataAdapter();
            adt.SelectCommand = ObjCommand;
            adt.Fill(ds);

            for (int r = 0; r < ds.Tables[0].Rows.Count; r++)
            {
                for (int c = 0; c < ds.Tables[0].Columns.Count; c++)
                {
                    workSheet.Cells[r + 12, c + 9] = ds.Tables[0].Rows[r][c].ToString();
                }
            }

            workSheet.get_Range("K12", "L27").Merge(true);
            workSheet.get_Range("I13:J17").EntireRow.Font.Size = 16;


            //----------------------DMS Running Hours---------------
            ds = null; adt = null;
            ObjCommand = new SqlCommand();
            ObjCommand.CommandText = "spgetdmsrunninghours";
            ObjCommand.CommandType = CommandType.StoredProcedure;
            ObjCommand.Connection = ObjConnection;
            ObjCommand.Parameters.AddWithValue("@date", Convert.ToDateTime(txtdate1.Text));
            ds = new DataSet();
            adt = new SqlDataAdapter();
            adt.SelectCommand = ObjCommand;
            adt.Fill(ds);
            workSheet.Cells[28, 9] = "DMS Running Hours";
            workSheet.Cells[28, 11] = "Today";
            workSheet.Cells[28, 12] = "Todate";
            workSheet.get_Range("I28", "L28").Font.Bold = true;
            workSheet.get_Range("K28", "L28").HorizontalAlignment = 3;
            workSheet.get_Range("I28", "J28").Merge(true);
            workSheet.get_Range("J29", "J32").Clear();
            workSheet.get_Range("I29", "J32").Merge(true);
            for (int r = 0; r < ds.Tables[0].Rows.Count; r++)
            {
                for (int c = 0; c < ds.Tables[0].Columns.Count; c++)
                {
                    workSheet.Cells[r + 29, c + 9] = ds.Tables[0].Rows[r][0].ToString();
                }
            }
            workSheet.get_Range("K29", "K32").Clear();
            for (int r = 0; r < ds.Tables[0].Rows.Count; r++)
            {
                for (int c = 0; c < ds.Tables[0].Columns.Count; c++)
                {
                    if (c == 2)
                        break;
                    workSheet.Cells[r + 29, c + 11] = ds.Tables[0].Rows[r][c + 1].ToString();
                }
            }
            workSheet.get_Range("K29", "L32").HorizontalAlignment = 3;

            workSheet.get_Range("K29:K32").EntireRow.Font.Size = 16;

            //----------- White Area -----------------
            workSheet.Cells[33, 9] = "White Area";
            workSheet.Cells[33, 11] = "Today";
            workSheet.get_Range("I33", "J33").Merge(true);
            workSheet.get_Range("K33", "L33").Merge(true);
            workSheet.get_Range("K33", "L33").HorizontalAlignment = 3;
            workSheet.get_Range("I33", "L33").Font.Bold = true;
            ds = null; adt = null;
            ObjCommand = new SqlCommand();
            ObjCommand.CommandText = "sp_getwhitearea";
            ObjCommand.CommandType = CommandType.StoredProcedure;
            ObjCommand.Connection = ObjConnection;
            ObjCommand.Parameters.AddWithValue("@date", Convert.ToDateTime(txtdate1.Text));
            ds = new DataSet();
            adt = new SqlDataAdapter();
            adt.SelectCommand = ObjCommand;
            adt.Fill(ds);

            for (int r = 0; r < ds.Tables[0].Rows.Count; r++)
            {
                for (int c = 0; c < ds.Tables[0].Columns.Count; c++)
                {
                    if (c == 1)
                        break;
                    workSheet.Cells[r + 34, c + 9] = ds.Tables[0].Rows[r][0].ToString();
                }
            }
            workSheet.get_Range("I34", "J37").Merge(true);
            for (int r = 0; r < ds.Tables[0].Rows.Count; r++)
            {
                for (int c = 0; c < ds.Tables[0].Columns.Count; c++)
                {
                    if (c == 1)
                        break;
                    workSheet.Cells[r + 34, c + 11] = ds.Tables[0].Rows[r][c+1].ToString();
                }
            }
            workSheet.get_Range("K34", "L37").Merge(true);
            workSheet.get_Range("K34", "L37").HorizontalAlignment=3;


            //--------------- Dispatches -----------------

            ds = null; adt = null;
            ObjCommand = new SqlCommand();
            ObjCommand.CommandText = "spgetdispatch";
            ObjCommand.CommandType = CommandType.StoredProcedure;
            ObjCommand.Connection = ObjConnection;
            ObjCommand.Parameters.AddWithValue("@date", Convert.ToDateTime(txtdate1.Text));
            ds = new DataSet();
            adt = new SqlDataAdapter();
            adt.SelectCommand = ObjCommand;
            adt.Fill(ds);
            workSheet.Cells[38, 9] = "Dispatches (MT)";
            workSheet.Cells[38, 11] = "Today";
            workSheet.Cells[38, 12] = "Todate";
            workSheet.get_Range("I38", "J38").Merge(true);
            workSheet.get_Range("I38", "L38").Font.Bold = true;
            workSheet.get_Range("K38", "L46").HorizontalAlignment = 3;

            for (int r = 0; r < ds.Tables[0].Rows.Count; r++)
            {
                for (int c = 0; c < ds.Tables[0].Columns.Count; c++)
                {
                    if (c == 1)
                        break;
                    workSheet.Cells[r + 39, c + 9] = ds.Tables[0].Rows[r][0].ToString();
                }
            }
            workSheet.get_Range("J39", "J45").Clear();
            workSheet.get_Range("I39", "J46").Merge(true);

            for (int r = 0; r < ds.Tables[0].Rows.Count; r++)
            {
                for (int c = 0; c < ds.Tables[0].Columns.Count; c++)
                {
                    if (c == 2)
                        break;
                    workSheet.Cells[r + 39, c + 11] = ds.Tables[0].Rows[r][c+1].ToString();
                }
            }
            workSheet.Cells[46, 9] = "Total Dispatch";
            workSheet.Cells[46, 11] = "=SUM(K39:K45)";
            workSheet.Cells[46, 12] = "=SUM(L39:L45)";
            workSheet.get_Range("I46", "L46").Font.Bold = true;

            //---------- New Excel Sheet for graph data -----------
            var xlSheets = excelApp.Sheets as Excel.Sheets;
            var xlNewSheet = (Excel.Worksheet)xlSheets.Add(xlSheets[1], Type.Missing, Type.Missing, Type.Missing);
            xlNewSheet.Name = "graphdata";
            // ------------- productiongraph --------------
            ds = null; adt = null;
            ObjCommand = new SqlCommand();
            ObjCommand.CommandText = "spgetproductiongraph2";
            ObjCommand.CommandType = CommandType.StoredProcedure;
            ObjCommand.Connection = ObjConnection;
            ObjCommand.Parameters.AddWithValue("@date", Convert.ToDateTime(txtdate1.Text));
            ds = new DataSet();
            adt = new SqlDataAdapter();
            adt.SelectCommand = ObjCommand;
            adt.Fill(ds);

            //xlNewSheet.Cells[1, 1] = "Production Graph Data";
            //xlNewSheet.get_Range("A1", "C1").Merge(true);
            xlNewSheet.Cells[1, 1] = "Date";
            xlNewSheet.Cells[1, 2] = "Hydrate";
            xlNewSheet.Cells[1, 3] = "Calcination";

            for (int r = 0; r < ds.Tables[0].Rows.Count; r++)
            {
                for (int c = 0; c < ds.Tables[0].Columns.Count; c++)
                {
                    xlNewSheet.Cells[r + 2, c + 1] = ds.Tables[0].Rows[r][c].ToString();
                }
            }
            range3 = xlNewSheet.get_Range("A2").EntireColumn;
            range3.NumberFormat = "dd-MMM;@";

            rng4 = xlNewSheet.get_Range("A2", "C2").CurrentRegion;


            var charts = workSheet.ChartObjects() as
            Microsoft.Office.Interop.Excel.ChartObjects;
            var chartObject = charts.Add(0, 1095, 240, 300) as
                Microsoft.Office.Interop.Excel.ChartObject;
            var chart = chartObject.Chart;

            // Set chart range.
            var range = rng4; // worksheet.get_Range(topLeft, bottomRight);
            chart.SetSourceData(range);

            // Set chart properties.
            chart.ChartType = Microsoft.Office.Interop.Excel.XlChartType.xlLine;
            chart.ChartWizard(Source: range,SeriesLabels:"=B2:C2",
                Title: "Production, MT",
                CategoryTitle:null,
                ValueTitle: null);


            var xlAxis = (Excel.Axis)chart.Axes(Excel.XlAxisType.xlCategory, Excel.XlAxisGroup.xlPrimary);
            xlAxis.HasMajorGridlines = false;
            xlAxis.HasMinorGridlines = false;

            chart.ChartArea.Border.Color = System.Drawing.Color.Black;
            chart.ChartArea.Border.Weight = Excel.XlBorderWeight.xlThin;

            //----------- Productivities gpl graph ------------
            ds = null; adt = null;
            ObjCommand = new SqlCommand();
            ObjCommand.CommandText = "spgetefficienciesgraph2";
            ObjCommand.CommandType = CommandType.StoredProcedure;
            ObjCommand.Connection = ObjConnection;
            ObjCommand.Parameters.AddWithValue("@date", Convert.ToDateTime(txtdate1.Text));
            ds = new DataSet();
            adt = new SqlDataAdapter();
            adt.SelectCommand = ObjCommand;
            adt.Fill(ds);

            //xlNewSheet.Cells[1, 1] = "Production Graph Data";
            //xlNewSheet.get_Range("A1", "C1").Merge(true);
            xlNewSheet.Cells[1, 5] = "Date";
            xlNewSheet.Cells[1, 6] = "Sp. Liq. Prod";
            xlNewSheet.Cells[1, 7] = "Digester Prod";

            for (int r = 0; r < ds.Tables[0].Rows.Count; r++)
            {
                for (int c = 0; c < ds.Tables[0].Columns.Count; c++)
                {
                    xlNewSheet.Cells[r + 2, c + 5] = ds.Tables[0].Rows[r][c].ToString();
                }
            }
            range3 = xlNewSheet.get_Range("E2").EntireColumn;
            range3.NumberFormat = "dd-MMM;@";

            rng5 = xlNewSheet.get_Range("E2", "G2").CurrentRegion;


            var charts2 = workSheet.ChartObjects() as
            Microsoft.Office.Interop.Excel.ChartObjects;
            var chartObject2 = charts2.Add(242, 1095, 335, 300) as
                Microsoft.Office.Interop.Excel.ChartObject;
            var chart2 = chartObject2.Chart;

            // Set chart range.
            var range2 = rng5; // worksheet.get_Range(topLeft, bottomRight);
            chart2.SetSourceData(range2);

            // Set chart properties.
            chart2.ChartType = Microsoft.Office.Interop.Excel.XlChartType.xlLine;
            chart2.ChartWizard(Source: range2, SeriesLabels: "=F2:G2",
                Title: "Productivities, gpl",
                CategoryTitle: null,
                ValueTitle: null);


            var xlAxis2 = (Excel.Axis)chart2.Axes(Excel.XlAxisType.xlCategory, Excel.XlAxisGroup.xlPrimary);
            xlAxis2.HasMajorGridlines = false;
            xlAxis2.HasMinorGridlines = false;

            chart2.ChartArea.Border.Color = System.Drawing.Color.Black;
            chart2.ChartArea.Border.Weight = Excel.XlBorderWeight.xlThin;


            //-------------- TAA & Silica------------------

            ds = null; adt = null;
            ObjCommand = new SqlCommand();
            ObjCommand.CommandText = "spgetbauxitequalitygraph2";
            ObjCommand.CommandType = CommandType.StoredProcedure;
            ObjCommand.Connection = ObjConnection;
            ObjCommand.Parameters.AddWithValue("@date", Convert.ToDateTime(txtdate1.Text));
            ds = new DataSet();
            adt = new SqlDataAdapter();
            adt.SelectCommand = ObjCommand;
            adt.Fill(ds);

            //xlNewSheet.Cells[1, 1] = "Production Graph Data";
            //xlNewSheet.get_Range("A1", "C1").Merge(true);
            xlNewSheet.Cells[1, 9] = "Date";
            xlNewSheet.Cells[1, 10] = "TAA";
            xlNewSheet.Cells[1, 11] = "Silica";

            for (int r = 0; r < ds.Tables[0].Rows.Count; r++)
            {
                for (int c = 0; c < ds.Tables[0].Columns.Count; c++)
                {
                    xlNewSheet.Cells[r + 2, c + 9] = ds.Tables[0].Rows[r][c].ToString();
                }
            }
            range3 = null;
            range3 = xlNewSheet.get_Range("I2").EntireColumn;
            range3.NumberFormat = "dd-MMM;@";


            rng6 = xlNewSheet.get_Range("I2", "K2").CurrentRegion;


            var charts3 = workSheet.ChartObjects() as
            Microsoft.Office.Interop.Excel.ChartObjects;
            var chartObject3 = charts3.Add(0, 1400, 240, 300) as
                Microsoft.Office.Interop.Excel.ChartObject;
            var chart3 = chartObject3.Chart;

            // Set chart range.
            //var rnge3 = rng6; // worksheet.get_Range(topLeft, bottomRight);
            chart3.SetSourceData(rng6);

            // Set chart properties.
            chart3.ChartType = Microsoft.Office.Interop.Excel.XlChartType.xlLine;
            chart3.ChartWizard(Source: rng6, SeriesLabels: "=J2:K2",
                Title: "TAA & Silica, %",
                CategoryTitle: null,
                ValueTitle: null);


            var xlAxis3 = (Excel.Axis)chart.Axes(Excel.XlAxisType.xlCategory, Excel.XlAxisGroup.xlPrimary);
            xlAxis3.HasMajorGridlines = false;
            xlAxis3.HasMinorGridlines = false;

            chart3.ChartArea.Border.Color = System.Drawing.Color.Black;
            chart3.ChartArea.Border.Weight = Excel.XlBorderWeight.xlThin;

            //----------- Process Steam Consumption Graph -----------
            ds = null; adt = null;
            ObjCommand = new SqlCommand();
            ObjCommand.CommandText = "spgetprocesssteamconsumptiongraph2";
            ObjCommand.CommandType = CommandType.StoredProcedure;
            ObjCommand.Connection = ObjConnection;
            ObjCommand.Parameters.AddWithValue("@date", Convert.ToDateTime(txtdate1.Text));
            ds = new DataSet();
            adt = new SqlDataAdapter();
            adt.SelectCommand = ObjCommand;
            adt.Fill(ds);

            //xlNewSheet.Cells[1, 1] = "Production Graph Data";
            //xlNewSheet.get_Range("A1", "C1").Merge(true);
            xlNewSheet.Cells[1, 13] = "Date";
            xlNewSheet.Cells[1, 14] = "Process Steam";


            for (int r = 0; r < ds.Tables[0].Rows.Count; r++)
            {
                for (int c = 0; c < ds.Tables[0].Columns.Count; c++)
                {
                    xlNewSheet.Cells[r + 2, c + 13] = ds.Tables[0].Rows[r][c].ToString();
                }
            }
            Excel.Range range4 = xlNewSheet.get_Range("M2").EntireColumn;
            range4.NumberFormat = "dd-MMM;@";

            Excel.Range rng8 = xlNewSheet.get_Range("M2", "N2").CurrentRegion;


            var charts4 = workSheet.ChartObjects() as
            Microsoft.Office.Interop.Excel.ChartObjects;
            var chartObject4 = charts4.Add(242, 1400, 335, 300) as
                Microsoft.Office.Interop.Excel.ChartObject;
            var chart4 = chartObject4.Chart;

            // Set chart range.
            //var range4 = rng5; // worksheet.get_Range(topLeft, bottomRight);
            chart4.SetSourceData(rng8);

            // Set chart properties.
            chart4.ChartType = Microsoft.Office.Interop.Excel.XlChartType.xlLine;
            chart4.ChartWizard(Source: rng8, SeriesLabels: "=N2",
                Title: "Process Steam Consumption, t/t",
                CategoryTitle: null,
                ValueTitle: null);


            var xlAxis4 = (Excel.Axis)chart4.Axes(Excel.XlAxisType.xlCategory, Excel.XlAxisGroup.xlPrimary);
            xlAxis4.HasMajorGridlines = false;
            xlAxis4.HasMinorGridlines = false;

            chart4.ChartArea.Border.Color = System.Drawing.Color.Black;
            chart4.ChartArea.Border.Weight = Excel.XlBorderWeight.xlThin;



            //--------- Saving Excel Sheet -----------;
            //range3 = workSheet.get_Range("A1", "L51");

            workSheet.get_Range("A1:L51").Borders.get_Item(Excel.XlBordersIndex.xlInsideHorizontal).LineStyle = Excel.XlLineStyle.xlContinuous;

            workSheet.get_Range("A1:L51").Borders.get_Item(Excel.XlBordersIndex.xlInsideVertical).LineStyle =
                                                        Excel.XlLineStyle.xlContinuous;

            workSheet.get_Range("A1:L51").Borders.get_Item(Excel.XlBordersIndex.xlEdgeTop).LineStyle =
                                                        Excel.XlLineStyle.xlContinuous;
            workSheet.get_Range("A1:L51").Borders.get_Item(Excel.XlBordersIndex.xlEdgeLeft).LineStyle =
                                                        Excel.XlLineStyle.xlContinuous;
            workSheet.get_Range("A1:L51").Borders.get_Item(Excel.XlBordersIndex.xlEdgeRight).LineStyle =
                                                        Excel.XlLineStyle.xlContinuous;
            workSheet.get_Range("A1:L51").Borders.get_Item(Excel.XlBordersIndex.xlEdgeBottom).LineStyle =
                                                        Excel.XlLineStyle.xlContinuous;
            rng7 = workSheet.get_Range("A2:L51");
            rng7.RowHeight = 25;

            rng7.VerticalAlignment = 2;

            //range3.BorderAround(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlMedium);
            workSheet.PageSetup.Zoom = false;
            workSheet.PageSetup.FitToPagesWide = 1;
            workSheet.PageSetup.FitToPagesTall = 1;
            workSheet.PageSetup.Orientation = Microsoft.Office.Interop.Excel.XlPageOrientation.xlPortrait;
            workSheet.PageSetup.PaperSize = Microsoft.Office.Interop.Excel.XlPaperSize.xlPaperA4;



            workSheet.SaveAs(FilePath);

             excelApp.Quit();
            lblMsg.Text = "Report Generated Successfully!!!";
        }
File si being generated on server but can not be downloaded on client machine. please help me to solve it.

print diagonal routes array

$
0
0

I make this code to print array if the number of array is

{1,2,3

,4,5,6

,7,8,9}

the out put of this code is  : 1,2,4,3,5,7,6,8,9

I want to change  in this my code to be the out put begging from

7,4,8,1,5,9,2,6,3

how can do this please

int [,] p = new int [3,3];
            int sum = 1;
            for (int i = 1; i <= 3; i++)
               
            {
                for (int j = 1; j <= 3; j++)
                {
                    p[i, j] = sum;
                    richTextBox1.Text += p[i, j].ToString();
                    sum++;

                }
            }
          
             int C;

             int R=1;

             for (int i = 1; i <= 3; i++)
             {

                 C = i;

                 for (int r = 1; r <= i; r++)
                 {

                     Output = Output + p[r, C];

                     C--;

                 }
             }
                 richTextBox2.Text += Output.ToString();
                
    //////////////////

    for (int i = 2; i >= 3; i++)
    {
              R = i;
        for (C = 3; C >= i; C--)
        {
            Output = Output + p[R, C];

            R++;

           }
        }
             richTextBox2.Text += Output.ToString();


Problem with and adapter command

$
0
0

I'm new to using adapters but somewhat experienced using SQL generally.  This is the third adapter that I've written for this project, and I'm certainly seeing how it might be easier to use adapters, but I'm having a time figuring out how to test them.

I'm having trouble with the Update Command.  Here's the code

    
// the update command
            cmd = new OleDbCommand(@"UPDATE tblReaders SET TA = ?, Building = ?, Room = ?, Location = ?, Active = ?, [Found] = True, WHERE ReaderID = ?", conn);
            cmd.Parameters.Add("TA", OleDbType.VarChar, 255, "TA");
            cmd.Parameters.Add("Building", OleDbType.VarChar, 255, "Building");
            cmd.Parameters.Add("Room", OleDbType.VarChar, 255, "Room");
            cmd.Parameters.Add("Location", OleDbType.VarChar, 255, "Location");
            cmd.Parameters.Add("Active", OleDbType.Boolean, 1, "Active");
            cmd.Parameters.Add("ReaderID", OleDbType.Integer, 6, "ReaderID");
            theAdapt.UpdateCommand = cmd;

I'm running this in a Unit Test and the error message that I get is Test Method threw exception OleDb.OleDbException: Syntax error in UPDATE statement.

This statement looks extremely similar to another Update statement I have in another adapter that is working.  I can't see where the problem is so it's probably so obvious I'm overlooking it.  I can't think of anything else but to beg for help.


Jack of all trades master of none.


Programic adding of BindingSources?

$
0
0
I am developing an application which uses data tables in a Parent-Child relationship. It is a time tracking app. The Parent holds identification information. The Child holds activity codes, dates and lengths of time.

In the form load procedure, the program creates TableAdapter instances, retrieves user data and assigns the data directly to the objects on the form.  I mention this, because I have seen references to BindingLists, and I wonder if (1) there is a better way to do the load, and (2) if BindingLists bear on my problem.

The child data is represented with a dataGridView.

I am saving the data with code similar to this:
DataRow row = dS.Tables["TableName"].NewRow();

row["field1"]       = field1;
row["field2"]       = field2;
row["field3"]       = field3;

dS.TableName.Rows.Add(row);

this.Validate();
this.tableNameBindingSource.EndEdit();
this.tableAdapterManager.TableNameTableAdapter.Update(dS);
The Child rows are processed using a loop, but the same technique is used.

My problem ...

I need to create a history record. There are two more tables to hold the history, Parent and Child. Both Parent and both Child tables are identical, with the exception of an integer field used to hold a sequence number in the History Parent.

The Original Parent-Child tables are bound to the objects on the form. The History Parent-Child are not. So, I am getting messages about how these tables are not bound.

So, I think I need to either
(1) find a way to add the History BindingSources to the form; or
(2) update the DataSet without the BindingSources.

Thank you for any nudges in the right direction.

from where i can find good learning for C# windows form application

$
0
0

dear friends I new in .net framework I am just developer of php now I want to learn .net framework from where I can find good tutorials of C# windows form application

thanks !

What tools are available to create a simple database usealble with 64 bit and 32 bit application?

$
0
0

I started my day yesterday looking towards using a MS Access database from my C# windows forms application.  What I found is a horror story.

Apparently you cannot use ODBC or OlleDb to access a 32 bit ms access database from a pure 64 bit application.  You need to use 64 bit drivers. In fact you cannot even install the drivers unless you migrate 32 bit office to 64 bit office.

This means that clients of mine that run a 64 bit version of my application would need to upgrade their copy of Office but many of my clients also need to connect to a different 32 bit installation of access from another product.

So to put a long story short, where can I find a database that I can use WITHOUT ODBC ?

The same goes for MySQL.  What were these developers thinking??? (MS of coarse).

I can't go ahead and ask my people to install sqlserver or Oracle.

Any suggestions?


Sending messages between processes

$
0
0

I have two instances of the same application and I want to send messages from one to the other.

I've googled extensively and have seen thousands of solutions but couldn't get any of them to work. I think I need to p/invoke the windows PostMessage API.

First I get the main window handle, then I need to do some IntPtr manipulations to convert my string to IntPtr. This is where there seems to be endless different ways to do it. Here's one I've tried:

IntPtr buffer = IntPtrAlloc(Message);
            COPYDATASTRUCT copyData = new COPYDATASTRUCT();
            copyData.dwData = IntPtr.Zero;
            copyData.lpData = buffer;
            copyData.cbData = Marshal.SizeOf(Message);
            IntPtr copyDataBuff = IntPtrAlloc(copyData);
            Process currentProcess = Process.GetCurrentProcess();
            Process[] processCollection = Process.GetProcessesByName(currentProcess.ProcessName);
            foreach (Process p in processCollection)
            {
                if (p.Id != currentProcess.Id)
                {
                    SendMessage(p.MainWindowHandle, WM_COPYDATA, IntPtr.Zero, copyDataBuff);
                }
            }
            IntPtrFree(copyDataBuff); copyDataBuff = IntPtr.Zero;
            IntPtrFree(buffer); buffer = IntPtr.Zero;

and:

        [StructLayout(LayoutKind.Sequential)]
        public struct COPYDATASTRUCT
        {
            public IntPtr dwData;
            public int cbData;
            public IntPtr lpData;
        }

Then in my main form:

        protected override void WndProc(ref Message m)
        {
            const int WM_COPYDATA = 0x4A;
            switch (m.Msg)
            {
                case WM_COPYDATA:
                    TestClass2.COPYDATASTRUCT CD =
                        (TestClass2.COPYDATASTRUCT)m.GetLParam(typeof(TestClass2.COPYDATASTRUCT));
                    byte[] B = new byte[CD.cbData];
                    System.Runtime.InteropServices.Marshal.Copy(CD.lpData, B, 0, CD.cbData);
                    string strData = Encoding.Default.GetString(B);
                    MessageBox.Show("Received data: " + strData);
                    break;
                default:
                    base.WndProc(ref m);
                    break;
            }
        }

Please help.

When to use Parallelelism while coding in C#

$
0
0

Hi,

I want to know when we can use Parallelism in .NET and when to avoid them. I am sure we can not blindly use it in all the cases. How can I really use no. of processors count in parallelism? For e.g. can I set degree of parallelism by calculating no. of cores in server and then use it in my code for Parallelism?

Thanks and Regards,

Kshitiz

Insert to table not workig

$
0
0

hi guis :)

i am using c# windows form with sql server but i have problem

selet from table is working but insert is not working

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlServerCe; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { SqlCeConnection cnn = new SqlCeConnection("Data Source=dd.sdf"); SqlCeCommand cm = new SqlCeCommand("INSERT INTO e VALUES ('s' ,'b')", cnn); cnn.Open(); cm.ExecuteNonQuery(); cnn.Close(); } } }

can guys any one help me?

thank you :)



Extension Method doesn't get implemted

$
0
0

Hi there,

What am i doing wrong here? Thanks in advance. Regards Bram

While building SQL Tables I get Error: Concurrency violation: UpdateCommand when selecting TN and build SQL Table

$
0
0

While building SQL Tables I get Error: Concurrency violation: UpdateCommand when selecting TN and build SQL Table

{"Concurrency violation: the UpdateCommand affected 0 of the expected 1 records."}

While testing my first application I encounter this error.  At the point of failure I have treeview and datagridview and a button to build sql tables. The datagridview is filtered based on treenode (TN) selection. The button builds a sql table for the selected treenode/datagridview.

Edits can be made in datagridview and underlying datatable immediately updated by utilizing PositionChanged event. It is in this event the error comes up when da.Update(tblvAttributes); is called. (Each time treenode changes or row in datagridview changes)

I replicate the error by selecting TN in succession and clicking button. If SQL table exists, a messagebox pops up stating existence in the Catch of Try/Catch and returns.

I have no idea what causes this or what to do about it.  I'm not updating DGV, simply selecting TN & clicking Button.

What causes this and what do I need to do to resolve?

Viewing all 31927 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>